Skip to content

PKIX path building failed (Java)

Key idea:

Java SSLException "PKIX path building failed: unable to find valid certification path to requested target" — Java cannot build the trust chain. JVM truststore ($JAVA_HOME/lib/security/cacerts) lacks the server's CA or intermediate. Fixes: (1) keytool -import into cacerts, (2) -Djavax.net.ssl.trustStore for an alternate truststore, (3) -Djavax.net.debug=ssl,handshake for diagnostics.

Below: details, example, related, FAQ.

Check your site's SSL →

Details

  • Default truststore: $JAVA_HOME/lib/security/cacerts, password "changeit"
  • JDK 8u101+ knows Let's Encrypt ISRG Root X1; older — does not
  • keytool -list -v -keystore cacerts — shows all trusted CAs
  • Per-app truststore: -Djavax.net.ssl.trustStore=/path/to/custom.jks
  • -Djavax.net.debug=ssl:handshake:verbose — full TLS debug

Example

# Download CA cert from server
$ echo | openssl s_client -connect server:443 -showcerts 2>/dev/null | \
    openssl x509 -out server-ca.crt

# Import into Java cacerts
$ sudo /bin/keytool -import \
    -alias server-ca \
    -keystore /lib/security/cacerts \
    -storepass changeit \
    -file server-ca.crt

# Debug app
$ java -Djavax.net.debug=ssl:handshake MyApp

Related

Understanding the PKIX Path Building Process

The PKIX path building process is crucial for establishing a secure SSL/TLS connection. This process involves constructing a chain of trust from the server's SSL certificate to a trusted root certificate stored in the Java truststore. Here’s how it works:

When a Java application attempts to establish an SSL connection, it first receives the server's certificate. The Java Virtual Machine (JVM) then checks if this certificate can be validated against the certificates in its truststore. If the server's certificate is issued by a Certificate Authority (CA) that is not in the truststore, the validation fails, resulting in the sun.security.validator.ValidatorException: PKIX path building failed error.

This process consists of several steps:

  • Certificate Retrieval: The server sends its SSL certificate during the handshake process.
  • Chain Verification: The JVM attempts to build a certificate chain from the server's certificate up to a trusted root certificate.
  • Truststore Check: Each certificate in the chain is checked against the JVM's truststore.

If any certificate in the chain is missing or untrusted, the PKIX path building will fail. To resolve this, ensure that all necessary CA and intermediate certificates are imported into the JVM's truststore.

Common Causes of PKIX Path Building Failures

Understanding the common causes of PKIX path building failed errors can help you troubleshoot SSL issues effectively. Here are the primary reasons:

  • Missing CA Certificates: The most common cause is the absence of the root or intermediate CA certificates in the JVM truststore. If the server's certificate is issued by a CA not recognized by the JVM, validation will fail.
  • Outdated Truststore: Sometimes, the truststore may not contain the latest CA certificates. Regular updates to the truststore are essential for maintaining trust.
  • Incorrect Truststore Path: If the application is configured to use a custom truststore, ensure that the path specified in the -Djavax.net.ssl.trustStore option is correct and accessible.
  • Self-Signed Certificates: When using self-signed certificates, they need to be explicitly imported into the truststore, as they are not trusted by default.

To prevent these issues, always verify the truststore contents and ensure that the necessary certificates are present. Using tools like keytool can help you manage and inspect your truststore efficiently.

Practical Commands for Resolving PKIX Path Building Issues

Resolving the PKIX path building failed error can often be accomplished with a few simple commands. Below are practical examples that demonstrate how to import certificates and configure the JVM:

1. Importing a Certificate into the Default Truststore

To import a server's certificate into the default JVM truststore, use the following command:

keytool -import -alias myserver -file server.crt -keystore $JAVA_HOME/lib/security/cacerts

When prompted, enter the truststore password, which is typically changeit.

2. Specifying an Alternate Truststore

If you prefer to use a custom truststore, you can specify its path when starting your Java application:

java -Djavax.net.ssl.trustStore=/path/to/custom.truststore -Djavax.net.ssl.trustStorePassword=yourpassword -jar yourapp.jar

3. Enabling SSL Debugging

To gain insights into the SSL handshake process and diagnose issues, enable SSL debugging by adding the following option:

-Djavax.net.debug=ssl,handshake

This will provide detailed logs of the SSL connection attempts, helping you identify where the PKIX path building is failing.

Using these commands, you can effectively manage your truststore and troubleshoot SSL connection issues related to PKIX path building.

CertificateExpiry, issuer, domains (SAN)
ChainIntermediate and root CA validation
TLS ProtocolTLS version and cipher suite
VulnerabilitiesHeartbleed, POODLE, weak ciphers

Why teams trust us

TLS 1.3
supported
Full
CA chain check
<2s
result
30/14/7
days-to-expiry alerts

How it works

1

Enter domain

2

TLS chain verified

3

Expiry date & vulnerabilities

What Does the SSL Check Cover?

SSL/TLS is the encryption protocol that protects data between the browser and server. Our tool analyzes the certificate, chain of trust, TLS version, and knownvulnerabilities.

Certificate Details

Issuer, validity period, signature algorithm, covered domains (SAN), and validation type (DV/OV/EV).

Chain of Trust

Full chain verification: from leaf certificate through intermediates to root CA.

TLS Analysis

Protocol version (TLS 1.2/1.3), cipher suites, Perfect Forward Secrecy (PFS) support.

Expiry Alerts

Set up a monitor — get Telegram and email alerts 30/14/7 days before expiration.

DV vs OV vs EV Certificates

DV (Domain Validation)
  • Confirms domain ownership only
  • Issued in minutes automatically
  • Free via Let's Encrypt
  • Suitable for most websites
  • Most common certificate type
OV / EV
  • Organization (OV) or Extended Validation (EV)
  • Issued in 1-5 business days
  • Costs $50 to $500/year
  • For finance, e-commerce, government sites
  • Increases user trust

Who uses this

DevOps

SSL certificate monitoring

Security

TLS config audit

SEO

HTTPS as ranking factor

E-commerce

customer trust

Common Mistakes

Expired certificateBrowsers block sites with expired SSL. Set up auto-renewal or monitoring.
Incomplete certificate chainWithout intermediate CA, some browsers and bots cannot verify the certificate.
Mixed content on HTTPS siteHTTP resources on an HTTPS page — the browser lock icon disappears, reducing trust.
Using TLS 1.0/1.1Legacy TLS versions have known vulnerabilities. Use TLS 1.2+ or 1.3.
Domain mismatch in certificateThe certificate must cover all site domains, including www and subdomains.

Best Practices

Set up auto-renewalLet's Encrypt + certbot with cron — certificate renews automatically every 60-90 days.
Enable HSTSStrict-Transport-Security header forces browsers to always use HTTPS.
Use TLS 1.3TLS 1.3 is faster (1-RTT handshake) and safer — legacy ciphers removed.
Monitor expiration datesCreate a monitor on Enterno.io — get notified well before expiration.
Verify chain after renewalAfter certificate renewal, confirm that intermediate certificates are installed.

Get more with a free account

SSL certificate monitoring, check history and alerts 30 days before expiry.

Sign up free

Learn more

Sources

Frequently Asked Questions

How to avoid editing the system cacerts?

Copy into an app-specific jks + -Djavax.net.ssl.trustStore. JDK updates won't reset it.

Self-signed dev/test?

For dev: a TrustManager that accepts everything. Never ship that in prod code.

Maven / Gradle?

-Djavax.net.ssl.trustStore in MAVEN_OPTS / GRADLE_OPTS, or <jvmArgs> in the build files.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.