Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Java "PKIX path building failed: unable to find valid certification path to requested target": see what the server sends, then fix the trust store or the chain

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

When a Java client fails a TLS connection with PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target, Java could not link the server's certificate, through any intermediates, to a root in the trust store it is using. Three things can be wrong: the store lacks the right root, the server did not send an intermediate, or the application is reading a different store from the one you changed. Check what the server sends and which store is in use before importing anything.

What the error means

In the OpenJDK source at tag jdk-21+35, PKIXValidator builds a certificate path and, when that fails, throws a ValidatorException whose text begins PKIX path building failed: followed by the underlying exception. SunCertPathBuilder throws the inner one with the text unable to find valid certification path to requested target. A stack trace shows the two joined, which is the long line above. The message is the validator reporting that no path exists from the presented certificate to a trust anchor. Our own reading: in stack traces it usually sits under javax.net.ssl.SSLHandshakeException.

Which store holds the trust anchors is set by the JSSE rules. Oracle's JSSE Reference Guide says that if javax.net.ssl.trustStore is defined, that file is used. "If the javax.net.ssl.trustStore property is defined but the specified file does not exist, then a default TrustManager using an empty keystore is created." If the property is not set, java-home/lib/security/jssecacerts is used when it exists, otherwise java-home/lib/security/cacerts.

The keytool page says the cacerts file ships "with a set of root certificates issued by the CAs of the Oracle Java Root Certificate program", that "It is your responsibility to verify the trusted root CA certificates bundled in the cacerts file", and that if a certificate authenticating a CA's public key "hasn't been added to cacerts, then you must import a certificate from that CA as a trusted certificate". The JSSE guide adds that "Depending on the certificate configuration of the servers that you contact, you may need to add additional root certificates."

Likely causes

Our own reading of the common causes.

Cause What you see How to confirm
The server's CA is private, or its root is not in the store Only internal or self-signed servers fail; public sites work The issuer of the top certificate is not in the store listing
The server does not send its intermediate certificate One certificate only in the server's output; other clients may fail too keytool -printcert -sslserver shows no intermediate
The application reads a different store from the one you changed An earlier import had no effect The JVM's javax.net.ssl.trustStore property names another file
A named trust store file is missing or holds only your CA Every site fails, including public ones The file named by the property does not exist, or lists only a few entries
A proxy that inspects TLS presents its own certificate Failures appear only behind the proxy The issuer printed is the proxy's, not the site's

Prove the cause before changing anything

All of these read only.

1. See what the server sends. The keytool page says -printcert with -sslserver server[:port] reads and prints the certificate from the server, using port 443 when none is given. -keystore is an optional option of -printcert, and the command below does not use it:

keytool -printcert -sslserver api.example.com:443

Our own reading: it prints each certificate the server sends. Note the owner and issuer of each. A good result is a leaf certificate followed by its intermediate. A bad result is a leaf only, which points to a missing intermediate on the server.

2. Find which trust store the JVM uses. jcmd must run on the same machine and as the same user as the JVM, per its page. VM.system_properties prints the system properties (Impact: Low):

jcmd 4120 VM.system_properties

Look for javax.net.ssl.trustStore. If it is absent, the default order applies: jssecacerts if it exists, otherwise cacerts. If it is set, check that the file exists.

3. List what is in that store. The keytool page documents -list and says keytool -list -cacerts lists the default certificates; the initial cacerts password is changeit, and administrators are advised to change it. The command prompts for it. Use -keystore for a named file:

keytool -list -v -cacerts

Search the output for the issuer from step 1. A good result finds a root with that name. A bad result finds none.

Fix

Choose by the finding.

The server does not send its intermediate

This is fixed on the server, not in Java: the server must send its leaf and intermediate certificates. How depends on the server product, and the change belongs to its owner. Our own advice: do not import the intermediate into every client's store to work around it, because each client would then carry a fault the server owns.

The CA's root is missing from the store the application uses

Get the root certificate file from the CA's own site or your PKI team. The keytool page says to check it before importing: view it with -printcert, or run -importcert without -noprompt, and make sure "the displayed certificate fingerprints match the expected fingerprints". It warns that otherwise "you would be trusting anything that the attacker signed".

