From 7e89b0c61c8f918913c97adce5407a1c618f1b57 Mon Sep 17 00:00:00 2001 From: qiuyuyang910 Date: Sat, 18 May 2024 19:37:18 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#4=20=E6=94=AF=E6=8C=81=E5=AE=89=E5=8D=93?= =?UTF-8?q?14=E4=BB=A5=E4=B8=8B=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- post-fs-data.sh | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/post-fs-data.sh b/post-fs-data.sh index 73b4b46..816625a 100644 --- a/post-fs-data.sh +++ b/post-fs-data.sh @@ -1,5 +1,13 @@ #!/system/bin/sh + +exec > /data/local/tmp/ProxyPinCA.log +exec 2>&1 + +#set -x + +MODDIR=${0%/*} + set_context() { [ "$(getenforce)" = "Enforcing" ] || return 0 @@ -13,18 +21,17 @@ set_context() { fi } -LOG_PATH="/data/local/tmp/ProxyPinCA.log" -echo "[$(date +%F) $(date +%T)] - ProxyPinCA post-fs-data.sh start." > $LOG_PATH - +#LOG_PATH="/data/local/tmp/ProxyPinCA.log" +echo "[$(date +%F) $(date +%T)] - ProxyPinCA post-fs-data.sh start." +chown -R 0:0 ${MODDIR}/system/etc/security/cacerts if [ -d /apex/com.android.conscrypt/cacerts ]; then # 检测到 android 14 以上,存在该证书目录 CERT_HASH=243f0bfb - MODDIR=${0%/*} CERT_FILE=${MODDIR}/system/etc/security/cacerts/${CERT_HASH}.0 - echo "[$(date +%F) $(date +%T)] - CERT_FILE: ${CERT_FILE}" >> $LOG_PATH + echo "[$(date +%F) $(date +%T)] - CERT_FILE: ${CERT_FILE}" if ! [ -e "${CERT_FILE}" ]; then - echo "[$(date +%F) $(date +%T)] - ProxyPinCA certificate not found." >> $LOG_PATH + echo "[$(date +%F) $(date +%T)] - ProxyPinCA certificate not found." exit 0 fi @@ -34,24 +41,30 @@ if [ -d /apex/com.android.conscrypt/cacerts ]; then mount -t tmpfs tmpfs "$TEMP_DIR" # 复制证书到临时目录 - cp -f /apex/com.android.conscrypt/cacerts/* /data/local/tmp/cacerts-copy/ + cp -f /apex/com.android.conscrypt/cacerts/* "$TEMP_DIR" cp -f $CERT_FILE "$TEMP_DIR" chown -R 0:0 "$TEMP_DIR" set_context /apex/com.android.conscrypt/cacerts "$TEMP_DIR" # 检查新证书是否成功添加 - CERTS_NUM="$(ls -1 /data/local/tmp/cacerts-copy | wc -l)" + CERTS_NUM="$(ls -1 "$TEMP_DIR" | wc -l)" if [ "$CERTS_NUM" -gt 10 ]; then mount -o bind "$TEMP_DIR" /apex/com.android.conscrypt/cacerts - echo "[$(date +%F) $(date +%T)] - $CERTS_NUM Mount success!" >> $LOG_PATH + for pid in 1 $(pgrep zygote) $(pgrep zygote64); do + nsenter --mount=/proc/${pid}/ns/mnt -- \ + mount --bind "$TEMP_DIR" /apex/com.android.conscrypt/cacerts + done + echo "[$(date +%F) $(date +%T)] - $CERTS_NUM Mount success!" else - echo "[$(date +%F) $(date +%T)] - $CERTS_NUM Mount failed!" >> $LOG_PATH + echo "[$(date +%F) $(date +%T)] - $CERTS_NUM Mount failed!" fi # 卸载临时目录 umount "$TEMP_DIR" rmdir "$TEMP_DIR" else - echo "[$(date +%F) $(date +%T)] - /apex/com.android.conscrypt/cacerts not exists." + echo "[$(date +%F) $(date +%T)] - Android version lower than 14 detected" + set_context /system/etc/security/cacerts ${MODDIR}/system/etc/security/cacerts + echo "[$(date +%F) $(date +%T)] - Mount success!" fi \ No newline at end of file