禁用Spring Web客户端的SSL检查

3
以下是我正在使用的代码,试图构建一个能够与具有无效证书的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: Received fatal alert:handshake_failure”。请问有没有人能够指导正确的方向?之前的SO帖子似乎不能解决问题,仍然导致握手错误。

你确定证书是问题吗?错误信息也可能意味着其他问题。 - Henry
1个回答

3

如果有人在使用Spring WebClient时遇到此错误,请注意,在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();

你结束了我长达一小时的痛苦!谢谢! - Jan Gassen

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