How to resolve 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 exception when using HTTP API of Mailgun in Java applications?
Environment
JDK 1.8.0_40
Spring Boot 1.2.5
Problem
Solution #1
Upgrade your JRE/JDK to 8u91 (or higher), which includes this CA root.
Solution #2
Download the CA certificate manually like this:
Import the “DigiCert Global Root G2”. You can download the root from DigiCert Root Certificates. Ensure you are downloading the correct root certificate.
Once the certificate is downloaded, you’ll need to import it using a command like the following:
Reason
Because Symantec’s PKI infrastructure becomes untrusted, we now need the “DigiCert Global Root G2” certificate. Some older versions of Java do not have the “DigiCert Global Root G2” CA. So you should upgrade your JDK/JRE or download and import the certificate manually into the existing JRE/JDK.
Summary
The javax.net.ssl.SSLHandshakeException: PKIX path building failed error occurs when the Java application cannot establish a trusted SSL connection due to a missing CA certificate. This post provides two solutions: upgrading the JDK/JRE to a version that includes the required certificate or manually importing the “DigiCert Global Root G2” certificate. Both methods ensure that your Java application can establish a secure connection with services like Mailgun.
Final Words + More Resources
My intention with this article was to help others who might be considering solving such a problem.
So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by
email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope: