尝试为Java1.7启用TLSv1.2时,TLS握手失败请赐教

问题描述

我阅读了Oracle的文档here,并试图在Java 7(1.7.0_80-b15)上启用TLSv1.2几天,但没有成功。

我想在其上启用TLSv1.2,因此我可以使用https协议调用Web服务。 我使用了我认为已经启用的代码

SSLContext ctx = SSLContext.getInstance("TLSv1.2");
            ctx.init(null,null,new SecureRandom());
            SSLContext.setDefault(ctx);

URL url = new URL ("https://testotp.ktc.co.th");
            HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
            conn.setSSLSocketFactory(ctx.getSocketFactory());

我什至把jdk.tls.disabledAlgorithms=SSLv2Hello,SSLv3,TLSv1,TLSv1.1放在java.security上。 仍然,在调用Web服务方法时仍然出现此错误

AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: java.net.socketException: Connection reset
 faultActor: 
 faultNode: 
 faultDetail: 
    {http://xml.apache.org/axis/}stackTrace:java.net.socketException: Connection reset
    ...

所以我在JVM上设置了这些调试器属性,这就是我得到的。

我得到了-Djavax.net.debug=ssl:defaultctx

trigger seeding of SecureRandom
done seeding SecureRandom
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
Ignoring unavailable cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
Ignoring unavailable cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
Ignoring unavailable cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA
Allow unsafe renegotiation: false
Allow legacy hello messages: true
Is initial handshake: true
Is secure renegotiation: false
%% No cached client session
*** ClientHello,TLSv1.2
...
...
main,WRITE: TLSv1.2 Handshake,length = 219
main,handling exception: java.net.socketException: Connection reset
main,SEND TLSv1 ALERT:  fatal,description = unexpected_message
main,WRITE: TLSv1 Alert,length = 2
main,Exception sending alert: java.net.socketException: Connection reset by peer: socket write error
main,called closeSocket()

对于-Djavax.net.debug=ssl:sslctx,我得到了

trigger seeding of SecureRandom
done seeding SecureRandom
trigger seeding of SecureRandom
done seeding SecureRandom
main,called closeSocket()

从第一个调试器开始,我假设我已经为其启用了TLSv1.2,所以我得到了“ ClientHello,TLSv1.2”,但是握手仍然失败并且套接字被关闭。 可能与defaultctx中的TLS版本与sslctx有所不同的事实有关,但我不太了解它们是什么。

我还通过运行telnet https://thathost.com 443来检查Web服务是否具有https协议,并且它确实存在。

这个post似乎是我的情况,但也没有答案。我接下来可以尝试什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)