gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 03:19:28 25 4
gpt4 key购买 nike

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 连接

最佳答案

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

对于 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://stackoverflow.com/a/32205864/386213

关于java - 忽略证书验证 - Tomcat8 WebSocket (JSR-356),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34849045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com