Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daubac402/500046e83594db336c22c79205ce3225 to your computer and use it in GitHub Desktop.
Save daubac402/500046e83594db336c22c79205ce3225 to your computer and use it in GitHub Desktop.

Make Java project works with Self-signed certificate in IntelliJ

Problem

Your company is using a proxy to decrypt the HTTPS in between. It has a self-signed certificate. You will get this kind of Exception when sending a HTTPS request if your Java project doesn't have that self-signed certificate in its CaCerts

detailed message sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

cause 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

Solution steps

Locate your self-signed certificate

It should be a .cer file.
If you don't have it, it has been installer in your PC's trusted root certificate store, you can export it (to Base64 .cer format) from there.

Locate your JAVA_HOME CaCerts that your Java project is using

In IntelliJ, go to File -> Project Structure -> SDKs -> JDK home path.
Your final cacerts path should be something like this (Windows): /c/Users/your_name/.jdks/openjdk-x.y.z/lib/security/cacerts

Import the self-signed certificate to the JAVA_HOME CaCerts

keytool -importcert -trustcacerts -alias any_alias_name_you_want -file your_self_signed_certificate.cer -keystore your_final_jdk_cacerts_path -storepass any_password_you_want
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment