Skip to content

Use default Trust manager and fallback to user installed CA#7044

Merged
TimoPtr merged 9 commits into
mainfrom
feature/use_default_keystore_and_fallback_to_user
Jun 18, 2026
Merged

Use default Trust manager and fallback to user installed CA#7044
TimoPtr merged 9 commits into
mainfrom
feature/use_default_keystore_and_fallback_to_user

Conversation

@TimoPtr

@TimoPtr TimoPtr commented Jun 18, 2026

Copy link
Copy Markdown
Member

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 AndroidCAStore that we started using in #6753. Using this snapshot caused users with cert containing only part of the chain a SSL handshake failed describe in #6810.

Fixes #6810
Re #5565 (I tested again the flow and custom CA are still working)

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Any other notes

To reproduce the issue fixed if you are using certbot with Let's encrypt you can simply swap the fullchain.pem with the cert.pem.

bpacholek and others added 5 commits June 18, 2026 08:15
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CompositeX509ExtendedTrustManager to consult a fallback trust manager only when the primary rejects with CertificateException.
  • Add unit tests for the composite trust manager and for filtering AndroidCAStore entries 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 jpelgrom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed in #7038

@TimoPtr TimoPtr enabled auto-merge (squash) June 18, 2026 08:12
@TimoPtr TimoPtr merged commit fef3058 into main Jun 18, 2026
37 of 39 checks passed
@TimoPtr TimoPtr deleted the feature/use_default_keystore_and_fallback_to_user branch June 18, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssl handshake failed

5 participants