# RFC-0014: Tamper-Evident Audit Trail - **Status:** Proposed; implements the reference checkpoint and sink that decision D-008 deferred "before beta". No change to `cs-audit/1` events. - **Owner:** Audit and security leads. - **Last updated:** 2026-11-29 ## Context `cs-audit/1` events are secret-free and allowlisted, but a log of them proves nothing on its own: whoever can write the log can also edit it. Regulated deployments (PCI DSS requirement 10, SOC 2 CC7, HIPAA ยง164.312(b)) need audit records whose alteration is detectable, and D-008 records that tamper evidence requires a checkpoint held outside the writer's control. ## Binding decision `cryptography_suite.audit.chain` provides: - **`AuditChain`**, an `AuditSink` that writes one canonical JSON line per event to an `AuditRecordWriter`. Each record carries `chain_id`, a 1-based `sequence`, `previous` (the prior record's hash, 64 zeros for the first), the event, `hash`, and `signature`. - `hash = SHA-256("cryptography-suite/v4 audit chain record" || 0x00 || canonical JSON of the record without hash and signature)`. - `signature = Ed25519(signing key, "cryptography-suite/v4 audit chain signature" || 0x00 || hash)`, base64url without padding. - Canonical JSON: sorted keys, no whitespace, ASCII escapes, no floats. - The head advances only after the writer stores the record, so a failed write leaves no gap; under an audit-required policy the operation fails. - **`AuditChain.checkpoint()`**, the latest `(chain_id, sequence, hash)`, to be published periodically somewhere the writer cannot modify (WORM storage, a ticketing system, a transparency log). - **`verify_audit_chain(lines, public_key, chain_id=..., start=..., expected_end=...)`**, which needs only the public key. It rejects any non-canonical line, wrong chain, sequence gap, broken link, hash mismatch, invalid or non-canonical signature, and any event that is not a valid `cs-audit/1` event, and reports the reason and line number. With `expected_end` it requires the trail to contain that exact record, which detects truncation up to the checkpoint; `start` verifies a segment after rotation. ## Security consequences - Verifiers cannot forge records: they hold only the public key. - A writer that holds the signing key can rewrite the records after the last published checkpoint. The checkpoint interval bounds that window; publish often, and keep the signing key in the audit component (or an HSM through a signing wrapper), not in the data path. - Records contain only the allowlisted event fields, so the trail can be shared with auditors without exposing secrets. ## Alternatives considered - **HMAC chains.** Rejected: every verifier would also be able to forge. - **A signature only on periodic checkpoints.** Rejected: an edit inside the current window would be undetectable until the next checkpoint; per-record signatures cost tens of microseconds. - **An external transparency-log dependency.** Rejected for the core package; checkpoints are plain values that any such system can store. ## Test and validation requirements `tests/unit/test_audit_chain.py` verifies a trail produced by `Protector` under an enterprise policy and covers edits, insertion, deletion, reordering, forged hashes without the key, a wrong key, records from another history, truncation against a checkpoint, resumption and segments, write failures, signature canonicality, malformed records and events, and argument validation.