|
| HmacProof | sign_command (*, str slot, str command, Mapping[str, object] args, bytes raw_secret, str hmac_key_id, Clock|None clock=None, int|None ts_ms=None) |
| VerifyResult | verify_hmac (*, str slot, str command, Mapping[str, object] args, HmacProof proof, CredentialMaterial|None credential, Clock|None clock=None, int max_skew_seconds=300) |
| str | canonical_payload (*, str slot, str command, Mapping[str, object] args, int ts_ms, str hmac_key_id) |
| str | payload_sha256 (Mapping[str, object] args) |
| str | _sign (str payload, bytes raw_secret) |
| int | _now_ms (Clock|None clock) |
Actor HMAC signing and verification.
Purpose
-------
Build and verify canonical HMAC-SHA256 proofs for mutating registry
commands.
Responsibilities
----------------
- Canonicalize the signed command payload.
- Produce proof mappings for CLI/API callers.
- Verify signatures with constant-time comparison and skew checks.
Diagnostics
-----------
Domain: OC_CHAT.MAIN
Levels:
L2 - lifecycle events
L3 - semantic details
L4 - deep tracing
Contracts
---------
- The signed payload includes slot, command, args, timestamp, and key id.
- Verification returns a structured failure reason for ``auth_events``.
- This module performs no registry writes and reads no secret files.
Dependencies
------------
- dataclasses (proof, credential and result records)
- hashlib (SHA-256 for signatures and payload digests)
- hmac (HMAC signing and constant-time comparison)
- oc_chat.registry.canonical (canonical JSON of the signed payload)
- oc_chat.registry.clock (timestamps for signing, skew and expiry checks)
- oc_diagnostics (structured debug logging via _dbg)