【问题标题】:Install User Certificate Via ADB通过 ADB 安装用户证书
【发布时间】:2017-12-10 02:29:08
【问题描述】:

有没有办法通过ADB在Security -> Trusted Credential -> User tab下安装CA证书(.crt文件)?或任何其他“可编写脚本”的方式。

【问题讨论】:

  • 问题解决了吗?
  • 静默安装证书的唯一方法是通过设备策略管理器,只有应用程序 (.apks) 可以注册为 DPM,所以很遗憾,经过长时间的研究,我走到了死胡同。@MohamedELAYADI
  • 我想出了一个办法; openssl x509 -inform PEM -subject_hash_old -in charles-proxy-ssl-proxying-certificate.pem | head -1>toto set /p totoVar= %totoVar% echo %totoVar% openssl x509 -inform PEM -text -in charles-proxy-ssl-proxying-certificate.pem -out nul >> %totoVar% adb shell mount -o rw,remount,rw /system adb push %totoVar% /system/etc/security/cacerts/ adb shell mount -o ro,remount,ro /system adb reboot

标签: android certificate adb x509certificate


【解决方案1】:

就我而言,我首先需要将模拟器启动为可写:

adb start-server
emulator -writable-system -avd Pixel_2_API_24

然后就可以安装证书了:

adb root
adb remount
adb push c8750f0d.0 /system/etc/security/cacerts

https://docs.mitmproxy.org/stable/howto-install-system-trusted-ca-android

【讨论】:

    【解决方案2】:

    感谢Install User Certificate Via ADB这个答案,我能够改编一个适用于 bash shell 的脚本:

    PEM_FILE_NAME=logger-charles-cert.pem
    hash=$(openssl x509 -inform PEM -subject_hash_old -in $PEM_FILE_NAME | head -1)
    OUT_FILE_NAME="$hash.0"
    
    cp $PEM_FILE_NAME $OUT_FILE_NAME
    openssl x509 -inform PEM -text -in $PEM_FILE_NAME -out /dev/null >> $OUT_FILE_NAME
    
    echo "Saved to $OUT_FILE_NAME"
    adb shell mount -o rw,remount,rw /system
    adb push $OUT_FILE_NAME /system/etc/security/cacerts/
    adb shell mount -o ro,remount,ro /system
    adb reboot
    

    (是的,我知道这应该是评论,但我还没有足够的声誉将其作为评论发布)

    【讨论】:

    • 我收到了这个错误。 ./ssl_pinning.sh: line 3: !!: command not found head: cert_name=.0: No such file or directory
    • @Gorio 您可能会发现this script 很有帮助。您肯定需要对其进行一些更新(我无法将生成的文件复制到 AVD 的 /system 分区,但使用 Genymotion 成功了)。
    【解决方案3】:

    通过以下步骤,我能够获得 服务器 证书以显示在 Trusted Credential -> User 选项卡下(而不是其他答案显示的系统选项卡):

    #!/bin/bash
    subjectHash=`openssl x509 -inform PEM -subject_hash_old -in server.crt | head -n 1`
    openssl x509 -in server.crt -inform PEM -outform DER -out $subjectHash.0
    adb root
    adb push ./$subjectHash.0 /data/misc/user/0/cacerts-added/$subjectHash.0
    adb shell "su 0 chmod 644 /data/misc/user/0/cacerts-added/$subjectHash.0"
    adb reboot
    

    【讨论】:

    • +1 在血统 android 10 上进行了测试,就像一个魅力。重启后不要忘记点击Trusted Credential -> User中的“信任”
    【解决方案4】:

    我想出了一种方法来做到这一点,因此我能够信任 charles 代理证书。它将被添加为受信任的 SSL 根证书。

    首先你需要获取证书哈希

    openssl x509 -inform PEM -subject_hash_old -in charles-proxy-ssl-proxying-certificate.pem | head -1>toto
    

    我使用 windows,将其存储在一个 var 中以自动化该过程set /p totoVar=<toto

    set totoVar=%totoVar%.0 && DEL toto
    
    cat charles-proxy-ssl-proxying-certificate.pem > %totoVar%
    
    openssl x509 -inform PEM -text -in charles-proxy-ssl-proxying-certificate.pem -out nul >> %totoVar%
    
    adb shell mount -o rw,remount,rw /system
    
    adb push %totoVar% /system/etc/security/cacerts/
    
    adb shell mount -o ro,remount,ro /system
    
    adb reboot
    

    【讨论】:

    • "adb shell mount -o rw,remount,rw /system" 不正确,应该使用"adb shell mount -o rw,remount /system"
    • 我还必须将证书的权限设置为 644 才能使其工作。否则无法识别证书。
    • @Incepter 我没看到,证书安装在哪里?我看到 PEM 证书被推送到 cacerts 文件夹中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 2015-11-03
    • 2022-11-06
    相关资源
    最近更新 更多