13

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 ..\lib\security\cacerts -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

3
  • What about ignoring the ssl certificate at all?
    – libik
    Sep 20, 2014 at 18:05
  • How could this be done? Please specify
    – mosawi
    Sep 20, 2014 at 18:25
  • look to answer of this response, there is "disable" certificate part : stackoverflow.com/questions/23462271/…
    – libik
    Sep 21, 2014 at 20:20

1 Answer 1

18

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.

2
  • path_to_key_store requires also a file name. is it important how we name it? what extension should it have?
    – AmiNadimi
    Mar 16, 2018 at 9:36
  • 2
    the cacerts keystore could also be in the jre/lib/security folder: $JAVA_HOME/jre/lib/security/cacerts Mar 11, 2020 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.