问题描述
我有一个在 docker 容器上的 tomcat (v8.0.44) 上运行的 Java 8 应用程序.此应用程序调用外部 https
网址(我无法提供网址),但出现以下错误:
I have a Java 8 application running on a tomcat (v8.0.44) on a docker container.This application call an external https
url (I can't provide the url) and i get the following error :
异常:类 javax.net.ssl.SSLHandshakeException:接收到致命警报:握手失败在sun.security.ssl.Alerts.getSSLException(Alerts.java:192) 在sun.security.ssl.Alerts.getSSLException(Alerts.java:154) 在sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023) atsun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125) atsun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)在sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)在sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)在sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)在sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)在sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)在sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)在java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)在sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
此错误仅发生在相同的网址上.其他 https
网址工作正常.
This error happend only with the same url. Other https
urls works fine.
我无法在 Spring boot
应用程序上重现此行为.所以我猜问题出在 tomcat 或容器配置上.
I can't reproduce this behavior on a Spring boot
application. So i guess the issue is on the tomcat or the container configuration.
您对这个问题的起源有什么建议.
Do you have any suggestions about the origin of this issue.
谢谢.
编辑:
当我添加选项 -Djavax.net.debug=all
我有这个输出:
When I add the option -Djavax.net.debug=all
I have this output :
trigger seeding of SecureRandom
done seeding SecureRandom
Allow unsafe renegotiation: false
Allow legacy hello messages: true
Is initial handshake: true
Is secure renegotiation: false
http-nio-8080-exec-5, setSoTimeout(0) called
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 for TLSv1
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 for TLSv1
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 for TLSv1
Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 for TLSv1.1
Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 for TLSv1.1
%% No cached client session
*** ClientHello, TLSv1.2
RandomCookie: GMT: 1535552913 bytes = { 156, 140, 20, 250, 150, 107, 55, 72, 40, 86, 58, 240, 204, 254, 26, 209, 76, 216, 97, 145, 48, 238, 91, 155, 53, 179, 190, 112 }
Session ID: {}
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
Compression Methods: { 0 }
Extension elliptic_curves, curve names: {secp256r1, secp384r1, secp521r1, sect283k1, sect283r1, sect409k1, sect409r1, sect571k1, sect571r1, secp256k1}
Extension ec_point_formats, formats: [uncompressed]
Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA224withECDSA, SHA224withRSA, SHA224withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA
***
[write] MD5 and SHA1 hashes: len = 209
0000: 01 00 00 CD 03 03 5C 87 AE 91 9C 8C 14 FA 96 6B ......\........k
0010: 37 48 28 56 3A F0 CC FE 1A D1 4C D8 61 91 30 EE 7H(V:.....L.a.0.
0020: 5B 9B 35 B3 BE 70 00 00 64 C0 24 C0 28 00 3D C0 [.5..p..d.$.(.=.
0030: 26 C0 2A 00 6B 00 6A C0 0A C0 14 00 35 C0 05 C0 &.*.k.j.....5...
0040: 0F 00 39 00 38 C0 23 C0 27 00 3C C0 25 C0 29 00 ..9.8.#.'.<.%.).
0050: 67 00 40 C0 09 C0 13 00 2F C0 04 C0 0E 00 33 00 g.@...../.....3.
0060: 32 C0 2C C0 2B C0 30 00 9D C0 2E C0 32 00 9F 00 2.,.+.0.....2...
0070: A3 C0 2F 00 9C C0 2D C0 31 00 9E 00 A2 C0 08 C0 ../...-.1.......
0080: 12 00 0A C0 03 C0 0D 00 16 00 13 00 FF 01 00 00 ................
0090: 40 00 0A 00 16 00 14 00 17 00 18 00 19 00 09 00 @...............
00A0: 0A 00 0B 00 0C 00 0D 00 0E 00 16 00 0B 00 02 01 ................
00B0: 00 00 0D 00 1C 00 1A 06 03 06 01 05 03 05 01 04 ................
00C0: 03 04 01 04 02 03 03 03 01 03 02 02 03 02 01 02 ................
00D0: 02 .
http-nio-8080-exec-5, WRITE: TLSv1.2 Handshake, length = 209
[Raw write]: length = 214
0000: 16 03 03 00 D1 01 00 00 CD 03 03 5C 87 AE 91 9C ...........\....
0010: 8C 14 FA 96 6B 37 48 28 56 3A F0 CC FE 1A D1 4C ....k7H(V:.....L
0020: D8 61 91 30 EE 5B 9B 35 B3 BE 70 00 00 64 C0 24 .a.0.[.5..p..d.$
0030: C0 28 00 3D C0 26 C0 2A 00 6B 00 6A C0 0A C0 14 .(.=.&.*.k.j....
0040: 00 35 C0 05 C0 0F 00 39 00 38 C0 23 C0 27 00 3C .5.....9.8.#.'.<
0050: C0 25 C0 29 00 67 00 40 C0 09 C0 13 00 2F C0 04 .%.).g.@...../..
0060: C0 0E 00 33 00 32 C0 2C C0 2B C0 30 00 9D C0 2E ...3.2.,.+.0....
0070: C0 32 00 9F 00 A3 C0 2F 00 9C C0 2D C0 31 00 9E .2...../...-.1..
0080: 00 A2 C0 08 C0 12 00 0A C0 03 C0 0D 00 16 00 13 ................
0090: 00 FF 01 00 00 40 00 0A 00 16 00 14 00 17 00 18 .....@..........
00A0: 00 19 00 09 00 0A 00 0B 00 0C 00 0D 00 0E 00 16 ................
00B0: 00 0B 00 02 01 00 00 0D 00 1C 00 1A 06 03 06 01 ................
00C0: 05 03 05 01 04 03 04 01 04 02 03 03 03 01 03 02 ................
00D0: 02 03 02 01 02 02 ......
[Raw read]: length = 5
0000: 15 03 03 00 02 .....
[Raw read]: length = 2
0000: 02 28 .(
http-nio-8080-exec-5, READ: TLSv1.2 Alert, length = 2
http-nio-8080-exec-5, RECV TLSv1.2 ALERT: fatal, handshake_failure
http-nio-8080-exec-5, called closeSocket()
http-nio-8080-exec-5, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
推荐答案
问题是,java 版本不包含 UnlimitedJCEPolicyJDK8 文件.我将 java 从版本 8u131-b11
升级到 8u201-b09
.
The problem was, the java version that not include the UnlimitedJCEPolicyJDK8 files. I upgrade java from version 8u131-b11
to 8u201-b09
.
这篇关于从tomcat服务器调用https时Tomcat握手失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!