We're working on a Cordova app and having difficulty signing the Android version of the app.
Using the command
jarsigner -keystore keystore.p12 -storetype pkcs12 android-release-unsigned.apk 1
gives the following exception
java.io.IOException: DerInputStream.getLength(): Redundant length bytes found
which comes from this line in OpenJDK apparently this was added to fix CVE-2016-5546 although I don't know enough about crypto to really understand it.
Exporting the certificate with openssl and creating a new p12 from that works fine but changes the signature which means the play store rejects the upload.
The keystore we have came from another company that we originally outsourced the app development to.
Any jarsigner or keytool command throws the same exception which I guess makes sense since they all use the same Java lib
I have spent hours finding a solution to this problem. Tried five different JDKs and nothing worked. I have an old PKCS12 certificate for a very popular playstore app that I have "inherited" from the previous developer, and JDK 8 + 9 will not use it. Olexandr's solution didn't help either.
Finally, almost by shear luck, I managed to find a solution here, in Weijung Wang's reponse. It involves exporting and reimporting the certificate using openssl. I then reimported the P12 keystore in the JKS keystore and it now works with JDK 8.
Quote:
I have keystore generated with JDK6. As workaround, I have been using JDK 1.8.0_112 by setting JDK under [Project Structure] - [SDK Location] - [JDK location].
I have solved with steps below (using macOS).
Convert to PKCS12 using JDK 1.8.0_112
Process with OpenSSL (Thanks to Weijung Wang and Anders Emil)
Convert to JKS using JDK 1.8.0_161.
Here I need to specify -destkeypass, -srcalias, and -destalias. Note that alias is "1" after openSSL commands, so needed to set alias.
So the results of fingerprints shows like this.
I have been having the same error, and Olexandr's solution wouldn't work, as using keytool on JDK8 (update 151) would throw an error while reading the certificate, which was generated with JDK7. As from Anders answer, using OpenSSL worked with (pasting the command lines for future reference) :
We had the same problem. We have found that JDK 1.8.0_112 doesn't have the bug that you're talking about. So we resolved the problem in this way:
At first we converted
temp_keystore.p12
intomycert.keystore
by using the following command (Java\jdk1.8.0_112\bin\keytool.exe
):Then we use the following command (
Java\jdk1.8.0_112\bin\jarsigner.exe)
:to sign
apk
. ("1
" at the end of command is the alias)PS.: Converting from
.p12
to.keystore
may be not necessary.