# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-stale-revocation-proofs-from-resurrecting-revoked-agent-capabilities-in-signed-agent-card-handshakes.md # Remnant Warrant: https://corpusfetch.com/c/which-invariants-prevent-stale-revocation-proofs-from-resurrecting-revoked-agent-capabilities-in-signed-agent-card-handshakes.warrant.json # Markdown SHA-256: ad4327daf74e208f737cdbb26e770130b1fef89dc0d46864263b5072200fc884 # Code AST SHA-256: ea69f3157f7f1d36c8bb92770a090a4e62d682bff76611840744cdfb8ff8967f # Verified Classes: StaleRevocationProofError, SignedTreeHead, NonRevocationProof, CapabilityVerifier # Defensive Guards: 7 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) import hashlib import time from dataclasses import dataclass class StaleRevocationProofError(RuntimeError): """Raised when a non-revocation proof verifies cryptographically but is too old, regresses the tree size, or lacks a consistency path to the verifier's current trust anchor. Fail closed: never fall back to cache.""" pass @dataclass(frozen=True) class SignedTreeHead: tree_size: int timestamp: float signature: bytes @dataclass(frozen=True) class NonRevocationProof: card_hash: bytes merkle_path: tuple sth: SignedTreeHead class CapabilityVerifier: def __init__(self, delta_seconds: float, log_pubkey: bytes): self.delta = delta_seconds self.log_pubkey = log_pubkey self._high_water_tree_size = 0 # monotonic floor self._last_sth: SignedTreeHead | None = None def _verify_sth_signature(self, sth: SignedTreeHead) -> bool: # Placeholder for real Ed25519/RSA verification against log_pubkey. return sth.signature == b"valid-log-sig" def _verify_merkle_path(self, proof: NonRevocationProof) -> bool: # Placeholder for real Merkle inclusion-of-absence check. return bool(proof.merkle_path) def _verify_consistency(self, older: SignedTreeHead, newer: SignedTreeHead) -> bool: # Placeholder: newer tree must provably extend older. return newer.tree_size >= older.tree_size def accept( self, proof: NonRevocationProof, fresh_sth: SignedTreeHead, now: float, ) -> None: # 1. Freshness anchor is verifier-supplied, never prover-supplied. if not self._verify_sth_signature(fresh_sth): raise StaleRevocationProofError("fresh STH signature invalid") # 2. Reject stale anchor outright, before any expensive crypto. if now - fresh_sth.timestamp > self.delta: raise StaleRevocationProofError( f"fresh STH is {now - fresh_sth.timestamp:.0f}s old, exceeds delta {self.delta:.0f}s" ) # 3. Monotonicity: no rollback below the high-water mark. if fresh_sth.tree_size < self._high_water_tree_size: raise StaleRevocationProofError( f"tree size regression: {fresh_sth.tree_size} < high-water {self._high_water_tree_size}" ) # 4. Proof's own STH must be a consistent ancestor of the fresh anchor. if proof.sth.tree_size > fresh_sth.tree_size: raise StaleRevocationProofError("proof STH ahead of verified anchor") if not self._verify_consistency(proof.sth, fresh_sth): raise StaleRevocationProofError("no consistency path from proof STH to anchor") # 5. The proof's STH must itself be within delta of the anchor's time. if fresh_sth.timestamp - proof.sth.timestamp > self.delta: raise StaleRevocationProofError( f"proof anchored to STH {fresh_sth.timestamp - proof.sth.timestamp:.0f}s " f"behind current log state; resurrection window open" ) # 6. Only now do the cryptographic checks on the proof body. if not self._verify_merkle_path(proof): raise StaleRevocationProofError("merkle path invalid") # Commit the new anchor only after full acceptance. self._high_water_tree_size = fresh_sth.tree_size self._last_sth = fresh_sth