Repository navigation
iOS: a Secure Enclave approval key, so payments and logins can be signed on an iPhone - #137
Draft
dbejarano820 wants to merge 2 commits into
Draft
dbejarano820 wants to merge 2 commits into
dbejarano820 wants to merge 2 commits into
Conversation
Contributor
|
Holding this one until it's been checked on an iPhone, as the description says. It's the approval key for payments and logins, so the phone test is the one that counts. Merge it yourself once it passes, or say so here and I'll merge it. 🦀 |
…ned on an iPhone (#125) The iOS approval key module no longer fails closed. It makes a P-256 key in the Secure Enclave with access control [.privateKeyUsage, .biometryCurrentSet], WhenPasscodeSetThisDeviceOnly: Face ID or Touch ID for every signature, no passcode fallback, never a software key. It signs the exact UTF-8 message with ecdsaSignatureMessageX962SHA256 (DER, as Android's SHA256withECDSA) and reports the public key as a P-256 SubjectPublicKeyInfo, so the cage verifies it unchanged. state() reports lost without a prompt when the enrolled biometric set changed. The prompt's words come from ApprovalText.swift, a port of ApprovalText.kt. ApprovalKeyLevel gains secure_enclave, with its line on the approval key screen in both locales. Signed-off-by: Daniel Bejarano <dbejarano820@gmail.com>
…fingerprint (#125) ApprovalText.swift was a port of Android's text and its enrollment line said fingerprint. It now names this iPhone's biometric from LAContext.biometryType, as the app's copy does (common.biometric.*): Face ID, Touch ID, or both names when the phone doesn't say. The payment and password prompts had no biometric word and are unchanged. Signed-off-by: Daniel Bejarano <dbejarano820@gmail.com>
dbejarano820
force-pushed
the
dbejarano820/125-ios-secure-enclave-key
branch
from
November 30, 2026 22:45
9997284 to
0093200
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Closes #125
On iOS the approval key failed closed. This puts a real key in the Secure Enclave, behind the same contract as the Android Keystore key: P-256, never exported, Face ID or Touch ID for each signature, no passcode fallback, and
lostwhen a face or a finger is added or removed. Payments and logins still stay off on an iPhone for now, because the vault and the wallet have no hardware-wrapped key on iOS yet (docs/devices.md says so).What the module does (
apps/mobile/modules/hermit-approval-key/ios):SecKeyCreateRandomKeywithkSecAttrTokenIDSecureEnclave, P-256, stored under the taghermit.approval-key.v1. Its access control is[.privateKeyUsage, .biometryCurrentSet], accessible onlyWhenPasscodeSetThisDeviceOnly. A key whose attributes don't say Secure Enclave and 256 bits is never used. If the Secure Enclave can't make the key, enrollment rejects withno_secure_hardwareand leaves nothing behind (for example on the Simulator). No software key is ever made..ecdsaSignatureMessageX962SHA256. That gives ECDSA SHA-256 in DER, the same as Android'sSHA256withECDSA, so the cage needs no conversion. The public key is the X9.63 point behind the P-256 SubjectPublicKeyInfo header (ApprovalKeyFormat.spki), so it reads the same as Android'sgetEncoded().enrollandsignuses a freshLAContextwith reuse duration 0, an empty fallback title (no "Enter Passcode" button), and is invalidated afterwards. At most one prompt is open at a time (busy).signrefuses before any prompt when the message isn't an approval (bad_message), has expired (expired), there's no key (lost), or the biometric set changed (lost).ApprovalText.swiftis a port ofApprovalText.kt: the module's own strings, picked by locale code, with every fact read from the message being signed. JavaScript passes no display text.lostwithout a prompt. At enrollment the module savesevaluatedPolicyDomainStatein a Keychain item on this device only.statecompares it with the current set, and a different or missing set meanslost. The Secure Enclave enforces this on its own as well:.biometryCurrentSetstops the key from signing after any change.statereturnsno_biometricwhen Face ID or Touch ID can't be used (a lockout still counts as enrolled), thennone,lostorreadywithlevel: "secure_enclave". Errors from the prompt map to the existing codes:cancelled,lockout,no_biometric,lostandfailed.On the JS side,
ApprovalKeyLevelgainssecure_enclave(APPROVAL_KEY_LEVELSin core). The runtime pins it, and the approval key screen has a line for it in both locales. Android is unchanged.Vision fit
Hermit asks for your fingerprint before money moves, and the same promise now holds on an iPhone: the key that approves a payment or a login lives in hardware and signs only behind your face or finger.
Non-negotiables
This keeps every non-negotiable in AGENTS.md as it is.
Or it changes one, and this is the accepted RFC: #
1, 2 and 3 (data stays on the phone, no telemetry, no network in packages): no network code, no dependency, nothing leaves the phone. The key and the biometric-set record are
ThisDeviceOnlyKeychain items.4 (the cage decides): nothing skips
decide()or the log. The cage still verifies every signature against the pinned key (verifySignedApproval) and spends its nonce. The module only signs.5 (untrusted text): unchanged. Taint still refuses money and logins before any sheet opens.
6 (money and logins need the sheet and the biometric): this is the hard part, and it holds in hardware. The access control allows biometry only, from the current set, with no passcode, and needs a new match for each signature. The approval stays bound to
argsHash, the request id, the nonce and the expiry, because those are in the signed bytes. A software key is never made.7 (sheets show only code-written words): the system prompt's text comes from
ApprovalText.swift, the module's own strings plus the facts from the signed payload with hidden characters stripped. No caller text is used.8 (testnet only): unchanged.
9 (copy): one new key,
HM-APPR-01.key.level.secure_enclave, in en and es-419, with no dashes. The prompt strings still say fingerprint, as on Android. Face ID wording is iOS: permission prompts in both languages, and copy that says Face ID instead of fingerprint #128.10 (tests first, made-up data): see below. The vector comes from a throwaway software key.
11 to 13: n/a.
Checklist
acceptedproposal.pnpm check:privacy,pnpm typecheck,pnpm lint,pnpm testandnode scripts/guard/check.mjs --patterns scripts/guard/patterns.txt.packages/copy, in es-419 and en, with matching keys and placeholders, and no em or en dashes.Tests written first, and the reason each one failed:
packages/runtime/test/approval-key.test.ts, "an iPhone's Secure Enclave key is pinned with its level and reads back as ready". It failed withexpected { kind: 'not_set_up' } to deeply equal { kind: 'ready', …}, because the pin rejected the new level.packages/copy/test/copy.test.ts, "every place an approval key can be kept has its line on the approval key screen". It failed becauseAPPROVAL_KEY_LEVELSdidn't exist yet.packages/cage/test/signed-approval.test.ts, "an iPhone's Secure Enclave key". This is a known vector made once on a Mac with a throwaway software P-256SecKey, using the module's own export (ApprovalKeyFormat.spki) and signature calls. The public key and the enrollment and payment signatures verify as they come. A changed amount ismismatch, and the changed payload with the old signature isbad_signature. This test passed without any cage change: it shows the iOS formats already match what the cage verifies, so no conversion is needed.ApprovalText.swiftwas checked against every case inApprovalTextTest.ktwith a localswiftcharness, and all of them pass. That harness isn't committed, because the pod has no test target.Model path
packages/model,agent,skillsoreval, the prompt, the router, tool descriptions, normalizers, examples or the model file.Screenshots
There is one new line on the approval key screen, and only on an iPhone: "Kept in this iPhone's Secure Enclave." / "Guardada en el Secure Enclave de este iPhone." The screenshots are still to come from a phone run, so none are below yet.
New dependencies and network calls
n/a. The module uses Apple's Security and LocalAuthentication frameworks, which make no network calls.
Still needs a phone test
Not run on a device yet:
signthrough the normal sheet.AI agents