feat(desktop): #142 PR-C — device pairing UI (initiator + approver, KEY-16 signed) #149

Merged
amiryahaya merged 6 commits from feat/desktop-pairing-ui into main 2026-11-11 05:29:37 +01:00
Owner

Part 3 of 3 for #142 slice 1 — the original pairing-UI scope, now buildable on PR #147 (device identity) + PR #148 (master-key lifecycle). Stacked on #148; diff vs main includes #148 until it merges.

What it fixes: the silent second-device fork — a second desktop generated a DIFFERENT master key and could read nothing the first desktop encrypted. Pairing transfers the existing key from an unlocked, enrolled device.

Rust — PairingService (5 tests incl. a full real-ML-KEM-768 blob roundtrip):

  • Initiator: init_pairing generates an EPHEMERAL ml-kem-768 wrapping keypair (in-process memory, zeroized), POSTs /api/keys/authorize/init, returns the pairing payload + key fingerprint. poll_pairing_complete finds the approver's wrap on GetWraps, decapsulates, and adopts the master key via the new MasterKeyService::import (persisted under this device's KEK).
  • Approver: approve_pairing parses the payload, encapsulates the master key to the challenge's wrapping pubkey, signs the KEY-16 canonical payload (ssdid-wrap-v1|challenge:{id}|...) with the enrolled Ed25519 device key (PR-A), and POSTs approve.
  • Wire format: base64url(json{challenge_id, pairing_secret, kem_algorithm, wrapping_pub_key}) — QR on mobile, copy/paste on desktop. Wrap blob (opaque to the server) = ml_kem_ct[1088] || AES-GCM(master key under shared secret), self-contained for decapsulation.
  • Fingerprint = hex(SHA-256(wrapping pubkey))[..16], shown on BOTH screens for visual matching (F-M8, 03-ux-flows.md).

UI — PairDeviceSection (Settings → Devices):

  • Initiator: QR (qrcode.react) + copyable payload + fingerprint chip + expiry countdown + waiting state (immediate first poll, then 4s — under the wrap-fetch limiter), paired/expired/cancel states.
  • Approver: paste dialog with inline validation, WebCrypto fingerprint preview BEFORE approval, confirm-to-approve spinner. Loading→success/error states throughout per UX guidance.

Tests: cargo test 25/25 src-tauri; vitest 1287 pass / 1 skip (4 new); typecheck clean; lint 0 errors (9 pre-existing warnings).

Part 3 of 3 for #142 slice 1 — the original pairing-UI scope, now buildable on PR #147 (device identity) + PR #148 (master-key lifecycle). Stacked on #148; diff vs main includes #148 until it merges. **What it fixes**: the silent second-device fork — a second desktop generated a DIFFERENT master key and could read nothing the first desktop encrypted. Pairing transfers the existing key from an unlocked, enrolled device. **Rust — PairingService** (5 tests incl. a full real-ML-KEM-768 blob roundtrip): - **Initiator**: `init_pairing` generates an EPHEMERAL ml-kem-768 wrapping keypair (in-process memory, zeroized), POSTs `/api/keys/authorize/init`, returns the pairing payload + key fingerprint. `poll_pairing_complete` finds the approver's wrap on GetWraps, decapsulates, and adopts the master key via the new `MasterKeyService::import` (persisted under this device's KEK). - **Approver**: `approve_pairing` parses the payload, encapsulates the master key to the challenge's wrapping pubkey, signs the KEY-16 canonical payload (`ssdid-wrap-v1|challenge:{id}|...`) with the enrolled Ed25519 device key (PR-A), and POSTs approve. - **Wire format**: base64url(json{challenge_id, pairing_secret, kem_algorithm, wrapping_pub_key}) — QR on mobile, copy/paste on desktop. Wrap blob (opaque to the server) = `ml_kem_ct[1088] || AES-GCM(master key under shared secret)`, self-contained for decapsulation. - **Fingerprint** = hex(SHA-256(wrapping pubkey))[..16], shown on BOTH screens for visual matching (F-M8, 03-ux-flows.md). **UI — PairDeviceSection** (Settings → Devices): - Initiator: QR (qrcode.react) + copyable payload + fingerprint chip + expiry countdown + waiting state (immediate first poll, then 4s — under the wrap-fetch limiter), paired/expired/cancel states. - Approver: paste dialog with inline validation, WebCrypto fingerprint preview BEFORE approval, confirm-to-approve spinner. Loading→success/error states throughout per UX guidance. **Tests**: cargo test 25/25 src-tauri; vitest 1287 pass / 1 skip (4 new); typecheck clean; lint 0 errors (9 pre-existing warnings).
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.
feat(desktop): #142 PR-C — device pairing UI (initiator + approver, KEY-16 signed)
Some checks failed
Security CI / security-scan (pull_request) Failing after 33s
721902aca2
The original slice-1 scope, now buildable on PR-A identity + PR-B master-key
lifecycle. Fixes the silent second-device fork: a second desktop used to
generate a DIFFERENT master key and could read nothing the first desktop
encrypted - pairing transfers the existing key.

