【发布时间】:2018-04-11 10:48:28
【问题描述】:
我在 linux 的 Tomcat 下运行一个 spring 应用程序。我使用 mongodb 作为我的数据库服务。
在搜索了很多以找到如何使用 SSL/TLS 连接到 mongodb 之后,我发现我必须将证书添加到 java keystore 并像这样在我的 spring 应用程序中使用它们。
System.setProperty("javax.net.ssl.trustStore","/path/truststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "apass");
System.setProperty("javax.net.ssl.keyStore", "/path/keystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "apass");
System.setProperty("javax.security.auth.useSubjectCredsOnly","false");
一切正常,我可以连接到 mongodb。但问题是我使用 Spring RestTemplate 从我的应用程序发送其他 HTTP 请求。使用 SSL 配置我的 mongodb 后,我无法连接到任何其他外部主机。
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
我使用这个SO answer 生成了我的 SSL 证书。我使用了 here 描述的 keytools。
我不是使用 keyTools 或 Key manager 的专家,而且我以前没有使用 ssl 的经验。
更新 即使删除了 Clearing 属性,甚至关闭了系统,我仍然会遇到同样的异常。好像连接仍在尝试使用错误的 ssl 证书。
【问题讨论】:
标签: java spring encryption openssl keytool