How can an Android app replace a public signing key while preserving a route to restore user data? Shelly’s 2026-10-14 implementation introduced private release-key signing with APK Signature Scheme v3 rotation, alongside encrypted backup/restore. [M1] Which Android versions can use the rotated signer, what must survive restoration, and how does the checked APK reach an update tracker?
Why the signing key had to change
Shelly release APKs had been signed with the public React Native / Expo debug.keystore, so anyone could sign an in-place update. [M1] On 2026-10-14, commit 2dbfca956 introduced a debug-to-release signing lineage with rotation min SDK 28. [M1]
Android 9 supports changing an app’s signing key as part of an APK update through APK Signature Scheme v3. [1] Its proof-of-rotation structure links certificates in order, with each certificate signing the next and giving the new key evidence that it should be trusted wherever the older key was trusted. [1] The signing block also carries supported SDK versions, allowing verification to select a signer whose range includes the device’s platform version. [1]
The trust relationship includes older certificates that the app itself still trusts, with flags identifying their permitted operations. [1] For example, a flag may allow another app signed by an older certificate to retain a signature permission defined by the app signed with the new certificate. [1]
How Shelly selected and checked the signer
In the 2026-10-14 implementation, plugins/with-release-signing.js used SHELLY_SIGNING_MODE to select the Gradle release signingConfig through rotation / release / legacy-debug modes. [M1] Release signing failed without a complete keystore, and CI failed without a mode rather than silently falling back to debug signing. [M1]
Rotation mode emitted an unsigned APK for apksigner. [M1] The build-android.yml workflow supplied signing and publish dispatch inputs, loaded the keystore from SHELLY_RELEASE_* secrets, and checked pinned fingerprints before the apksigner rotation step. [M1] Verification included API 28+ signer and API 24-27 signer checks. [M1]
Which Android versions use the rotated key?
For Android 9 and higher, APK verification can use v3, v2, or v1; older platforms ignore v3 signatures and try v2, then v1. [1] The documented configuration table specifies that a lineage with rotation-min-sdk-version set to x < 33 uses the rotated signer in the v3 block, targeting Android 9 and higher. [2]
An explicit rotation minimum differs from the apksig default: when a rotated key and lineage are supplied in the signing configuration, the library defaults to the v3.1 signing block. [2] Android 13 supports v3.1, including SDK version targeting that allows rotation to target a later platform release. [2]
Platform versions also matter for interactions beyond installation: Android 11 corrected PackageManager#checkSignatures handling of original signing keys, which had broken instrumentation using the original key against an app using a rotated key. [2] Android 12 corrected signature-permission and APK rollback problems involving rotated keys. [2]
What had to survive restoration?
On 2026-10-14, commit 82b9f8b99 added Settings > Backup & restore, also accessible through shelly://backup and shelly://restore. [M1] The implementation separated non-secret home files into /sdcard/Download/shelly-backup-<ts>.tar and placed settings and credentials in an encrypted .shellybak. [M1]
The encrypted bundle contained settings from AsyncStorage, every SecureStore secret, and credential files, optionally including ~/.codex/auth.json. [M1] A drift test kept the SecureStore inventory complete. [M1]
Encryption used AES-256-GCM with an authenticated SHLYBAK1 header and a key derived through scrypt with N=2^16, r=8, p=1, and random salt. [M1] A generated passphrase had 150 bits and was shown once; alternatively, a user-chosen passphrase had a strength floor. [M1] The passphrase never left component state. [M1]
Restoration re-imported settings, secrets, and files, including memory DEK and ClosePaw pre-approvals. [M1] The policy seal was re-signed on the new install before restart. [M1]
How release checks reached delivery
On 2026-10-29, commit df6bb820a added the dependency-free scripts/release-safety-scan.js to scan the source tree, APK, runtime payload, and manifests. [M1] Its checks covered tokens, private keys, .env-style secrets, keystores, and signing passwords. [M1]
APK/zip contents were read in memory, with redacted output and an allowlist file. [M1] The scanner ran in build-android.yml before upload/publish and also in ota-update.yml, with unit tests using runtime-constructed fake tokens. [M1]
The release-delivery change in commit e9b5d2cf0 on 2026-10-29 addressed the following failure chain. [M1]
| Stage | Before the fix | After the fix |
|---|---|---|
| APK location | APKs lived in android-latest; versioned releases carried no APK. [M1] | The release workflow copied the APK built from the tagged commit onto the release. [M1] |
| Tracker handoff | GitHub-release trackers such as Obtainium had nothing to install from those versioned releases. [M1] | The attached APK was scanned by the release-safety scanner and accompanied by a .sha256. [M1] |
Other approaches and their constraints
Target rotation to a later platform release
For the signing problem, the documented v3.1 arrangement lets Android 13 or higher use the rotated signer in the v3.1 block, while older Android versions use the original signer in the v3 block. [2] This supports later-platform rotation while retaining the original signer on older platforms. [2] If an app’s minSdkVersion is less than Android 12 and a rotated key is used, the original signing key must also be specified to sign the v3 block. [2]
Supply an APK link directly
For the delivery problem, Obtainium supports direct APK links and an HTML fallback that extracts APK links from a page. [3] Multiple release assets can still require manual selection and prevent silent background updating; Filter APKs by Regular Expression addresses that selection problem. [3]
Migration checklist
- When installation differs across devices, check device support with the PkgInstallSignatureVerificationTest.java CTS tests for v3 or v3.1. [2]
- When verification fails at a platform boundary, inspect minSDK and maxSDK: v3 requires the current platform to be in range and the signed and unsigned SDK values to match. [1]
- When a lineage fails verification, inspect its final certificate: the selected signer must be the last certificate in the proof-of-rotation list. [1]
- When verification finds competing signers, check the platform ranges: v3 verification succeeds only when exactly one signer is in range and verification succeeds for that signer. [1]
- When a signing design requires multiple signers, check that requirement against v3’s limitation: multiple signers are not supported. [1]
- When restoring a backup against its home-file archive, check the archive pairing and extraction inputs: Shelly’s 2026-10-14 bundle pinned the tar’s SHA-256, and restore validated tar entries before extraction. [M1]
- When update notifications arrive but version detection fails, inspect Obtainium’s Track-Only mode: it provides notifications without downloading APKs, and version detection does not work for apps added that way. [3]
Sources
- [1] APK signature scheme v3
- [2] APK signature scheme v3.1
- [3] App Sources
- [M1]
dev/ep32.md(author's own material)
AI disclosure: this post was researched, written and reviewed by AI tools.
Publishing: a post that passes automated checks may be published automatically, before the author reads it.
Top comments (0)