feat(desktop): #142 PR-B — master-key lifecycle + pairing wrap primitive #148

Merged
amiryahaya merged 1 commit from feat/desktop-master-key into main 2026-11-11 04:42:49 +01:00
Owner

Part 2 of 3 for #142 slice 1 (restructured — see the issue comment). Builds on PR #147 (device identity, merged).

The gap: the account master key never existed on desktop — CryptoService::set_master_key had zero callers, so every path that needs it errored "Master key not loaded" (folder decryption, KEM keypair generation, sharing, and the pairing wrap this milestone ships).

Landed here

  • MasterKeyService (trait-seamed store; 5 hermetic tests): ensure_ready() generates on first run (32-byte master key + random KEK, AES-256-GCM-wrapped via the previously-dormant encrypt_master_key/decrypt_master_key helpers, persisted as encrypted_master_key + mk_nonce + mk_kek keychain entries) or reloads from store on "restart". At-rest model = KEK-in-keychain: the OS keychain is the boundary; the wrap keeps the master key out of plaintext storage. A passphrase-derived KEK (Argon2id, with #15's floor parameters) replaces the random KEK when the passphrase-unlock surface lands (documented in-code).
  • unlock_session command: unlocking now loads/creates the master key — no silent unlock without key material. Wired into unlock_with_biometric (biometric auth failure keeps the app locked) and the authStore.unlock() frontend flip, which was previously a pure UI toggle that touched no key material.
  • pair_wrap_master_key command (the PR-C approve primitive): encapsulates the unlocked master key to a new device's wrapping public key. Single-KEM ml-kem-768 — the server stores exactly one wrapping_pub_key + kem_algorithm per wrap, and the new device holds its decapsulation secret from its own init call, persisting it encrypted under the master key it just unwrapped.

Tests: cargo test 20/20 in src-tauri (5 MasterKeyService incl. tamper + restart-reload + missing-KEK; +1 existing recovery test matched by filter). vitest 1283 pass / 1 skip; typecheck clean; lint 0 errors.

Next: PR-C pairing UI — initiator QR/secret surface + approver sheet calling pair_wrap_master_key + sign_data per F-M8 (03-ux-flows.md).

Part 2 of 3 for #142 slice 1 (restructured — see the issue comment). Builds on PR #147 (device identity, merged). **The gap**: the account master key never existed on desktop — `CryptoService::set_master_key` had zero callers, so every path that needs it errored "Master key not loaded" (folder decryption, KEM keypair generation, sharing, and the pairing wrap this milestone ships). **Landed here** - **MasterKeyService** (trait-seamed store; 5 hermetic tests): `ensure_ready()` generates on first run (32-byte master key + random KEK, AES-256-GCM-wrapped via the previously-dormant `encrypt_master_key`/`decrypt_master_key` helpers, persisted as `encrypted_master_key` + `mk_nonce` + `mk_kek` keychain entries) or reloads from store on "restart". At-rest model = **KEK-in-keychain**: the OS keychain is the boundary; the wrap keeps the master key out of plaintext storage. A passphrase-derived KEK (Argon2id, with #15's floor parameters) replaces the random KEK when the passphrase-unlock surface lands (documented in-code). - **`unlock_session` command**: unlocking now loads/creates the master key — no silent unlock without key material. Wired into `unlock_with_biometric` (biometric auth failure keeps the app locked) and the `authStore.unlock()` frontend flip, which was previously a pure UI toggle that touched no key material. - **`pair_wrap_master_key` command** (the PR-C approve primitive): encapsulates the unlocked master key to a new device's wrapping public key. **Single-KEM ml-kem-768** — the server stores exactly one `wrapping_pub_key` + `kem_algorithm` per wrap, and the new device holds its decapsulation secret from its own init call, persisting it encrypted under the master key it just unwrapped. **Tests**: cargo test 20/20 in src-tauri (5 MasterKeyService incl. tamper + restart-reload + missing-KEK; +1 existing recovery test matched by filter). vitest 1283 pass / 1 skip; typecheck clean; lint 0 errors. **Next**: PR-C pairing UI — initiator QR/secret surface + approver sheet calling `pair_wrap_master_key` + `sign_data` per F-M8 (03-ux-flows.md).
feat(desktop): #142 PR-B — master-key lifecycle + pairing wrap primitive
All checks were successful
Security CI / security-scan (pull_request) Successful in 3m42s
2d1a22a62c
The account master key never existed on desktop: CryptoService::set_master_key
had zero callers, so every path needing it errored 'Master key not loaded'
(folder decryption, KEM keypair generation, sharing, pairing wrap).

- MasterKeyService (trait-seamed store, 5 hermetic tests): ensure_ready()
  creates on first run (generate 32B master key + random KEK, AES-256-GCM
  wrap via the dormant encrypt_master_key helpers, persist encrypted_master_key
  + mk_nonce + mk_kek in the keychain) or loads from store on restart.
  KEK-in-keychain at-rest model — the keychain is the boundary; a
  passphrase-derived KEK (Argon2id, #15 floors) replaces the random KEK when
  the passphrase-unlock surface lands. Tamper/missing-KEK fail cleanly.
- unlock_session command: unlock now loads/creates the master key — no
  silent unlock without key material. Wired into unlock_with_biometric
  (auth failure keeps app locked) and the authStore.unlock() frontend flip
  (was a pure UI toggle).
- pair_wrap_master_key command: the pairing-approve primitive (PR-C consumes
  it) — encapsulates the unlocked master key to a new device's wrapping
  public key. Single-KEM ml-kem-768: the server stores exactly one
  wrapping_pub_key + kem_algorithm per wrap, and the new device holds the
  decapsulation secret from its init call.

cargo test: src-tauri 20/20 (6 new incl. tamper + restart-reload).
vitest: 1283/1skip; typecheck clean; lint 0 errors.
amiryahaya deleted branch feat/desktop-master-key 2026-11-11 04:42:49 +01:00
Sign in to join this conversation.
No description provided.