當我們需要進行OpenSSL認證時,需要將相應的CA certificate證書安裝到系統中,以便實現OpenSSL。證書安裝的地方兩種,分別是用戶級別和系統級別。若是安裝到“系統”級別中,可以帶來很大的方便。
現在講一下如何將CA證書安裝到Android的System中,前提是Android手機已經Root啦。
1.生成Android要求的證書格式
由於Android系統級別的證書文件名是以‘0’為后綴,以證書的hash值為名字,所以,我們需要根據證書生成對應的hash值,命令如下:
openssl x509 -inform PEM -subject_hash_old -in ***.pem | head -1
然后就會生成唯一的hash值,此處的***.pem,是當前的CA證書。假設:生成的hash值為845ea074,那么就像***.pem復制為845ea074.0
cp ***.pem 845ea074.0
2.將證書安裝到System中
重啟adb,作為root啟動
adb root
獲取Android設備上訪問/system的權限
在早期的Android版本中(API LEVEL < 28),需要使用如下命令獲得訪問權限:
adb shell "mount -o rw,remount /system"
API LEVEL >= 29,否則,使用如下命令:
adb shell "mount -o rw,remount /system"
將自己的證書push到系統證書目錄
adb push 845ea074.0 /system/etc/security/cacerts adb shell "chmod 664 /system/etc/security/cacerts/845ea074.0"
重啟Android系統
4.將電腦端的證書成為可信任證書
參考:https://jingyan.baidu.com/article/9f7e7ec0c1107c6f29155461.html
5.證書的唯一性
每個電腦上,使用Charles所產生的證書是不同的。一個比較好的方法是,將有效電腦上的證書復制到一台新的電腦上。
Charles的證書路徑為:AppData\Roaming\Charles\data\ca
6.問題
'/dev/block/dm-0' is read-only
需要輸入一下命令:
adb root adb disable-verity adb reboot
adb root adb remount adb shell mount -o rw,remount /system
這樣就確保了有system的訪問權限,然后再將證書安裝到指定目錄下,有兩種做法:
方法一:
adb push 845ea074.0 /system/etc/security/cacerts adb shell "chmod 664 /system/etc/security/cacerts/845ea074.0"
方法二:
直接通過Android Stuido中右下邊的“Device File Explorer”,將845ea074.0上傳到/system/etc/security/cacerts/中
In order to know build type of your android, in adb shell
enter the following command:
cat /system/build.prop | grep build.type
參考:
https://docs.mitmproxy.org/stable/howto-install-system-trusted-ca-android/
https://blog.csdn.net/xiangguiwang/article/details/76400805
https://www.jianshu.com/p/47fc5bb61f36?utm_campaign=hugo