Rust - PairingService (5 tests incl. full real-ML-KEM blob roundtrip):
- Initiator: init_pairing generates an EPHEMERAL ml-kem-768 wrapping keypair
  (held in process memory, zeroized), calls /api/keys/authorize/init,
  returns the pairing payload + key fingerprint. poll_pairing_complete finds
  the approver's wrap on GetWraps, decapsulates (blob = ml_kem_ct[1088] ||
  AES-GCM(master_key under shared secret) - self-contained, opaque to the
  server), and adopts the master key via the new MasterKeyService::import.
- Approver: approve_pairing parses the payload, encapsulates the master key
  to the challenge pubkey, packs the blob, signs the KEY-16 canonical
  payload (ssdid-wrap-v1|challenge:{id}|...) with the enrolled Ed25519
  device key, posts approve.
- Wire format: base64url(json{challenge_id, pairing_secret, kem_algorithm,
  wrapping_pub_key}) - QR-encoded on mobile, copy/paste on desktop.
  Fingerprint = hex(SHA-256(wrapping pubkey))[..16] shown on BOTH screens
  (F-M8 visual matching).

UI - PairDeviceSection (Settings -> Devices):
- Initiator: QR + copyable payload + fingerprint chip + countdown + waiting
  state (first poll immediate, then 4s - under the wrap-fetch limiter);
  paired/expired states; cancel.
- Approver: paste dialog with inline payload validation, fingerprint
  preview via WebCrypto before approval, approve-with-spinner.
- Mounted under the Devices list; copy per F-M8 ("Confirm this fingerprint
  on the approving device before approving").

cargo test 25/25; vitest 1287 pass / 1 skip (4 new); typecheck clean;
lint 0 errors.
fix(desktop,ci): harden SharedWithMePage mocks + extend gitleaks test-fixture filter
All checks were successful
Security CI / security-scan (pull_request) Successful in 2m58s
fdce74f9ed
PR #149 CI surfaced two issues:

1. SharedWithMePage (5 CI failures, passes locally): the accept/decline/
   message/badges/error tests still used mockResolvedValueOnce chains -
   a re-render's list_shared_with_me consumes the next Once slot, the
   accept_share invoke resolves undefined, and the click never lands
   ("Network error" cascade - the exact #141 family). Rewritten to the
   persistent command-switch pattern (#141) that survives arbitrary
   re-render counts.

2. gitleaks generic-api-key on pairing test fixtures: the security-ci
   report-and-filter treated tests/, android test/, and iOS test dirs as
   benign but desktop test paths weren't covered. Filter now also treats
   clients/desktop/src/test/ and any /__tests__/ directory as benign
   (deterministic path filter per the #82 rule - no .gitleaks.toml
   allowlists). The one fixture under a production prefix (Rust cfg(test)
   module) uses a short obviously-fake literal instead.

Both are CI-infrastructure fixes found by real runs; no production code
changed.
fix(desktop): pairing preview moves to the Rust codec (jsdom has no WebCrypto)
All checks were successful
Security CI / security-scan (pull_request) Successful in 2m37s
4de77cadc3
Second CI failure on PR #149: the approver dialog previewed the pasted
payload with a JS mirror (atob + crypto.subtle) - fine locally, but the
CI jsdom has no crypto.subtle, so the fingerprint never computed and the
approve button stayed disabled.

Better design anyway: preview_pairing command parses the payload through
the SAME Rust codec the approve path uses (single source of truth, no
JS mirror to drift), runs pure-local (parse + SHA-256), and returns the
authoritative fingerprint + supported flag. The dialog now calls it on
paste; invalid payloads surface via the preview rejection.

cargo test 25/25; vitest 1287/1skip locally; typecheck clean.
fix(desktop): last two CI flakes - MySharesPage persistent default + paste via change event
All checks were successful
Security CI / security-scan (pull_request) Successful in 2m11s
eee664583d
- MySharesPage: whole-file persistent default for list_my_shares (the
  remaining Once-chains - incl. the revoke-share block - could exhaust
  under CI load and cascade into the empty state). Tests still override
  with their own implementations where needed.
- PairDeviceSection approver test: paste is a single change event
  (fireEvent.change), not 200 userEvent keystrokes - the per-keystroke
  async preview stalls past the 5s timeout on saturated 2-core runners;
  test timeout bumped to 15s for headroom.

vitest 1287/1skip locally; no production code changed.
merge main (post-#148 squash) into feat/desktop-pairing-ui
All checks were successful
Security CI / security-scan (pull_request) Successful in 2m38s
1d41fb0498
amiryahaya deleted branch feat/desktop-pairing-ui 2026-11-11 05:29:37 +01:00
Sign in to join this conversation.
No description provided.