Two stores are possible: the default cacerts, or a named trust store that the application sets with javax.net.ssl.trustStore. Run only the save, the import and the undo that apply to the store in use.

First save the current state. If the application uses the default cacerts, save a copy of the store and its listing:

cp -p /opt/jdk-21/lib/security/cacerts /opt/jdk-21/lib/security/cacerts.2026-12-03
keytool -list -cacerts > cacerts-list-before.txt

If the application uses its own file, save a copy of that file and its listing instead; keytool prompts for the store password:

cp -p /opt/app01/conf/truststore.jks /opt/app01/conf/truststore.jks.2026-12-03
keytool -list -keystore /opt/app01/conf/truststore.jks > truststore-list-before.txt

Risk: the next command adds a certificate authority to the store the application trusts. Every certificate that CA signs becomes trusted by every application that uses this store, so import only a root you have verified. The cacerts file is shared by every Java program using this JDK. Our own reading: a running JVM reads its store once, so the application has to be restarted afterwards; a restart drops every request in flight. The keytool page documents -delete for removing an entry; the back-out below restores the saved copy instead.

Run only the command that applies. If the application uses the default cacerts:

keytool -importcert -cacerts -alias exampleroot -file example-root-ca.pem

If the application sets javax.net.ssl.trustStore to its own file, use that file in place of -cacerts:

keytool -importcert -keystore /opt/app01/conf/truststore.jks -alias exampleroot -file example-root-ca.pem

The command shows the certificate and asks whether to trust it; compare the fingerprint, then answer. Then restart the application the way you normally do: stop it, wait until its process has ended (our own advice), and start it.

Only if you need to back out, restore the saved copy of the store you changed. Run only the one that applies.

Risk: the next command overwrites the shared cacerts file with the saved copy, so every certificate authority added to it since the save is removed for every Java program using this JDK. The application has to be restarted afterwards, which drops every request in flight, in the same way as the restart after the import.

cp -p /opt/jdk-21/lib/security/cacerts.2026-12-03 /opt/jdk-21/lib/security/cacerts

Risk: the next command overwrites the application's trust store with the saved copy, so every certificate authority added to it since the save is removed. The application has to be restarted afterwards, which drops every request in flight, in the same way as the restart after the import.

cp -p /opt/app01/conf/truststore.jks.2026-12-03 /opt/app01/conf/truststore.jks

Nothing reads the restored store until that restart is done. Then run keytool -list -cacerts (or keytool -list -keystore /opt/app01/conf/truststore.jks) and compare it with cacerts-list-before.txt (or truststore-list-before.txt).

The application reads another store

If step 2 showed a javax.net.ssl.trustStore that names a file lacking the root, import into that file, as above. Do not set the property to a file that holds only your CA. The JSSE guide says the file named by the property is the store used. Our own reading: a file holding only your CA then trusts nothing else, so public sites fail.

Example (illustrative): On app01, a job calling https://api.example.com fails with the PKIX message, and public HTTPS calls from the same job work. keytool -printcert -sslserver api.example.com:443 shows a leaf issued by Example Issuing CA 1, then that CA's certificate, issued by Example Root CA. jcmd 4120 VM.system_properties shows no javax.net.ssl.trustStore, so the JVM uses cacerts; keytool -list -v -cacerts has no entry for Example Root CA. The PKI team supplies example-root-ca.pem, and the administrator checks its fingerprint against the one the PKI team states, saves cacerts and its listing, imports the root and restarts the job.

Confirm the fix

  1. keytool -list -cacerts (or the named file) shows the new alias.
  2. The failing call succeeds after the restart, with no PKIX line in the log.
  3. A public HTTPS call from the same application still works, which shows the store was not replaced by a short one.

What to watch afterwards

  • Our own reading: a JDK upgrade brings its own cacerts, and the JSSE guide says maintaining that file is your responsibility, so keep a record of what you added.
  • Root and intermediate certificates expire. Note their dates.
  • Our own reading: a separate trust store for each application avoids editing the file every Java program on the server shares.

Risks and limits

  • These commands have not been run or lab-tested.
  • Trusting a CA is a security decision. Verify the root's fingerprint through a second channel.
  • The message text comes from JDK 21 source; other releases may word it differently.
  • The behaviour described for default stores and properties is that of JDK 21's JSSE guide.

Sources