java SSLHandshakeException 虽然证书受信任的系统范围

标签 java linux security ssl

我获得了一个 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/

相关文章:

java - Spring 端点为较大的 http 请求接收截断的正文

php - 在 linux 中的 bash 的 .sh 之类的脚本中使用 php 和 perl 以及 R 等等?是否可以?

git - git push 和 pulls 是否加密?

c++ - 使用 C++/C 的安全网络编程

java - Android - 如何每分钟运行一段代码(与设备时间同步)

java - 将 Spring 依赖注入(inject)到 JPA 实体监听器中

java - Android Stop Runnable 在新线程中创建

linux - 如何在 CentOS 5 上升级到 Subversion 1.5?

linux - .bashrc for/bin/sh 有替代方案吗?

security - Wildfly 在 Web 应用程序中注销后缓存角色