I have a websocket server (API of jetty 9.0.1.v20130408), which worked fine without ssl. Now I configured my server like this:
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath("/src/main/resources/keystore.jks");
sslContextFactory.setKeyStorePassword(password);
sslContextFactory.setTrustStorePath("/src/main/resources/truststore.jks");
sslContextFactory.setTrustStorePassword(password);
ConnectionFactory sslConnFactory = new SslConnectionFactory(sslContextFactory, "http/1.1);
connector.addConnectionFactory(sslConnFactory);
server.addConnector(connector);
No I tried to configurate the client. I thought, that on the client side I need to set path to truststore.jks and the password. But then I get on client.start() the Exception: SSL doesn't have a valid keystore. When I set the keystore, then I get on client.connect java.nio.channels.WritePendingException. Here is the code for my client:
WebSocketClient client = new WebSocketClient(sslContextFactory);
URI wssUri = new URI("wss://localhost:"+port);
sslContextFactory.start();
client.start();
client.connect(myClientSocket, wssUri);
Can anybody help me? I also tried on server side to set setWantClientAuth(false) and setTrustall(true), but it also did not work this way;
ADDED:
I generate my ssl files with keytool.
$ keytool -genkeypair -alias certificatekey -keyalg RSA -validity 365 -keystore keystore.jks
$ keytool -export -alias certificatekey -keystore keystore.jks -rfc -file selfsignedcert.cer
$ keytool -import -alias certificatekey -file selfsignedcert.cer -keystore truststore.jks