Repository navigation
[Android] Avoid eager trust-anchor enumeration in certificate-chain builds - #135928
Merged
Merged
Conversation
Resolve candidate anchors against a fresh AndroidCAStore, retain independent PKIX validation and full-store fallback, and keep custom trust isolated. Add concurrent system-chain, fallback, policy, and expiry coverage in the existing test project. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use the platform-validated root only as a temporary hint, independently recheck live system membership and PKIX policy, and retain callback certificate ownership. Cover system-hint lifetimes and custom trust, hostname, policy, and callback behavior in the existing Android TLS test project. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The managed ExtraStore handle array already contains the target. Skip candidates referring to that same Java certificate during anchor discovery without changing the certificate store or independent validation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger |
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Revocation-triggered fallback needs regression coverage verifying fresh checker/error state and the final validation result.
1 open finding
What changed in this PR
Reduces Android certificate-chain setup overhead by trying verified system-anchor hints before enumerating the full trust store.
Changes:
- Adds targeted anchor lookup with fresh full-store fallback.
- Passes temporary TLS anchor hints without granting trust or exposing them to application callbacks.
- Adds Android chain, policy, and certificate-ownership tests.
Validation here was limited to source inspection; no builds or tests were run.
| File | Description |
|---|---|
| src/native/libs/System.Security.Cryptography.Native.Android/pal_x509chain.h | Declares targeted-trust and fallback interfaces. |
| src/native/libs/System.Security.Cryptography.Native.Android/pal_x509chain.c | Implements anchor lookup and fresh fallback state. |
| src/native/libs/System.Security.Cryptography.Native.Android/pal_trust_manager.h | Extends callback signatures with anchor hints. |
| src/native/libs/System.Security.Cryptography.Native.Android/pal_trust_manager.c | Verifies hints and manages callback references. |
| src/native/libs/System.Security.Cryptography.Native.Android/pal_jni.h | Declares new Java method bindings. |
| src/native/libs/System.Security.Cryptography.Native.Android/pal_jni.c | Registers bindings and updated callback signature. |
| src/native/libs/System.Security.Cryptography.Native.Android/net/dot/android/crypto/DotnetProxyTrustManager.java | Forwards the platform-selected server anchor. |
| src/libraries/System.Security.Cryptography/tests/X509Certificates/ChainTests.cs | Tests supplied anchors, fallback, policies, and concurrency. |
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ChainPal.Android.cs | Retries targeted failures using full-store parameters. |
| src/libraries/System.Net.Security/tests/AndroidPlatformTrustTests/System.Net.Security.AndroidPlatformTrust.Tests.csproj | Includes HTTP test configuration. |
| src/libraries/System.Net.Security/tests/AndroidPlatformTrustTests/AndroidPlatformTrustTests.cs | Tests certificate ownership and custom-trust policies. |
| src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Android.cs | Scopes anchor hints to synchronous validation. |
| src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Android.cs | Temporarily supplies hints during chain building. |
| src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.X509Chain.cs | Marshals trust selection and build outcomes. |
| src/libraries/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Ssl.cs | Updates the managed callback signature. |
🧠 Review effort: Balanced
This was referenced Oct 16, 2026
Closed
wfurt
approved these changes
Oct 17, 2026
Member
Author
|
/azp run runtime-android |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Reduce Android certificate-chain setup overhead by avoiding full AndroidCAStore enumeration when a supplied certificate identifies a usable system trust anchor.
Constructing PKIXBuilderParameters directly from AndroidCAStore enumerates its certificate entries and materializes every trust anchor. On the investigated Samsung A16, this setup took approximately 123 ms, substantially more than the subsequent path-building operation.
This change:
No cross-build trust-store, root-certificate, or mutable PKIX-state cache is introduced. No public API changes are included.
Performance
An earlier prototype measured offline system-trust X509Chain.Build at a median of 169.819 ms before the change and 8.166 ms afterward, approximately a 95% reduction.
These measurements used a Samsung SM-A165F running Android 16/API 36, arm64 CoreCLR, Release/full trimming, and three fresh processes with eight samples each. Revocation checking and certificate downloads were disabled for this offline comparison.
The physical-device figures describe the earlier prototype, not a rerun of the final three-commit series. They demonstrate the cost of eager trust-anchor setup; they are not evidence of a historical .NET regression.
Validation
The final local series was built for Android arm64 CoreCLR Release, including the native, Java, and managed changes. Both affected test projects were rebuilt.
On an API 35 arm64 emulator:
Coverage includes supplied/missing anchors, fallback from an unrelated trusted anchor, policy and expiry failures, concurrent builders, custom-trust isolation, hostname/policy rejection, and callback-certificate ownership.
The final series has not been rerun on the physical device. The new tests do not directly exercise revocation-triggered fallback.
Related to dotnet/android#12934.
Note
This description was drafted with GitHub Copilot.
/cc @wfurt @vcsjones