Friday, December 14, 2012

Spring JavaMail - SSLHandshakeException, SunCertPathBuilderException

If you get the following exception, that means your Java run time doesn't trust the certificate.
javax.mail.MessagingException: Can't send command to SMTP host (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)

Get the cert:
openssl s_client -connect email-smtp.us-east-1.amazonaws.com:25 -starttls smtp > amazon_ses.cert

If you get
verify error:num=20:unable to get local issuer certificate

Open the file and copy everything between the following two lines:
-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

Save it to amazon_ses.cert.

Import the cert to Java

sudo keytool -import -alias [alias] -file [cert_file] -keystore [java_home]/lib/security/cacerts
Fill in the correct keystore password when prompted.

No comments:

Post a Comment