feat(crypto): key enrollment per verified identity, create-once (#175) #300
All Vouch review confidence checks passed
Residual risk 0.34 = Change Risk (0.78) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.78 · 597 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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.383
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.078
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #300"
general
weight: 0.35
abendrothj
What and why
Closes #175 (P33). ADR 0004 decides the design: one key per tenant, created once; replacing it is an explicit, audited rotation. A second device, a cleared browser or a worker restart can no longer silently re-key a tenant.
PUT /api/v1/drive/enrollmentis create-once (put_if_absent). The record carrieskey_id(SHA-256 of the raw key, from the newTenantPublicKey::fingerprint()), the key's ownsuiteandcreated_at_unix. The same key again succeeds; a different key is a 409, auditedcrypto.key_enrollment"denied". A stored record that fails verification is a backend fault (502, audited "failed"), asenrolled_suitetreats one, not another device's key.POST /api/v1/drive/enrollment/rotaterefuses (403, audited) until P30 wires in the fresh second factor. Worker initialization never calls it.verify_enrollment_record(stored, policy)refuses a record with unknown fields, no creation time, a key that doesn't parse, a suite the policy refuses or that isn't the key's own, or akey_idthat isn't the key's fingerprint. Records written before this change are refused.iss,sub,tid), and AADs use the session'stid. A stored row that doesn't match the session is refused. Database version 2 leaves the olddevicerow in place, unread; data sealed under its random UUID is unsupported pre-v1 data.KeySetupGateshows a second-device refusal with no way into the drive. Its acknowledgement is per identity, and a device without an HPKE key gets one later without losing its master key.Notes for reviewers:
VaultStorehas no compare-and-swap), so two devices migrating at once both succeed and the last write wins. A comment input_enrollmentrecords this development-only race.verify_enrollment_record(#289). #280 also editsworker.ts; whichever lands second rebases ontoloadDeviceKeys(identity).Clearing old development records
Enrollment records written before this PR have no
key_idorcreated_at_unix, so they fail verification, and every enrollment for that tenant is a 502 until the record is deleted. Any deployment holding such records needs them cleared before it runs this change. Deleting a record removes only the enrolled key, not files or datasets.$STORAGE_LOCAL_DIR/control/enrollments/.json.docker compose -f docker-compose.simulated-tee.yml exec enclave-api sh -c 'rm -f /var/lib/quackxide/vault/control/enrollments/.json'.STORAGE_LOCAL_DIRnorSTORAGE_BUCKETset): restartplatform-api.The browser enrolls again on the next drive load.
How it was tested
audit_coverage.rs: first enrollment and same-key retry succeed; a different key returns 409, is audited "denied" and leaves the record unchanged; rotation returns 403 and is audited; a record written before this PR returns 502 and is audited "failed".platform-apiunit tests:verify_enrollment_recordrefuses a key id mismatch, a wrong or unknown suite, an invalid key, a zero creation time, a production-refused HPK1 key and a pre-#175 record.platform-crypto: the fingerprint is the lowercase hex SHA-256 of the raw key.envelope_vectors.rsanddataset_upload_api.rs: adjusted for create-once; the P36 migration test passes.keystore.test.ts(fake-indexeddb): per-identity storage, the session'stidrequired, mismatched rows refused, version 1 to 2 upgrade without using the legacy row, round-trip with an encrypted HPKE key.worker.test.ts: keys bound to the session identity, no keys without a session, enrolled vs. refused reporting, an HPKE key added later with the same master key.KeySetupGate.test.tsx: the second-device refusal shows no button or checkbox.Checklist
scripts/check.shpasses locallySECURITY_AUDIT_EVENTcovered byaudit_coverage.rsdocs/DATA_POLICY.md)CHANGELOG.mdupdated for user-visible changesdocs/adr/if one was made