feat(android): wrap the store passphrase in the Android Keystore #44
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/android-keystore-store-passphrase"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
The store passphrase can now be remembered on the device instead of being retyped
every launch. It is sealed with AES-256-GCM under a key that never leaves the
Android Keystore (alias
onionwire.store), so pulling the app's private dataoff a device yields ciphertext, not the passphrase.
Deliverable, mapped to the card
crypto/StoreSecret.kt— the envelope (OWSEAL1magic + IV + ciphertext +128-bit GCM tag) plus
wipe(ByteArray)/wipe(CharArray). Deliberately free ofandroid.*imports so the code that runs on a device is the code the JVM unittests exercise.
crypto/KeystorePassphraseCipher.kt— AES-256-GCM Keystore key,setRandomizedEncryptionRequired(true), StrongBox first(
setIsStrongBoxBacked(true), gated onFEATURE_STRONGBOX_KEYSTORE/ API 28+)with a graceful fallback:
StrongBoxUnavailableException extends ProviderException,caught, then a normal Keystore key is generated.
setUserAuthenticationRequired(false)is the default and stays that way.
crypto/StoredPassphraseStore.kt— only ciphertext + IV on disk, atfilesDir/secrets/store-passphrase.bin(app-private, andallowBackup="false"+data_extraction_rulesalready exclude it from backup/device transfer). Writtentmp+rename. Nothing is logged; the plaintext
CharArrayis zeroed infinally.Unlock.OneTapwhen a blob exists and decrypts; otherwise thetype-it form, with a notice explaining why. Checkbox "Remember on this device"
defaults to on. "Forget stored passphrase" deletes the blob and the Keystore
key.
unlock(passphrase, remember)picks up the secret as aCharArrayand wipesit after the SDK call.
wipe, or an invalidated key yields
Load.Unavailable(reason); the UI says so andfalls back to typing. A failed decrypt does not delete the blob, so a transient
Keystore failure cannot destroy the only copy.
Evidence (real output, this machine, JDK 21, AGP 8.13.2, Kotlin 2.2.21)
Test XML from that run (
app/build/test-results/testDebugUnitTest/*.xml):The APK is a real, installable debug artifact containing the new classes:
What is NOT verified here — read this before trusting the StrongBox claim
There is no device or emulator attached to this machine (
adb devicesis empty), sonone of the following was observed, only written:
setIsStrongBoxBacked(true), theProviderExceptionfallback path,Cipher.initwith a Keystore key, andKeyInfo.isInsideSecureHardware/securityLevel. The unit-test JVM has noAndroidKeyStoreprovider, so these are unverified.backing()returns whateverKeyInfosays; the lock screen prints it verbatim and labels a software key
"software key, NOT hardware-backed". The actual value on any given phone is unknown
to me.
The device test is written and compiles (
:app:assembleDebugAndroidTest→BUILD SUCCESSFUL,apk at
app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk), but it must berun on hardware:
KeystorePassphraseCipherTestasserts the round trip, that the on-device blob is not theplaintext, that a deleted key reports
goneinstead of crashing, that a regenerated keycannot open an old blob, and that
backing()is notUNKNOWN. Anyone with a phone can getthe real answer in one command.
The one plaintext copy this card cannot remove
openWire(home, passphrase)is UniFFI-generated and takes a KotlinString, i.e. animmutable heap object that cannot be zeroed. Everything else on the path is a
CharArraythat gets wiped. Follow-up SDK signature this card is not allowed to make
(
crates/onionwire-sdk/**is out of scope):A
Vec<u8>/ByteArrayparameter lets the Kotlin side wipe its buffer after the callinstead of leaking an immutable
String. Until then, theStringis unavoidable.Scope
Touched:
android/**only (README.mdat the repo root is untouched — deferred wordingbelow). No changes to
.forgejo/workflows/**,crates/**,src/**.Unrelated finding (not fixed here, out of scope)
crates/onionwire-sdk/Cargo.lockis stale onmain: the rootCargo.toml:47declaressha2 = "0.10"but the lock file'sonionwirepackage block does not list it, so everycargo buildin that workspace (including:sdk:preBuild) rewrites the lock file(+
"sha2",). I reverted it and did not commit it — someone who ownscrates/**shouldcommit the regenerated lock.
README (deferred)
README.mdis owned by PR #38; this is the exact wording to add at the end of the## Android (SDK + APK)section, after the sentence pointing atandroid/README.md:CI evidence: the existing workflow still builds the APK
No
.forgejo/**file is touched by this PR (git diff --name-only origin/main...HEAD→ 0 matches forforgejo), so the strongest available check is running the unchanged workflow on this branch:Dispatched with
POST /api/v1/repos/sirius/onionwire/actions/workflows/android-release.yml/dispatches→HTTP 204.Result, from
GET /api/v1/repos/sirius/onionwire/actions/tasks:https://forgejo.siriusdevops.com/sirius/onionwire/actions/runs/146 — 10 minutes wall clock, the same shape as the previous successful dry-runs (run 133 at 8m31s, run 134 at 8m11s); the failing ones on this workflow fail in seconds, so this is a real build.
dry_run=truedid what it says — nothing was published or tagged:Caveat, stated plainly: this Forgejo exposes run status but no per-step log endpoint (
/actions/runs/480/jobs,/jobs/0/logs,/artifactsall 404), and the run page is a JS SPA, so I could not retrieve theci-verify.logline (apk_bytes=… aar_bytes=…) from here. What is verified: the workflow ran tosuccesson this exact commit, and the publish step was skipped bydry_run. Step-level output is visible to anyone who opens run 146 in the UI.36e9b27623to2fd640e230Merge order 4 of 7: #38 -> #42 -> #41 -> #44 -> #43 -> #45 -> #46
Android-only (
android/**), disjoint from every core PR; its card also forbade.forgejo/workflows/, which is respected. Keystore cipher, stored-passphrase store and unit tests are in the PR; no hardware-backing claim was made beyond what was observable.Note: Forgejo refuses a formal approval from this token ("approve your own pull is not allowed" — the PRs were pushed by account
sirius, which is also the token's user). This review records the sign-off and the merge position; a human approval click is still needed. Rebased onto currentmainbefore this review, diff verified byte-identical.