gpt4 book ai didi

java - 为 Spring Web 客户端禁用 SSL 检查

转载 作者:行者123 更新时间:2023-12-04 15:24:12 24 4
gpt4 key购买 nike

下面的代码是我用来尝试构建可以与具有无效证书的 https 服务器通信的 Web 客户端实例的代码。

SslContext sslContext = SslContextBuilder
.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
HttpClient httpClient = HttpClient
.create()
.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
ClientHttpConnector connector = new ReactorClientHttpConnector(httpClient);
WebClient client = WebClient
.builder()
.clientConnector(connector)
// ...
.build();

这样做的目的是让 Web 客户端不检查 ssl,但是当运行 JVM 时崩溃并出现错误“javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure”。有人能给我指出正确的方向吗,因为以前的 SO 帖子似乎无法解决问题并导致同样的握手错误。

最佳答案

以防万一有人在他们的 spring webclient 上遇到这个错误,最终对我有用的解决方案是将协议(protocol)和密码添加到 SSLcontext 中。

Iterable<String> allowedCiphers = List.of("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384");

SslContext sslContext = SslContextBuilder
.forClient()
.protocols("SSLv3","TLSv1","TLSv1.1","TLSv1.2")
.ciphers(allowedCiphers)
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();

关于java - 为 Spring Web 客户端禁用 SSL 检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62649865/

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