我有一个websocket服务器(jetty 9.0.1.v20130408的API),在没有ssl的情况下工作正常。现在我像这样配置我的服务器:
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);
不,我试图配置客户端。我想,在客户端我需要设置truststore.jks和密码的路径。但后来我得到了client.start()异常:SSL没有有效的密钥库。当我设置密钥库时,我得到了client.connect java.nio.channels.WritePendingException。这是我的客户的代码:
WebSocketClient client = new WebSocketClient(sslContextFactory);
URI wssUri = new URI("wss://localhost:"+port);
sslContextFactory.start();
client.start();
client.connect(myClientSocket, wssUri);
任何人都可以帮助我吗?我也尝试在服务器端设置setWantClientAuth(false)和setTrustall(true),但它也没有这样工作;
增加:
我使用keytool生成我的ssl文件。
$ 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