Commit Graph

11 Commits

Author SHA1 Message Date
Morten V. Christiansen 56132528fe Add CardEmulator and fix fido2-direct id= constructor bugs
tests/card_emulator.py: software emulator of the ChromeCard FIDO2
authenticator. Implements make_credential and get_assertion with real P-256
cryptography and an in-memory credential store. Both methods accept
user_confirms=True/False to simulate the card's Yes/No confirmation dialog;
False raises CtapError(OPERATION_DENIED). refusing() returns a wrapper that
forces user_confirms=False for integration tests that route through
_with_direct_ctap2. forget_user() simulates card-side credential removal.
Module docstring serves as the usage guide.

tests/test_k_proxy.py: 22 new tests across TestCardEmulatorUnit (direct
emulator calls) and TestCardEmulatorIntegration (full ProxyState flows
covering register, authenticate, user-says-no, forget, two-user isolation,
and sign-count monotonicity).

k_proxy_app.py: fix two bugs where RegistrationResponse and
AuthenticationResponse were constructed with id= instead of raw_id=. Both
calls raised TypeError at runtime, silently caught by the surrounding except
block, making all fido2-direct register and authenticate calls fail.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 16:31:07 +02:00
Morten V. Christiansen 2cf44e97df Refactor all three service files and fix enroll-clears-session bug
- Update module docstrings to concise service descriptions
- Add _require_json() helper to Handler in k_proxy and k_client_portal,
  eliminating repetitive try/except JSON-parse blocks in handler methods
- Cache SSL context once in ClientState.__init__ instead of per-request
- Fix: ClientState.enroll() now calls /session/logout on k_proxy before
  re-enrolling, so the old server-side session is invalidated rather than
  left to expire (discovered via live test where re-register after login
  caused subsequent logout to fail with missing bearer token)
- Add targeted comments explaining non-obvious invariants: _gc_locked lock
  ownership, _with_direct_ctap2 retry-on-reopen, _require_session None
  convention, will_close connection reuse, HTTP/1.1 body-drain requirement,
  90 s interactive timeout margin, and enroll session-clearing rationale

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 11:27:57 +02:00
Morten V. Christiansen e7212b49a0 Add k_proxy unit tests with mocked card and upstream
100 tests covering session management, enrollment CRUD, probe and direct
FIDO2 auth routing, UpstreamPool connection handling, and all HTTP
endpoints via a live in-process server. Card (FIDO2/CTAP) and k_server
are fully mocked so the suite runs locally without hardware or VMs.

Also hardens the fido2.features.webauthn_json_mapping import guard to
tolerate older python-fido2 versions that lack the attribute.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 10:44:43 +02:00
Morten V. Christiansen bd839ea42d Add Playwright portal regression and harden direct auth 2026-04-25 21:06:08 +02:00
Morten V. Christiansen e57f8a446f Improve portal enrollment controls and direct hidraw selection 2026-04-25 19:29:28 +02:00
Morten V. Christiansen 689587629a Harden direct auth path and regression helper 2026-04-25 15:49:52 +02:00
Morten V. Christiansen 2448956946 Add CTAP probe and update phase docs 2026-04-25 10:25:40 +02:00
Morten V. Christiansen d0d27a0896 Move browser portal to k_proxy 2026-04-25 01:47:26 +02:00
Morten V. Christiansen 4893eb8312 Add Phase 6 client portal and enrollment flow 2026-04-25 01:42:03 +02:00
Morten V. Christiansen 4b0b126bf9 Add Phase 2 HTTPS prototype and runbook updates 2026-04-25 01:29:37 +02:00
Morten V. Christiansen 37600548ac Start Phase 5 proxy/server session reuse prototype 2026-04-24 10:30:40 +02:00