Java8安全WebSocket握手问题(Tyrus和Jetty)

时间:2017-06-27 16:11:33

标签: java ssl jetty java-websocket tyrus

我正在尝试在支持通过SSL进行安全传输的应用程序中实现WebSocket客户端。该应用程序已经通过实现自定义密钥和信任管理器支持HTTP上的标准SSL连接(这些自定义实现适用于在需要时提示用户提供证书)。

我无法获得与远程WebSocket端点的安全连接。握手期间发生故障。我尝试了两种不同的WebSocket API实现(Tyrus和Jetty),两者都以同样的方式失败,这当然导致我指向我们的SSL实现。

正如我所提到的,握手期间发生了失败。似乎连接无法确定是否存在由服务器返回的受支持权限签名的客户端证书。我很难理解我是否没有正确地向WebSocket API提供客户端证书,或者我们的自定义密钥/信任管理器是否被使用。

这是SSL调试日志的转储:

*** CertificateRequest
Cert Types: RSA, DSS
Cert Authorities:
(list of about 15 cert authorities supported by the server)
*** ServerHelloDone
Warning: no suitable certificate found - continuing without client authentication
*** CertificateChain
<empty>
***

我在我们的TrustManager实现中设置了断点,以确定它们是否被调用,并且它们似乎此时未被调用。

我一直在尝试调试这几天,并且我没有尝试过。

任何建议都将不胜感激!

以下是码头代码的片段:

SSLContext context = SSLContext.getInstance("TLS");
// getKeyManagers / getTrustManagers retrieves an 
// array containing the custom key and trust manager
// instances:
KeyManager[] km = getKeyManagers();
TrustManager[] tm = getTrustManagers();
context.init(km, tm, null);

SslContextFactory contextFactory = new SslContextFactory();
contextFactory.setContext(context);

WebSocketClient client = new WebSocketClient(contextFactory);
SimpleEchoClient echoClient = new SimpleEchoClient();

try { 
    client.start();
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    Future<Session> connection = client.connect(echoClient, uri, request);

    Session session = connection.get();

    // if everything works, do stuff here

    session.close();
    client.destroy();
} catch (Exception e) {
    LOG.error(e);
}

1 个答案:

答案 0 :(得分:0)

您可以尝试使用rejectUnAuthorized:false,以便您的浏览器无法授权的证书将跳过授权。

var ws = new WebSocket('wss://localhost:xxxx', {
  protocolVersion: 8,
  origin: 'https://localhost:xxxx',
  rejectUnauthorized: false
});
相关问题