Use default Trust manager and fallback to user installed CA#7044
Merged
Conversation
PR #6753 changed the OkHttp trust manager from the platform default (TrustManagerFactory.init(null)) to one seeded from AndroidCAStore, which bypasses Android's network_security_config-aware validation and rejects otherwise-valid server certificates. Use the platform default trust manager as the authoritative path again, and add a composite fallback that trusts only user-installed CAs, consulted solely for certificates the platform rejects. This restores correct certificate validation while still honoring user-installed CAs on ROMs that do not surface them through the default path. Fixes #6810 Re #5565
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the app’s TLS configuration to use Android’s default trust manager (restoring proper chain building and network_security_config behavior) while adding a targeted fallback that trusts only user-installed CAs on ROMs where the default path does not honor them.
Changes:
- Switch OkHttp TLS setup back to the platform default trust manager and add a user-installed-CA-only fallback trust manager.
- Introduce
CompositeX509ExtendedTrustManagerto consult a fallback trust manager only when the primary rejects withCertificateException. - Add unit tests for the composite trust manager and for filtering
AndroidCAStoreentries to user-installed CAs; add a StrictMode ignore rule for the keystore disk read during OkHttp configuration.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/TLSHelper.kt | Reworks OkHttp TLS setup to use the default trust manager and optionally wrap it with a user-CA-only fallback; adds helpers for keystore loading/filtering. |
| common/src/main/kotlin/io/homeassistant/companion/android/common/data/CompositeX509ExtendedTrustManager.kt | Adds a composite trust manager that retries server validation against a fallback only after primary CertificateException. |
| common/src/test/kotlin/io/homeassistant/companion/android/common/data/CompositeX509ExtendedTrustManagerTest.kt | Adds unit tests covering fallback decision logic and error propagation/suppression behavior. |
| common/src/test/kotlin/io/homeassistant/companion/android/common/data/TLSHelperTest.kt | Adds unit tests for filtering user-installed CA entries from a keystore. |
| app/src/main/kotlin/io/homeassistant/companion/android/util/IgnoreViolationRules.kt | Ignores a StrictMode disk-read violation triggered during OkHttp client configuration (keystore access). |
jpelgrom
approved these changes
Jun 18, 2026
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
This PR is mostly the work of @bpacholek (thanks for the initial PR #7024), with the comments addressed.
It basically use the default TrustManager from Android instead of getting a snapshot of the
AndroidCAStorethat we started using in #6753. Using this snapshot caused users with cert containing only part of the chain aSSL handshake faileddescribe in #6810.Fixes #6810
Re #5565 (I tested again the flow and custom CA are still working)
Checklist
Any other notes
To reproduce the issue fixed if you are using certbot with Let's encrypt you can simply swap the
fullchain.pemwith thecert.pem.