[vault] Android: the android key kind and the apk sign kind (v0.14.0) #16

Manually merged
mnovak merged 1 commits from feature/apk-signing into main 2026-11-08 00:33:15 +01:00
Owner

Android APK signing for Postea, so its release is signed by Custos instead of a keystore file and environment variables (the app side is the Custos PR that pins this tag).

What

  • Key kind android: RSA-4096, a self-signed X.509 v3 end-entity certificate CN=<cn>, O=<o>, C=<c> (not a CA, keyUsage digitalSignature + nonRepudiation, no EKU, under no root), valid 100 × 365 days. Vault::signing_create_android(&AndroidKey, now) makes one at a time (id [a-z0-9-]{1,64}, used once). Not exportable, like every signing key; its certificate is its public half (signing_export_cert).
  • Sign kind apk: digest = 1–4 SHA-512 digests of APK Signature Scheme signed data (64·n bytes) → the n RSA PKCS#1 v1.5 signatures with the SHA-512 DigestInfo, concatenated. One request = one card line = one audit entry, so a v2+v3 APK needs one card.
  • android signs only apk, and only android signs apk (an Authenticode leaf cannot sign an APK, an Android key cannot sign an exe or minisign).
  • apk is not on unattended_sign's list: an Android key cannot be revoked or replaced, so it always shows the card, even on the hands-off vault.
  • Docs: SIGNING.md (key, certificate profile, the apk kind and why SHA-512, the two-pass client, the backup warning, compatibility), FORMAT.md (values older cores refuse; unattended_sign), THREAT_MODEL.md (losing the vault loses its signing keys; an Android key's loss ends the app's updates). Version 0.14.0.

Why SHA-512, not SHA-256 as first planned

