Created
July 26, 2023 16:17
-
-
Save Forgo7ten/19a444b9de51d5c321426e1b38bc322f to your computer and use it in GitHub Desktop.
用于快速的转换证书并放入Android设备中
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 检查是否提供了文件名参数 | |
if [ -z "$1" ]; then | |
echo "请提供证书文件名作为参数!" | |
exit 1 | |
fi | |
# 获取输入文件名和扩展名 | |
input_file="$1" | |
file_name="${input_file%.*}" | |
extension="${input_file##*.}" | |
# 如果是cer证书文件,则转换为pem证书。(因为系统中是pem文件) | |
if [ "$extension" = "cer" ]; then | |
openssl x509 -inform der -in "$input_file" -out "$file_name.pem" | |
echo "***** Certificate conversion completed." | |
fi | |
# 计算证书的hashcode | |
hash=$(openssl x509 -subject_hash_old -in "$file_name.pem" | head -n 1 | cut -c 1-8) | |
# 放入设备中 [hash].0 | |
adb push "$file_name.pem" "/sdcard/${hash}.0" | |
# 由于不确定是否有root权限,或者磁盘已经挂载;所以这部分交由用户复制执行。 | |
echo "***** Execute the following command as su:" | |
echo "mount -o rw,remount /" | |
echo "mv /sdcard/${hash}.0 /system/etc/security/cacerts/" | |
echo "cd /system/etc/security/cacerts/" | |
echo "chmod 644 ${hash}.0" | |
echo "chown root:root ${hash}.0" | |
echo "***** Done!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment