0

我正在尝试在支持通过 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);
}
4

1 回答 1

0

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

var ws = new WebSocket('wss://localhost:xxxx', {
  protocolVersion: 8,
  origin: 'https://localhost:xxxx',
  rejectUnauthorized: false
});
于 2017-06-27T16:28:38.680 回答