
手摸手教你高版本安卓安装 Charles 证书
众所周知(其实以前我也不知道), 在安卓 7 以上, 系统收敛了证书权限. 也就是说你在 Charles 下载了证书, 然后通过手机安装, 只会安装到用户列表中, 而安卓只信任系统级别的证书, 所以你安装的证书仍然不能访问 HTTPS.
解决方案


这里使用小米 11 PRO 来演示. 首先你得把手机 root 掉, 当然猴米比较蛋疼, 得先解锁手机, 解锁手机需要先用小米账号申请, 申请成功后需要等待 168 小时(7 天) 才能解锁(注意解锁手机会抹掉手机数据); 解锁完毕后, 就可以在手机安装开发版 ROM 了, 注意这个 ROM 普通小米账号下载不到, 得是深度玩家账号. 因此我建议去某宝租一个小米账号, 一把梭. 这里不多赘述解锁和 root, 都是泪.
打开 Charles, 首先把证书下载下来.

然后在终端执行下面的脚本. 注意, 下面的脚本是我从网上看到了, 然鹅我电脑的 openssl 是 v2.8.3(可通过 openssl version 查看版本), 但通过第二个脚本解析出来的不能用, 但第一个成功了, 很迷.
#openssl版本在<1.0执行上面 openssl x509 -inform PEM -subject_hash_old -in xxx.pem #openssl版本>1.0 执行下面 openssl x509 -inform PEM -subject_hash -in xxx.pem

记录上面图片中红框的 hash 值 `1dcbf3b0`
, 将你的 `xxx.pem`
重命名成 `1dcbf3b0.0`
待用.
在电脑上安装 `adb`
, 这玩意儿可以让你通过脚本跟安卓手机进行交互. 然后数据线连接你的手机, 记得打开 USB 调试模式.
`brew install --cask android-platform-tools
`
在终端执行 `adb devices`
, 不出意外能看到你的手机, 找不到说明你手机没插好.

然后执行 `adb root`
, 来切换到 root 模式.

使用 `adb disable-verify`
禁用安卓的系统验证.

使用 `adb remount`
重新挂载下手机, 如果下一步执行不了, 可以执行下该步骤.

最后通过如下命令, 将你修改后的证书传到系统认证根证书列表中.
`adb push Downloads/1dcbf3b0.0 /system/etc/security/cacerts/
`

重启下手机, 就会发现系统下已经安装了 Charles 的证书. 愉快地抓包吧~


PREVIOUS POST
Introducing GraphQL

NEXT POST
《重学前端》学习笔记