androidapk

Is it possible to strip a V2/V3 signature from APK and retain a valid V1 signature?


Based on my understanding of the the Android V1 (jarsigner-type) APK signature and V2/V3 APK signatures it seems like it should be possible to strip the APK Signing Block (which contains V2 and V3 signatures) from its location immediately before the ZIP Central Directory such that the V1 signature is still valid. Is that correct? If so perhaps there is an open source tool to do this already?


Solution

  • Theoretically you can remove an APKv2/v3 signature from an APK and keep only v1 signature. This can be done easily by unzipping the APK file and then zip it back to an ZIP/APK (alternatively it may be sufficient to use a ZIP modifying tool: add an arbitrary file to the ZIP that does not exist and then remove it. This should remove the v2/v3 signature date from a ZIP file). The old v1 signature will not be affected by this procedure.

    However when designing v2/v3 signatures Google considered such attacks and implemented a "Rollback Protection":

    An attacker could attempt to have a v2-signed APK verified as a v1-signed APK on Android platforms that support verifying v2-signed APK. To mitigate this attack, v2-signed APKs that are also v1-signed must contain an X-Android-APK-Signed attribute in the main section of their META-INF/.SF files. The value of the attribute is a comma-separated set of APK signature scheme IDs (the ID of this scheme is 2). When verifying the v1 signature, APK verifier is required to reject APKs which do not have a signature for the APK signature scheme the verifier prefers from this set (e.g., v2 scheme). This protection relies on the fact that contents META-INF/.SF files are protected by v1 signatures. See the section on JAR signed APK verification.

    An attacker could attempt to strip stronger signatures from the APK Signature Scheme v2 Block. To mitigate this attack, the list of signature algorithm IDs with which the APK was being signed is stored in the signed data block which is protected by each signature.

    Faking the v2/v3 signature is also not possible because the signature verification process is designed to only verify the APK signature of the highest available version as shown in the published diagram on the Google developer pages:

    APK signature verification process