Android: trust user-installed CA certs via Network Security Config#248
Open
skylord123 wants to merge 1 commit into
Open
Android: trust user-installed CA certs via Network Security Config#248skylord123 wants to merge 1 commit into
skylord123 wants to merge 1 commit into
Conversation
Since Android 7.0 (API 24), apps only trust the system CA store by default. PKJS apps connecting to self-hosted servers with a self-signed or private-CA cert (e.g. Home Assistant over wss://) fail to connect even after the user installs and trusts the cert on their device, because the WebView and its WebSocket connections ignore the user CA store. Add a Network Security Config that trusts both the system and user stores and reference it from the manifest's application tag.
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.
Problem
On Android, PKJS apps that open
https/wssconnections to a server using a self-signed or private-CA cert fail to connect, even after the user installs and trusts that cert on their device.Since Android 7.0 (API 24), apps only trust the system CA store by default. The app targets
targetSdk = 35and ships no Network Security Config, so the WebView that runs PKJS (and its WebSocket connections) ignores the user CA store. The cert is trusted by the device but ignored by the app, and there's nothing the user can do on-device to fix it.This came up with a Home Assistant PKJS app where users self-host with self-signed certs. The WebSocket fails the TLS handshake and closes immediately (abnormal close, 1006).
Fix
Add a Network Security Config that trusts the user store alongside the system store, and reference it from the manifest's
<application>tag.composeApp/src/androidMain/res/xml/network_security_config.xml:Manifest:
iOS already honors user-trusted roots (NSURLSession, once "Full Trust" is enabled), so this brings Android in line.
Notes