将其他证书添加到现有 jks 或不使用 javax.net.ssl.trustStore 请求
Adding other certificates to existing jks or not using javax.net.ssl.trustStore for a request
我是 运行 spring 在 linux 中的 Tomcat 申请。我正在使用 mongodb 作为我的数据库服务。
在大量搜索以找到如何使用 SSL/TLS 连接到 mongodb 之后,我发现我必须将证书添加到 java 密钥库并在我的 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
我使用此 . And I used keytools as described here.
生成了我的 SSL 证书
我不是使用 keyTools 或 Key manager 的专家,我以前也没有使用 ssl 的经验。
更新
即使在删除 Clearing 属性,甚至关闭系统后,我仍然会遇到同样的异常。它就像连接仍在尝试使用错误的 ssl 证书。
您所做的是创建一个自定义信任库来替换 JVM 提供的信任库,并且您的信任库不包含 public 互联网服务使用的所有 well-known CA 证书。因此,当您尝试通过互联网验证证书时,您会收到 trust-path 错误。
最快的解决方法是 不 设置 javax.net.ssl.trustStore
和 javax.net.ssl.trustStorePassword
属性。相反,将您的 mongodb CA 证书导入 JVM 默认信任库(通常是 cacerts 文件)。如果您 replace/upgrade JVM,则需要记住重复此操作。
如果您没有必要的权限来修改 cacerts,或者您在共享服务器上被禁止,那么您仍然可以使用您的自定义信任库,但增加它cacerts 文件中的所有 well-known 证书。当新的 CA 证书出现时,您将负责维护它。
我是 运行 spring 在 linux 中的 Tomcat 申请。我正在使用 mongodb 作为我的数据库服务。
在大量搜索以找到如何使用 SSL/TLS 连接到 mongodb 之后,我发现我必须将证书添加到 java 密钥库并在我的 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
我使用此
我不是使用 keyTools 或 Key manager 的专家,我以前也没有使用 ssl 的经验。
更新 即使在删除 Clearing 属性,甚至关闭系统后,我仍然会遇到同样的异常。它就像连接仍在尝试使用错误的 ssl 证书。
您所做的是创建一个自定义信任库来替换 JVM 提供的信任库,并且您的信任库不包含 public 互联网服务使用的所有 well-known CA 证书。因此,当您尝试通过互联网验证证书时,您会收到 trust-path 错误。
最快的解决方法是 不 设置 javax.net.ssl.trustStore
和 javax.net.ssl.trustStorePassword
属性。相反,将您的 mongodb CA 证书导入 JVM 默认信任库(通常是 cacerts 文件)。如果您 replace/upgrade JVM,则需要记住重复此操作。
如果您没有必要的权限来修改 cacerts,或者您在共享服务器上被禁止,那么您仍然可以使用您的自定义信任库,但增加它cacerts 文件中的所有 well-known 证书。当新的 CA 证书出现时,您将负责维护它。