Gangmax Blog

SunCertPathBuilderException: unable to find valid certification path to requested target

Today I got an error when running a Java application on a new CentOS server:

1
SunCertPathBuilderException: unable to find valid certification path to requested target

Here is the solution.

From here and here.

  1. Download the “InstallCert.java” file from here.

  2. Run it as below:

1
2
3
4
5
6
7
8
9
# Compile.
javac InstallCert.java
# Access server, and retrieve certificate (accept default certificate 1).
java InstallCert [host]:[port]
# Extract certificate from created jssecacerts keystore.
keytool -exportcert -alias [host]-1 -keystore jssecacerts -storepass changeit -file [host].cer
# Import certificate into system keystore.
keytool -importcert -alias [host] -keystore [path to system keystore] -storepass changeit -file [host].cer
# In my environment the "keystore" is "/etc/pki/ca-trust/extracted/java/cacerts".

Comments