feat(keys): per-device key wraps + device pairing (task 1.6, KEY-03/04/05) #62

Merged
amiryahaya merged 1 commit from feat/1.6-device-key-wraps into main 2026-11-05 16:37:36 +01:00
Owner

Closes #21 (task 1.6)

KEY-03 — per-device wraps (device_key_wraps)

  • One wrap per device (unique index + FK cascade): KEM algorithm, wrapping pubkey, wrapped master key, KEY-13 KDF params
  • GET /api/keys/wraps (own) · POST (upsert, enrolled-active-device required) · DELETE /wraps/{deviceId}
  • RevokeDevice deletes the revoked device's wrap — other devices + passphrase baseline unaffected (acceptance); device.revoked audited

KEY-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 TTL
  • POST /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)
  • Errors: 404 cross-user · 410 expired · 409 replay · 403 wrong secret

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).

Closes #21 (task 1.6) ## KEY-03 — per-device wraps (`device_key_wraps`) - One wrap per device (unique index + FK cascade): KEM algorithm, wrapping pubkey, wrapped master key, KEY-13 KDF params - `GET /api/keys/wraps` (own) · `POST` (upsert, enrolled-active-device required) · `DELETE /wraps/{deviceId}` - **RevokeDevice deletes the revoked device's wrap** — other devices + passphrase baseline unaffected (acceptance); `device.revoked` audited ## KEY-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 TTL - `POST /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`) - Errors: 404 cross-user · 410 expired · 409 replay · 403 wrong secret ## 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`).
feat(keys): per-device key wraps + device pairing — wrap CRUD, authorize init/approve (task 1.6, KEY-03/04/05)
All checks were successful
API CI / build-and-test (pull_request) Successful in 34m27s
b75448ab37
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.
Sign in to join this conversation.
No description provided.