Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
160 views
in Technique[技术] by (71.8m points)

java - Adding an SSL Certificate to JRE in order to access HTTPS sites

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.

So after some research, I'm going to try to import the offending SSL certificates into my JRE, that way it can be validated.

Question:

What is the mac equivalent of this command using the keytool for importing certificates:

keytool -import -alias mycertificate -keystore ..libsecuritycacerts -file c:mycert.cer

Reference:

http://www.jyothis.co.in/2011/11/12/javax-net-ssl-sslhandshakeexception/

Any help or assistance would be much appreciated, thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

$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

If prompted, the default truststore password is changeit.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...