feat(desktop): M8-3 KEM key provisioning — server-truth SK blob, unlock-hooked (#223) #227
No reviewers
Labels
No labels
epic
phase-0
phase-1
phase-2
phase-3
phase-4
phase-5
phase-6
phase-7
phase-8
phase-9
priority/P0
priority/P1
priority/P2
type/backend
type/client
type/docs
type/ops
type/security
type/spike
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/failsulit!227
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/m8-3-kem-provisioning"
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?
Implements M8-3 per the merged design (docs/plans/2026-11-18-m8-3-kem-key-provisioning-design.md, PR #226) — first work item of M4 epic #223. Fixes audit #214 M8-3: fresh-install folder creation always failed and shares were one-way.
Core
KeyProvisioningService::ensure_provisionedat the end of every successful REAL-tree unlock (decoy unlock excluded — the decoy master key must never provision). Idempotent fast path; 5s timeout so a black-holed network never parks unlock./me/keys.encrypted_private_keys(SK blob AES-GCM under the account master key); local settings = cache tagged withkem_provisioned_user— account switch drops the stale cache, second device adopts instead of clobbering.{v:1, ml_kem_pk, kaz_kem_pk}via PATCH /me/keys (never touchesKemPublicKey); offline → same-keys retry; corrupt server state refuses to regenerate.generate_kem_keypaircommand.⚠ TWO APP-WIDE LATENT BUGS FOUND AND FIXED (caught by the new tests)
api_clientpassedArc<rustls::ClientConfig>to reqwest 0.12'suse_preconfigured_tls(downcasts bareOption<ClientConfig>) — every API client construction failed since 2026-11-12 (#190): the desktop could not reach the API at all. TS tests mock Tauri, so no gate ran this path.failsulit-cryptocached init in aOnceLock; after any CryptoService drop → cleanup() the native state stayed uninitialized and the cached result blocked re-init — "KAZ-KEM keygen failed: Library not initialized". Fixed in both kaz_kem and kaz_sign (init keyed off native is_initialized under FFI_LOCK).Review: dual-pass per repo rules — ponytail pass (2 lean fixes: dead decision arm, double fetch) + full correctness review (1 Critical: account-scoped cache — fixed + tested; 2 Important: unlock timeout — fixed, test re-scoping — done via real decapsulate-path test + design §5.1 amendment; comment-mechanism corrections + zeroized SK strings — fixed; minors M3/M4/M5 noted in #222 scope).
Tests: 14 provisioning tests (decision matrix, bundle schema, executor vs in-process HTTP stub: fresh-install repro, same-keys publish retry, second-device adopt-without-publish, account-switch, corrupt-server refusal, offline defer, real
folder_keys::decapsulateround trip). Full gates: cargo test 82/82, clippy clean, tsc clean, vitest 1303 green.Closes the M8-3 portion of #222 (M8-13 receive-envelope unblocks next).
Implements docs/plans/2026-11-18-m8-3-kem-key-provisioning-design.md: - KeyProvisioningService::ensure_provisioned runs at the end of every successful REAL-tree unlock (session / passphrase-real / biometric — decoy unlock is excluded: the decoy master key must never provision). Idempotent fast path; offline-tolerant (network failures defer to the next unlock, never regenerating); published-bundle corruption surfaces instead of regenerating over possibly-wrapped grants. - Source of truth = /me/keys.encrypted_private_keys (SK blob AES-GCM under the account master key); local settings rows are a cache — a second device reconstructs instead of clobbering. - Publishes {v:1, ml_kem_pk, kaz_kem_pk} via PATCH /me/keys; never touches KemPublicKey (pairing/recovery channel) or encrypted_master_key. - CryptoService::encrypt_with_master_key/decrypt_with_master_key added. - Dead generate_kem_keypair command removed (zero callers, superseded). - Tests (15): decision matrix, bundle schema, executor behaviors vs a canned local HTTP stub — fresh-install repro, publish-retry-same-keys, second-device adopt-without-publish, corrupt-server refusal, offline defer. Database::open_temp (test-only) + init_schema extraction. Latent bugs found by the new tests (both app-wide, both fixed here): - api_client passed Arc<rustls::ClientConfig> to use_preconfigured_tls, which reqwest 0.12 downcasts as Option<ClientConfig> — EVERY client build failed ('builder error') since #190 (2026-11-12): the desktop could not reach the API at all. TS tests mock Tauri, so nothing ran this path. Fixed: pass the bare ClientConfig. - failsulit-crypto cached init in OnceLock; the native context dies with its initializing thread, and the cached result blocked re-init — 'KAZ-KEM keygen failed: Library not initialized' after any cleanup. Fixed: init keyed off the native is_initialized state (kem + sign). Gates: cargo test 81/81, clippy clean (new code), tsc clean, vitest 1303 passed.