如何在 java7 中处理异常“javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure”

Posted

技术标签:

【中文标题】如何在 java7 中处理异常“javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure”【英文标题】:how to handle exception "javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure" in java7 【发布时间】:2019-11-22 06:03:17 【问题描述】:

我在尝试了许多选项后发布了这个问题。以下是我尝试过的选项。 1. 将属性添加到 JAVA_HOME/jre/lib/security/java.security security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider

从以下链接下载 jar 并添加到 JAVA_HOME/jre/lib/security http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html

2.添加java -Dhttps.protocols=TLSv1.2,TLSv1.1,TLSv1

3.添加 System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");连接之前。

我仍然遇到这个问题,任何帮助都非常感谢。

14:37:28,040 INFO  [STDOUT] SALM:login#TID:224#ST:2019-07-12 14:35:03.614, WRITE: TLSv1.2 Handshake, length = 227

14:37:28,311 INFO  [STDOUT] SALM:login#TID:224#ST:2019-07-12 14:35:03.614, READ: TLSv1.2 Alert, length = 2

14:37:28,314 INFO  [STDOUT] SALM:login#TID:224#ST:2019-07-12 14:35:03.614, RECV TLSv1 ALERT:  fatal, handshake_failure

14:37:28,317 INFO  [STDOUT] SALM:login#TID:224#ST:2019-07-12 14:35:03.614, called closeSocket()

14:37:28,319 INFO  [STDOUT] SALM:login#TID:224#ST:2019-07-12 14:35:03.614, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

14:37:32,023 FATAL [com.de.teamdynamics.webhelper.TeamDynamicHelper] CurrentThreadID=224 TeamDynamicHelper:processTeamDynamicsDataJob:Error - javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
14:37:32,024 FATAL [com.de.base.util.general.WebUtil] CurrentThreadID=224 Exception===> Values ===>javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1092)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
    at com.de.teamdynamics.webhelper.TeamDynamicHelper.pushTeamDynamicsData(TeamDynamicHelper.java:1039)

【问题讨论】:

删除所有测试并添加-Djavax.net.debug=all,返回完整日志 这最终对我有用: SSLContext context = SSLContext.getInstance("TLSv1.2"); context.init(null,null,null); SSLContext.setDefault(context); 【参考方案1】:

我多次遇到这个问题,对我来说,它通过更新 US_export_policy.jar 并在$JAVA_HOME/jre/lib/security/cacerts 中添加 ssl 证书来工作 你可以参考这个链接: https://drissamri.be/blog/2017/02/22/trusting-lets-encrypt-java/

【讨论】:

【参考方案2】:

这最终对我有用:

SSLContext context = SSLContext.getInstance("TLSv1.2");
context.init(null,null,null);
SSLContext.setDefault(context);

【讨论】:

以上是关于如何在 java7 中处理异常“javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure”的主要内容,如果未能解决你的问题,请参考以下文章

处理异常:javax.net.ssl.SSLHandshakeException:没有合适的协议(协议被禁用或密码套件不合适)

如何解决 Tomcat 7.0.100 上的 javax.net.ssl.SSLHandshake 异常错误?

Java7的异常处理新特性addSuppressed()方法

Java Java7处理异常新特性

线程“主”javax.net.ssl.SSLHandshakeException 中的异常:sun.security.validator.ValidatorException:未找到受信任的证书

Java异常处理