gpt4 book ai didi

java - SSLHandshakeException - %% 无效 : [Session-1, SSL_RSA_WITH_3DES_EDE_CBC_SHA]

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:45 25 4
gpt4 key购买 nike

我正在尝试连接到安全服务器,Java 代码因 SSLHandshakeException 而失败。当我启用 -Djavax.net.debug=all 时,出现以下错误:

main, RECV TLSv1.2 ALERT: fatal, handshake_failure

%% Invalidated: [Session-1, SSL_RSA_WITH_3DES_EDE_CBC_SHA] main, called closeSocket()

main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

我已经进行了足够多的搜索并尝试了:-Dhttps.protocols-Dhttps.cipherSuites 选项,但它们似乎都不起作用。

我还检查了:

socketfactory.getDefaultCipherSuites() which lists the cipher stated in the error.

我检查过

openssl s_client -connect url:443

但是它抛出一个错误:

verify error:num=20:unable to get local issuer certificate

verify return:0

58555:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:/SourceCache/OpenSSL098/OpenSSL098-52.30.1/src/ssl/s3_pkt.c:1145:SSL alert number 40

58555:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:/SourceCache/OpenSSL098/OpenSSL098-52.30.1/src/ssl/s23_lib.c:185:

感谢在此方面的快速帮助和指导。

我正在使用 spring ws 执行此操作,我正在创建自己的 HttpClient,因为此连接需要服务器 keystore 才能进行连接。以下是我正在使用的代码:

    public NewHttpClient(KeyStore keyStore, String pwd, Integer maxTotal, Integer defaultMaxPerRoute) throws KeyManagementException, UnrecoverableKeyException,
NoSuchAlgorithmException, KeyStoreException {
HttpClientBuilder builder = HttpClientBuilder.create();
SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, pwd.toCharArray()).build();
builder.setSSLContext(sslContext);
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext);
builder.setSSLSocketFactory(sslConnectionFactory);
Registry<ConnectionSocketFactory> schemeRegistry = RegistryBuilder.<ConnectionSocketFactory> create().register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory()).build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(schemeRegistry);
connectionManager.setMaxTotal(maxTotal);
connectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
builder.setConnectionManager(connectionManager);
customHttpClient = builder.build();
}

更新 1:当我使用来自 SOAP-UI 的 keystore 时,它可以正常工作,没有任何问题。它只是 java 方法中的一个问题!

更新 2:我已尝试使用 3 个 JVM 6、7 和 8,但问题仍然存在。此外,我尝试从纯 Java 代码而不是 Spring 创建 SSL 连接,并且能够成功地进行握手而没有任何问题。

最佳答案

我看到这是基于我的更新 2 的 spring 问题。所以我改变了我的方法来使用

org.springframework.ws.transport.http.HttpsUrlConnectionMessageSender

& 瞧,它工作没有任何问题。

我不得不从一个新的 maven jar 中导入上面的类:

  <dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-support</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>

关于java - SSLHandshakeException - %% 无效 : [Session-1, SSL_RSA_WITH_3DES_EDE_CBC_SHA],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41847100/

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