commit | ad82f37021a0b66d57f52746fc1ac34c809ba534 | [log] [tgz] |
---|---|---|
author | Michael Groover <mpgroover@google.com> | Tue Feb 26 18:47:34 2019 -0800 |
committer | Michael Groover <mpgroover@google.com> | Wed Mar 20 18:52:12 2019 -0700 |
tree | 6281a9a31df6f7c1e6df1562e6f10f95e2294ddd | |
parent | b6b4a0a9a66e6afd49413b5d611c14e4b4d43802 [diff] |
Reencode negative modulus in APK signing block to allow app updates The V2 and V3 signature schemes verify the public key from the signature block against the public key in the certificate that acts as the signature / identity for the app. If the certificate is incorrectly encoded with a negative modulus (the modulus has a leading 1 in the encoding without a preceding zero byte to encode the integer as positive), then the V2 / V3 signature verification will fail as the public key will be reencoded with a positive modulus which will not match the key in the signature block. This change adds support for this improper encoding by reencoding the modulus for the public key that is written in the signature block to ensure the public key verification is successful on device. Bug: 80184678 Test: Manually verified a certificate with a negative modulus could be used to sign and install APKs with the V2 and V3 signature schemes. Change-Id: I24df8e30ed52a8034e75bd8f72cbd76209bb0db7
apksig is a project which aims to simplify APK signing and checking whether APK signatures are expected to verify on Android. apksig supports JAR signing (used by Android since day one) and APK Signature Scheme v2 (supported since Android Nougat, API Level 24). apksig is meant to be used outside of Android devices.
The key feature of apksig is that it knows about differences in APK signature verification logic between different versions of the Android platform. apksig thus thoroughly checks whether an APK's signature is expected to verify on all Android platform versions supported by the APK. When signing an APK, apksig chooses the most appropriate cryptographic algorithms based on the Android platform versions supported by the APK being signed.
The project consists of two subprojects:
apksig library offers three primitives:
ApkSigner
which signs the provided APK so that it verifies on all Android platform versions supported by the APK. The range of platform versions can be customized.ApkVerifier
which checks whether the provided APK is expected to verify on all Android platform versions supported by the APK. The range of platform versions can be customized.(Default)ApkSignerEngine
which abstracts away signing APKs from parsing and building APKs. This is useful in optimized APK building pipelines, such as in Android Plugin for Gradle, which need to perform signing while building an APK, instead of after. For simpler use cases where the APK to be signed is available upfront, the ApkSigner
above is easier to use.NOTE: Some public classes of the library are in packages having the word “internal” in their name. These are not public API of the library. Do not use *.internal.* classes directly because these classes may change any time without regard to existing clients outside of apksig
and apksigner
.
apksigner command-line tool offers two operations:
apksigner sign
for usage information.apksigner verify
for usage information.The tool determines the range of Android platform versions (API Levels) supported by the APK by inspecting the APK's AndroidManifest.xml. This behavior can be overridden by specifying the range of platform versions on the command-line.