我在 Linux 实例上的 Java 8 JVM 中打开了 SSL 日志记录,这再现了问题。使用 打开 SSL 日志记录。这揭示了一些有用的信息。-Djavax.net.debug=ssl:handshake:verbose
我们在生产中使用并已被证明对我们有用的解决方法是在JVM上设置此参数:
-Djdk.tls.client.protocols=TLSv1
如果您想了解更多详细信息,请继续阅读。
在可以重现问题的服务器上(同样,只有5-10%的时间),我观察到以下内容:
*** ClientHello, TLSv1.2
--- 8<-- SNIP -----
main, WRITE: TLSv1.2 Handshake, length = 195
main, READ: TLSv1.2 Handshake, length = 1130
*** ServerHello, TLSv1.2
--- 8<-- SNIP -----
%% Initialized: [Session-79, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256]
** TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
--- 8<-- SNIP -----
Algorithm: [SHA1withRSA]
--- 8<-- SNIP -----
*** Diffie-Hellman ServerKeyExchange
--- 8<-- SNIP -----
*** ServerHelloDone
*** ClientKeyExchange, DH
--- 8<-- SNIP -----
main, WRITE: TLSv1.2 Handshake, length = 133
--- 8<-- SNIP -----
main, WRITE: TLSv1.2 Change Cipher Spec, length = 1
*** Finished
verify_data: { 108, 116, 29, 115, 13, 26, 154, 198, 17, 125, 114, 166 }
***
main, WRITE: TLSv1.2 Handshake, length = 40
main, called close()
main, called closeInternal(true)
main, SEND TLSv1.2 ALERT: warning, description = close_notify
main, WRITE: TLSv1.2 Alert, length = 26
main, called closeSocket(true)
main, waiting for close_notify or alert: state 5
main, received EOFException: ignored
main, called closeInternal(false)
main, close invoked again; state = 5
main, handling exception: java.io.IOException: SQL Server returned an incomplete response. The connection has been closed. ClientConnectionId:12a722b3-d61d-4ce4-8319-af049a0a4415
请注意,TLSv1.2 由数据库服务器选择并用于此交换。我观察到,当有问题的Linux服务的连接失败时,TLSv1.2始终是选择的级别。但是,使用 TLSv1.2 时,连接并不总是失败。他们只有5-10%的时间失败。
现在,这是来自没有问题的服务器的交换。其他一切都是平等的。即,连接到相同的数据库,相同版本的JVM(Java 1.8.0_60),相同的JDBC驱动程序等。请注意,此处,TLSv1 是由数据库服务器选择的,而不是像故障服务器那样选择 TLSv1.2。
*** ClientHello, TLSv1.2
--- 8<-- SNIP -----
main, WRITE: TLSv1.2 Handshake, length = 207
main, READ: TLSv1 Handshake, length = 604
*** ServerHello, TLSv1
--- 8<-- SNIP -----
Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA
--- 8<-- SNIP -----
%% Initialized: [Session-79, TLS_RSA_WITH_AES_128_CBC_SHA]
** TLS_RSA_WITH_AES_128_CBC_SHA
--- 8<-- SNIP -----
Algorithm: [SHA1withRSA]
--- 8<-- SNIP -----
***
*** ServerHelloDone
*** ClientKeyExchange, RSA PreMasterSecret, TLSv1
--- 8<-- SNIP -----
main, WRITE: TLSv1 Handshake, length = 134
main, WRITE: TLSv1 Change Cipher Spec, length = 1
*** Finished
verify_data: { 26, 155, 166, 89, 229, 193, 126, 39, 103, 206, 126, 21 }
***
main, WRITE: TLSv1 Handshake, length = 48
main, READ: TLSv1 Change Cipher Spec, length = 1
main, READ: TLSv1 Handshake, length = 48
*** Finished
因此,当在 Linux JVM 和 SQL Server 之间协商 TLSv1 时,连接始终是成功的。协商 TLSv1.2 时,我们会得到零星的连接故障。
(注意:Java 7 (1.7.0_51) 总是协商 TLSv1,这就是为什么使用 Java 7 JVM 时从未出现过这个问题的原因。
我们仍然有悬而未决的问题是:
- 为什么从2个不同的Linux服务器运行的相同的Java 8 JVM总是会协商TLSv1,但是当从另一个Linux服务器连接时,它总是协商TLSv1.2。
- 另外,为什么 TLSv1.2 协商的连接在该服务器上大部分(但不是全部)都成功?
6/10/2017 更新:Microsoft 发布的这篇文章描述了问题及其建议的解决方案。
资源:
http://www.infoworld.com/article/2849292/operating-systems/more-patch-problems-reported-with-the-ms14-066-kb-2992611-winshock-mess.html
http://www.infoworld.com/article/2849292/operating-systems/more-patch-problems-reported-with-the-ms14-066-kb-2992611-winshock-mess.html
http://blogs.msdn.com/b/jdbcteam/archive/2008/09/09/the-driver-could-not-establish-a-secure-connection-to-sql-server-by-using-secure-sockets-layer-ssl-encryption.aspx
Java 8,JCE无限强度策略和SSL握手通过TLS
http://blogs.msdn.com/b/saponsqlserver/archive/2013/05/10/analyzing-jdbc-connection-issues.aspx
https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#descPhase2
https://blogs.oracle.com/java-platform-group/entry/java_8_will_use_tls