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

Comments