ngr lineage
Reads a signing certificate lineage, either a file or the one inside a rotated apk, and prints its certificates
with the capabilities of each. With --ks it also changes the capabilities of the signers you name and writes the
changed lineage. ngr rotate creates the lineage; this command inspects it and adjusts it.
Usage
ngr lineage [options] <lineage>
Inputs
| Input | What it is |
|---|---|
<lineage> |
A lineage file or a rotated apk |
Options
Each --ks opens a signer, and the options after it (--ks-pass, --ks-key-alias, --key-pass, --set,
--unset) belong to that --ks, until the next one. One of them before its --ks is a usage error.
| Option | What it does | Default |
|---|---|---|
-o, --output <file> |
Where the changed lineage is written | |
-f, --force |
Overwrites the output if it already exists | |
--ks <file> |
PKCS#12 keystore of a signer that is already in the lineage. Each --ks opens a new signer. Can be repeated |
|
--ks-pass <spec> |
Keystore password: pass:<password>, env:<variable>, file:<path> or stdin. Applies to the preceding --ks |
|
--ks-key-alias <alias> |
The signer's key. Applies to the preceding --ks |
The only key in the keystore |
--key-pass <spec> |
Key password, for when you do not give --ks-pass. Applies to the preceding --ks |
|
--set <capability> |
Grants a capability to the signer. Applies to the preceding --ks. Can be repeated |
|
--unset <capability> |
Removes a capability from it. Applies to the preceding --ks. Can be repeated |
|
--print-certs |
Prints all the certificates of the resulting lineage, with their capabilities | |
--print-certs-pem |
Also prints the certificates in PEM. Implies --print-certs |
|
-v, --verbose |
Says what changed and what was written, and also prints the key details | |
-h, --help |
Shows the help |
The capabilities are installed-data, shared-uid, permission, rollback and auth. Only the ones you name
change.
What it writes
The changed lineage, in the -o file, and only if something changed. If the capabilities you name already had that
value, it writes nothing and exits with 0. The final line goes to stderr:
wrote lineage2.bin
With --print-certs, to stdout, each certificate with its capabilities:
Signer #1 in lineage certificate DN: CN=Example Old, O=Example, C=ES
Signer #1 in lineage certificate SHA-256 digest: 5647da8c1450d839...
Signer #1 in lineage certificate SHA-1 digest: 664c1fd744da684e...
Signer #1 in lineage certificate MD5 digest: 623f9d2aa8ac6673...
Has installed data capability: true
Has shared UID capability : true
Has permission capability : true
Has rollback capability : false
Has auth capability : true
Signer #2 in lineage certificate DN: CN=Example New, O=Example, C=ES
...
With -v and --print-certs, also the key algorithm and size and the public key digests of each certificate, and,
if there was a change, to stdout:
Updated signer capabilities for CN=Example New, O=Example, C=ES
Updated lineage saved to lineage2.bin
Examples
See the certificates of a lineage file and their capabilities:
ngr lineage --print-certs lineage.bin
See the rotation of an apk:
ngr lineage --print-certs app.apk
Give rollback and remove auth from the new key, and write the changed lineage:
ngr lineage --ks new.p12 --ks-pass env:KS_PASS --set rollback --unset auth -o lineage2.bin lineage.bin
Change two signers at once, each with its own --ks:
ngr lineage --ks old.p12 --ks-pass env:OLD_PASS --unset auth \
--ks new.p12 --ks-pass env:NEW_PASS --set rollback \
-o lineage2.bin lineage.bin
Change and see the result in the same command:
ngr lineage --ks new.p12 --ks-pass env:KS_PASS --set rollback --print-certs -o lineage2.bin lineage.bin
Exit codes
| Code | When |
|---|---|
| 0 | The lineage was read, and written if there were changes |
| 1 | The file does not exist or is neither a lineage nor an apk, the apk has no lineage, a signer is not in the lineage, the output already exists and you did not pass -f, or there was a change without -o |
| 2 | The options are wrong: <lineage> is missing, or a signer option comes before its --ks |
Things to know
- A change without
-ofails after printing. With--print-certs, the resulting lineage is printed to stdout and then the command ends with code 1 without writing anything:
ngr lineage: the lineage changed but no -o was given; nothing was written.
- The signer must be in the lineage. If the
--kskeystore has a certificate that is none of the links, it fails with code 1:
ngr lineage: Certificate (CN=Example Other, O=Example, C=ES) not found in the SigningCertificateLineage.
- An apk without a lineage cannot be read. An apk signed without rotation ends with code 1 and says:
ngr lineage: 's.apk' has no signing certificate lineage in its v3 or v3.1 signature block.
One with no v3 or v3.1 signature says has no v3 nor v3.1 signature block to read a lineage from.
- Without
--ks,lineageonly reads.ngr lineage lineage.binwith no other option prints nothing; add--print-certs. - With an apk as input you can write the changed lineage with
-o: the result is a lineage file, not an apk.
See also
ngr rotate, which creates and extends lineages.ngr sign, which signs with--lineage.ngr verify, to check the signature of a rotated apk.- “Rotating the signing key”.