一:签名类型
android的标准签名key有:
testkey
media
platform
shared
以上的四种,可以在源码的/build/target/product/security里面看到对应的密钥,其中shared.pk8代表私钥,shared.x509.pem公钥,一定是成对出现的。
其中testkey是作为android编译的时候默认的签名key,如果系统中的apk的android.mk中没有设置LOCAL_CERTIFICATE的值,就默认使用testkey。
而如果设置成:
LOCAL_CERTIFICATE := platform
就代表使用platform来签名,这样的话这个apk就拥有了和system相同的签名,因为系统级别的签名也是使用的platform来签名,此时使用android:sharedUserId="android.uid.system"才有用!
二:自定义签名Key
在/build/target/product/security目录下有个README,里面有说怎么制作这些key以及使用问题(android4.2):
The following commands were used to generate the test key pairs:
development/tools/make_key testkey '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
development/tools/make_key platform '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
development/tools/make_key shared '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
development/tools/make_key media '/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
The following standard test keys are currently included:
testkey -- a generic key for packages that do not otherwise specify a key.
platform -- a test key for packages that are part of the core platform.
shared -- a test key for things that are shared in the home/contacts process.
media -- a test key for packages that are part of the media/download system.
These test keys are used strictly in development, and should never be assumed
to convey any sort of validity. When $BUILD_SECURE=true, the code should not
honor these keys in any context.
或者执行命令:
subject='/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
mkdir ~/.android-certs
for x in releasekey platform shared media networkstack; do \
./development/tools/make_key ~/.android-certs/$x "$subject"; \
done
然后把相关文件拷贝到/build/target/product/security目录
来自:签名版本以供发布 | Android 开源项目 | Android Open Source Project
从上面可以看出来在源码下的/development/tools目录下有个make_key的脚本,通过传入两个参数就可以生成一对签名用的key。
其中第一个为key的名字,一般都默认成android本身有的,因为很多地方都默认使用了这些名字,我们自定义的话只需要对第二个参数动手脚,定义如下:
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
另外在使用上面的make_key脚本生成key的过程中会提示输入password,我的处理是不输入,直接enter,不要密码!后面解释,用自定义的key替换/security下面的。
可以看到android源码里面的key使用的第二个参数就是上面README里面的,是公开的,所以要release版本的系统的话,肯定要有自己的签名key才能起到一个安全控制作用。
三、修改系统默认签名key
在上面提到如果apk中的编译选项LOCAL_CERTIFICATE没有设置的话,就会使用默认的testkey作为签名key,我们可以修改成自己想要的key,按照上面的步骤制作一个releasekey.
通过在源码根目录搜索关键字:
grep -rn "test-keys" ./*
修改android配置在/build/core/config.mk中定义变量:
DEFAULT_SYSTEM_DEV_CERTIFICATE := build/target/product/security/releasekey
在主/build/core/makefile文件里面:
ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/target/product/security/releasekey)
BUILD_VERSION_TAGS += release-keys
或者直接在pixelexperience aosp里面文件修改
vim ./vendor/aosp/build/core/main_version.mk
把BUILD_SIGNATURE_KEYS := test-keys
ifneq ($(filter OFFICIAL,$(CUSTOM_BUILD_TYPE)),)
BUILD_SIGNATURE_KEYS := release-keys
else
BUILD_SIGNATURE_KEYS := release-keys
endif
这样的话默认的所有签名将会使用releasekey。
最后重新编译系统。
安装系统:
来自:Install PixelExperience on alioth - PixelExperience Wiki
1、Flashing the vendor boot partition(当前不是pixelexperience系统时需要操作)
fastboot flash vendor_boot <vendor_boot>.img
2、Flash a recovery on your device by typing (replace <recovery_filename>
with the actual filename!):
fastboot flash boot boot.img
3、Now reboot into recovery to verify the installation
fastboot reboot-recovery
4、Installing PixelExperience from recovery
- Now tap Factory Reset, then Format data / factory reset and continue with the formatting process. This will remove encryption and delete all files stored in the internal storage, as well as format your cache partition (if you have one).
- On the device, select “Apply Update”, then “Apply from ADB” to begin sideload.
- On the host machine, sideload the package using:
adb sideload filename.zip
Android系统10 RK3399 init进程启动(三十五) 属性文件介绍和生成过程_旗浩的技术博客_51CTO博客
参考:[原创]源码编译(4)——root指纹定制和抹除-Android安全-看雪论坛-安全社区|安全招聘|bbs.pediy.com (kanxue.com)