【问题标题】:javax.net.ssl.SSLProtocolException: The certificate chain length (11) exceeds the maximum allowed length (10)javax.net.ssl.SSLProtocolException:证书链长度 (11) 超过了允许的最大长度 (10)
【发布时间】:2021-02-19 14:26:32
【问题描述】:

由于我的 java MVC Web 应用程序在尝试创建具有特定 https 地址 (https://barramento.caixa.gov.br/sibar/ManutencaoCobrancaBancaria/Boleto/Externo?xsd=xsd0) 的 WebService 时开始引发异常,因此我一直在苦苦挣扎。

启用 javax.net.debug 后,我发现问题的根本原因似乎是我尝试连接的服务器应用程序的证书链长度

起初,我怀疑 TLS 版本,但使用 nmap 我能够找到服务器正在使用的 TLS 版本以及密码,它们不是问题。服务器支持 TLS1.1。我已经将我的服务器配置为使用此版本,但它根本没有帮助。

我在整个网络上搜索了一些可以提供帮助的信息,但我在 Google 上找不到任何指向 "javax.net.ssl.SSLProtocolException: The certificate chain length" 的东西

她是堆栈跟踪:

javax.net.ssl|FINE|26|http-nio-8080-exec-2|2020-11-06 17:30:36.178 BRT|Logger.java:765|READ: TLSv1.1 handshake, length = 3835
javax.net.ssl|SEVERE|26|http-nio-8080-exec-2|2020-11-06 17:30:36.188 BRT|Logger.java:765|Fatal (HANDSHAKE_FAILURE): Couldn't kickstart handshaking (
"throwable" : {
  javax.net.ssl.SSLProtocolException: The certificate chain length (11) exceeds the maximum allowed length (10)
        at sun.security.ssl.CertificateMessage$T12CertificateMessage.<init>(CertificateMessage.java:143)
        at sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:363)

Caused by: javax.net.ssl.SSLProtocolException: The certificate chain length (11) exceeds the maximum allowed length (10)
                at sun.security.ssl.CertificateMessage$T12CertificateMessage.<init>(CertificateMessage.java:143)
                at sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:363)
                at sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:377)
                at sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:444)
                at sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:422)
                at sun.security.ssl.TransportContext.dispatch(TransportContext.java:182)
                at sun.security.ssl.SSLTransport.decode(SSLTransport.java:149)
                at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1143)
                at sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1054)
                at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:394)

这个post澄清了很多,给了我一些理解问题的指导。但还不够。

注意:奇怪的是,当我使用 Java 1.8.0_272 从 ubuntu 实例运行我的应用程序时,就会出现这个问题。当从 Windows 机器(也使用 Java 1.8.0_272)运行我的应用程序时,它不会发生。

是否有任何 JVM 参数或任何其他方式来设置允许的证书链的长度?

有人遇到过类似的事情吗?

【问题讨论】:

  • 我从来没有听说过这么长的证书链,而且我在 DoD 看到过一些长链。你有一条 11 长的链条,为什么这么长?
  • 其实这个证书来自第三方服务器。我也不知道为什么这么长。
  • This is a new 'feature' in 8u271 并且应该也适用于 Windows - 您的 Windows 机器是否可能使用与您想象的不同的 Java、HTTPS 代理或访问不同的服务器?虽然看起来消息和描述不精确——限制的是 message 中的证书数量,而不是 chain;消息包含应该是链,但在这种情况下它们不是。无论如何,请按照发行说明中的​​说明设置 sysprop。
  • @PresidentJamesK.Polk+ 实际链只有 4 个(如果您使用现代 Comodo 根,可以减少到 3 个)。但是该服务器(200.201.170.24)也发送了其他不相关的证书——其中一些已过期——显然是 message 而不是 JSSE 的实际 chain (现在)检查。 ssllabs.com/ssltest/analyze.html?d=barramento.caixa.gov.br 也发现了许多其他问题。
  • 非常感谢@dave_thompson_085。这正是我一直在寻找的。设置 jdk.tls.maxCertificateChainLength sysprop 就像一个魅力!

标签: java ssl tomcat


【解决方案1】:

@dave_thompson_085 指出,实际链只有 4 个。问题是服务器发送的许多证书(@dave_thompson_085 也指出)。

添加“-Djdk.tls.maxCertificateChainLength=15”JVM 参数解决了这个问题。

非常感谢@dave_thompson_085

【讨论】:

  • 真正的解决方案是修复服务器。
  • 很遗憾,这不是一个选项。
猜你喜欢
  • 1970-01-01
  • 2016-07-13
  • 2012-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-01
  • 2019-10-10
  • 1970-01-01
相关资源
最近更新 更多