Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use provided upload_cert.der to sign a release Android APK file

I've just enrolled in the Google Play App Signing program, which required uploading an encrypted version of the release keystore and had an "optional" step for creating an upload keystore - optional is in quotes, because I think it should be a required step, but anyway, after a successful enrollment, I'm now left with an Upload certificate, which I should somehow use to sign my future app releases.

What I've done so far: I created a new keystore from Android Studio, set the store and alias passwords and tried to import the upload_cert.der to the existing alias - failed:

keytool -importcert -file upload_cert.der -alias upload -keystore upload-keystore.jks

keytool error: java.lang.Exception: Public keys in reply and keystore don't match

I've also tried to import the upload certificate without specifying an alias (or removing the existing alias and creating a new one), or with a different alias:

keytool -importcert -file upload_cert.der -keystore upload-keystore.jks

...failed as well: ended up creating a new alias called mykey, which wasn't password protected and failed with the message:

Caused by: java.lang.RuntimeException: com.android.ide.common.signing.KeytoolException: Failed to read key upload from store "/path/to/upload-keystore.jks": trusted certificate entries are not password-protected

...so naturally, I tried to set a password for the alias:

keytool -keypasswd -alias upload -keystore upload-keystore.jks

which failed as well with the message:

keytool error: java.lang.Exception: Alias has no key

...and now I've run out of ideas.

In the meantime, I've sent a question/request to Google Play Support to renew my upload key, but, I'm hoping there is a solution to this situation (the support is kinda slow to reply), since the documentation doesn't imply in any way that generating an upload keystore and uploading the encrypted private key of that key store is a requirement. So, either the documentation is vague/unclear/wrong, or there is a way to use the generated upload_cert.der. Any thoughts?

Edit:

Thanks to the answer and comment provided by Pierre, I realized that if you do not create/provide an upload key, your existing original signing key should be used, with the upload_cert.der. So, the only requirement would be to insert the upload certificate by running:

keytool -importcert -file upload_cert.der -keystore original-signing-keystore.jks

...and you should be able to continue publishing your applications to the Play Store.

like image 312
Bojan Ilievski Avatar asked Jun 29 '18 18:06

Bojan Ilievski


People also ask

How do I sign an unsigned APK?

Sign an APK You can include this information in two different ways: Specify a KeyStore file using the --ks option. Specify the private key file and certificate file separately using the --key and --cert options, respectively. The private key file must use the PKCS #8 format, and the certificate file must use the X.

How do I find the signature of an APK file?

Verifying an APK signature The correct way to verify an APK file is to use apksigner . apksigner is part of the Android build tools, therefore you may find multiple versions installed, one for each build-tools version installed. For more details on how to get apksigner see last chapter of this answer.


1 Answers

The .der file you uploaded to the Play Console (and that is also available for download in the App Signing page in the Play Console) does not contain the private key, it only contains the public key, so you won't be able to sign anything with it.

Only the keystore you created to generate your upload certificate contains the private key and must be used to sign your APKs (or App Bundles).

In other words, you shouldn't create another keystore after enrollment in Play Signing, you should use the keystore you have created to generate the upload certificate to sign your future artifacts.

Hope that helps.

like image 131
Pierre Avatar answered Sep 19 '22 04:09

Pierre