https告诉java客户端代码接受自签名证书
我想连接到一个https
服务器,它有一个self signed certificate
,而不修改我的客户机代码
我知道这个问题已经被问过很多次了,但我没能让它起作用。以下是我所做的:
在Firefox中打开
https
服务器单击url信息,然后单击更多信息,然后查看证书,然后单击详细信息,然后单击导出
选择默认的导出类型设置(
X.509 Certificate (PEM)
,另存为certificate.crt
),并将其保存到磁盘打开命令提示符,转到客户机代码使用的
java_home
文件夹,在我的例子中是c:\jdk-7u55-windows-x64\jre\bin
输入以下命令:
keytool -import -v -trustcacerts -alias server-alias -file C:\Downloads\certificate.crt -keystore cacerts.jks -keypass changeit -storepass changeit
我也试过:
keytool -import -v -trustcacerts
-alias server-alias2 -file C:\Downloads\certificate.crt
-keystore keystore.jks
- 重新启动客户端应用程序
在所有这些之后,我仍然得到一个SSLHandshakeException
(无法找到到请求目标的有效认证路径)。
日志中的完全异常:
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
我不知道我做错了什么,还需要做什么,或者如何进一步调试
# 1 楼答案
指定所需
cacerts.jks
的绝对路径应该会有所帮助。当前使用keytool
只会产生新的结果。jks到您当前的目录(我想)是c:\jdk-7u55-windows-x64\jre\bin
。默认的cacerts位置通常在JAVA_HOME/jre/lib/security/cacerts
。或者你可以使用-Djavax.net.ssl.trustStore=<path to custom store> -Djavax.net.ssl.trustStorePassword=<custom store_passwd>
作为应用程序的起始参数More info