feat(crypto): open tenant envelopes in the browser #200
All Vouch review confidence checks passed
Residual risk 0.41 = Change Risk (0.71) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.71 · 541 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.377
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.071
Real PR Conversation Timeline
1 comments
"Review active on #200"
general
weight: 0.35
abendrothj
What and why
P34 (#171), checkpoint B: open in the browser, with private-key custody as ADR 0007 ("Browser private-key storage") decides. The scheme is applied to the current
HPK1X25519 key now, so the hybrid suite (#186) changes only the KEM behind it.platform-crypto:hpke_open_with_private_key(suite from the frame magic) andtenant_public_key_from_private. Both take a raw 32-byte key, refuse any other length, and scrub the parsed key before returning.TenantKeypairstays as it was and now shares the open and scrub code.envelope-wasm: exportsopenEnvelopeandpublicKeyFromPrivateKey. Each zeroizes its copy of the private key whether or not the call succeeds.-
lib/crypto/devicekey.ts: the device HPKE key is 32 random bytes, with its public key derived by the wasm module. It is stored only AES-256-GCM-encrypted under a separate non-extractable seed key (encrypt/decrypt only), with AADx25519-key-v1|{tenant}|{SHA-256 of the public key}, theHPK1counterpart of ADR 0007'sxwing-seed-v1.openWithDeviceKeydecrypts it just before an open;envelope.tszeroes the JavaScript copy when the open ends.- The Web Crypto X25519 key, which could never open an envelope, is removed.
keystore.tsloads an old-shape record with no HPKE key, and the worker generates one in the new form and re-enrolls its public key on the next init.- Key setup in the worker runs one at a time, so concurrent requests cannot each generate and save a different key.
-
InitResult.x25519Supportedis nowhpkeKeyAvailable(false while the envelope module cannot load); the key-setup warning is reworded.fixtures/envelope/hpk1.jsoncarries each recipient's test-only private key, derived from the seed published in the file (docs/DATA_POLICY.mdrule 3).ARCHITECTURE.md(KEK note exception, crypto-agility seam),THREAT_MODEL.md(steward and researcher private-key rows, residual risk for the key during an open),TESTING.md,CHANGELOG.md.Not in this PR:
docs/BENCHMARKS.md, a Chromium run, a target to agree with the maintainer).How it was tested
platform-crypto:raw_private_key_opens_what_its_public_key_sealed(wronginfo, wrong recipient and wrong magic refused),raw_private_keys_of_the_wrong_length_are_refused.envelope-wasm:open_round_trips_with_the_raw_private_key,open_refuses_a_malformed_private_key.tests/vectors.rschecks each recipient's private key against its seed and public key, and that the raw-key open agrees withTenantKeypairon every vector.envelope.test.ts: the wasm build opens everyhpk1.jsonenvelope (opens; tampered ciphertext, wrong info, wrong recipient, wrong frame magic and truncated frame fail with the recorded error) — the Rust-to-browser direction. Also: the caller's key is zeroed on success and failure, wrong-length keys are refused, public keys derive as recorded, and the device key seals and opens, is stored only encrypted, and is refused when moved to another tenant, paired with another public key or decrypted under another seed key.core.test.ts: the seed key is non-extractable with encrypt/decrypt only; the AAD binds tenant and full public-key digest.keystore.test.ts: round trip, and an old-shape record loads with no HPKE key.scripts/check.shpasses locally.Checklist
scripts/check.shpasses locallySECURITY_AUDIT_EVENTcovered byaudit_coverage.rs(no server-side decision added; browser-only)docs/DATA_POLICY.md)CHANGELOG.mdupdated for user-visible changesdocs/adr/if one was made (ADR 0007)