尝试为Java1.7启用TLSv1.2时TLS握手失败。请开导我

尝试为Java1.7启用TLSv1.2时TLS握手失败。请开导我,java,ssl,https,protocols,tls1.2,Java,Ssl,Https,Protocols,Tls1.2,我阅读了Oracle的文档,尝试在Java7(1.7.0_80-b15)上启用TLSv1.2有几天没有成功 我想在上面启用TLSv1.2,这样我就可以使用https协议调用web服务。 我使用了我认为已经启用的代码 SSLContext ctx = SSLContext.getInstance("TLSv1.2"); ctx.init(null, null, new SecureRandom()); SSLContext.set

我阅读了Oracle的文档,尝试在Java7(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, handling exception: java.net.SocketException: Connection reset
main, SEND TLSv1 ALERT:  fatal, description = unexpected_message
main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error
main, called closeSocket()
从第一个调试器开始,我假设我已经为它启用了TLSv1.2,所以我得到了“ClientHello,TLSv1.2”,但握手仍然失败,套接字关闭。 这可能与defaultctx中的TLS版本与sslctx的不同有关,但我不太明白它们是什么

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


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

此外,如果您还没有阅读过TLS握手的相关内容,请务必阅读。谢谢在我看来,这个过程要清晰得多。不管怎样,我还是呆在同一个地方。我尝试添加证书,甚至最终信任所有证书,但在客户端Hello之后握手仍然失败。我想这可能是因为密码套件,所以我实现了JCE无限强度权限策略,并尝试使用System.setProperty(“https.ciphersuites”,…)和sslSocket.setEnabledCipherSuites(新字符串[]{*some CipherSuiteThinkitMightWork})添加一些密码套件,但我仍然没有做进一步的工作。实际上,我不能仅仅从Chrome上获取密码套件,因为我是在一个远程桌面上完成的,这个桌面没有互联网,也无法通过浏览器访问。无论如何,我都可以使用http协议访问主机,因为它是主机的内部服务器,站点是web服务wsdl页面。我已经通过telnet连接到该主机的443端口,并且工作正常。我的目标是通过该主机的https调用webservice。客户端使用TLS1.2发送客户端hello,但我仍然失败,没有看到服务器hello。你知道这里怎么了吗?我从你的评论中得到了什么错误吗?请尝试将不安全的重新协商设置为true
System.setProperty(“sun.security.ssl.allowUnsaference”、“true”)我只是尝试了你的建议,但我还是没有运气。这是我从调试器得到的响应。