feat(keys): wrap authenticity — device-key-signed wrap uploads (task 1.11, KEY-16, H-3) #78

Merged
amiryahaya merged 1 commit from feat/1.11-wrap-authenticity into main 2026-11-06 17:59:48 +01:00
Owner

Closes #26 (task 1.11 — the last design-audit H-finding gating M1's exit)

KEY-16: a session alone is never sufficient

Every DeviceKeyWrap upload now requires a signature from the registered device signing key, verified server-side (via the SDK CryptoProviderFactory) before storing — fail-closed on absent signature, unknown algorithm, or key-less devices.

ssdid-wrap-v1 canonical payload: ssdid-wrap-v1|{subject}|{kem}|{wrappingPubKeyB64}|{wrappedMasterKeyB64}|{signedAtUnix} — subject is the device id (self-upload) or challenge:{id} (pairing approve, wrapping key taken from the challenge row).

Gated surfaces

  • POST /api/keys/wraps — signed by the caller's device
  • POST /api/keys/authorize/approve — wrap signed by the approving device
  • recovery rekey exempt (documented): trust anchor = KeyProof + 2-of-3 trustees, not a session

Freshness (IDA-07 step-up proxy): ±300 s new wraps, ≤120 s replacements (full IdP re-auth step-up lands with Phase 2, task 2.2). Poisoned attempts → 403 + wrap.signature_rejected audit (acceptance line).

Deferred (documented in code): the account-signing-key alternative needs structured PublicKeys JSON (currently opaque client-managed).

Contract migration

Legacy suites (DeviceKeyWrapTests / Phase1JourneyTests / ZkCanaryTests) updated to enroll real ed25519 keys + sign via the shared WrapTestSigning helper — contract change, tests updated not deleted (§2.1).

Verification

TDD: 6 tests first, RED ×5, then implemented. Suite 859 / 0 failed / 39 skipped (Release + Debug) · gate 85.04% ≥ 80

Closes #26 (task 1.11 — the last design-audit H-finding gating M1's exit) ## KEY-16: a session alone is never sufficient Every `DeviceKeyWrap` upload now requires a signature from the **registered device signing key**, verified server-side (via the SDK `CryptoProviderFactory`) **before** storing — fail-closed on absent signature, unknown algorithm, or key-less devices. **ssdid-wrap-v1 canonical payload**: `ssdid-wrap-v1|{subject}|{kem}|{wrappingPubKeyB64}|{wrappedMasterKeyB64}|{signedAtUnix}` — subject is the device id (self-upload) or `challenge:{id}` (pairing approve, wrapping key taken from the challenge row). **Gated surfaces** - `POST /api/keys/wraps` — signed by the caller's device - `POST /api/keys/authorize/approve` — wrap signed by the **approving** device - recovery rekey **exempt** (documented): trust anchor = KeyProof + 2-of-3 trustees, not a session **Freshness (IDA-07 step-up proxy)**: ±300 s new wraps, **≤120 s replacements** (full IdP re-auth step-up lands with Phase 2, task 2.2). Poisoned attempts → 403 + `wrap.signature_rejected` audit (acceptance line). Deferred (documented in code): the account-signing-key alternative needs structured PublicKeys JSON (currently opaque client-managed). ## Contract migration Legacy suites (DeviceKeyWrapTests / Phase1JourneyTests / ZkCanaryTests) updated to enroll real ed25519 keys + sign via the shared `WrapTestSigning` helper — contract change, tests updated not deleted (§2.1). ## Verification TDD: 6 tests first, **RED ×5**, then implemented. Suite **859 / 0 failed / 39 skipped** (Release + Debug) · gate **85.04% ≥ 80**
feat(keys): wrap authenticity — device-key-signed wrap uploads (task 1.11, KEY-16, audit H-3)
All checks were successful
API CI / build-and-test (pull_request) Successful in 36m19s
f5cc6b4771
Closes #26. A session token alone is no longer sufficient to store a
DeviceKeyWrap — every wrap upload must carry a signature from the
enrolling/authorizing device's REGISTERED signing key (fail-closed on
missing/unknown-algorithm/no-key devices).

ssdid-wrap-v1 canonical payload (UTF-8):
  ssdid-wrap-v1|{subject}|{kem}|{wrappingPubKeyB64}|{wrappedMasterKeyB64}|{signedAtUnix}
- subject = device id (self-upload) or challenge:{id} (pairing approve)
- server verifies via the SDK CryptoProviderFactory against
  Device.PublicKey; enrollment KeyAlgorithm mapped to registry vmTypes
  (ed25519/kaz_sign/ml_dsa variants — unknown -> 403)

Freshness = IDA-07 step-up proxy: ±300s new wraps, <=120s replacements
(full IdP re-auth step-up lands with the Phase 2 identity work, task 2.2).

Gated surfaces:
- POST /api/keys/wraps (self upload, signed by the caller's device)
- POST /api/keys/authorize/approve (wrap signed by the APPROVING device;
  wrapping key for the canonical payload comes from the challenge row)
- recovery rekey EXEMPT (documented): its trust anchor is KeyProof +
  2-of-3 trustee approval, not a session — no registered device key exists
  on a recovering fresh device

Poisoned attempts audited: wrap.signature_rejected (actor + device/target).

KEY-16 account-signing-key alternative deferred (needs structured
PublicKeys JSON — current field is opaque client-managed JSON).

Tests: 6 new (absent -> 403, invalid -> 403 + audited + not stored,
valid -> 200, stale -> 403, replacement freshness window, approve
requires authorizer signature). RED x5 first. Legacy suites
(DeviceKeyWrapTests / Phase1JourneyTests / ZkCanaryTests) updated to
enroll real keys + sign — contract change, tests updated not deleted.
Shared helper WrapTestSigning mirrors the canonical format.

Suite 859 / 0 failed / 39 skipped (Release + Debug); gate 85.04% >= 80.
Sign in to join this conversation.
No description provided.