Results 1 to 20 of 46
Thread: [SOLVED] Start SSL socket
- 05-05-2009, 05:41 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
[SOLVED] Start SSL socket
Hello, I am a begginer in programimg and I programmed the chat with SSL sockets. I created the certificate via tutorial on this website: Installing and Configuring SSL Support . I use IDE NetBeans and I would like to know the place/folder where the certificate has to be saved. Could you tell me in detail the procedure in Netbeans.
But momentarily it doesn't work because of the error: javax.net.ssl.SSLException: No available certificate or key corresponds to the SSL cipher suites which are enabled.
This is the code of server:
Java Code:import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSocket; /** * * @author Lolek */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { try { int port = 5000; SSLServerSocketFactory serverSocketFactory = null; SSLServerSocket serverSocket = null; SSLSocket socket = null; serverSocketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); serverSocket = (SSLServerSocket) serverSocketFactory.createServerSocket(port); while (true) { socket = (SSLSocket) serverSocket.accept(); ChatHandler handler = new ChatHandler(socket); handler.start(); } } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } } class ChatHandler extends Thread { static ArrayList handlers = new ArrayList(10); private SSLSocket socket; private BufferedReader read; private BufferedWriter write; public ChatHandler(SSLSocket socket) { try { this.socket = socket; this.read = new BufferedReader(new InputStreamReader(socket.getInputStream())); this.write = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); } catch (IOException ex) { Logger.getLogger(ChatHandler.class.getName()).log(Level.SEVERE, null, ex); } } public void run(){ String line=null; synchronized(handlers) { handlers.add(this); } try { while(!(line = read.readLine()).equalsIgnoreCase("/q")) { for(int i = 0; i < handlers.size(); i++) { synchronized(handlers) { ChatHandler handler = (ChatHandler)handlers.get(i); handler.write.write(line); handler.write.newLine(); handler.write.flush(); } } } } catch(IOException ioe) { ioe.printStackTrace(); } finally { try { read.close(); write.close(); socket.close(); } catch(IOException ioe) { } finally { synchronized(handlers) { handlers.remove(this); } } } } }
- 05-05-2009, 07:04 PM #2
You need to set up an SSLContext with your keystore, and use that to create get an SSLServerSocketFactory. The keystore goes wherever you can access it from your code.
Last edited by OrangeDog; 05-18-2009 at 02:40 PM.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-05-2009, 07:11 PM #3
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
And could you show some example how can i set up an SSLContext? I am begginer I don´t know what are you talking about. I need this just to the school. Thank you
- 05-05-2009, 07:16 PM #4
Java Code:SSLContext ctx = null; // load keystore KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); char[] password = getPassword(); InputStream in = ClassLoader.getSystemResourceAsStream(keystore); ks.load(in, password); in.close(); // set-up SSLContext KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509", "SunJSSE"); kmf.init(ks, password); TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX", "SunJSSE"); tmf.init(ks); ctx = SSLContext.getInstance("TLS"); ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-05-2009, 08:14 PM #5
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0

I did how you wrote but something is wrong where is the problem?
- 05-05-2009, 09:37 PM #6
Member
- Join Date
- Dec 2008
- Posts
- 64
- Rep Power
- 0
The getPassword() refered to is an example, you must replace getPassword() with a password OR write a getPassword() method as follows:
Java Code:private static char[] getPassword() { // this is a bad example but you get the point return("My Password".toCharArray()); }
- 05-06-2009, 12:13 AM #7
Likewise, replace keystore with a path to your keystore
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-07-2009, 04:31 PM #8
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
OK where is the problem now?

Thank you very much.
- 05-07-2009, 05:04 PM #9
What's the argument type for getSystemResourceAsStream?
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-07-2009, 05:24 PM #10
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
:) I am sory I am stupid. String "" . Thank you.
But nullpointer:
Last edited by Koren3; 05-07-2009 at 05:29 PM.
- 05-07-2009, 05:48 PM #11
It's a lot easier to not use IDE screenshots.
The class loader couldn't find that as it's not relative to the classpath. Use some other method to get the InputStream.Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-08-2009, 02:55 PM #12
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
What other metod can i use?
- 05-08-2009, 06:26 PM #13
As you have done, but with a correct path
Using a URL
Using a File
Using a Socket
and a few othersDon't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-09-2009, 08:19 AM #14
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
I used this:
But it write this error: java.io.StreamCorruptedException: invalid stream header: FEEDFEEDJava Code:ObjectInputStream in = new ObjectInputStream(new FileInputStream("C:\\Koren\\Java\\SSLCentralServer\\src\\sslcentralserver\\keystore"));
- 05-09-2009, 05:45 PM #15
Don't use an Object stream.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-12-2009, 07:51 AM #16
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
OK but what can I use? If I use
This error write: javax.net.ssl.SSLException: No available certificate or key corresponds to the SSL cipher suites which are enabled.Java Code:InputStream in = (new FileInputStream("C:\\Koren\\Java\\SSLCentralServer\\src\\sslcentralserver\\keystore"));
- 05-12-2009, 03:16 PM #17
Then you need to change the values in the getInstance() methods to match the format of your keystore, or change the keystore to match the available SSL cipher suites.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-13-2009, 08:20 AM #18
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
Could you show some example? Thank you.
- 05-13-2009, 09:39 AM #19
No, because I don't know the format of your keystore.
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-13-2009, 09:53 AM #20
Member
- Join Date
- Apr 2009
- Posts
- 50
- Rep Power
- 0
Similar Threads
-
append response to the request from Socket and write to another socket
By vaibhav_singh_vs@yahoo.co in forum NetworkingReplies: 3Last Post: 04-17-2009, 07:02 PM -
help about Socket
By fahien_akim in forum New To JavaReplies: 0Last Post: 04-16-2009, 10:41 AM -
How do you start a Java program from the "Start" menu under Windows?
By ScottVal in forum New To JavaReplies: 5Last Post: 03-20-2009, 10:04 PM -
Socket
By rob in forum New To JavaReplies: 1Last Post: 03-19-2009, 02:24 PM -
Socket
By vortex in forum New To JavaReplies: 2Last Post: 05-25-2008, 06:41 AM


LinkBack URL
About LinkBacks

Bookmarks