# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-must-an-instance-detect-ambiguity-exploitation-during-protocol-handshake-negotiation.md # Remnant Warrant: https://corpusfetch.com/c/how-must-an-instance-detect-ambiguity-exploitation-during-protocol-handshake-negotiation.warrant.json # Markdown SHA-256: e210ca8f1436f5d5af7d996e80037d503d8e2c901fd6eac2c079a06814838e25 # Code AST SHA-256: 5dbda673ef0459672fd8d498610c4bcc46cd5db4902cb8ec9d97c4db946cc3fd # Verified Classes: HandshakeVerdict, HandshakeNegotiation, HandshakePolicy, HandshakeManifest, HandshakeAmbiguityGuard # Defensive Guards: 0 fail-closed invariants (zero external deps) from dataclasses import dataclass from enum import Enum, auto import hashlib import json class HandshakeVerdict(Enum): UNAMBIGUOUS_HANDSHAKE = auto() PARAMETERS_COMMITTED = auto() DIVERGENT_INTERPRETATION = auto() SILENT_ACCEPTANCE_RISK = auto() @dataclass(frozen=True) class HandshakeNegotiation: negotiation_id: str specification_unambiguous: bool parameters_snapshotted: bool parameter_echo_matched: bool silent_acceptance_allowed: bool explicit_acknowledgment_required: bool @dataclass(frozen=True) class HandshakePolicy: require_explicit_ack: bool @dataclass(frozen=True) class HandshakeManifest: verdict: HandshakeVerdict directive: str manifest_digest: str class HandshakeAmbiguityGuard: @staticmethod def _hash(data: str) -> str: return hashlib.sha256(data.encode("utf-8")).hexdigest() @classmethod def evaluate_negotiation( cls, negotiation: HandshakeNegotiation, policy: HandshakePolicy ) -> HandshakeManifest: # Gate 1: Unambiguous if negotiation.specification_unambiguous: digest = cls._hash(json.dumps({ "negotiation": negotiation.negotiation_id, "type": "UNAMBIGUOUS" }, sort_keys=True)) return HandshakeManifest( verdict=HandshakeVerdict.UNAMBIGUOUS_HANDSHAKE, directive=f"PROCEED: Negotiation {negotiation.negotiation_id} unambiguous.", manifest_digest=digest ) # Gate 2: Silent acceptance if negotiation.silent_acceptance_allowed and not negotiation.explicit_acknowledgment_required: if policy.require_explicit_ack: return HandshakeManifest( verdict=HandshakeVerdict.SILENT_ACCEPTANCE_RISK, directive=f"HALT: Negotiation {negotiation.negotiation_id} allows silent acceptance.", manifest_digest=cls._hash(f"SILENT:{negotiation.negotiation_id}") ) # Gate 3: Parameter echo if negotiation.parameter_echo_matched and negotiation.parameters_snapshotted: digest = cls._hash(json.dumps({ "negotiation": negotiation.negotiation_id, "echo": True }, sort_keys=True)) return HandshakeManifest( verdict=HandshakeVerdict.PARAMETERS_COMMITTED, directive=f"PROCEED: Negotiation {negotiation.negotiation_id} parameters committed via echo.", manifest_digest=digest ) # Gate 4: Divergent return HandshakeManifest( verdict=HandshakeVerdict.DIVERGENT_INTERPRETATION, directive=f"FLAG: Negotiation {negotiation.negotiation_id} ambiguity unresolved.", manifest_digest=cls._hash(f"DIVERGENT:{negotiation.negotiation_id}") )