我获得了一个 jar 文件,但无法访问代码(或无法修改)和一个 .cer
ca 证书文件。
运行jar文件时;我收到此错误(我输入了 placeholder.hostname.com
):
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "placeholder.hostname.com": PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我在我的 linux 机器上信任系统范围内的 ca 证书,并且似乎能够通过 curl
与服务器通信和浏览器。我也将它添加到此 /etc/ssl/certs/java/cacerts/
与 keytool
(不确定这是否有意义,因为我不是 Java 开发人员)。但是,我仍然遇到与上述相同的错误。有没有办法让java信任代码之外的证书?或者这甚至不是问题?
(对不起,如果我的安全/证书条款已关闭)
谢谢
最佳答案
错误消息是这样说的:TLS 客户端无法从 TLS 握手期间服务器提供的叶证书到信任库中的任何受信任证书构建完整的证书路径。在没有更多细节的情况下,正如您所说的 curl 和浏览器工作正常,我假设浏览器和 curl 都使用包含所需证书的信任库。
如果确实如此,Java 应用程序使用的信任库可能不包含相同的证书。换句话说,它使用不同的信任库。
您应该检查的第一件事是 Java 应用程序实际使用的信任库。为此,请使用 -Djavax.net.debug=ssl,handshake
运行您的 Java 应用程序。 .除非javax.net.ssl.trustStore
已被覆盖,它将根据以下 hierarchy 使用信任库之一:
[...] If the javax.net.ssl.trustStore system property was not specified, then: if the file java-home/lib/security/jssecacerts exists, that file is used; if the file java-home/lib/security/cacerts exists, that file is used; if neither of these files exists, then the TLS cipher suite is anonymous, does not perform any authentication, and thus does not need a truststore. [...]
我怀疑您已将证书添加到系统范围的信任库,但没有添加到特定于 Java 的信任库。
关于java SSLHandshakeException 虽然证书受信任的系统范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68896430/