Security key required to sign in on a new device (Phase 2 of #989) #38

Open
backmeupplz wants to merge 8 commits from board/989-aaf0c7 into main
Owner

Phase 2 of #989: an account can require a security key to sign in on a new device, on top of the password and Secret Key. End-to-end encryption is unchanged; this guards session issuance only (DESIGN "Signing in with a security key").

How it works

  • Setting = the list. While an account has any sign-in key, signing in needs one. Adding, removing and new recovery codes are signed by the login key (plaintext/v1/signin-keys ‖ id ‖ ts ‖ host ‖ SHA-256(action)), so neither a stolen session nor an admin can change them. There's no admin path.
  • Adding makes a non-discoverable credential and proves it with an assertion over SHA-256("plaintext/v1/signin-key-add" ‖ id ‖ ts). No attestation. ES256 and EdDSA, at most 10 keys.
  • Recovery codes: 10 × 80 bits, shown once, stored as SHA-256, consumed atomically.
  • Two-step login. The signed login is checked first (nothing about keys leaks before that) and spends its timestamp. The answer key carries a pending id that only this client gets, a challenge, and the credential ids. POST /v1/login/finish takes an assertion, a recovery code, or nothing once the approval page has approved. Failed attempts count against the failed-login limiter.
  • Trusted devices. A finished key sign-in returns a trust token, stored hashed. Later logins that carry it skip the key, never the signed login. A password change wipes them. Without this the extension and the CLI would need the key on every unlock.
  • RP ID = the host the user typed, without the port. It's taken from the client's own address, never from the server.
    • The CLI talks CTAP directly (ctap-hid-fido2, already a dependency), so it works for any host, IPs and http on LANs included.
    • Browsers, iOS (associated domains) and Android (Digital Asset Links) can't claim an arbitrary self-hosted host. The extension and the apps therefore open the server's static approval page (/v1/login/key#<challenge>, strict CSP, no framing). There the RP ID is the page's own host.
    • The page posts the key's answer to /v1/login/approve/{challenge}. The app then finishes with its pending id, which the page never sees.
  • Assertion checks: webauthn.get, exact challenge, origin host ∈ the server's own hosts, rpIdHash, UP flag, signature over authData ‖ SHA-256(clientDataJSON), growing counter. Each has a negative test (server/src/webauthn.rs). Pure Rust (p256, ciborium); no OpenSSL.

Clients

  • CLI: plaintext signin-key add NAME | ls | remove NAME | codes.
    • Password sign-ins (signin, unlock, and Phase 1's key add and renewal) touch the key when the account needs one.
    • If no key answers, the CLI offers the approval page URL or a recovery code. That also makes it work on the static Linux and Windows builds.
    • The trust token goes into the keychain.
  • Extension:
    • When an unlock or add needs the key, the popup (or Settings) shows "Approve with my security key", which opens the page, then Continue, or a recovery code.
    • The pending state is kept in storage.session, memory only, because MV3 can stop the background while the tab is open. It holds the Account Unlock Key, never the login key, so it's as sensitive as the Account Key already kept there.
    • The trust token lives in storage.local.
  • Apps (iOS, macOS, Android):
    • FFI login fails with KeyNeeded. pending_key_page() returns the page, and finish_login(recovery) / cancel_login() finish or drop the sign-in.
    • The lock screen and the sign-in step show a key step that opens the page in the browser.
    • The trust token is in the app's private folder (no-backup dir on Android).

Tests

  • Server unit tests for every assertion check.
  • Client e2e over HTTP: add, wrong signer, wrong proof, duplicate, old-client 403, not approved yet, wrong challenge, wrong origin, replay/counter, trust, the approval page, pending-state restore, recovery codes once and replaced, password change wipes trust, removing the last key.
  • CLI: a software authenticator covers add, sign-in with a touch, a remembered device, Phase 1 key add on a trusted computer, the recovery-code prompt, and removal.
  • wasm: native e2e plus the Node bridge.
  • FFI e2e.

No real hardware key was used (Nikita's decision on the ticket); the CTAP path for sign-in (Hid::register/assert) isn't exercised by tests.

🤖 Generated with Claude Code

Phase 2 of #989: an account can require a security key to sign in on a new device, on top of the password and Secret Key. End-to-end encryption is unchanged; this guards session issuance only (DESIGN "Signing in with a security key"). ## How it works - **Setting = the list.** While an account has any sign-in key, signing in needs one. Adding, removing and new recovery codes are signed by the login key (`plaintext/v1/signin-keys ‖ id ‖ ts ‖ host ‖ SHA-256(action)`), so neither a stolen session nor an admin can change them. There's no admin path. - **Adding** makes a non-discoverable credential and proves it with an assertion over `SHA-256("plaintext/v1/signin-key-add" ‖ id ‖ ts)`. No attestation. ES256 and EdDSA, at most 10 keys. - **Recovery codes:** 10 × 80 bits, shown once, stored as SHA-256, consumed atomically. - **Two-step login.** The signed login is checked first (nothing about keys leaks before that) and spends its timestamp. The answer `key` carries a `pending` id that only this client gets, a challenge, and the credential ids. `POST /v1/login/finish` takes an assertion, a recovery code, or nothing once the approval page has approved. Failed attempts count against the failed-login limiter. - **Trusted devices.** A finished key sign-in returns a `trust` token, stored hashed. Later logins that carry it skip the key, never the signed login. A password change wipes them. Without this the extension and the CLI would need the key on every unlock. - **RP ID = the host the user typed, without the port.** It's taken from the client's own address, never from the server. - The CLI talks CTAP directly (ctap-hid-fido2, already a dependency), so it works for any host, IPs and http on LANs included. - Browsers, iOS (associated domains) and Android (Digital Asset Links) can't claim an arbitrary self-hosted host. The extension and the apps therefore open the server's static **approval page** (`/v1/login/key#<challenge>`, strict CSP, no framing). There the RP ID is the page's own host. - The page posts the key's answer to `/v1/login/approve/{challenge}`. The app then finishes with its pending id, which the page never sees. - **Assertion checks:** `webauthn.get`, exact challenge, origin host ∈ the server's own hosts, rpIdHash, UP flag, signature over authData ‖ SHA-256(clientDataJSON), growing counter. Each has a negative test (`server/src/webauthn.rs`). Pure Rust (`p256`, `ciborium`); no OpenSSL. ## Clients - **CLI:** `plaintext signin-key add NAME | ls | remove NAME | codes`. - Password sign-ins (`signin`, `unlock`, and Phase 1's `key add` and renewal) touch the key when the account needs one. - If no key answers, the CLI offers the approval page URL or a recovery code. That also makes it work on the static Linux and Windows builds. - The trust token goes into the keychain. - **Extension:** - When an unlock or add needs the key, the popup (or Settings) shows "Approve with my security key", which opens the page, then Continue, or a recovery code. - The pending state is kept in `storage.session`, memory only, because MV3 can stop the background while the tab is open. It holds the Account Unlock Key, never the login key, so it's as sensitive as the Account Key already kept there. - The trust token lives in `storage.local`. - **Apps (iOS, macOS, Android):** - FFI `login` fails with `KeyNeeded`. `pending_key_page()` returns the page, and `finish_login(recovery)` / `cancel_login()` finish or drop the sign-in. - The lock screen and the sign-in step show a key step that opens the page in the browser. - The trust token is in the app's private folder (no-backup dir on Android). ## Tests - Server unit tests for every assertion check. - Client e2e over HTTP: add, wrong signer, wrong proof, duplicate, old-client 403, not approved yet, wrong challenge, wrong origin, replay/counter, trust, the approval page, pending-state restore, recovery codes once and replaced, password change wipes trust, removing the last key. - CLI: a software authenticator covers add, sign-in with a touch, a remembered device, Phase 1 `key add` on a trusted computer, the recovery-code prompt, and removal. - wasm: native e2e plus the Node bridge. - FFI e2e. No real hardware key was used (Nikita's decision on the ticket); the CTAP path for sign-in (`Hid::register`/`assert`) isn't exercised by tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Apps: the security-key step on the lock screen and in sign-in (iOS, macOS, Android); README
Some checks failed
Apple / Apple (pull_request) Successful in 49s
release / build (macos-latest, true, aarch64-apple-darwin) (pull_request) Successful in 4m34s
release / build (macos-latest, true, x86_64-apple-darwin) (pull_request) Successful in 4m46s
Android / android (pull_request) Has been cancelled
CI / check (pull_request) Has been cancelled
CI / wasm (pull_request) Has been cancelled
release / build (ubuntu-24.04, false, x86_64-pc-windows-gnu) (pull_request) Has been cancelled
release / build (ubuntu-24.04, true, aarch64-unknown-linux-musl) (pull_request) Has been cancelled
release / build (ubuntu-24.04, true, x86_64-unknown-linux-musl) (pull_request) Has been cancelled
release / release (pull_request) Has been cancelled
release / homebrew (pull_request) Has been cancelled
release / docker (pull_request) Has been cancelled
43d25d80e8
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes: clippy; trust for the device that adds a key; finishing survives a failed account load; the CLI reuses its open key; key steps tied to their screen; no background lock while approving; unique key names; pending sign-ins dropped on password change; extension keeps trust per account and expires pending state
Some checks failed
Apple / Apple (pull_request) Successful in 1m10s
release / build (macos-latest, true, aarch64-apple-darwin) (pull_request) Successful in 5m46s
release / build (macos-latest, true, x86_64-apple-darwin) (pull_request) Successful in 6m9s
Android / android (pull_request) Has been cancelled
CI / check (pull_request) Has been cancelled
CI / wasm (pull_request) Has been cancelled
release / build (ubuntu-24.04, false, x86_64-pc-windows-gnu) (pull_request) Has been cancelled
release / build (ubuntu-24.04, true, aarch64-unknown-linux-musl) (pull_request) Has been cancelled
release / build (ubuntu-24.04, true, x86_64-unknown-linux-musl) (pull_request) Has been cancelled
release / release (pull_request) Has been cancelled
release / homebrew (pull_request) Has been cancelled
release / docker (pull_request) Has been cancelled
b0ca3f37f4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Re-check fixes: iOS key step can't finish another account, one-shot lock exemption for the approval page, pending state keeps a finished sign-in, CLI retries opening once, Android key step survives recreation
Some checks failed
Apple / Apple (pull_request) Successful in 1m38s
release / build (macos-latest, true, aarch64-apple-darwin) (pull_request) Successful in 7m19s
release / build (macos-latest, true, x86_64-apple-darwin) (pull_request) Successful in 7m3s
Android / android (pull_request) Has been cancelled
CI / check (pull_request) Has been cancelled
CI / wasm (pull_request) Has been cancelled
release / build (ubuntu-24.04, false, x86_64-pc-windows-gnu) (pull_request) Has been cancelled
release / build (ubuntu-24.04, true, aarch64-unknown-linux-musl) (pull_request) Has been cancelled
release / build (ubuntu-24.04, true, x86_64-unknown-linux-musl) (pull_request) Has been cancelled
release / release (pull_request) Has been cancelled
release / homebrew (pull_request) Has been cancelled
release / docker (pull_request) Has been cancelled
2f16b43d86
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/main' into board/989-aaf0c7
Some checks are pending
Android / android (pull_request) Waiting to run
CI / check (pull_request) Waiting to run
CI / wasm (pull_request) Waiting to run
release / build (ubuntu-24.04, false, x86_64-pc-windows-gnu) (pull_request) Waiting to run
release / build (ubuntu-24.04, true, aarch64-unknown-linux-musl) (pull_request) Waiting to run
release / build (ubuntu-24.04, true, x86_64-unknown-linux-musl) (pull_request) Waiting to run
release / release (pull_request) Blocked by required conditions
release / homebrew (pull_request) Blocked by required conditions
release / docker (pull_request) Blocked by required conditions
Apple / Apple (pull_request) Successful in 59s
release / build (macos-latest, true, aarch64-apple-darwin) (pull_request) Successful in 19m1s
release / build (macos-latest, true, x86_64-apple-darwin) (pull_request) Successful in 19m28s
2c5839a1e5
Some checks are pending
Android / android (pull_request) Waiting to run
CI / check (pull_request) Waiting to run
CI / wasm (pull_request) Waiting to run
release / build (ubuntu-24.04, false, x86_64-pc-windows-gnu) (pull_request) Waiting to run
release / build (ubuntu-24.04, true, aarch64-unknown-linux-musl) (pull_request) Waiting to run
release / build (ubuntu-24.04, true, x86_64-unknown-linux-musl) (pull_request) Waiting to run
release / release (pull_request) Blocked by required conditions
release / homebrew (pull_request) Blocked by required conditions
release / docker (pull_request) Blocked by required conditions
Apple / Apple (pull_request) Successful in 59s
release / build (macos-latest, true, aarch64-apple-darwin) (pull_request) Successful in 19m1s
release / build (macos-latest, true, x86_64-apple-darwin) (pull_request) Successful in 19m28s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'board/989-aaf0c7:board/989-aaf0c7'
git switch 'board/989-aaf0c7'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
backmeupplz/plaintext!38
No description provided.