【发布时间】:2018-11-02 08:49:26
【问题描述】:
我的 Spring Boot 应用程序使用 REST 连接到不同的外部 URL,它们都具有相同的域。我收到了此 URL 的证书和不同的凭据。
自 2 天以来,连接不再起作用,因为我收到“ValidatorException PKIX 路径构建失败”错误(下面是异常的所有堆栈跟踪)。
在为每个 URL 创建一个特定的 REST 模板之前,我已将 SSLContext 与特定的密钥库信息和客户端凭据一起设置。
如果我向我的 SSLContext 添加以下信任存储(我收到一个 CA 文件),我设法修复了错误:
// Create Trust Managers
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
Certificate ca = certificateFactory.generateCertificate(caInput);
String alias = ((X509Certificate) ca).getSubjectX500Principal().getName();
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null);
trustStore.setCertificateEntry(alias, ca);
TrustManager[] trustManagers = {new CustomTrustManager(trustStore)};
你能给我一个提示吗:
- 如何为我的所有连接使用同一个 TrustStore? 即使我有相同的域,我也收到了这个 URL、不同的证书并且需要不同的客户端凭据来连接 - 所以对于每个 RestTemplate 对象,我配置不同的 SSLContext)。我还在并行调用 URL(使用 JMS 队列),所以我想知道在同一时间访问同一个 CA 文件是否没有问题......
- 您如何解释为什么这些 URL 突然停止工作?我们没有在本地或云端更改我们的 Java 版本....我对授权部分有点陌生,我无法理解它之前是如何工作的,然后突然停止了。
谢谢!
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://....": sun.security.validator.ValidatorException: 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: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:696)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:644)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:296)
【问题讨论】:
标签: java spring spring-boot spring-security