Java 向 JRE 添加 SSL 证书以访问 HTTPS 站点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25951602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding an SSL Certificate to JRE in order to access HTTPS sites
提问by mosawi
Context:
语境:
So I'm trying to access an HTTPS site from my Java code but I am not able due to an SSL Handshake issues between my localhost and the server. It seems the reason for this issues is that the URL I am trying to access has no valid certificate issued from an authorized CA.
所以我试图从我的 Java 代码访问一个 HTTPS 站点,但由于我的本地主机和服务器之间的 SSL 握手问题,我无法访问。出现此问题的原因似乎是我尝试访问的 URL 没有由授权 CA 颁发的有效证书。
So after some research, I'm going to try to import the offending SSL certificates into my JRE, that way it can be validated.
因此,经过一些研究,我将尝试将有问题的 SSL 证书导入我的 JRE,这样就可以对其进行验证。
Question:
题:
What is the mac equivalent of this command using the keytool for importing certificates:
使用 keytool 导入证书的此命令的 mac 等效项是什么:
keytool -import -alias mycertificate -keystore ..\lib\security\cacerts -file c:\mycert.cer
Reference:
参考:
http://www.jyothis.co.in/2011/11/12/javax-net-ssl-sslhandshakeexception/
http://www.jyothis.co.in/2011/11/12/javax-net-ssl-sslhandshakeexception/
Any help or assistance would be much appreciated, thank you
任何帮助或帮助将不胜感激,谢谢
采纳答案by ivan.sim
You should be able to import the server (self-signed?) SSL certificate onto your localhost using the command you specified. To be more complete, you can try
您应该能够使用您指定的命令将服务器(自签名?)SSL 证书导入到您的本地主机上。为了更完整,您可以尝试
$JAVA_HOME/bin/keytool -import -alias mycertificate -keystore path_to_keystore -file certificate_file
where
在哪里
$JAVA_HOME
on Mac is/System/Library/Frameworks/JavaVM.framework/Home/
path_to_key_sotre
is$JAVA_HOME/lib/security/cacerts
certificate_file
is where you store the downloaded certificate
$JAVA_HOME
在 Mac 上是/System/Library/Frameworks/JavaVM.framework/Home/
path_to_key_sotre
是$JAVA_HOME/lib/security/cacerts
certificate_file
是您存储下载的证书的地方
If prompted, the default truststore password is changeit
.
如果出现提示,默认信任库密码为changeit
。