Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

SSLHandshakeException: trust anchor for certification path not found on Android

Errorjavax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Short answer

Android could not build a chain from your server certificate to a CA it trusts. There are three documented reasons: the issuing CA is unknown, the certificate is self-signed, or the server does not send its intermediate certificate. Fix the server chain, or add your own CA through a network security config. Do not disable certificate checks.

  • Applies to Android 14, Android 15, Android Studio
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look at the certificate chain your server really sends. One certificate only, from a public CA, usually means the intermediate is missing.

    openssl s_client -connect example.com:443
  2. 2Match what you see, then jump to its fix

    1. 1The chain printed by openssl shows only the server certificate; desktop browsers still open the site, but the Android app fails.The server does not send its intermediate certificateFix
    2. 2Development or staging server with its own certificate; subject and issuer in the openssl output are the same.The certificate is self-signedFix
    3. 3Company or school CA, or a new public CA on an old Android version.The issuing CA is private or not known to this Android versionFix

What does the error look like?

  • javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Cause 1 of 3

The server does not send its intermediate certificate

1Check

Public CAs rarely sign server certificates directly. The server should send the intermediates too. Desktop browsers cache intermediates, which hides the problem there.

openssl s_client -connect example.com:443

2Fix

Configure the web server to send the full chain, the server certificate followed by the intermediate certificates. Your CA documents how to do this for common servers.

# nginx: ssl_certificate must point to a file that holds the
# server certificate followed by the intermediate certificates

3Verify

Reload the server and run the openssl command again: the chain now lists more than one certificate.

openssl s_client -connect example.com:443

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

The certificate is self-signed

1Check

A self-signed certificate makes the server its own CA, which the system does not know.

openssl s_client -connect staging.example.com:443 | openssl x509 -noout -subject -issuer

2Fix

Put the certificate (PEM or DER) in res/raw and trust it for that domain in a network security config. Do it for debug builds only if you can, with debug-overrides.

<!-- res/xml/network_security_config.xml -->
<network-security-config>
    <debug-overrides>
        <trust-anchors>
            <certificates src="@raw/debug_cas"/>
        </trust-anchors>
    </debug-overrides>
</network-security-config>

3Verify

Install a debug build and repeat the request.

./gradlew installDebug

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 3

The issuing CA is private or not known to this Android version

1Check

Compare the issuer from openssl with the CAs your device trusts. A private CA is unknown to Android by design.

openssl s_client -connect example.com:443 | openssl x509 -noout -issuer

2Fix

Add the CA certificate as a trust anchor for your domain, keeping the system CAs for everything else.

<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">example.com</domain>
        <trust-anchors>
            <certificates src="@raw/my_ca"/>
        </trust-anchors>
    </domain-config>
</network-security-config>

<!-- AndroidManifest.xml -->
<application android:networkSecurityConfig="@xml/network_security_config" ...>

3Verify

Rebuild, then repeat the HTTPS request on the device.

./gradlew installDebug

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Never ship a TrustManager that accepts every certificate. It lets anyone on a public Wi-Fi network pose as your server.
  • After each certificate renewal, check the served chain with openssl, not only with a desktop browser.
  • Keep test certificates in debug-overrides so a release build never trusts them.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android app crashes because the Apache HTTP classes are missing

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.