ngr verify
Checks whether the signatures of an apk verify. By default it prints nothing but the warnings; with -v, the
verdict for each signature scheme. The result is read from the exit code: 0 if it verifies, 3 if it does not. You
use it to check what you have just signed and to find out who signed an apk.
Usage
ngr verify [options] <apk>
Inputs
| Input | What it is |
|---|---|
<apk> |
An apk file |
Options
| Option | What it does | Default |
|---|---|---|
-v, --verbose |
Prints the verdict for each scheme and the number of signers | |
--min-sdk-version <n> |
Lowest API level to check against | The apk's minSdkVersion |
--max-sdk-version <n> |
Highest API level to check against | No limit |
--v4-signature-file <file> |
The .idsig with the v4 signature. Without it, v4 is not checked |
|
--print-certs |
Prints the certificate of each signer | |
--print-certs-pem |
Also prints the certificates in PEM. Implies --print-certs |
|
-h, --help |
Shows the help |
What it writes
It writes no files.
With no options, if the apk verifies, nothing is printed, except any warnings, which go to stdout:
WARNING: META-INF/services/j$.nio.file.spi.FileSystemProvider not protected by signature. Unauthorized modifications to this JAR entry will not be detected. Delete or move the entry outside of META-INF/.
With -v, to stdout, the verdict for each scheme and the number of signers:
Verifies
Verified using v1 scheme (JAR signing): true
Verified using v2 scheme (APK Signature Scheme v2): true
Verified using v3 scheme (APK Signature Scheme v3): true
Verified using v3.1 scheme (APK Signature Scheme v3.1): false
Verified using v3.2 scheme (APK Signature Scheme v3.2): false
Verified using v4 scheme (APK Signature Scheme v4): true
Verified for SourceStamp: false
Number of signers: 1
With --print-certs, after the verdict, the certificate of each signer and the digests of its certificate:
V3.0 Signer: certificate DN: CN=Example, O=Example, C=ES
V3.0 Signer: certificate SHA-256 digest: 5647da8c1450d839...
V3.0 Signer: certificate SHA-1 digest: 664c1fd744da684e...
V3.0 Signer: certificate MD5 digest: 623f9d2aa8ac6673...
With -v and --print-certs together, the key algorithm and size and the public key digests are printed too.
--print-certs-pem adds the certificate in PEM, between -----BEGIN CERTIFICATE----- and
-----END CERTIFICATE-----.
If the apk does not verify, no table is printed: stderr gets DOES NOT VERIFY and one ERROR: line for each
problem, and the exit code is 3.
Examples
Check an apk and use the result in a script:
ngr verify app.apk && echo "signature ok"
See which schemes the apk carries:
ngr verify -v app.apk
See who signed it:
ngr verify --print-certs app.apk
Also check the v4 signature, with the .idsig that ngr sign wrote:
ngr verify -v --v4-signature-file app_signed.apk.idsig app_signed.apk
Check only what a device running Android 13 or later will see:
ngr verify -v --min-sdk-version 33 app.apk
An apk modified after it was signed:
ngr verify app.apk
DOES NOT VERIFY
ERROR: APK Signature Scheme v3 signer #1: APK integrity check failed. CHUNKED_SHA256 digest mismatch. Expected: <858178d2...>, actual: <d1642a83...>
Exit codes
| Code | When |
|---|---|
| 0 | The apk verifies |
| 1 | The apk or the --v4-signature-file file does not exist or cannot be read |
| 2 | The options are wrong: <apk> is missing, a value is not a number, or --min-sdk-version is greater than --max-sdk-version |
| 3 | The apk does not verify, or has no signature |
Things to know
- An unsigned apk gives 3. It says
ERROR: Missing META-INF/MANIFEST.MF. - API levels change which schemes are checked. With an apk signed with a key rotated for level 33,
-v --min-sdk-version 30 --max-sdk-version 32saysv3.1 ... false, and with--min-sdk-version 33it saystrue. - v4 is only checked if you give the
.idsig. Without--v4-signature-file, the v4 line saysfalseeven if the.idsigexists next to the apk. If you give it an.idsigthat does not belong to that apk, the line also saysfalseand the exit code is 0: read the verdict with-v. - Warnings do not change the exit code. A
WARNING:exits with code 0. verifydoes not say whether you trust the certificate, only whether the signatures are consistent with the content. Compare the digests from--print-certswith the ones you expect.
See also
ngr sign, which writes the signatures checked here.ngr lineage, to read the key rotation of an apk.- “Signing and verifying”.