@@ -20,38 +20,47 @@ set_context() {
2020 fi
2121}
2222
23- chown -R 0:0 ${MODDIR} /system/etc/security/cacerts
24- set_context /system/etc/security/cacerts ${MODDIR} /system/etc/security/cacerts
23+ merge_ca_certs () {
24+ target_path=" $1 "
25+ tmpfs_path=" $2 "
2526
26- # Android 14 support
27- # Since Magisk ignore /apex for module file injections, use non-Magisk way
28- if [ -d /apex/com.android.conscrypt/cacerts ]; then
29- # Clone directory into tmpfs
30- rm -f /data/local/tmp/sys-ca-copy
31- mkdir -p /data/local/tmp/sys-ca-copy
32- mount -t tmpfs tmpfs /data/local/tmp/sys-ca-copy
33- cp -f /apex/com.android.conscrypt/cacerts/* /data/local/tmp/sys-ca-copy/
34-
35- # Do the same as in Magisk module
36- cp -f ${MODDIR} /system/etc/security/cacerts/* /data/local/tmp/sys-ca-copy
37- chown -R 0:0 /data/local/tmp/sys-ca-copy
38- set_context /apex/com.android.conscrypt/cacerts /data/local/tmp/sys-ca-copy
39-
40- # Mount directory inside APEX if it is valid, and remove temporary one.
41- CERTS_NUM=" $( ls -1 /data/local/tmp/sys-ca-copy | wc -l) "
27+ rm -f " ${tmpfs_path} "
28+ mkdir -p " ${tmpfs_path} "
29+ mount -t tmpfs tmpfs " ${tmpfs_path} "
30+ cp -f " ${target_path} " /* " ${tmpfs_path} /"
31+
32+ cp -f ${MODDIR} /system/etc/security/cacerts/* " ${tmpfs_path} "
33+ chown -R 0:0 " ${tmpfs_path} "
34+ set_context " ${target_path} " " ${tmpfs_path} "
35+
36+ CERTS_NUM=" $( ls -1 " ${tmpfs_path} " | wc -l) "
4237 if [ " $CERTS_NUM " -gt 10 ]; then
43- mount --bind /data/local/tmp/sys-ca-copy /apex/com.android.conscrypt/cacerts
38+ mount --bind " ${tmpfs_path} " " ${target_path} "
4439 for pid in 1 $( pgrep zygote) $( pgrep zygote64) ; do
4540 nsenter --mount=/proc/${pid} /ns/mnt -- \
46- mount --bind /data/local/tmp/sys-ca-copy /apex/com.android.conscrypt/cacerts
41+ mount --bind " ${tmpfs_path} " " ${target_path} "
4742 done
4843 else
49- echo " Cancelling replacing CA storage due to safety"
44+ echo " Cancelling replacing ${target_path} due to safety"
5045 fi
5146 for pid in 1 $( pgrep zygote) $( pgrep zygote64) ; do
5247 nsenter --mount=/proc/${pid} /ns/mnt -- \
53- umount /data/local/tmp/sys-ca-copy
48+ umount " ${tmpfs_path} "
5449 done
55- umount /data/local/tmp/sys-ca-copy
56- rmdir /data/local/tmp/sys-ca-copy
50+ umount " ${tmpfs_path} "
51+ rmdir " ${tmpfs_path} "
52+ }
53+
54+ chown -R 0:0 ${MODDIR} /system/etc/security/cacerts
55+ set_context /system/etc/security/cacerts ${MODDIR} /system/etc/security/cacerts
56+
57+ # Android 14+ APEX Conscrypt store
58+ # Since Magisk ignores /apex for module file injections, use non-Magisk way
59+ if [ -d /apex/com.android.conscrypt/cacerts ]; then
60+ merge_ca_certs /apex/com.android.conscrypt/cacerts /data/local/tmp/sys-ca-copy
61+ fi
62+
63+ # System CA store (for Flutter/dart:io HttpClient and other legacy clients)
64+ if [ -d /system/etc/security/cacerts ]; then
65+ merge_ca_certs /system/etc/security/cacerts /data/local/tmp/sys-ca-copy-system
5766fi
0 commit comments