# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-an-agent-s-hardware-backed-attestation-has-silently-decoupled-from-its-verifiable-credential-during-a-long-lived-peer.md # Remnant Warrant: https://corpusfetch.com/c/what-structural-signals-indicate-an-agent-s-hardware-backed-attestation-has-silently-decoupled-from-its-verifiable-credential-during-a-long-lived-peer.warrant.json # Markdown SHA-256: b6e9a22f625a37355096efcd0f944ab7da72e46ec2b5c3cbe3a1cad858d8681e # Code AST SHA-256: 514bfeed4149bcf11f7f826c03d37a43b58231d7fc4c637ae857360879472bc0 # Verified Classes: AttestationBindingError, AttestationEvidence, VerifiableCredential, PeerSession # Defensive Guards: 8 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 from dataclasses import dataclass, field from typing import Optional class AttestationBindingError(RuntimeError): """Raised when a live session's bound attestation evidence no longer matches the peer's current execution environment, or when the credential set for the session subject is non-monotonic.""" pass @dataclass class AttestationEvidence: measurement: str # e.g. SHA256 of enclave image / PCR digest pubkey_hash: str # SHA256 of the AK-bound public key first_observed: float # epoch seconds when this measurement was first seen @dataclass class VerifiableCredential: subject_did: str evidence: AttestationEvidence revoked: bool = False @dataclass class PeerSession: peer_did: str bound_evidence: AttestationEvidence issued_at: float credential_evidence_hash: str open: bool = True def _evidence_hash(ev: AttestationEvidence) -> str: return hashlib.sha256( f"{ev.measurement}:{ev.pubkey_hash}".encode() ).hexdigest() def open_session( peer_did: str, quote: AttestationEvidence, vc: VerifiableCredential, now: float, ) -> PeerSession: if vc.revoked: raise AttestationBindingError(f"cannot open session: VC for {peer_did} is revoked") if _evidence_hash(vc.evidence) != _evidence_hash(quote): raise AttestationBindingError( f"handshake evidence mismatch for {peer_did}: " f"VC embeds {vc.evidence.measurement}, quote reports {quote.measurement}" ) return PeerSession( peer_did=peer_did, bound_evidence=quote, issued_at=now, credential_evidence_hash=_evidence_hash(vc), ) def revalidate_session( session: PeerSession, fresh_quote: Optional[AttestationEvidence], credentials_for_subject: list[VerifiableCredential], now: float, ) -> None: """Enforce the continuity invariant before a peer relies on the session for any authorization decision. Raises on any drift and closes the session. """ if not session.open: raise AttestationBindingError(f"session for {session.peer_did} already closed") # Signal 3: credential set must be a singleton for the subject. live = [c for c in credentials_for_subject if not c.revoked] if len(live) != 1: session.open = False raise AttestationBindingError( f"non-monotonic credential set for {session.peer_did}: " f"{len(live)} unrevoked VCs; rotation did not revoke prior credential" ) # Signal 1+2: key binding alone is insufficient; measurement must match. if fresh_quote is None: # No fresh evidence available: cannot confirm continuity. Refuse to # rely on the session for authorization rather than assume it holds. raise AttestationBindingError( f"no fresh quote for {session.peer_did}; cannot confirm measurement continuity" ) if fresh_quote.pubkey_hash != session.bound_evidence.pubkey_hash: session.open = False raise AttestationBindingError( f"key binding changed for {session.peer_did}; session key no longer valid" ) if fresh_quote.measurement != session.bound_evidence.measurement: session.open = False raise AttestationBindingError( f"measurement drift for {session.peer_did}: " f"session bound to {session.bound_evidence.measurement}, " f"peer now running {fresh_quote.measurement}; re-handshake required" ) # Signal 4: session must not predate the running measurement's epoch. if session.issued_at < fresh_quote.first_observed: session.open = False raise AttestationBindingError( f"session for {session.peer_did} issued at {session.issued_at} " f"precedes current measurement epoch {fresh_quote.first_observed}" ) # Invariant holds: bound evidence matches live evidence, credential set is # a singleton, and the session postdates the measurement epoch. return None