我是网络服务
的新手。我想通过 SSL
连接进行连接。我关注了这个网站:SSLHandshakeException: PKIX: unable to find valid certification path to requested target , 这个线程 How to solve javax.net.ssl.SSLHandshakeException Error?我确实将 certificate
添加到 keystore
中,如下所示:
keytool -importcert -alias <some name> -file <Certifacate path> -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -storepass changeit
我使用 keytool -list
命令检查它是否存在
问题是当我尝试在应用程序中通过 SSL
连接时收到此错误消息:
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
我还尝试在应用程序中添加 trustStore
位置和密码,如下所示:
System.setProperty("javax.net.ssl.trustStore","C:\\Program Files (x86)\\Java\\jre7\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
还是报同样的错
我正在使用 Jdeveloper 11g R1
和 JDK 7
,如果有帮助的话。
更新:
在进一步阅读一些解决方案后,我需要走这条路:
C:\Program Files\Java\jdk1.7.0_09\jre\lib\security\cacerts
作为信任库
我把上面的java语句替换成如下:
System.setProperty("javax.net.ssl.trustStore","C:\\Program Files\\Java\\jdk1.7.0_09\\jre\\lib\\security\\cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
但我仍然遇到同样的错误!!
最佳答案
在我获得第三方的证书后,我做了以下事情:
将证书添加到浏览器中受信任的根证书,并使用服务器身份验证检查表单
advance option
.使用
keytool
将证书添加到信任证书中command prompt
中的选项请引用此链接:Resolving javax.net.ssl.SSLHandshakeException获取更多信息。
找了半天发现问题的原因unable to find valid certification path to requested target
如下:(注意:这是我发现的,可能还有更多)
一个。缺少未添加的中间证书。
要解决此问题,您需要添加根证书,其他所有证书将默认添加。要找出您的第三方使用的证书,请参阅以下链接。基本上,建议的解决方案将为您提供一个名为 ( InsertCert.java
) 的 java 类,该类将为您提供服务器使用的证书。你需要的是通过 host name
作为参数。在以下链接中找到详细信息:
- > No more 'unable to find valid certification path to requested target'
- > Step by step video to solve the issue using information from the provisos link
b .您在错误的 cacerts 文件中添加了证书。
要解决此问题,请引用前面提到的同一 java 类 (InsertCert.java
),它将提供正确的 cacerts
。在我的例子中我使用的路径 Jdeveloper 11.1.1.7
路径是:
C:\Oracle\Middleware\JDeveloper\JDeveloper11117\jdk160_24\jre\lib\security\cacerts
关于java - 尝试通过 SSL 连接时出错。无法找到到请求目标的有效证书路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23180644/