仅为java_WebSocket设置TLSv1.3

oxosxuxt  于 2023-10-20  发布在  Java
关注(0)|答案(1)|浏览(128)

如何为java_WebSocket设置TLSv1.3?如果所有最古老的协议都被禁止。

javax.net.ssl.SSLHandshakeException: Received fatal alert: protocol_version
    at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
    at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:358)
    at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:293)
    at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:204)
    at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:172)
    at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1505)
    at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1420)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:455)
    at java.base/sun.security.ssl.SSLSocketImpl.ensureNegotiated(SSLSocketImpl.java:920)
    at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1011)
    at java.base/java.io.InputStream.read(InputStream.java:218)
    at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:515)
    at java.base/java.lang.Thread.run(Thread.java:833)
klh5stk1

klh5stk11#

在constructor中需要这样的代码:

SSLContext sslContext = SSLContext.getInstance("TLSv1.3");
sslContext.init(null, null, null);
this.setSocketFactory(sslContext.getSocketFactory());

相关问题