ngr rotate
Writes a signing certificate lineage in which the old key hands over to the new one. The lineage is what lets you
change the signing key without losing an app's updates. If you give it a lineage, or an apk that is already
rotated, it extends it with one more key. The resulting lineage is passed to ngr sign with
--lineage.
Usage
ngr rotate [options] [<lineage>]
Inputs
| Input | What it is |
|---|---|
<lineage> |
Optional. A lineage file or a rotated apk, which is extended. The old key must be the newest certificate in that lineage |
Options
| Option | What it does | Default |
|---|---|---|
-o, --output <file> |
The lineage file to write. Required | |
-f, --force |
Overwrites the output if it already exists | |
--old-ks <file> |
PKCS#12 keystore of the key being retired. Required | |
--old-ks-pass <spec> |
Its password: pass:<password>, env:<variable>, file:<path> or stdin |
|
--old-ks-key-alias <alias> |
Its key | The only key in the keystore |
--old-key-pass <spec> |
Key password, for when you do not give --old-ks-pass |
|
--old-set <capability> |
Grants a capability to the key being retired. Can be repeated | |
--old-unset <capability> |
Removes a capability from it. Can be repeated | |
--new-ks <file> |
PKCS#12 keystore of the incoming key. Required | |
--new-ks-pass <spec> |
Its password, in the same forms | |
--new-ks-key-alias <alias> |
Its key | The only key in the keystore |
--new-key-pass <spec> |
Key password, for when you do not give --new-ks-pass |
|
--new-set <capability> |
Grants a capability to the incoming key. Can be repeated | |
--new-unset <capability> |
Removes a capability from it. Can be repeated | |
-v, --verbose |
Also prints how many certificates the lineage has and where it was written | |
-h, --help |
Shows the help |
The capabilities are installed-data, shared-uid, permission, rollback and auth. A new link grants all
of them except rollback. The --old-set, --new-unset options and their siblings change only the capabilities
they name.
What it writes
The lineage file you name with -o. The final line goes to stderr:
wrote lineage.bin
With -v, to stdout:
Rotated into a lineage of 2 certificates
wrote lineage.bin
Examples
Create a lineage with two keys:
ngr rotate --old-ks old.p12 --old-ks-pass env:OLD_PASS \
--new-ks new.p12 --new-ks-pass env:NEW_PASS -o lineage.bin
Extend it with a third key. The one that was new becomes the old one, and the lineage is the input:
ngr rotate --old-ks new.p12 --old-ks-pass env:NEW_PASS \
--new-ks newer.p12 --new-ks-pass env:NEWER_PASS \
-v -o lineage3.bin lineage.bin
wrote lineage3.bin
Rotated into a lineage of 3 certificates
wrote lineage3.bin
Give the rollback capability to the old key and remove two from the new one:
ngr rotate --old-ks old.p12 --old-ks-pass env:OLD_PASS --old-set rollback \
--new-ks new.p12 --new-ks-pass env:NEW_PASS \
--new-unset shared-uid --new-unset auth -o lineage.bin
Extend the lineage of an apk that is already rotated, without having the lineage file:
ngr rotate --old-ks new.p12 --old-ks-pass env:NEW_PASS \
--new-ks newer.p12 --new-ks-pass env:NEWER_PASS -o lineage3.bin app.apk
To see the result, ngr lineage --print-certs lists the certificates and their capabilities.
Exit codes
| Code | When |
|---|---|
| 0 | The lineage was written |
| 1 | A keystore cannot be read or the password is wrong, the output already exists and you did not pass -f, or the old key is not the newest certificate in the lineage |
| 2 | The options are wrong: -o, --old-ks or --new-ks is missing, or a capability is not one of the five |
Things to know
-ois required.rotatehas no default output name:
ngr rotate: missing -o <file>, the lineage to write. See 'ngr help rotate'.
- The old key must be the last one in the lineage. If you extend a lineage of
oldandnewwitholdas the old key, it fails with code 1:
ngr rotate: SignerConfig Certificate containing private key to sign the new SigningCertificateLineage record does not match the existing most recent record.
rotateneeds both keystores, the one for the key being retired and the one for the incoming key.- A capability that is not one of the five is a usage error:
'bogus' is not a valid value for --old-set; use one of: installed-data, shared-uid, permission, rollback, auth. - To sign with the rotation,
ngr signtakes the two keystores, each with its own--ks, and the lineage with--lineage(ngr sign).
See also
ngr lineage, to read a lineage and change its capabilities.ngr sign, which uses the lineage with--lineage.- “Rotating the signing key”.