diff options
| author | CrypticC3s4r <27031384+CrypticC3s4r@users.noreply.github.com> | 2024-12-28 20:12:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-28 21:12:19 +0200 |
| commit | 82f1f61c6b3dc9b4c073e57049dd46967be18013 (patch) | |
| tree | 6b9b808383653e4739ed17ce87381a9284dd0fc8 | |
| parent | a1a3a7e0f402850091885e5ac088ad7af1f5d27a (diff) | |
| download | karakeep-82f1f61c6b3dc9b4c073e57049dd46967be18013.tar.zst | |
fix(mobile): Add support for self signed certs in android. Fixes #381 (#416)
Co-authored-by: MohamedBassem <me@mbassem.com>
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | apps/mobile/app.json | 1 | ||||
| -rw-r--r-- | apps/mobile/plugins/network_security_config.xml | 9 | ||||
| -rw-r--r-- | apps/mobile/plugins/trust-local-certs.js | 43 |
4 files changed, 59 insertions, 1 deletions
@@ -3,6 +3,7 @@ # dependencies node_modules .pnp +.pnpm-store .pnp.js .yarn/install-state.gz @@ -53,4 +54,8 @@ data # Idea .idea *.iml -.aider* + +# Aider +.vscode + +# VS-Code diff --git a/apps/mobile/app.json b/apps/mobile/app.json index 87db856f..c1dc6bf9 100644 --- a/apps/mobile/app.json +++ b/apps/mobile/app.json @@ -51,6 +51,7 @@ "versionCode": 20 }, "plugins": [ + "./plugins/trust-local-certs.js", "./plugins/camera-not-required.js", "expo-router", [ diff --git a/apps/mobile/plugins/network_security_config.xml b/apps/mobile/plugins/network_security_config.xml new file mode 100644 index 00000000..bb6ab93d --- /dev/null +++ b/apps/mobile/plugins/network_security_config.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<network-security-config> + <base-config cleartextTrafficPermitted="true"> + <trust-anchors> + <certificates src="system" /> + <certificates src="user" /> + </trust-anchors> + </base-config> +</network-security-config>
\ No newline at end of file diff --git a/apps/mobile/plugins/trust-local-certs.js b/apps/mobile/plugins/trust-local-certs.js new file mode 100644 index 00000000..40275034 --- /dev/null +++ b/apps/mobile/plugins/trust-local-certs.js @@ -0,0 +1,43 @@ +const { AndroidConfig, withAndroidManifest } = require("@expo/config-plugins"); +const { Paths } = require("@expo/config-plugins/build/android"); +const path = require("path"); +const fs = require("fs"); +const fsPromises = fs.promises; + +const { getMainApplicationOrThrow } = AndroidConfig.Manifest; + +const withTrustLocalCerts = (config) => { + return withAndroidManifest(config, async (config) => { + config.modResults = await setCustomConfigAsync(config, config.modResults); + return config; + }); +}; + +async function setCustomConfigAsync(config, androidManifest) { + const src_file_pat = path.join(__dirname, "network_security_config.xml"); + const res_file_path = path.join( + await Paths.getResourceFolderAsync(config.modRequest.projectRoot), + "xml", + "network_security_config.xml", + ); + + const res_dir = path.resolve(res_file_path, ".."); + + if (!fs.existsSync(res_dir)) { + await fsPromises.mkdir(res_dir); + } + + try { + await fsPromises.copyFile(src_file_pat, res_file_path); + } catch (e) { + throw e; + } + + const mainApplication = getMainApplicationOrThrow(androidManifest); + mainApplication.$["android:networkSecurityConfig"] = + "@xml/network_security_config"; + + return androidManifest; +} + +module.exports = withTrustLocalCerts; |
