Android - Signing an apk with Platfom key

If you sign your app with platform key, you can get system permissions. such as like below.

<!-- Allows applications to call into AccountAuthenticators.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.ACCOUNT_MANAGER"
    android:protectionLevel="signature" />

Or, you can set your UserId to "android.uid.system" meaning the "android" package. because your app is signed with platform key.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="my.app"
    android:sharedUserId="android.uid.system"

The ways introduced here are only available in the android emulator, not for devices sold in the market.

You need to get 2 files in "/build/target/product/security" in AOSP sources.

  • platform.x509.pem
  • platform.pk8

You can sign your app with these files or you can generate "jsk" file and use it in Android Studio when you sign it.

Sign your app with 2 files

If you get platform.pk8, app-debug.apk, then you need to download the tool called Apk Sign. You can download signapk.jar file in this page.

You can sign it with platform key like below. you have to provide the unsigned apk file "app-unsigned.apk". and Signed apk file "app-signed.apk" will be created.

$ java -jar signapk.jar platform.x509.pem platform.pk8 app-unsigned.apk app-signed.apk

Generate jks file

Type below commands to created a jks file called platform.jks.

$ openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out platform.pem
$ openssl pkcs12 -export -in platform.x509.pem -inkey platform.pem -out platform.p12 -password pass:android -name platform
$ keytool -importkeystore -deststorepass android -destkeystore platform.jks -srcstoretype PKCS12 -srcstorepass android -srckeystore

You can register this jks file in Android Studio and use it to sign an app.

In the above commands, key alias, key store password and key password are defined as follows. Of course, you can change these.

key store password: android
key alias: platform
key password: android

Note that this platform key applies to Android Image compiled with AOSP sources. It will not work with Android emulator images provided by Android studio.

References

Related Posts

codechachaCopyright ©2019 codechacha