Import SSL Certificate into Java keystore


Import SSL Certificate into Java keystore

We will get the javax.net.ssl.SSLHandshakeException error when we try to access HTTPS urls in java. To avoid these certificate issues, we need to import the SSL Certificate into JVM

Caused by: 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

Steps:

  1. Download the Certificate
  2. Import the Certificate into JVM using keytool

 

  • Download the certificate:

 

  1. Open the URL in chrome browser: https://services.gradle.org
  2. Press F12 to access developer tools
  3. Go to security tab
  4. Click on View certificate and click on Details tab in the following window.
  5. Click on “Copy to File”  and again click on “Next button”
  6. Specify the file name by clicking on “Browse” button.
  7. Now click on finish

 

 

Step2: Import the SSL Certificate

JDK provides keytool to import the SSL Certificate

  1. Open CMD prompt in admin mode and enter “keytool -importcert -help”

    Java Keytool
    Java Keytool
  2. In the above steps, i downloaded the certificate into  C:\Users\pokurija\Pictures\javasavvy\gradle.cer path
  3. Navigate to “C:\Program Files\Java\jre\lib\security” path and give the following command to import the cert.
    • C:\Program Files\Java\jre\lib\security>keytool -importcert -trustcacerts -file C:\Users\jai\Pictures\javasavvy\gradle.cer -keystore cacerts -alias "gradle"
    • It will prompt for keystore password and enter  “changeit” for both times. chnageit is default password for cacerts, so do no change this. Java SSL Certificate Installation

Hope this helps.

4 thoughts on “Import SSL Certificate into Java keystore”
  1. This is extremely simple and helpful in configuring the “spring.io” website certificate into JVM and then accessing through the Eclipse IDE.

Comments are closed.