SSLHandshakeException: trust anchor for certification path not found on Android
javax.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.
Fix it fast
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:4432Match what you see, then jump to its fix
- 1
The 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
Development or staging server with its own certificate; subject and issuer in the openssl output are the same.The certificate is self-signedFix - 3
Company 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
- 1
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:4432Fix
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 certificates3Verify
Reload the server and run the openssl command again: the chain now lists more than one certificate.
openssl s_client -connect example.com:443Confirmed by developer.android.com
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 -issuer2Fix
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 installDebugConfirmed by developer.android.com
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 -issuer2Fix
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 installDebugConfirmed by developer.android.com
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 fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
Gradle cannot apply the Android application or library plugin
Failed to apply plugin 'com.android.internal.application'.
Gradle loaded the Android Gradle plugin but could not run it.
2 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fix