忽略证书验证 - Tomcat8 WebSocket (JSR-356)

4
SslContextFactory sec = new SslContextFactory();
sec.setValidateCerts(false);
WebSocketClient client = new WebSocketClient(sec);

上述代码是针对Jetty WebSockets实现的,用于告知Java客户端禁用证书验证。在Tomcat8 WebSockets(JSR-356)的Java API中是否有同样的方法可以实现相同的功能?
PS:我已经尝试了this方法,但它没有在Tomcat WebSockets的安全WebSocket连接中起作用。
1个回答

2

您是否生成了自签名证书并尝试使用它?然后将您的自签名证书导入到新的密钥库中,并将该密钥库用作客户端信任库。

对于 Tyrus WebSocket 客户端,我使用以下方式:

String keyStorePath = StompClientTest.class.getResource("/myapp.keystore").getPath();
System.getProperties().put("javax.net.debug", "all"); // debug your certificate checking
System.getProperties().put(SslContextConfigurator.KEY_STORE_FILE, keyStorePath);
System.getProperties().put(SslContextConfigurator.TRUST_STORE_FILE, keyStorePath);
System.getProperties().put(SslContextConfigurator.KEY_STORE_PASSWORD, "secret");
System.getProperties().put(SslContextConfigurator.TRUST_STORE_PASSWORD, "secret");
final SslContextConfigurator defaultConfig = new SslContextConfigurator();
defaultConfig.retrieve(System.getProperties());

SslEngineConfigurator sslEngineConfigurator = new SslEngineConfigurator(defaultConfig);
sslEngineConfigurator.setHostVerificationEnabled(false);
StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
webSocketClient.getUserProperties().put(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);

如果要在Tomcat中读取答案,请参考以下问题:https://dev59.com/L47ea4cB1Zd3GeqPAmUm#32205864


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接