Install user certificate through ADB

Is there a way to install a CA certificate ( .crtfile) in Security -> Trusted Credential -> User tabvia ADB? or any other way of "scripting".

+10
source share
3 answers

I figured out a way to do this, so I was able to trust the charles proxy certificate. it will be added as a trusted root SSL certificate.

First you need to get a certificate hash

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

I use windows, save them in var variable to automate the process 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
+8
source

ADB , bash:

#!/bin/bash
openssl x509 -inform PEM -subject_hash_old -in charles-proxy-ssl-proxying-certificate.pem | head -1
cert_name=$(!!).0
cat charles-proxy-ssl-proxying-certificate.pem > $cert_name
openssl x509 -inform PEM -text -in charles-proxy-ssl-proxying-certificate.pem-out nul >> $cert_name
adb shell mount -o rw,remount,rw /system
adb push $cert_name /system/etc/security/cacerts/
adb shell mount -o ro,remount,ro /system
adb reboot

(, , , , , , )

+5

I managed to get the server certificate to display on the tab Trusted Credential -> User(and not on the system tab, as other answers show) by doing the following:

#!/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
0
source

All Articles