feat(keys): per-device key wraps + device pairing (task 1.6, KEY-03/04/05) #62
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!62
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/1.6-device-key-wraps"
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?
Closes #21 (task 1.6)
KEY-03 — per-device wraps (
device_key_wraps)GET /api/keys/wraps(own) ·POST(upsert, enrolled-active-device required) ·DELETE /wraps/{deviceId}device.revokedauditedKEY-05 — device pairing (
pairing_challenges)POST /api/keys/authorize/init: 256-bit one-time secret (≥128 required), returned once — QR-only; server stores SHA-256 only; 10-min TTLPOST /api/keys/authorize/approve: constant-time secret check, atomic Pending→Consumed (single use), enrolls the new Device + stores its wrap; audited (pairing.challenge_created/approved/rejected)Boundaries (per plan)
KEY-04 passphrase unwrap is client-side (GET wraps = server half); KEY-16 signature verification → task 1.11; KEY-19 channel enforcement → task 3.8.
Tests
12 new integration tests. 786 / 0 failed / 39 skipped (Release, green ×2) · coverage gate 81.77% ≥ 80
Contract: request/response names follow the API's SnakeCaseLower policy exactly (
wrapping_pub_key,kdf_memory_kib).KEY-03 — DeviceKeyWrap entity (device_key_wraps): - one wrap per device (unique index, FK cascade to devices): KEM algorithm, wrapping pubkey, wrapped master key, KEY-13 KDF params (salt/memory/iter) - endpoints: GET /api/keys/wraps (own), POST (upsert own device wrap — enrolled active device required), DELETE /wraps/{deviceId} - RevokeDevice now deletes the revoked device's wrap (acceptance: other devices + passphrase baseline unaffected) + device.revoked audit event KEY-05 — device-to-device pairing (pairing_challenges): - POST /api/keys/authorize/init (new device, session-authed): 256-bit one-time secret (≥128 required), returned ONCE — travels via QR only; server stores SHA-256 only; 10-min TTL - POST /api/keys/authorize/approve (enrolled active device): constant-time secret check, atomic Pending→Consumed (single use), enrolls the new Device + stores its wrap; audit pairing.challenge_created/approved/rejected - errors: 404 cross-user/unknown, 410 expired, 409 replay, 403 wrong secret KEY-04: passphrase unwrap is client-side; the wrap download (GET) is its server half. KEY-16 (wrap-upload signature verification) deliberately stays with task 1.11 per plan; KEY-19 channel enforcement with task 3.8. Contract note: request/response names follow the API's SnakeCaseLower policy exactly (wrapping_pub_key, kdf_memory_kib) — the policy splits PubKey→pub_key; tests bind against the policy output, not intuition. Tests: 12 new integration tests (wrap round-trip/replace/delete/isolation, revoke-cascade, init entropy+TTL, full pairing flow + single-use replay, wrong-secret 403 + audit row, expired 410, cross-user 404). Suite 786 / 0 failed / 39 skipped (Release, green x2); coverage gate 81.77% >= 80.