Android 7.1.2 ROM 预置 CA证书
总体步骤
1、Android 支持以 .crt 或 .cer 文件格式 X.509 证书。
2、将.crt 或 .cer 转换为*.0文件
(1).crt格式文件
a. openssl x509 -inform PEM -subject_hash_old -in CA_Name.crt | head -1
得到类似字符串:9a5ba575
b.cat CA_Name.crt(或者CA_Name.cer) > 9a5ba575.0
c.openssl x509 -inform PEM -text -in CA_Name.crt -out /dev/null >> 9a5ba575.0
d.放入/system/ca-certificates/files/
(2).cer(非.crt)格式文件
a. openssl x509 -inform DER -subject_hash_old -in CA_Name.cer | head -1
得到类似字符串:9a5ba575
b.cat CA_Name.cer > 9a5ba575.0
c.openssl x509 -inform DER -text -in CA_Name.cer -out /dev/null >> 9a5ba575.0
d.放入/system/ca-certificates/files/
实际测试,可能会报错,报错后不管格式,DER 换成PEM 试试
编译到:/system/etc/security/cacerts/
e:烧录重启验证
http://wiki.cacert.org/FAQ/ImportRootCert#CAcert_user_trusted_certificates
3、源码(Android 7.0)文件夹路径:/system/ca-certificates/files/
124bbd54.0
12d55845.0
1676090a.0
17b51fe6.0
1dac3003.0
…
4、新建文件夹/system/ca-certificates/QS5509-QL/files/
---QS5509-QL/QS5509-QL/files/
---Android.mk
实例:
1. 在 Burp 中设置 Proxy
设置 Proxy - Options - Proxy Listeners,让它监听合适的地址和端口,并且选择 “Generate CA-signed per-host certificates”。
2. 在 Mac 或 PC 中安装 Burp 的 CA
将浏览器代理指向Burp proxy,访问任意一个https地址, 如 https://www.baidu.com. 由于 Burp 此时将自己的根证书(PortSwiggerCA)签发一个目标服务器的证书,替换了真正服务器的证书。浏览器应该会有安全报警,因为系统并不信任签发这个证书的CA。查看证书详细信息,选择根证书并且信任这个根证书,就会把PortSwiggerCA的证书加入到系统的信任列表中.
或者
将浏览器代理指向Burp proxy, 让问 http://burp/cert, 浏览器将会下载 cacert.der, 改名为PortSwiggerCA.der
或者
Proxy –> Options –> CA Certificate –> Certificate in DER format –> Next –> Select File –> cacert.der –> Save –> Next –> Close
3. 在 Android 中安装 CA
Android Phone 中安装 CA 有两种方式:
a. user
b. system
a. User
一般情况下, 我们都可以以 user 方式安装 CA. CA 需要是 crt 格式.
要将这个根证书装进Android,需要先从系统 key chain 里将它导出到文件(.pem格式),然后执行下面的命令将它转换为DER格式后缀为.crt的文件。
- $ openssl x509 -in PortSwigger.der -out PortSwigger.crt -outform PEM -inform DER
接下来,将 PortSwiggerCA.crt 放入Android的sdcard.
Settings - General - Security - Install from device storage
在系统安全菜单中安装证书。证书安装后,Android系统就会信任所有Burp签发的证书了。
这种方式, 有个局限就是需要用户开启手势解锁.
b. System
- 需要 Root
获取 Burp CA 的 hash
'''
-
// if your CA is in PEM format
-
$ openssl x509 -inform PEM -subject_hash_old -in PortSwiggerCA.pem | head -1
-
// if your CA is in DER format
-
$ openssl x509 -inform DER -subject_hash -in PortSwiggerCA.der | head -1
'''
结果是9a5ba575.
教程中说, 需要使用
-subject_hash_old
, 但是实际操作中, 我发现只能使用-subject_hash
否则会报错.(note the use of '-subject_hash_old' instead of '-subject_hash', to get an openssl 0.9 compatible hash)
-
// if your CA is not crt format
-
$ openssl x509 -inform DER -in PortSwiggerCA.der -out PortSwiggerCA.crt
-
// We will use this hash value, append '.0' (dot zero) and use this as the filename for the resulting Android certificate:
-
$ cat PortSwiggerCA.crt > 9a5ba575.0
-
$ openssl x509 -inform PEM -text -in PortSwiggerCA.crt -out /dev/null >> 9a5ba575.0
用数据线连接 Android Phone
-
// Copy the files to the /sdcard folder
-
$ adb push 9a5ba575.0 /sdcard/
-
$ adb shell
-
// Gain superuser/root rights, neccessary to perform privileged actions:
-
su
-
// Make the /system folder writable (will return to read-only upon reboot):
-
mount -o remount,rw /system
-
// Copy the new certificate files to the correct folder on your Android device
-
cp /sdcard/9a5ba575.0 /system/etc/security/cacerts/
-
chmod 644 /system/etc/security/cacerts/9a5ba575.0
检查 CA 是否正常
- $ ls -al -Z
</pre>
重启手机
参考
- How to Import Burp's CA Certificate Into Android Devices
- Installing CAcert certificates on Android as 'system' credentials without lockscreen - instructions
- 拦截Android应用HTTPS通讯内容
- Installing Burp's CA Certificate (official, but useless)
- How can I trust CAcert's root certificate?
- Manually Install SSL Certificate in Android Jelly Bean
- http://www.realmb.com/droidCert/
- Man-in-the-Middle (MiTM) and certificate setup on Android 4.0
- Android Phones & Tablets ImportRootCert
- Installing a new trusted SSL root certificate on Android
网友评论