版权归作者所有,如有转发,请注明文章出处:https://cyrus-studio.github.io/blog/
为什么需要使用 release key
test-key 是一个公开的、众所周知的开发测试密钥,广泛用于测试阶段。这意味着任何人都可以获取这个密钥,并用它签署自己修改的 APK 或系统文件。
使用 test-key 签署的系统镜像通常无法通过 Google 的 CTS(兼容性测试套件)认证,Google Play 商店、Google 服务框架等应用可能无法正常运行,某些第三方应用(例如银行应用或数字版权管理应用)也可能拒绝在设备上运行。
OTA 更新包必须使用 Release Key 来签名。签名的更新包经过验证,只有具有相同 Release Key 的设备才能接收和安装更新。
生成 release key
执行 nano make_keys.sh 创建脚本,内容如下
subject='/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=linchaolong.dev@gmail.com'
# 创建 keys 目录(如果不存在)
mkdir -p keys
for cert in bluetooth cyngn-app media networkstack nfc platform releasekey sdk_sandbox shared testcert testkey verity; do \
./development/tools/make_key keys/$cert "$subject"; \
done
通过脚本创建 keys 目录并使用 make_key 命令生成你自己的密钥。
运行脚本生成密钥文件。
# 添加执行权限
chmod +x make_keys.sh
# 运行脚本
./make_keys.sh
为了避免密码解密的复杂性,生成一个未加密的私钥,防止签名过程提示输入密码。
Enter password for 'keys/bluetooth' (blank for none; password will be visible):
creating keys/bluetooth.pk8 with no password
Enter password for 'keys/cyngn-app' (blank for none; password will be visible):
creating keys/cyngn-app.pk8 with no password
Enter password for 'keys/media' (blank for none; password will be visible):
creating keys/media.pk8 with no password
Enter password for 'keys/networkstack' (blank for none; password will be visible):
creating keys/networkstack.pk8 with no password
Enter password for 'keys/nfc' (blank for none; password will be visible):
creating keys/nfc.pk8 with no password
Enter password for 'keys/platform' (blank for none; password will be visible):
creating keys/platform.pk8 with no password
Enter password for 'keys/releasekey' (blank for none; password will be visible):
creating keys/releasekey.pk8 with no password
Enter password for 'keys/sdk_sandbox' (blank for none; password will be visible):
creating keys/sdk_sandbox.pk8 with no password
Enter password for 'keys/shared' (blank for none; password will be visible):
creating keys/shared.pk8 with no password
Enter password for 'keys/testcert' (blank for none; password will be visible):
creating keys/testcert.pk8 with no password
Enter password for 'keys/testkey' (blank for none; password will be visible):
creating keys/testkey.pk8 with no password
Enter password for 'keys/verity' (blank for none; password will be visible):
creating keys/verity.pk8 with no password
生成的密钥都在 keys 目录下,每条命令会生成两个文件:一个 .x509.pem 公钥证书文件和一个 .pk8 私钥文件:
-
releasekey:主要用于签署系统中的所有 APK 文件,确保这些 APK 来自可信任的来源。
-
platform:签署系统框架和其他核心组件,确保这些组件未被篡改。
-
shared:用于签署需要跨应用共享 UID 的 APK,例如具有相同签名的应用可以共享数据。
-
media:专门用于签署与多媒体相关的 APK 文件。
-
networkstack:用于签署与网络堆栈相关的组件和应用,确保网络功能的安全性。
-
testkey:这是 Android 系统中的默认密钥,主要用于开发和测试环境下的签名,但不应在生产环境中使用。
-
cyngn-priv-app:可能与 CyanogenMod 或 LineageOS 特定的私有应用签名有关。
-
bluetooth:用于签署蓝牙服务或相关的 APK 文件。
-
sdk_sandbox:签署与 SDK 沙箱相关的应用或组件,确保开发环境的安全。
-
verity:用于签署与 Verified Boot 相关的组件,确保设备启动时的安全性。
ls keys
bluetooth.p