我有一个需要客户端证书的网络服务,我使用以下命令在运行时加载该证书:
System.setProperty("javax.net.ssl.keyStore", keystore.getAbsolutePath());
System.setProperty("javax.net.ssl.keyStorePassword", "password");
System.setProperty("javax.net.ssl.keyStoreType", "jks");
System.setProperty("javax.net.ssl.trustStore", cafile.getAbsolutePath());
System.setProperty("javax.net.ssl.trustStorePassword", "password");
但是,现在我通过常规 https(没有任何客户端证书)连接的其他网络服务已损坏:
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
有没有一种方法可以在运行时加载证书而不破坏现有的 https 网络服务?
最佳答案
我为类似的问题尝试了很久,并且正在工作。
System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
Security.addProvider (new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("https.protocols", "SSLv3,TLSv1");
System.setProperty("javax.net.ssl.trustStore", "");
System.setProperty("javax.net.ssl.trustStorePassword", "");
System.setProperty("javax.net.ssl.trustStoreType", "");
Security.ssl.allowUnsafeRenegotiation", "true");
System.setProperty("javax.net.ssl.keyStore", "");
System.setProperty("javax.net.ssl.keyStorePassword", "");
System.setProperty("javax.net.ssl.keyStoreType", "");
System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
同样可以通过在您正在使用的应用程序服务器中配置 trustore
和 keystore
来实现。
问题是证书没有正确导入。 我希望下面的链接对您有所帮助。
关于java - Java 中的客户端 SSL 证书 : PKIX path building failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24745299/