LineageOS 20/AOSP 生成并替换默认系统签名

LineageOS 20/AOSP 生成并替换默认系统签名


本文介绍如何将Lineageos中的testKey替换成releaseKey,基于LineageOS android13。

生成系统签名

LineageOS编译默认使用test-keys,位于build/target/product/security目录:

Android.bp                 networkstack.pk8       sdk_sandbox.x509.pem
Android.mk                 networkstack.x509.pem  shared.pk8
bluetooth.pk8              platform.keystore      shared.x509.pem
bluetooth.x509.pem         platform.p12           testkey.pk8
cts_uicc_2021.pk8          platform.pem           testkey.x509.pem
cts_uicc_2021.x509.pem     platform.pk8           verity_key
fsverity-release.x509.der  platform.x509.pem      verity.pk8
media.pk8                  README                 verity.x509.pem
media.x509.pem             sdk_sandbox.pk8

test-keys是公开的,任何app拿到testkey都可以使用系统签名,所以对外发布的版本需要使用自己生成的release-keys.
生成系统签名在android系统源码根目录执行下面的脚本:

subject='/C=CN/ST=Beijing/L=Beijing View/O=Xiaomi/OU=MIUI/CN=MIUI/emailAddress=miui@xiaomi.com'mkdir ~/.android-certsfor x in releasekey platform shared media networkstack; do \
    ./development/tools/make_key ~/.android-certs/$x "$subject"; \  done

上面脚本会在用户根目录下创建.android-certs目录,并在该目录下生成 releaseKey、platform、shared、media、networkstack几种key文件。提示输入密码直接回车即可。

lili@adam:~/.android-certs$ lsmedia.pk8         networkstack.x509.pem  releasekey.pk8       shared.x509.pem
media.x509.pem    platform.pk8           releasekey.x509.pem
networkstack.pk8  platform.x509.pem      shared.pk8

$subject 可以根据自己的公司信息修改。subject每个参数的代表的意思如下:

C —> Country Name (2 letter code)
ST —> State or Province Name (full name)
L —> Locality Name (eg, city)
O —> Organization Name (eg, company)
OU —> Organizational Unit Name (eg, section)
CN —> Common Name (eg, your name or your server’s hostname)
emailAddress —> Contact email address

以上每种key分别生成了两个文件,.x509.pem后缀的是证书文件,包含key的公共信息。.pk8后缀的是私钥。
android构建使用的5种key都在build/target/product/security目录下:

  • testKey
    包的默认签名

  • platform 平台核心包的test key

  • shared
    home/contracts进程共享内容的test key

  • media
    media/download系统的test key

  • networkstack
    网络系统的test key. 独立的包可以在其模块的Android.mk里面设置LOCAL_CERTIFICATE设置签名。

LOCAL_CERTIFICATE := platform

也可以指定key路基本:

LOCAL_CERTIFICATE := device/xiaomi/security/special

指定系统签名为release-Keys

首先,将上面生成的系统签名文件拷贝到 build/target/product/security目录下:

cd build/target/product/security  
cp -f ~/.android-certs/* ./

修改build/make/core/config.mk:

ifdef PRODUCT_DEFAULT_DEV_CERTIFICATE
  DEFAULT_SYSTEM_DEV_CERTIFICATE := $(PRODUCT_DEFAULT_DEV_CERTIFICATE) else
   DEFAULT_SYSTEM_DEV_CERTIFICATE := build/make/target/product/security/testkey
 endif

将上面配置替换成:

ifdef PRODUCT_DEFAULT_DEV_CERTIFICATE
  DEFAULT_SYSTEM_DEV_CERTIFICATE := $(PRODUCT_DEFAULT_DEV_CERTIFICATE) else
   DEFAULT_SYSTEM_DEV_CERTIFICATE := build/make/target/product/security/releasekey
 endif

替换完成后整编即可:

ili@adam:/p44pro/lineage/mi6$ source build/envsetup.sh 
lili@adam:/p44pro/lineage/mi6$ breakfast sagit 
Looking for dependencies in device/xiaomi/sagit
Looking for dependencies in device/xiaomi/msm8998-common
Looking for dependencies in hardware/xiaomi
hardware/xiaomi has no additional dependencies.
Looking for dependencies in kernel/xiaomi/msm8998
kernel/xiaomi/msm8998 has no additional dependencies.

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=13
LINEAGE_VERSION=20.0-20230722-UNOFFICIAL-sagit
TARGET_PRODUCT=lineage_sagit
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=generic
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-a
TARGET_2ND_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.19.0-46-generic-x86_64-Ubuntu-22.04.2-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=TQ3A.230605.012
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/xiaomi/msm8998-common hardware/xiaomi vendor/xiaomi/msm8998-common vendor/xiaomi/sagit hardware/qcom-caf/msm8998 vendor/qcom/opensource/data-ipa-cfg-mgr-legacy-um vendor/qcom/opensource/dataservices
============================================
lili@adam:/p44pro/lineage/mi6$ brunch sagit

生成android studio keystore文件

  1. 生成platform.pem

openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out platform.pem
  1. 生成p12文件

openssl pkcs12 -export -in platform.x509.pem -out platform.p12 -inkey platform.pem -password pass:密码 -name 别名
  1. 生成keystore

keytool -importkeystore -deststorepass 密码 -destkeystore ./platform3.keystore -srckeystore ./platform.p12 -srcstoretype PKCS12 -srcstorepass 密码

输入后当前目录下会生成 platform3.keystore文件。


Adam博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论
  • Powered by bjyblog modified by Adam © 2014-2024 www.lixiaopeng.com 版权所有 ICP证:鲁ICP备15039297号
  • 联系邮箱:14846869@qq.com