I have been using SSL sockets for a messaging system recently.
I finally started using a CA issued certificate. I imported it into my keystore, set the keystore property, and started up my client, but I keep getting handshake exceptions when I try to send data.
I enabled debug mode and I found that it is due to no cipher suites supported
. Any thoughts on this?
If it helps, It also says that it is ignoring about 10 cipher suites from TLSV1 and TLSV1.1.
I also installed Unlimited Strength Cryptographic Policy.
Client code
public static void Message(String args){
System.setProperty("https.protocols", "TLSv1");
System.setProperty("javax.net.debug", "all");
try
{
String host = "localhost";
int port = 3498;
InetAddress address = InetAddress.getByName(host);
socket = (SSLSocket)SSLSocketFactory.getDefault().createSocket(address, port);
//Send the message to the server
OutputStream os = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
String number = "Hello from the other side!";
String sendMessage = number + "\n";
bw.write(args);
bw.flush();
System.out.println("Message sent to the server : "+sendMessage);
//Get the return message from the server
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
//Closing the socket
try
{
socket.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Server code
private void initListen() {
System.setProperty("javax.net.ssl.keyStore", "/Users/181095/server.jks");
try {
SSLServerSocketFactory sf = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket serverSocket = (SSLServerSocket)sf.createServerSocket(Ting.port);
System.out.println("Server Started and listening to the port "
+ Ting.port);
// Server is running always. This is done using this while(true)
// loop
while (true) {
// Reading the message from the client
socket = (SSLSocket)serverSocket.accept();
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String input = br.readLine();
System.out.println("Message received from client is " + input);
/*if(PacketReader.isPacket(input)){
if(PacketReader.shouldSendDataBack(input)){
}
}*/
/*
*
* if client has data waiting or client has new data
* request new data.
* else, wait 5 seconds and repeat
*
*
*/
// Sending the response back to the client.
/*OutputStream os = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
bw.write("");*/
//TODO Implement method to send this data to client storage data.
//bw.flush();
}
//Check for exceptions and try to close the socket.
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
socket.close();
} catch (Exception e) {
}
}
}
Edit: I have just added the password, but my entry/certificate does not have a key, could this be contributing to the error? How can I fix it?
Surprisingly, this can mean that the server couldn't find a private key/certificate pair. In this case it is because you haven't specified the keystore password via
javax.net.ssl.keyStorePassword
.