javax.net.ssl.SSLProtocolException: 证书链长度 (11) 超过允许的最大长度 (10)

Ren*_*ral 5 java ssl tomcat

我很挣扎,因为我的 Java MVC Web 应用程序在尝试创建具有特定 https 地址的 WebService 时开始抛出异常(https://barramento.caixa.gov.br/sibar/ManutencaoCobrancaBancaria/Boleto/Externo?xsd=xsd0)。

启用 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)
Run Code Online (Sandbox Code Playgroud)

这篇文章澄清了很多,并给了我一些理解问题的指导。但还不够。

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

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

有没有人遇到过这样的事情?

Ren*_*ral 9

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

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

非常感谢@dave_thompson_085