SSLPeerUnverifiedException: peer not authenticated

It seems that you need to import the certificate into the trusted keystore your JVM is using. If you are not using a different trusted keystore in your application this will be “cacerts”.

You can follow a step by step guide at “How to Fix ‘SSLPeerUnverifiedException: peer not authenticated’ Exception in Groovy / Java “.

Short version:

  1. Run the following command, replace $ADDRESS with the URL, minus the “https://”:

    echo -n | openssl s_client -connect $ADDRESS:443 | \
      sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/$ADDRESS.cert
    
  2. Run the following command, replace $ALIAS a short name for the key, $ADDRESS with the cert name from above, $PATH with the path to cacerts in your JRE.

     sudo keytool -importcert -alias "$ALIAS" -file /tmp/$ADDRESS.cert \
       -keystore $PATH/cacerts -storepass changeit
    

Leave a Comment