INSTALL_PARSE_FAILED_NO_CERTIFICATES failure installing modified apk file (invalid SHA1 signature), even after signing with jarsigner

后端 未结 2 1442
逝去的感伤
逝去的感伤 2020-12-30 16:55

I know there are a lot of other people experiencing the INSTALL_PARSE_FAILED_NO_CERTIFICATES error when they forget to sign their apk. This is not the problem I\'m describi

相关标签:
2条回答
  • 2020-12-30 17:04

    I have delete the file CERT.SF/CERT.RSA/MANIFEST.MF,and re-sign,and it goes well.

    0 讨论(0)
  • 2020-12-30 17:24

    Ok, after a bit of digging, here's what I found...

    When instrumenting a previously signed application, but using a new keystore to sign it, there is a problem. Specifically, we end up with multiple signing manifests in \meta-inf that all point to the same set of files. The app fails to install with the error INSTALL_PARSE_FAILED_NO_CERTIFICATES.

    If you look at the signing manifest, you see two files:

    once-signed apk file

    Now, we modify classes.dex and sign the app with our own keystore:

    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore android_new_sample.keystore AndroidWorld-release-final.apk asample
    Enter Passphrase for keystore: mypass
     updating: META-INF/ASAMPLE.SF
     updating: META-INF/ASAMPLE.RSA
      signing: assets/x.js
      signing: assets/xx.css
      signing: assets/special_offers.html
      signing: res/layout/displayjourneylist.xml
      signing: res/layout/journey_row.xml
      signing: res/layout/login.xml
      signing: res/layout/searchjourney.xml
      signing: res/layout/settings.xml
      signing: res/layout/webview.xml
      signing: res/layout/window_title.xml
      signing: res/menu/option_menu.xml
      signing: AndroidManifest.xml
      signing: resources.arsc
      signing: res/drawable-hdpi/header.png
      signing: res/drawable-hdpi/ic_launcher.png
      signing: res/drawable-ldpi/header.png
      signing: res/drawable-ldpi/ic_launcher.png
      signing: res/drawable-mdpi/header.png
      signing: res/drawable-mdpi/ic_launcher.png
      signing: classes.dex
      signing: assets/xxx.properties
    

    No problems so far, we have all of the new signatures added to the manifest. However, attempting to verify the integrity of this apk now fails:

    jarsigner.exe -verify -verbose -certs C:\apk\AndroidWorld-release-signed.apk
    jarsigner: java.lang.SecurityException: invalid SHA1 signature file digest for classes.dex
    

    The reason is that we now have duplicate signing information in \meta-inf:

    twice-signed apk file

    So classes.dex has 2 different signatures, one in Asample.sf, and one in Cert.sf:

    Name: classes.dex (ASample.cf) 
    SHA1-Digest: mTf659/NTkTqqsAEZc3gTlbRpW8=
    
    Name: classes.dex (Cert.sf)
    SHA1-Digest: hkAsCEcLyM52Q6gq2uQIqc/7Gh8=
    

    This causes verification and installation to fail. If I delete Cert.rsa and Cert.sf from the archive, it will verify and install. So the solution was to modify the zipfile and remove the original signing cert, leaving only my own.

    0 讨论(0)
提交回复
热议问题