apksig 36.0.0 (V2SchemeSigner.getSuggestedSignatureAlgorithms) uses RSA_PKCS1_V1_5_WITH_SHA512 for every RSA key over 3072 bits and has no option to choose. RSA-4096 was kept (the owner's design), so the kind takes SHA-512 digests.

Tests (cargo test --workspace: 215 passed, 0 failed)

  • custos-sign kat.rs: apk equals openssl pkeyutl -sign -pkeyopt digest:sha512 (new fixture digest512.*, throwaway key), two digests → two signatures in order, bad lengths refused; new_android makes RSA-4096, the subject, self-signed, 100 years, not a CA, no EKU, its key verifies its signatures; bad subjects refused.
  • custos-vault tests/android.rs (9): view and certificate, id rules and once only, sign + verify with the certificate's key, wrong kind both ways (exe/minisign with the Android key, apk with the leaf, Ed25519, root, test leaf), out of scope (other repo, bare Postea, other pipeline) even when approved, release needs Mark / test twin signs alone but never a tag, malformed requests (0/1/32/63/65/320 bytes, no file, a path, approval text, bad run), refused/expired/approved through a save and reopen, never unattended.
  • The unit test "no API path returns a private key" now holds two Android keys and apk requests (and the wrong-kind ones) and searches every output for their private exponents and primes.
  • Outside the suite: apksig 36.0.0 signed Postea's unsigned dry-run APK with a throwaway key from new_android through the two-pass helper; apksigner verify --print-certs -v → v2 true, v3 true, v1 false, CN=Postea, O=Marek Novak, C=CZ, RSA 4096.

Self-review

  • No new crypto: RSA PKCS#1 v1.5 with rsa 0.9 + sha2 0.10 (already used for Authenticode), certificates with x509-cert's builder (the Leaf profile with the subject as its own issuer, so no CA extensions).
  • Fail closed for older readers: android and apk are closed-list values, so a core before 0.14.0 refuses such a vault (Corrupted) instead of misreading an Android key as something it could use. The desktop moves to this tag in the same change; the web vault (core v0.7.0) never reads signing.
  • No secret in any error: new_android failures map to a fixed message (or the core's own error text, which names no key).
  • Not done here: remote (/api/sign/*) APK requests; the factor service does not list apk, so a remote one is refused there.
Android APK signing for Postea, so its release is signed by Custos instead of a keystore file and environment variables (the app side is the Custos PR that pins this tag). ## What - **Key kind `android`**: RSA-4096, a self-signed X.509 v3 end-entity certificate `CN=<cn>, O=<o>, C=<c>` (not a CA, keyUsage digitalSignature + nonRepudiation, no EKU, under no root), valid 100 × 365 days. `Vault::signing_create_android(&AndroidKey, now)` makes one at a time (id `[a-z0-9-]{1,64}`, used once). Not exportable, like every signing key; its certificate is its public half (`signing_export_cert`). - **Sign kind `apk`**: `digest` = 1–4 SHA-512 digests of APK Signature Scheme signed data (64·n bytes) → the n RSA PKCS#1 v1.5 signatures with the SHA-512 DigestInfo, concatenated. One request = one card line = one audit entry, so a v2+v3 APK needs one card. - `android` signs only `apk`, and only `android` signs `apk` (an Authenticode leaf cannot sign an APK, an Android key cannot sign an exe or minisign). - `apk` is **not** on `unattended_sign`'s list: an Android key cannot be revoked or replaced, so it always shows the card, even on the hands-off vault. - Docs: SIGNING.md (key, certificate profile, the `apk` kind and why SHA-512, the two-pass client, the backup warning, compatibility), FORMAT.md (values older cores refuse; `unattended_sign`), THREAT_MODEL.md (losing the vault loses its signing keys; an Android key's loss ends the app's updates). Version 0.14.0. ## Why SHA-512, not SHA-256 as first planned apksig 36.0.0 (`V2SchemeSigner.getSuggestedSignatureAlgorithms`) uses `RSA_PKCS1_V1_5_WITH_SHA512` for every RSA key over 3072 bits and has no option to choose. RSA-4096 was kept (the owner's design), so the kind takes SHA-512 digests. ## Tests (cargo test --workspace: 215 passed, 0 failed) - custos-sign `kat.rs`: `apk` equals `openssl pkeyutl -sign -pkeyopt digest:sha512` (new fixture `digest512.*`, throwaway key), two digests → two signatures in order, bad lengths refused; `new_android` makes RSA-4096, the subject, self-signed, 100 years, not a CA, no EKU, its key verifies its signatures; bad subjects refused. - custos-vault `tests/android.rs` (9): view and certificate, id rules and once only, sign + verify with the certificate's key, wrong kind both ways (exe/minisign with the Android key, apk with the leaf, Ed25519, root, test leaf), out of scope (other repo, bare `Postea`, other pipeline) even when approved, release needs Mark / test twin signs alone but never a tag, malformed requests (0/1/32/63/65/320 bytes, no file, a path, approval text, bad run), refused/expired/approved through a save and reopen, never unattended. - The unit test "no API path returns a private key" now holds two Android keys and `apk` requests (and the wrong-kind ones) and searches every output for their private exponents and primes. - Outside the suite: apksig 36.0.0 signed Postea's unsigned dry-run APK with a throwaway key from `new_android` through the two-pass helper; `apksigner verify --print-certs -v` → v2 true, v3 true, v1 false, `CN=Postea, O=Marek Novak, C=CZ`, RSA 4096. ## Self-review - No new crypto: RSA PKCS#1 v1.5 with `rsa` 0.9 + `sha2` 0.10 (already used for Authenticode), certificates with `x509-cert`'s builder (the `Leaf` profile with the subject as its own issuer, so no CA extensions). - Fail closed for older readers: `android` and `apk` are closed-list values, so a core before 0.14.0 refuses such a vault (`Corrupted`) instead of misreading an Android key as something it could use. The desktop moves to this tag in the same change; the web vault (core v0.7.0) never reads `signing`. - No secret in any error: `new_android` failures map to a fixed message (or the core's own error text, which names no key). - Not done here: remote (`/api/sign/*`) APK requests; the factor service does not list `apk`, so a remote one is refused there.
mnovak added 1 commit 2026-11-08 00:32:54 +01:00
mnovak manually merged commit 54ce09ce61 into main 2026-11-08 00:33:15 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/CustosPublic#16