From c90c7a98d4677d13d1193a951ba6d7194af43bc6 Mon Sep 17 00:00:00 2001 From: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:35:10 -0600 Subject: [PATCH 1/2] feat(trace-adapters): reconcile GapDisclosure/1.0 without trusted fixture assertions Extract the section 3.3.4 verifier into agentrust-trace-adapters. Missing evidence stays receipt_missing_required, a two-sided splice is receipt_gap_disclosed, and a tail disclosure stays gap_disclosure_unverified. Credential coverage uses an explicit inventory. cause and fencing epochs do not authorize retry. Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com> --- packages/agentrust-trace-adapters/README.md | 13 + .../docs/gap-disclosure-reconciler.md | 91 ++ .../agentrust-trace-adapters/pyproject.toml | 7 +- .../src/agentrust_trace_adapters/__init__.py | 20 + .../gap_reconciler.py | 851 +++++++++++++++++ .../01-gap-disclosed-valid.json | 72 ++ ...2-gap-disclosure-dangling-predecessor.json | 72 ++ ...ap-disclosure-successor-does-not-link.json | 72 ++ .../04-gap-disclosure-contradicted.json | 74 ++ .../05-gap-disclosure-foreign-key.json | 72 ++ ...ap-disclosed-parent-key-null-estimate.json | 72 ++ .../07-gap-disclosure-unknown-key.json | 72 ++ .../08-gap-disclosure-tampered.json | 72 ++ .../09-gap-disclosure-key-case-variant.json | 72 ++ ...10-gap-disclosure-signature-malformed.json | 72 ++ ...ap-disclosure-confusable-ancestor-key.json | 77 ++ .../12-gap-disclosure-replayed-stream.json | 72 ++ ...13-gap-disclosure-stream-case-variant.json | 72 ++ ...-gap-disclosure-predecessor-link-tail.json | 72 ++ .../15-gap-disclosure-seal-tail-mismatch.json | 72 ++ ...6-gap-disclosure-contradicted-at-tail.json | 76 ++ .../17-gap-disclosure-at-unsealed-tail.json | 72 ++ ...8-gap-disclosure-tail-with-stale-link.json | 72 ++ ...9-gap-disclosure-type-version-unknown.json | 72 ++ .../20-gap-disclosure-type-absent.json | 71 ++ .../tests/test_gap_reconciler.py | 852 ++++++++++++++++++ 26 files changed, 3283 insertions(+), 1 deletion(-) create mode 100644 packages/agentrust-trace-adapters/docs/gap-disclosure-reconciler.md create mode 100644 packages/agentrust-trace-adapters/src/agentrust_trace_adapters/gap_reconciler.py create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/01-gap-disclosed-valid.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/02-gap-disclosure-dangling-predecessor.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/03-gap-disclosure-successor-does-not-link.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/04-gap-disclosure-contradicted.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/05-gap-disclosure-foreign-key.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/06-gap-disclosed-parent-key-null-estimate.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/07-gap-disclosure-unknown-key.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/08-gap-disclosure-tampered.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/09-gap-disclosure-key-case-variant.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/10-gap-disclosure-signature-malformed.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/11-gap-disclosure-confusable-ancestor-key.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/12-gap-disclosure-replayed-stream.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/13-gap-disclosure-stream-case-variant.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/14-gap-disclosure-predecessor-link-tail.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/15-gap-disclosure-seal-tail-mismatch.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/16-gap-disclosure-contradicted-at-tail.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/17-gap-disclosure-at-unsealed-tail.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/18-gap-disclosure-tail-with-stale-link.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/19-gap-disclosure-type-version-unknown.json create mode 100644 packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/20-gap-disclosure-type-absent.json create mode 100644 packages/agentrust-trace-adapters/tests/test_gap_reconciler.py diff --git a/packages/agentrust-trace-adapters/README.md b/packages/agentrust-trace-adapters/README.md index d0b728c6..ed2ce5c7 100644 --- a/packages/agentrust-trace-adapters/README.md +++ b/packages/agentrust-trace-adapters/README.md @@ -148,3 +148,16 @@ acceptance cases in [the producer contract](docs/openshell-bundle-candidate.md). The contract is development work for NVIDIA/OpenShell#2745 and does not exist upstream yet, so no live exporter compatibility or hardware assurance is claimed. The OpenShell transcript adapter is unaffected. + +## Gap disclosure reconciliation + +`reconcile_chain` judges a receipt chain that may contain `GapDisclosure/1.0`. +It implements the library slice of [integrations#416](https://github.com/agentrust-io/integrations/issues/416) +against trace-spec section 3.3.4. Splice facts are derived from the chain. +`cause` and `receipts_lost_estimate` are reported and never select an outcome. +A missing credential is `receipt_missing_required` unless an independently +retained inventory entry is bound by a verified two-sided disclosure. A tail +disclosure stays `gap_disclosure_unverified`. Retry is not authorized. + +The contract, the four review rules, and the non-claims are in +[docs/gap-disclosure-reconciler.md](docs/gap-disclosure-reconciler.md). diff --git a/packages/agentrust-trace-adapters/docs/gap-disclosure-reconciler.md b/packages/agentrust-trace-adapters/docs/gap-disclosure-reconciler.md new file mode 100644 index 00000000..b3665617 --- /dev/null +++ b/packages/agentrust-trace-adapters/docs/gap-disclosure-reconciler.md @@ -0,0 +1,91 @@ +# Gap disclosure reconciler + +Library slice for [agentrust-io/integrations#416](https://github.com/agentrust-io/integrations/issues/416). +The rules below are trace-spec section 3.3.4 at `b938790f7f46d3a943c76a5360d2de60bb72112c`, +as narrowed by the contract review on that issue. This module does not change +`ca2a` or `cmcp`, does not emit an orphaned-session disclosure, and does not +authorize a retry. + +```python +from agentrust_trace_adapters import reconcile_chain + +result = reconcile_chain( + elements, # JSON bytes, one object per chain element + session_id="wf-001", + trusted_issuer_keys=public_jwks, + expected_credential_ids=["cred-0", "cred-1", "cred-2"], +) +assert result.effect_status == "unknown" +assert result.retry_authorized is False +``` + +`verify_disclosure` judges one element. `reconcile_chain` walks the chain. +Untrusted documents must be bytes or str so the parser can reject duplicate +keys. A pre-parsed dict is accepted only by `verify_disclosure`, and only +after the same value bounds. + +## Outcomes + +| Status | When | +|---|---| +| `receipt_missing_required` | An inventory entry has no authenticated hop and no bound disclosure. Case A. | +| `receipt_gap_disclosed` | Ed25519 signature verifies, the issuer is the predecessor's key or an authenticated ancestor, `session_id` matches, and both splice ends are present and hash-linked. Case B. | +| `gap_disclosure_unverified` | The other checks pass but no successor seals the splice. A tail. Not coverage, and not invalid. | +| `receipt_invalid` | A check ran and failed: bad signature, wrong type, wrong stream, dangling or unsealed splice, unauthorized signer, or a record inside the gap. | +| `complete` | The inventory is present, every entry has one authenticated hop, and the chain has no disclosure. | + +`accepted_as_complete` is true only for `complete`. A profile that requires +proven completeness must pass `completeness_required=True`. That flag ignores +`accept_disclosed_gaps`. A disclosed gap is attested absence, not completeness. + +## The four contract rules + +1. **Case A is not Case B.** No disclosure means `receipt_missing_required`. + Case B requires the authenticated splice above. A tail stays + `gap_disclosure_unverified`. +2. **Inventory is an input, not an inference.** `expected_credential_ids` is + the independently retained inventory. `chain[:2]` does not imply a third + credential. A disclosure covers an entry only when its signed + `credential_id` names that entry. The binding does not prove the credential + ran, and a disclosure with no `credential_id` covers nothing. +3. **Descriptive fields stay descriptive.** `cause` and + `receipts_lost_estimate` are echoed when their shapes are a string and a + safe integer or null. A `lease_id` in `cause`, or `cas_fence_epoch` on a + hop, does not change status, does not prove non-execution, and does not + set `retry_authorized`. A second hop for the same credential is + `receipt_invalid`, not a retry. +4. **Fixture booleans are not evidence.** The API has no + `predecessor_present`, `successor_present`, `permitted_ancestor_key_ids`, + or `claimed_absent_but_present` parameter. Presence is an element whose + digest equals `previous_receipt_hash`. The seal is the next non-hierarchy + element after the disclosure. Ancestors come only from a + `KeyHierarchy/1.0` element signed by the ancestor key. Contradiction is a + receipt positioned in the splice span, or a receipt whose `sequence` falls + strictly between the predecessor and successor sequences. Those sequence + fields impeach; they never grant coverage. + +`KeyHierarchy/1.0` is this library's carrier for the section 3.2.1 ancestor +link. It is not a TRACE record type and it is not a wire change for `ca2a`. + +## Parser bounds + +`parse_untrusted_json` rejects oversize input, duplicate keys, non-finite +numbers, non-integral numbers, integers outside ±(2^53−1), nesting deeper +than 32, and private JWK members (`d`). A malformed signature is +`disclosure_signature_invalid`, not an exception, including a 32-byte value +and non-canonical base64url. + +## Corpus + +`tests/fixtures/gap-disclosure/` is the twenty-vector corpus from +`trace-spec` `examples/action-receipts/gap-disclosure/`. The tests rebuild +each contrast with signed elements and compare outcome codes to the fixture +oracle. The fixture chain object itself is hostile input: passing it to the +verifier must not produce `receipt_gap_disclosed`. + +## Out of scope + +- `ca2a_verify.verify_trace_dag` and `cross_check_trace_dag` +- cMCP orphaned-session emission +- manifest binding +- resource-side lease expiry, fencing enforcement, and automatic retry diff --git a/packages/agentrust-trace-adapters/pyproject.toml b/packages/agentrust-trace-adapters/pyproject.toml index 81519865..90435e77 100644 --- a/packages/agentrust-trace-adapters/pyproject.toml +++ b/packages/agentrust-trace-adapters/pyproject.toml @@ -28,7 +28,12 @@ requires-python = ">=3.11" # TRACE 0.7.0 introduced the origin block and its software-only platform rule. # The "declared" enforcement mode additionally requires TRACE 0.9.0; # earlier models reject that policy mode. -dependencies = ["agentrust-trace>=0.9.0", "cryptography>=43.0.0"] +dependencies = [ + "agentrust-trace>=0.9.0", + "cryptography>=43.0.0", + # Direct import. RFC 8785 canonicalization is the GapDisclosure signature preimage. + "rfc8785>=0.1.4", +] [project.urls] Homepage = "https://github.com/agentrust-io/integrations" diff --git a/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/__init__.py b/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/__init__.py index 85d61631..3b71d7b7 100644 --- a/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/__init__.py +++ b/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/__init__.py @@ -24,6 +24,17 @@ SourceSystem, digest_bytes, ) +from .gap_reconciler import ( + GAP_DISCLOSURE_UNVERIFIED, + RECEIPT_GAP_DISCLOSED, + RECEIPT_INVALID, + RECEIPT_MISSING_REQUIRED, + DisclosureVerdict, + MalformedInput, + Reconciliation, + reconcile_chain, + verify_disclosure, +) from .openshell import ( OpenShellEvidence, build_openshell_record, @@ -34,9 +45,16 @@ __all__ = [ "AppraisalEvidence", "DIGEST_RE", + "DisclosureVerdict", + "GAP_DISCLOSURE_UNVERIFIED", + "MalformedInput", "MissingEvidence", "OpenShellEvidence", "PolicyEvidence", + "RECEIPT_GAP_DISCLOSED", + "RECEIPT_INVALID", + "RECEIPT_MISSING_REQUIRED", + "Reconciliation", "SourceSystem", "TRACE_PROFILE", "appraisal_from_evidence", @@ -45,7 +63,9 @@ "build_policy_bundle", "build_transcript", "digest_bytes", + "reconcile_chain", "software_measurement", + "verify_disclosure", ] __version__ = "0.2.0" diff --git a/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/gap_reconciler.py b/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/gap_reconciler.py new file mode 100644 index 00000000..d3b1bdb3 --- /dev/null +++ b/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/gap_reconciler.py @@ -0,0 +1,851 @@ +"""Reconcile a TRACE receipt chain that may contain ``GapDisclosure/1.0``. + +This is the library extraction of ``trace-spec`` section 3.3.4 +(``trace-spec@b938790f7f46d3a943c76a5360d2de60bb72112c``) for +``agentrust-io/integrations#416``. It does not change ``ca2a`` or ``cmcp``, +and it does not authorize a retry. + +Four rules from the contract review are enforced here: + +1. A missing required hop with no disclosure is ``receipt_missing_required``. + ``receipt_gap_disclosed`` requires an authenticated issuer, stream binding, + and a two-sided splice. A tail disclosure is ``gap_disclosure_unverified``: + not coverage, and not automatically invalid. +2. A disclosure proves a position in the chain. It does not prove which + credential ran. Credential coverage is judged only against an independently + retained ``expected_credential_ids`` inventory, and a disclosure covers an + inventory entry only when its signed ``credential_id`` binds that entry. + ``chain[:2]`` does not imply a third credential. +3. ``cause`` and ``receipts_lost_estimate`` are descriptive. A ``lease_id`` in + ``cause``, or an emitter-asserted fencing epoch, never selects an outcome, + proves non-execution, or authorizes retry. ``effect_status`` stays + ``unknown``. +4. ``predecessor_present``, ``successor_present``, ``permitted_ancestor_key_ids`` + and ``claimed_absent_but_present`` are not inputs. Presence, the seal, + ancestor entitlement and contradiction are derived from authenticated chain + elements. Untrusted JSON is parsed with duplicate-key, non-finite, depth + and size bounds. + +Ancestor entitlement is not a caller-supplied id list. A ``KeyHierarchy/1.0`` +element counts only when the ancestor key verifies its signature. That carrier +is this library's explicit binding for section 3.2.1; it is not a TRACE record +type and it is not a ``ca2a`` wire change. +""" + +from __future__ import annotations + +import base64 +import binascii +import hashlib +import json +from collections.abc import Mapping, Sequence +from dataclasses import dataclass +from typing import Any + +import rfc8785 +from cryptography.exceptions import InvalidSignature +from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey + +__all__ = [ + "COMPLETE", + "CredentialCoverage", + "DISCLOSURE_TYPE", + "DisclosureVerdict", + "EFFECT_UNKNOWN", + "GAP_DISCLOSURE_UNVERIFIED", + "HIERARCHY_TYPE", + "INVENTORY_NOT_SUPPLIED", + "MalformedInput", + "RECEIPT_GAP_DISCLOSED", + "RECEIPT_INVALID", + "RECEIPT_MISSING_REQUIRED", + "RECEIPT_PRESENT", + "Reconciliation", + "element_digest", + "parse_untrusted_json", + "reconcile_chain", + "verify_disclosure", +] + +RECEIPT_GAP_DISCLOSED = "receipt_gap_disclosed" +RECEIPT_MISSING_REQUIRED = "receipt_missing_required" +GAP_DISCLOSURE_UNVERIFIED = "gap_disclosure_unverified" +RECEIPT_INVALID = "receipt_invalid" +RECEIPT_PRESENT = "receipt_present" +COMPLETE = "complete" +INVENTORY_NOT_SUPPLIED = "inventory_not_supplied" +EFFECT_UNKNOWN = "unknown" +DISCLOSURE_TYPE = "GapDisclosure/1.0" +HIERARCHY_TYPE = "KeyHierarchy/1.0" + +_SAFE_INT = 2**53 - 1 +_MAX_ELEMENT_BYTES = 65_536 +_MAX_CHAIN_ELEMENTS = 256 +_MAX_DEPTH = 32 +_MAX_KEYS = 64 +_MAX_ARRAY = 256 +_MAX_STRING = 16_384 +_MAX_CAUSE = 512 +_MAX_ID = 512 +_STATUSES = frozenset( + { + RECEIPT_GAP_DISCLOSED, + RECEIPT_MISSING_REQUIRED, + GAP_DISCLOSURE_UNVERIFIED, + RECEIPT_INVALID, + RECEIPT_PRESENT, + } +) +_SEVERITY = ( + RECEIPT_INVALID, + RECEIPT_MISSING_REQUIRED, + GAP_DISCLOSURE_UNVERIFIED, + RECEIPT_GAP_DISCLOSED, + RECEIPT_PRESENT, +) + + +class MalformedInput(ValueError): + """Untrusted input failed a bound or a parse rule. + + This is not a verification finding. A finding means the element was read + and judged. Malformed input is refused before that judgment. + """ + + +@dataclass(frozen=True) +class DisclosureVerdict: + """One disclosure, judged from the chain rather than from fixture assertions.""" + + status: str + controller_outcome: str + effect_status: str + retry_authorized: bool + failures: tuple[str, ...] + warnings: tuple[str, ...] + consecutive_disclosures: int + linked_predecessor: str | None + cause: str | None + receipts_lost_estimate: int | None + bound_credential_id: str | None + derived_predecessor_present: bool + derived_successor_present: bool + derived_ancestor_key_ids: tuple[str, ...] + derived_contradicting_digests: tuple[str, ...] + + def __post_init__(self) -> None: + if self.status not in _STATUSES: + raise MalformedInput(f"internal status {self.status!r} is not a disclosure outcome") + if self.effect_status != EFFECT_UNKNOWN or self.retry_authorized: + raise MalformedInput("effect status is unknown and retry is not authorized") + if self.controller_outcome != EFFECT_UNKNOWN: + raise MalformedInput("controller outcome is unknown") + + def as_fixture_dict(self) -> dict[str, Any]: + """The outcome shape pinned by the section 3.3.4 fixtures.""" + return { + "status": self.status, + "controller_outcome": self.controller_outcome, + "failures": list(self.failures), + "warnings": list(self.warnings), + "consecutive_disclosures": self.consecutive_disclosures, + "linked_predecessor": self.linked_predecessor, + "cause": self.cause, + } + + +@dataclass(frozen=True) +class CredentialCoverage: + """Coverage of one inventory entry. A disclosure does not prove it ran.""" + + credential_id: str + status: str + + def __post_init__(self) -> None: + if self.status not in _STATUSES: + raise MalformedInput(f"internal status {self.status!r} is not a coverage outcome") + + +@dataclass(frozen=True) +class Reconciliation: + """Chain reconciliation. ``retry_authorized`` is always false in this slice.""" + + status: str + effect_status: str + retry_authorized: bool + accepted_as_complete: bool + policy_accepted: bool + inventory_supplied: bool + disclosures: tuple[DisclosureVerdict, ...] + credentials: tuple[CredentialCoverage, ...] + failures: tuple[str, ...] + + def __post_init__(self) -> None: + if self.effect_status != EFFECT_UNKNOWN or self.retry_authorized: + raise MalformedInput("effect status is unknown and retry is not authorized") + + +def parse_untrusted_json(data: bytes | str) -> dict[str, Any]: + """Parse one JSON object. Duplicate keys, non-finite numbers and oversize input fail closed.""" + if isinstance(data, str): + raw = data.encode("utf-8") + elif isinstance(data, (bytes, bytearray)): + raw = bytes(data) + else: + raise MalformedInput("untrusted JSON must be bytes or str") + if not raw: + raise MalformedInput("untrusted JSON is empty") + if len(raw) > _MAX_ELEMENT_BYTES: + raise MalformedInput("untrusted JSON exceeds the size bound") + try: + text = raw.decode("utf-8") + except UnicodeDecodeError as exc: + raise MalformedInput("untrusted JSON is not UTF-8") from exc + try: + parsed = json.loads( + text, + object_pairs_hook=_reject_duplicate_keys, + parse_constant=_reject_non_finite, + ) + except RecursionError as exc: + raise MalformedInput("JSON nesting exceeds the bound") from exc + except MalformedInput: + raise + except ValueError as exc: + raise MalformedInput("untrusted JSON is not a JSON document") from exc + if not isinstance(parsed, dict): + raise MalformedInput("untrusted JSON must be an object") + _walk_bounds(parsed, 0) + return parsed + + +def element_digest(element: Mapping[str, Any]) -> str: + """Chain digest over the element's full canonical form, signature included.""" + try: + canonical = rfc8785.dumps(dict(element)) + except (TypeError, ValueError) as exc: + raise MalformedInput("chain element is not RFC 8785 canonicalizable") from exc + return "sha256:" + hashlib.sha256(canonical).hexdigest() + + +def verify_disclosure( + disclosure: bytes | str | Mapping[str, Any], + chain: Sequence[bytes | str | Mapping[str, Any]], + *, + session_id: str, + trusted_issuer_keys: Mapping[str, Mapping[str, Any]], +) -> DisclosureVerdict: + """Judge one disclosure. Chain facts are derived; fixture booleans are ignored.""" + session = _required_id("session_id", session_id) + keys = _trust_store(trusted_issuer_keys) + element = _as_object(disclosure) + elements = _chain_objects(chain) + return _judge_disclosure(element, elements, session, keys) + + +def reconcile_chain( + elements: Sequence[bytes | str], + *, + session_id: str, + trusted_issuer_keys: Mapping[str, Mapping[str, Any]], + expected_credential_ids: Sequence[str] | None = None, + completeness_required: bool = False, + accept_disclosed_gaps: bool = False, +) -> Reconciliation: + """Reconcile hop records and disclosures against an optional credential inventory. + + ``expected_credential_ids`` is the independently retained inventory. Omitting + it does not infer missing hops from ``len(elements)``. A disclosure covers an + inventory entry only through its signed ``credential_id``. That binding is + attested absence, not proof the credential ran. + """ + session = _required_id("session_id", session_id) + if type(completeness_required) is not bool or type(accept_disclosed_gaps) is not bool: + raise MalformedInput("policy flags must be bool") + keys = _trust_store(trusted_issuer_keys) + parsed = _chain_objects(elements, bytes_only=True) + inventory = _inventory(expected_credential_ids) + disclosures = tuple( + _judge_disclosure(element, parsed, session, keys) + for element in parsed + if _is_disclosure_candidate(element) + ) + credentials = _cover_credentials(parsed, disclosures, inventory, session, keys) + status = _aggregate(disclosures, credentials, inventory is not None) + failures = tuple( + dict.fromkeys(code for verdict in disclosures for code in verdict.failures) + ) + complete = _is_complete(credentials, disclosures, inventory is not None) + policy_accepted = _policy_accepted( + credentials, + disclosures, + inventory is not None, + completeness_required=completeness_required, + accept_disclosed_gaps=accept_disclosed_gaps, + complete=complete, + ) + return Reconciliation( + status=status, + effect_status=EFFECT_UNKNOWN, + retry_authorized=False, + accepted_as_complete=complete, + policy_accepted=policy_accepted, + inventory_supplied=inventory is not None, + disclosures=disclosures, + credentials=credentials, + failures=failures, + ) + + +def _judge_disclosure( + disclosure: Mapping[str, Any], + elements: Sequence[Mapping[str, Any]], + session_id: str, + keys: Mapping[str, Ed25519PublicKey], +) -> DisclosureVerdict: + _reject_descriptive_shape(disclosure) + digest = element_digest(disclosure) + indexes = [i for i, element in enumerate(elements) if element_digest(element) == digest] + disclosure_index = indexes[0] if len(indexes) == 1 else None + if len(indexes) > 1: + raise MalformedInput("duplicate chain element digest") + + predecessor = _element_by_digest(elements, disclosure.get("previous_receipt_hash"), disclosure_index) + successor = _successor(elements, disclosure_index) + ancestors = _authenticated_ancestors(elements, keys) + predecessor_issuer = _authenticated_issuer(predecessor, keys) + derived_ancestors = ancestors.get(predecessor_issuer, ()) if predecessor_issuer else () + contradicting = _contradicting( + elements, + predecessor, + successor, + disclosure_index, + digest, + ) + + failures: list[str] = [] + warnings: list[str] = [] + issuer_key_id = disclosure.get("issuer_key_id") + if not isinstance(issuer_key_id, str) or issuer_key_id not in keys: + warnings.append("disclosure_key_unknown") + elif not _signature_holds(disclosure, keys[issuer_key_id]): + failures.append("disclosure_signature_invalid") + + if disclosure.get("type") != DISCLOSURE_TYPE: + failures.append("disclosure_type_unsupported") + if _descriptive_malformed(disclosure): + failures.append("disclosure_descriptive_field_malformed") + if predecessor is None or predecessor_issuer is None: + failures.append("disclosure_predecessor_absent") + elif issuer_key_id not in {predecessor_issuer, *derived_ancestors}: + failures.append("disclosure_issuer_not_chain_key") + if disclosure.get("session_id") != session_id: + failures.append("disclosure_stream_mismatch") + if contradicting: + failures.append("disclosure_contradicted") + if successor is None: + warnings.append("disclosure_not_yet_sealed") + elif successor.get("previous_receipt_hash") != digest: + failures.append("disclosure_not_sealed_by_successor") + + if failures: + status = RECEIPT_INVALID + elif warnings: + status = GAP_DISCLOSURE_UNVERIFIED + else: + status = RECEIPT_GAP_DISCLOSED + warnings = [RECEIPT_GAP_DISCLOSED] + + cause = disclosure.get("cause") + estimate = disclosure.get("receipts_lost_estimate", None) + bound = disclosure.get("credential_id") + return DisclosureVerdict( + status=status, + controller_outcome=EFFECT_UNKNOWN, + effect_status=EFFECT_UNKNOWN, + retry_authorized=False, + failures=tuple(failures), + warnings=tuple(warnings), + consecutive_disclosures=_consecutive(elements, disclosure_index), + linked_predecessor=disclosure.get("previous_receipt_hash") + if isinstance(disclosure.get("previous_receipt_hash"), str) + else None, + cause=cause if isinstance(cause, str) else None, + receipts_lost_estimate=estimate if type(estimate) is int else None, + bound_credential_id=bound if isinstance(bound, str) else None, + derived_predecessor_present=predecessor is not None and predecessor_issuer is not None, + derived_successor_present=successor is not None, + derived_ancestor_key_ids=tuple(derived_ancestors), + derived_contradicting_digests=tuple(dict.fromkeys(contradicting)), + ) + + +def _cover_credentials( + elements: Sequence[Mapping[str, Any]], + disclosures: Sequence[DisclosureVerdict], + inventory: Sequence[str] | None, + session_id: str, + keys: Mapping[str, Ed25519PublicKey], +) -> tuple[CredentialCoverage, ...]: + if inventory is None: + return () + coverage: list[CredentialCoverage] = [] + for credential_id in inventory: + hops = [ + element + for element in elements + if element.get("credential_id") == credential_id and not _skipped_for_coverage(element) + ] + verified = [ + element + for element in hops + if element.get("session_id") == session_id + and _hop_signature_holds(element, keys) + ] + forged = [ + element + for element in hops + if isinstance(element.get("issuer_key_id"), str) + and element["issuer_key_id"] in keys + and not _signature_holds(element, keys[element["issuer_key_id"]]) + ] + bound = [item for item in disclosures if item.bound_credential_id == credential_id] + if any(item.status == RECEIPT_INVALID for item in bound) or forged or len(verified) > 1: + # A second verified hop is not a fenced retry. Fence epochs are ignored. + status = RECEIPT_INVALID + elif verified: + status = RECEIPT_PRESENT + elif any(item.status == RECEIPT_GAP_DISCLOSED for item in bound): + status = RECEIPT_GAP_DISCLOSED + elif any(item.status == GAP_DISCLOSURE_UNVERIFIED for item in bound): + status = GAP_DISCLOSURE_UNVERIFIED + else: + status = RECEIPT_MISSING_REQUIRED + coverage.append(CredentialCoverage(credential_id, status)) + return tuple(coverage) + + +def _aggregate( + disclosures: Sequence[DisclosureVerdict], + credentials: Sequence[CredentialCoverage], + inventory_supplied: bool, +) -> str: + if _is_complete(credentials, disclosures, inventory_supplied): + return COMPLETE + statuses = [item.status for item in disclosures] + statuses.extend(item.status for item in credentials) + for status in _SEVERITY: + if status in statuses: + return status + return INVENTORY_NOT_SUPPLIED + + +def _is_complete( + credentials: Sequence[CredentialCoverage], + disclosures: Sequence[DisclosureVerdict], + inventory_supplied: bool, +) -> bool: + return bool( + inventory_supplied + and credentials + and not disclosures + and all(item.status == RECEIPT_PRESENT for item in credentials) + ) + + +def _policy_accepted( + credentials: Sequence[CredentialCoverage], + disclosures: Sequence[DisclosureVerdict], + inventory_supplied: bool, + *, + completeness_required: bool, + accept_disclosed_gaps: bool, + complete: bool, +) -> bool: + if not inventory_supplied: + return False + if completeness_required: + return complete + if any(item.status in {RECEIPT_INVALID, RECEIPT_MISSING_REQUIRED, GAP_DISCLOSURE_UNVERIFIED} for item in credentials): + return False + if any(item.status in {RECEIPT_INVALID, GAP_DISCLOSURE_UNVERIFIED} for item in disclosures): + return False + if any(item.status == RECEIPT_GAP_DISCLOSED for item in (*credentials, *disclosures)): + return accept_disclosed_gaps + return complete or bool(credentials) + + +def _authenticated_ancestors( + elements: Sequence[Mapping[str, Any]], + keys: Mapping[str, Ed25519PublicKey], +) -> dict[str, tuple[str, ...]]: + found: dict[str, list[str]] = {} + for element in elements: + if element.get("type") != HIERARCHY_TYPE: + continue + ancestor = element.get("ancestor_key_id") + subject = element.get("subject_key_id") + issuer = element.get("issuer_key_id") + if not all(isinstance(value, str) and value for value in (ancestor, subject, issuer)): + continue + if ancestor != issuer or ancestor not in keys: + continue + if not _signature_holds(element, keys[ancestor]): + continue + bucket = found.setdefault(subject, []) + if ancestor not in bucket: + bucket.append(ancestor) + return {subject: tuple(ancestors) for subject, ancestors in found.items()} + + +def _authenticated_issuer( + element: Mapping[str, Any] | None, + keys: Mapping[str, Ed25519PublicKey], +) -> str | None: + if element is None: + return None + issuer = element.get("issuer_key_id") + if not isinstance(issuer, str) or not issuer: + return None + if issuer not in keys: + # Section 3.3.2: the verifier not holding the key is not proof of forgery. + # The id is still the id bound into the element digest. + return issuer + if not _signature_holds(element, keys[issuer]): + return None + return issuer + + +def _element_by_digest( + elements: Sequence[Mapping[str, Any]], + digest: Any, + skip_index: int | None, +) -> Mapping[str, Any] | None: + if not isinstance(digest, str): + return None + found: list[Mapping[str, Any]] = [] + for index, element in enumerate(elements): + if index == skip_index: + continue + if element_digest(element) == digest: + found.append(element) + if len(found) > 1: + raise MalformedInput("duplicate chain element digest") + return found[0] if found else None + + +def _successor( + elements: Sequence[Mapping[str, Any]], + disclosure_index: int | None, +) -> Mapping[str, Any] | None: + if disclosure_index is None: + return None + for element in elements[disclosure_index + 1 :]: + if element.get("type") == HIERARCHY_TYPE: + continue + return element + return None + + +def _consecutive(elements: Sequence[Mapping[str, Any]], disclosure_index: int | None) -> int: + if disclosure_index is None: + return 1 + count = 0 + index = disclosure_index + while index >= 0: + element = elements[index] + if element.get("type") == HIERARCHY_TYPE: + index -= 1 + continue + if index != disclosure_index and _gap_type(element) is None: + break + count += 1 + index -= 1 + return count + + +def _contradicting( + elements: Sequence[Mapping[str, Any]], + predecessor: Mapping[str, Any] | None, + successor: Mapping[str, Any] | None, + disclosure_index: int | None, + disclosure_digest: str, +) -> list[str]: + if predecessor is None or disclosure_index is None: + return [] + predecessor_index = _index_of(elements, predecessor) + if predecessor_index is None: + return [] + hits: list[str] = [] + right = disclosure_index + if successor is not None: + successor_index = _index_of(elements, successor) + if successor_index is not None: + right = successor_index + start, end = sorted((predecessor_index, right)) + for index in range(start + 1, end): + if index == disclosure_index: + continue + element = elements[index] + if element.get("type") == HIERARCHY_TYPE or _gap_type(element) is not None: + continue + hits.append(element_digest(element)) + predecessor_sequence = _sequence(predecessor) + successor_sequence = _sequence(successor) if successor is not None else None + if ( + predecessor_sequence is not None + and successor_sequence is not None + and predecessor_sequence < successor_sequence + ): + for index, element in enumerate(elements): + if index in {predecessor_index, disclosure_index} or element is successor: + continue + if element.get("type") == HIERARCHY_TYPE or _gap_type(element) is not None: + continue + sequence = _sequence(element) + digest = element_digest(element) + if sequence is not None and predecessor_sequence < sequence < successor_sequence: + if digest != disclosure_digest: + hits.append(digest) + return hits + + +def _index_of( + elements: Sequence[Mapping[str, Any]], + target: Mapping[str, Any], +) -> int | None: + target_digest = element_digest(target) + for index, element in enumerate(elements): + if element_digest(element) == target_digest: + return index + return None + + +def _sequence(element: Mapping[str, Any] | None) -> int | None: + if element is None: + return None + value = element.get("sequence") + if type(value) is int and -_SAFE_INT <= value <= _SAFE_INT: + return value + return None + + +def _gap_type(element: Mapping[str, Any]) -> str | None: + kind = element.get("type") + if isinstance(kind, str) and kind.startswith("GapDisclosure"): + return kind + return None + + +def _is_disclosure_candidate(element: Mapping[str, Any]) -> bool: + """A typed disclosure, or a typeless object with the disclosure members. + + Vector 20 omits ``type``. A presence check would skip it; an equality check + has to see it. Hop records in this slice carry ``credential_id`` and are + not candidates. + """ + if _gap_type(element) is not None: + return True + if "type" in element or "credential_id" in element: + return False + return all( + isinstance(element.get(field), str) + for field in ("previous_receipt_hash", "issuer_key_id", "signature") + ) + + +def _skipped_for_coverage(element: Mapping[str, Any]) -> bool: + return element.get("type") == HIERARCHY_TYPE or _gap_type(element) is not None + + +def _hop_signature_holds(element: Mapping[str, Any], keys: Mapping[str, Ed25519PublicKey]) -> bool: + issuer = element.get("issuer_key_id") + if not isinstance(issuer, str) or issuer not in keys: + return False + return _signature_holds(element, keys[issuer]) + + +def _signature_holds(element: Mapping[str, Any], key: Ed25519PublicKey) -> bool: + raw = _canonical_b64url(element.get("signature")) + if raw is None: + return False + body = {field: value for field, value in element.items() if field != "signature"} + try: + signed = rfc8785.dumps(body) + except (TypeError, ValueError): + return False + try: + key.verify(raw, signed) + except (InvalidSignature, ValueError): + return False + return True + + +def _reject_descriptive_shape(disclosure: Mapping[str, Any]) -> None: + """Shape gate only. Values that pass are never read again to choose a status.""" + if "credential_id" in disclosure: + credential_id = disclosure.get("credential_id") + if type(credential_id) is not str or not credential_id or len(credential_id) > _MAX_ID: + raise MalformedInput("credential_id binding is malformed") + cause = disclosure.get("cause", None) + if "cause" in disclosure and cause is not None and type(cause) is not str: + return + if isinstance(cause, str) and len(cause) > _MAX_CAUSE: + return + estimate = disclosure.get("receipts_lost_estimate", None) + if "receipts_lost_estimate" in disclosure and estimate is not None and type(estimate) is not int: + return + if type(estimate) is int and not -_SAFE_INT <= estimate <= _SAFE_INT: + return + + +def _descriptive_malformed(disclosure: Mapping[str, Any]) -> bool: + if "cause" in disclosure and disclosure.get("cause") is not None: + cause = disclosure.get("cause") + if type(cause) is not str or len(cause) > _MAX_CAUSE: + return True + if "receipts_lost_estimate" not in disclosure: + return False + estimate = disclosure.get("receipts_lost_estimate") + if estimate is None: + return False + if type(estimate) is not int or not -_SAFE_INT <= estimate <= _SAFE_INT: + return True + return False + + +def _chain_objects( + chain: Sequence[bytes | str | Mapping[str, Any]], + *, + bytes_only: bool = False, +) -> list[dict[str, Any]]: + if isinstance(chain, (str, bytes, bytearray)) or not isinstance(chain, Sequence): + raise MalformedInput("chain must be a sequence of elements") + if len(chain) > _MAX_CHAIN_ELEMENTS: + raise MalformedInput("chain exceeds the length bound") + parsed: list[dict[str, Any]] = [] + digests: set[str] = set() + for element in chain: + if bytes_only and isinstance(element, Mapping): + raise MalformedInput("reconcile_chain accepts JSON bytes, not pre-parsed objects") + obj = _as_object(element) + digest = element_digest(obj) + if digest in digests: + raise MalformedInput("duplicate chain element digest") + digests.add(digest) + parsed.append(obj) + return parsed + + +def _as_object(element: bytes | str | Mapping[str, Any]) -> dict[str, Any]: + if isinstance(element, Mapping): + if not isinstance(element, dict): + element = dict(element) + _walk_bounds(element, 0) + return element + return parse_untrusted_json(element) + + +def _inventory(expected: Sequence[str] | None) -> tuple[str, ...] | None: + if expected is None: + return None + if isinstance(expected, (str, bytes)) or not isinstance(expected, Sequence): + raise MalformedInput("expected_credential_ids must be a sequence of credential ids") + if len(expected) > _MAX_CHAIN_ELEMENTS: + raise MalformedInput("expected credential inventory exceeds the length bound") + ids: list[str] = [] + for credential_id in expected: + ids.append(_required_id("expected credential id", credential_id)) + if len(set(ids)) != len(ids): + raise MalformedInput("expected credential inventory has a duplicate id") + return tuple(ids) + + +def _required_id(name: str, value: Any) -> str: + if type(value) is not str or not value or len(value) > _MAX_ID or "\x00" in value: + raise MalformedInput(f"{name} must be a non-empty string") + return value + + +def _trust_store(trusted: Mapping[str, Mapping[str, Any]]) -> dict[str, Ed25519PublicKey]: + if not isinstance(trusted, Mapping): + raise MalformedInput("trusted_issuer_keys must be a mapping") + store: dict[str, Ed25519PublicKey] = {} + for key_id, jwk in trusted.items(): + if type(key_id) is not str or not key_id or len(key_id) > _MAX_ID: + raise MalformedInput("trusted issuer key id is malformed") + store[key_id] = _public_key(jwk) + return store + + +def _public_key(jwk: Mapping[str, Any]) -> Ed25519PublicKey: + if not isinstance(jwk, Mapping): + raise MalformedInput("trusted issuer key is not a JWK object") + if any(field in jwk for field in ("d", "priv", "p", "q")): + raise MalformedInput("private key material is not a trust anchor") + if jwk.get("kty") != "OKP" or jwk.get("crv") != "Ed25519": + raise MalformedInput("trusted issuer key is not Ed25519") + raw = _canonical_b64url(jwk.get("x")) + if raw is None or len(raw) != 32: + raise MalformedInput("trusted issuer key has a malformed x") + return Ed25519PublicKey.from_public_bytes(raw) + + +def _canonical_b64url(encoded: Any) -> bytes | None: + if type(encoded) is not str or not encoded or "=" in encoded: + return None + alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" + if any(char not in alphabet for char in encoded): + return None + try: + raw = base64.urlsafe_b64decode(encoded + "=" * (-len(encoded) % 4)) + except (binascii.Error, ValueError): + return None + if base64.urlsafe_b64encode(raw).rstrip(b"=").decode("ascii") != encoded: + return None + return raw + + +def _reject_duplicate_keys(pairs: list[tuple[str, Any]]) -> dict[str, Any]: + value: dict[str, Any] = {} + for key, item in pairs: + if key in value: + raise MalformedInput(f"duplicate JSON key {key!r}") + value[key] = item + return value + + +def _reject_non_finite(name: str) -> Any: + raise MalformedInput(f"non-finite JSON number {name}") + + +def _walk_bounds(value: Any, depth: int) -> None: + if depth > _MAX_DEPTH: + raise MalformedInput("JSON nesting exceeds the bound") + if isinstance(value, dict): + if len(value) > _MAX_KEYS: + raise MalformedInput("JSON object exceeds the key bound") + for key, item in value.items(): + if type(key) is not str or len(key) > _MAX_STRING: + raise MalformedInput("JSON object key exceeds the bound") + _walk_bounds(item, depth + 1) + return + if isinstance(value, list): + if len(value) > _MAX_ARRAY: + raise MalformedInput("JSON array exceeds the length bound") + for item in value: + _walk_bounds(item, depth + 1) + return + if type(value) is int: + if not -_SAFE_INT <= value <= _SAFE_INT: + raise MalformedInput("integer outside the safe range") + return + if type(value) is float: + raise MalformedInput("non-integral JSON number") + if type(value) is str: + if len(value) > _MAX_STRING: + raise MalformedInput("JSON string exceeds the bound") + return + if value is None or type(value) is bool: + return + raise MalformedInput("unsupported JSON value") diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/01-gap-disclosed-valid.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/01-gap-disclosed-valid.json new file mode 100644 index 00000000..c95c8088 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/01-gap-disclosed-valid.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosed-valid", + "description": "A disclosure spliced into the chain: it links back to a present element and the next element links back to it. Coverage is structural, so nothing is asserted about a range.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:cf36ee4d9b9dd71cb37c34dc57bcdacbb3c7b3ef42615a48409c2c4463c1b3d3", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "receipt_gap_disclosed", + "controller_outcome": "unknown", + "failures": [], + "warnings": [ + "receipt_gap_disclosed" + ], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/02-gap-disclosure-dangling-predecessor.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/02-gap-disclosure-dangling-predecessor.json new file mode 100644 index 00000000..44a7ffc7 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/02-gap-disclosure-dangling-predecessor.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-dangling-predecessor", + "description": "The disclosure links back to an element that is not in the chain. Half a splice is not a splice: it fixes nothing in place.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": false, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:cf36ee4d9b9dd71cb37c34dc57bcdacbb3c7b3ef42615a48409c2c4463c1b3d3", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_predecessor_absent" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/03-gap-disclosure-successor-does-not-link.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/03-gap-disclosure-successor-does-not-link.json new file mode 100644 index 00000000..27b3fa76 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/03-gap-disclosure-successor-does-not-link.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-successor-does-not-link", + "description": "The next element after resumption links past the disclosure to the element before the gap, leaving the disclosure attached at one end only. A disclosure no successor names can be minted later and slid over any gap.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_not_sealed_by_successor" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/04-gap-disclosure-contradicted.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/04-gap-disclosure-contradicted.json new file mode 100644 index 00000000..595c3008 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/04-gap-disclosure-contradicted.json @@ -0,0 +1,74 @@ +{ + "name": "gap-disclosure-contradicted", + "description": "Elements the disclosure implies are absent are present in the chain. A self-contradictory disclosure impeaches the emitter rather than excusing it.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:cf36ee4d9b9dd71cb37c34dc57bcdacbb3c7b3ef42615a48409c2c4463c1b3d3", + "successor_present": true, + "claimed_absent_but_present": [ + "sha256:c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9" + ], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_contradicted" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/05-gap-disclosure-foreign-key.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/05-gap-disclosure-foreign-key.json new file mode 100644 index 00000000..2d8fedde --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/05-gap-disclosure-foreign-key.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-foreign-key", + "description": "Signed by a key the verifier trusts, but which is neither the key that signed the linked element nor an ancestor of it. A gap is where introducing an unrelated key is most useful and least distinguishable from recovery.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:3c543561f448216d7569a5c3f6edabfb4694ef3d79ab5bc4998d2d1d0c47980a", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "k1OEGRftz9gN8m6CWBaM_MHoi9pSleIws7Y3gS4AWPYDIgq_76ljP9ZQCmMlLapC8L059matDjbQKK0Vj36YBQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_issuer_not_chain_key" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/06-gap-disclosed-parent-key-null-estimate.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/06-gap-disclosed-parent-key-null-estimate.json new file mode 100644 index 00000000..1a8441e3 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/06-gap-disclosed-parent-key-null-estimate.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosed-parent-key-null-estimate", + "description": "Signed by the hierarchical parent, because the crash took the session key with it, and the count of lost receipts is not bounded. The estimate is an unverifiable self-report either way; the chain links are what hold.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:38617e4db9e0cb7279fe4f9b2f9938aa686692c4e56ed4451c4bd61286f37a9f", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 3 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-workload-attestation", + "cause": "crash", + "receipts_lost_estimate": null, + "signature": "SQpH6hCFdjHPDivRcHc0PYHgrpAVpsKEOu6w9WlSbDs7c5ktGsLmrehbUtco-6ulNHcvKderbqudHNF8bmalAw" + }, + "expected": { + "status": "receipt_gap_disclosed", + "controller_outcome": "unknown", + "failures": [], + "warnings": [ + "receipt_gap_disclosed" + ], + "consecutive_disclosures": 3, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/07-gap-disclosure-unknown-key.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/07-gap-disclosure-unknown-key.json new file mode 100644 index 00000000..f3af39ef --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/07-gap-disclosure-unknown-key.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-unknown-key", + "description": "The named key is the one that signed the linked element, but the verifier does not hold it. Chain position does not confer trust \u2014 and the verifier's ignorance does not prove forgery. Unverifiable is not invalid (spec section 3.3.2): the disclosure is surfaced as unverified with an advisory, conferring nothing and accusing no one.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2027q1", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:5f3d5ff3bb8b196a81cb9f1614adb226a840a2eb30a53ced9f85bbf883b587d7", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2027q1", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "3OVGq6kohVs6Eg8IBse-PQyZVszCPinjTDyGwMJGlf36rMoDivcyCgGxL6c6amIGnZ6S-0icgTehZJUCPpHlCg" + }, + "expected": { + "status": "gap_disclosure_unverified", + "controller_outcome": "unknown", + "failures": [], + "warnings": [ + "disclosure_key_unknown" + ], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/08-gap-disclosure-tampered.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/08-gap-disclosure-tampered.json new file mode 100644 index 00000000..250bc710 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/08-gap-disclosure-tampered.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-tampered", + "description": "Altered after signing, so the signature no longer covers its contents.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:28c867b119337dafd739982482e612bab1667de1c993d2edeab303adc669cb50", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "shutdown", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_signature_invalid" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "shutdown" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/09-gap-disclosure-key-case-variant.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/09-gap-disclosure-key-case-variant.json new file mode 100644 index 00000000..4058ee3c --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/09-gap-disclosure-key-case-variant.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-key-case-variant", + "description": "The trusted set pins the right public key under a case-variant of the disclosure's issuer_key_id. Key identifiers are opaque strings: holding the key under a different spelling is not holding the key the disclosure names.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:cf36ee4d9b9dd71cb37c34dc57bcdacbb3c7b3ef42615a48409c2c4463c1b3d3", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "DID:WEB:FACTORY.EXAMPLE:SAFETY-CONTROLLER#ED25519-2026Q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "gap_disclosure_unverified", + "controller_outcome": "unknown", + "failures": [], + "warnings": [ + "disclosure_key_unknown" + ], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/10-gap-disclosure-signature-malformed.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/10-gap-disclosure-signature-malformed.json new file mode 100644 index 00000000..0e1bb597 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/10-gap-disclosure-signature-malformed.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-signature-malformed", + "description": "The signature is valid base64url of the wrong length. Together with the tampered vector this separates structural validation from verification.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:63a0d2c102e487b710cf8e130d9f680f71803efe9e089d0ffa233b5f41364b70", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_signature_invalid" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/11-gap-disclosure-confusable-ancestor-key.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/11-gap-disclosure-confusable-ancestor-key.json new file mode 100644 index 00000000..e7d89f3b --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/11-gap-disclosure-confusable-ancestor-key.json @@ -0,0 +1,77 @@ +{ + "name": "gap-disclosure-confusable-ancestor-key", + "description": "Signed by a trusted key whose id is the permitted ancestor's id in a different case \u2014 a confusable registration, not the ancestor. Entitlement to disclose is bound to the chain's exact key ids.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:c9419cb47d7089bdb592077bfc8affeb2d6442cca6b6eafc3d8fbf40f43ef19d", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + }, + "did:web:factory.example:safety-controller#ED25519-WORKLOAD-ATTESTATION": { + "kty": "OKP", + "crv": "Ed25519", + "x": "VVaRCvqm79Hib-vDRkLCnvAjgtm_qNIedhrdnglPNac" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ED25519-WORKLOAD-ATTESTATION", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "q0OJTMnU3j87iGnqWe2zQ5seF8SAfKPUtRG3JztZtsdUWTYP8tj3pzG6w4QBNUxWDlDtGWd6GeWVUhLPGlAvBg" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_issuer_not_chain_key" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/12-gap-disclosure-replayed-stream.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/12-gap-disclosure-replayed-stream.json new file mode 100644 index 00000000..4d17f08d --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/12-gap-disclosure-replayed-stream.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-replayed-stream", + "description": "A disclosure honestly signed for a different session, presented against this one. Every structural check passes \u2014 the splice is sound, the key is entitled \u2014 because the disclosure was genuine where it was minted. Stream binding is the only thing that refuses the transplant.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:27f335fe7549fa68a09b8711ee05eab7c54447a2a10fa73e728ee6fc237a054a", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-01T08:00:00Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "nB83NMX6qU8NdDpDG4c7hKb9_4Kj9JqxMJhlUeBu0kbad2DmHD3WceaLSnKgzxCbuHeVpkbSolUX8Z_cBjiTCA" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_stream_mismatch" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/13-gap-disclosure-stream-case-variant.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/13-gap-disclosure-stream-case-variant.json new file mode 100644 index 00000000..7ef78feb --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/13-gap-disclosure-stream-case-variant.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-stream-case-variant", + "description": "The disclosure's session_id is this session's id upper-cased. Session identifiers are opaque: a case-normalising comparison reads this as bound to the stream, and it is not.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:332a69b3a03bcf17c414870775ae8ccba14a7696e2d9c9c9b43797d8c7b2bc7a", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "TRACE-SESSION-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "YIfDSNIUmnPUG-VXDYOqeeyhPogEeH36pC4nIufeiuCk01M1mFVhIy6PjsXpOVb-n7JBqPV7AmqZVyH6H9TMDQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_stream_mismatch" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/14-gap-disclosure-predecessor-link-tail.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/14-gap-disclosure-predecessor-link-tail.json new file mode 100644 index 00000000..ee52e4f4 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/14-gap-disclosure-predecessor-link-tail.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-predecessor-link-tail", + "description": "The disclosure's previous_receipt_hash matches the present predecessor's hash in all but the final character. A link to almost the right element is a link to nothing.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:d300b19c0adb8f40d1891034e257d0b5c7a44d7fcacd271152cf3914fc8ab3c9", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a0", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "2QmCKKsvJiheUIv6QamvoQtkZ77Rjjj0lQgJRRM3dY30fEBn4_sgFArF_8v_3YoU62TivAFdkv5Oy7_L92IvDQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_predecessor_absent" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a0", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/15-gap-disclosure-seal-tail-mismatch.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/15-gap-disclosure-seal-tail-mismatch.json new file mode 100644 index 00000000..935c76b9 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/15-gap-disclosure-seal-tail-mismatch.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-seal-tail-mismatch", + "description": "The next element's previous_receipt_hash matches the disclosure's digest in all but the final character: sealed to a truncated comparison, unsealed in fact.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:cf36ee4d9b9dd71cb37c34dc57bcdacbb3c7b3ef42615a48409c2c4463c1b3d0", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_not_sealed_by_successor" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/16-gap-disclosure-contradicted-at-tail.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/16-gap-disclosure-contradicted-at-tail.json new file mode 100644 index 00000000..8061473b --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/16-gap-disclosure-contradicted-at-tail.json @@ -0,0 +1,76 @@ +{ + "name": "gap-disclosure-contradicted-at-tail", + "description": "Elements the disclosure implies are absent are present, and the disclosure sits at the live tail with no successor yet. Self-contradiction impeaches the emitter wherever it stands.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": null, + "successor_present": false, + "claimed_absent_but_present": [ + "sha256:c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9" + ], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_contradicted" + ], + "warnings": [ + "disclosure_not_yet_sealed" + ], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/17-gap-disclosure-at-unsealed-tail.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/17-gap-disclosure-at-unsealed-tail.json new file mode 100644 index 00000000..d1820cc8 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/17-gap-disclosure-at-unsealed-tail.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-at-unsealed-tail", + "description": "A well-formed disclosure at the live tail of the chain: signed by the chain key, linked to a present predecessor, and with no successor yet to seal it. Not invalid \u2014 nothing is defective \u2014 and not disclosed either: half a splice covers nothing until the chain resumes and the seal can be checked. Re-verification after resumption upgrades it.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": null, + "successor_present": false, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "gap_disclosure_unverified", + "controller_outcome": "unknown", + "failures": [], + "warnings": [ + "disclosure_not_yet_sealed" + ], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/18-gap-disclosure-tail-with-stale-link.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/18-gap-disclosure-tail-with-stale-link.json new file mode 100644 index 00000000..006d8ee5 --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/18-gap-disclosure-tail-with-stale-link.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-tail-with-stale-link", + "description": "The same unsealed tail, but the successor-link field in the verification context holds a leftover value from a previous verification. There is still no successor: sealed-ness is a fact about the chain, not about a field being non-null.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7", + "successor_present": false, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/1.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "0WTbD_j2neboOUN8WmkWbVweYp0R-rYWb53LnWWjSomFzAtiZlHDmbKBVbVQ_dlpOj7ZN8cWz6WWzsCwGyCQDQ" + }, + "expected": { + "status": "gap_disclosure_unverified", + "controller_outcome": "unknown", + "failures": [], + "warnings": [ + "disclosure_not_yet_sealed" + ], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/19-gap-disclosure-type-version-unknown.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/19-gap-disclosure-type-version-unknown.json new file mode 100644 index 00000000..ffd0d0ff --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/19-gap-disclosure-type-version-unknown.json @@ -0,0 +1,72 @@ +{ + "name": "gap-disclosure-type-version-unknown", + "description": "A well-signed disclosure whose type names a version this verifier does not implement. An unknown version is rejected rather than parsed best-effort.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:2072655dec5d5535d56acfaf1d006ce9118eeca871b05e01190e5f3789661c6b", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "type": "GapDisclosure/2.0", + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "xtjWyVMJzp4Bdx7cl537-cUK-L9RLo9QfBbgVWdM0GXWR6Wov-qWIy9NBd71bbGxST-YegDK83C_jTr-xFDmBg" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_type_unsupported" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/20-gap-disclosure-type-absent.json b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/20-gap-disclosure-type-absent.json new file mode 100644 index 00000000..6f4de50a --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/fixtures/gap-disclosure/20-gap-disclosure-type-absent.json @@ -0,0 +1,71 @@ +{ + "name": "gap-disclosure-type-absent", + "description": "A well-signed disclosure with no type member at all. A presence check and an equality check differ exactly here.", + "profile": "trace.action_receipt.conformance.v0", + "source": { + "issue": "agentrust-io/trace-spec#117", + "spec": "spec/trace-v0.2.md section 3.3.4" + }, + "context": { + "session_id": "trace-session-2026-07-06T15:22:11Z", + "require_receipt": true, + "verification_time": "2026-07-06T15:24:00Z", + "max_receipt_age_seconds": 300, + "expected_previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "chain": { + "predecessor_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "predecessor_present": true, + "predecessor_issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "permitted_ancestor_key_ids": [ + "did:web:factory.example:safety-controller#ed25519-workload-attestation" + ], + "successor_previous_receipt_hash": "sha256:e0832935b71ce78048d0ccfc80a5d451b3ae1fb87d1d0af24b4f567459935232", + "successor_present": true, + "claimed_absent_but_present": [], + "consecutive_disclosures": 1 + } + }, + "action": { + "agent_id": "spiffe://factory.example/agent/ros2-fibonacci/dev", + "action_type": "ros2.action.example_interfaces/Fibonacci", + "action_scope": "/abort_fibonacci_process", + "action_timestamp": "2026-07-06T15:22:13Z", + "action_ref": "sha256:e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3" + }, + "trusted_issuer_keys": { + "did:web:factory.example:safety-controller#ed25519-2026q3": { + "kty": "OKP", + "crv": "Ed25519", + "x": "A6EHv_POEL4dcN0Y50vAmWfk1jCbpQ1fHdyGZBJVMbg" + }, + "did:web:factory.example:safety-controller#ed25519-workload-attestation": { + "kty": "OKP", + "crv": "Ed25519", + "x": "Kay64UG8yvCyLhqU000LxzYeUm0L_hLIl5S8kyKWbdc" + }, + "did:web:factory.example:safety-controller#ed25519-unrelated-but-trusted": { + "kty": "OKP", + "crv": "Ed25519", + "x": "XUDXAF07AOpCkKoxJLKnzU4nNa4X8rnk_j3gAv82Rig" + } + }, + "gap_disclosure": { + "previous_receipt_hash": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "session_id": "trace-session-2026-07-06T15:22:11Z", + "issuer_key_id": "did:web:factory.example:safety-controller#ed25519-2026q3", + "cause": "crash", + "receipts_lost_estimate": 3, + "signature": "hS5tYu3UoPEiqdsO_FI0HCzomdvOYrwRXUpTO3OAGK7AuDTCNaHsWXiqH_4RRQMumOzTofkJTPGd8YC24u29Aw" + }, + "expected": { + "status": "receipt_invalid", + "controller_outcome": "unknown", + "failures": [ + "disclosure_type_unsupported" + ], + "warnings": [], + "consecutive_disclosures": 1, + "linked_predecessor": "sha256:a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1", + "cause": "crash" + } +} diff --git a/packages/agentrust-trace-adapters/tests/test_gap_reconciler.py b/packages/agentrust-trace-adapters/tests/test_gap_reconciler.py new file mode 100644 index 00000000..731cb55f --- /dev/null +++ b/packages/agentrust-trace-adapters/tests/test_gap_reconciler.py @@ -0,0 +1,852 @@ +"""Section 3.3.4 vectors, plus the consumer cases the #416 contract review required. + +The vendored fixtures are the trace-spec corpus. Their chain booleans are not +inputs to the library. Each vector is rebuilt as signed elements, and the +fixture file remains the oracle for the outcome codes. +""" + +from __future__ import annotations + +import base64 +import hashlib +import inspect +import json +from pathlib import Path +from typing import Any + +import pytest +import rfc8785 +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey + +from agentrust_trace_adapters.gap_reconciler import ( + COMPLETE, + DISCLOSURE_TYPE, + EFFECT_UNKNOWN, + GAP_DISCLOSURE_UNVERIFIED, + HIERARCHY_TYPE, + INVENTORY_NOT_SUPPLIED, + RECEIPT_GAP_DISCLOSED, + RECEIPT_INVALID, + RECEIPT_MISSING_REQUIRED, + RECEIPT_PRESENT, + MalformedInput, + element_digest, + parse_untrusted_json, + reconcile_chain, + verify_disclosure, +) + +FIXTURE_DIR = Path(__file__).parent / "fixtures" / "gap-disclosure" +SESSION = "trace-session-2026-07-06T15:22:11Z" +ISSUER = "did:web:factory.example:safety-controller" +KEY_ID = f"{ISSUER}#ed25519-2026q3" +PARENT_KEY_ID = f"{ISSUER}#ed25519-workload-attestation" +FOREIGN_KEY_ID = f"{ISSUER}#ed25519-unrelated-but-trusted" +CONFUSABLE_KEY_ID = f"{ISSUER}#ED25519-WORKLOAD-ATTESTATION" +UNKNOWN_KEY_ID = f"{ISSUER}#ed25519-2027q1" + +KEY = Ed25519PrivateKey.from_private_bytes(bytes(range(32))) +PARENT = Ed25519PrivateKey.from_private_bytes(bytes(range(32, 64))) +FOREIGN = Ed25519PrivateKey.from_private_bytes( + hashlib.sha256(b"trace-spec#117 unrelated trusted key").digest() +) +CONFUSABLE = Ed25519PrivateKey.from_private_bytes( + hashlib.sha256(b"trace-spec#117 confusable ancestor key").digest() +) +KEYS = { + KEY_ID: KEY, + PARENT_KEY_ID: PARENT, + FOREIGN_KEY_ID: FOREIGN, + CONFUSABLE_KEY_ID: CONFUSABLE, +} +FORBIDDEN = { + "predecessor_present", + "successor_present", + "permitted_ancestor_key_ids", + "claimed_absent_but_present", +} + + +def b64u(raw: bytes) -> str: + return base64.urlsafe_b64encode(raw).rstrip(b"=").decode() + + +def jwk(key: Ed25519PrivateKey) -> dict[str, str]: + return { + "kty": "OKP", + "crv": "Ed25519", + "x": b64u( + key.public_key().public_bytes( + encoding=serialization.Encoding.Raw, + format=serialization.PublicFormat.Raw, + ) + ), + } + + +def sign(document: dict[str, Any], key: Ed25519PrivateKey) -> dict[str, Any]: + body = {field: value for field, value in document.items() if field != "signature"} + return {**document, "signature": b64u(key.sign(rfc8785.dumps(body)))} + + +def trust(*key_ids: str, **extra: dict[str, str]) -> dict[str, dict[str, str]]: + store = {key_id: jwk(KEYS[key_id]) for key_id in key_ids} + store.update(extra) + return store + + +def receipt( + *, + issuer_key_id: str, + key: Ed25519PrivateKey, + credential_id: str, + previous: str | None, + sequence: int, + session_id: str = SESSION, + **extra: Any, +) -> dict[str, Any]: + body: dict[str, Any] = { + "type": "TraceHop/1.0", + "credential_id": credential_id, + "issuer_key_id": issuer_key_id, + "previous_receipt_hash": previous, + "sequence": sequence, + "session_id": session_id, + } + body.update(extra) + return sign(body, key) + + +def hierarchy(subject_key_id: str, ancestor_key_id: str, key: Ed25519PrivateKey) -> dict[str, Any]: + return sign( + { + "type": HIERARCHY_TYPE, + "subject_key_id": subject_key_id, + "ancestor_key_id": ancestor_key_id, + "issuer_key_id": ancestor_key_id, + }, + key, + ) + + +def disclosure_for( + *, + previous: str, + issuer_key_id: str, + key: Ed25519PrivateKey, + session_id: str = SESSION, + cause: str | None = "crash", + estimate: int | None = 3, + type_name: str | None = DISCLOSURE_TYPE, + credential_id: str | None = None, + omit_estimate: bool = False, + **extra: Any, +) -> dict[str, Any]: + body: dict[str, Any] = { + "previous_receipt_hash": previous, + "session_id": session_id, + "issuer_key_id": issuer_key_id, + } + if type_name is not None: + body["type"] = type_name + if cause is not None: + body["cause"] = cause + if not omit_estimate: + body["receipts_lost_estimate"] = estimate + if credential_id is not None: + body["credential_id"] = credential_id + body.update(extra) + return sign(body, key) + + +def tail_flip(value: str) -> str: + return value[:-1] + ("0" if value[-1] != "0" else "1") + + +def dumps(element: dict[str, Any]) -> bytes: + return json.dumps(element).encode("utf-8") + + +def load_fixtures() -> list[tuple[str, dict[str, Any]]]: + paths = sorted(FIXTURE_DIR.glob("*.json")) + return [(path.name, json.loads(path.read_text(encoding="utf-8"))) for path in paths] + + +def signing_key(key_id: str) -> Ed25519PrivateKey: + return KEYS.get(key_id, KEY) + + +def rebuild(doc: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, Any]], dict[str, dict[str, str]]]: + """Build signed elements that isolate the same rule as one fixture. + + Fixture chain booleans drive the builder. They are not passed to the library. + """ + flags = doc["context"]["chain"] + source = doc["gap_disclosure"] + issuer_key_id = source.get("issuer_key_id", KEY_ID) + predecessor_issuer = flags["predecessor_issuer_key_id"] + trusted = doc["trusted_issuer_keys"] + predecessor = receipt( + issuer_key_id=predecessor_issuer, + key=signing_key(predecessor_issuer), + credential_id="cred-predecessor", + previous=None, + sequence=1, + ) + predecessor_hash = element_digest(predecessor) + link = source.get("previous_receipt_hash") + if flags["predecessor_present"] and link == flags["predecessor_hash"]: + previous = predecessor_hash + elif flags["predecessor_present"] and link != flags["predecessor_hash"]: + previous = tail_flip(predecessor_hash) + else: + previous = "sha256:" + "b2" * 32 + + run = int(flags["consecutive_disclosures"]) + chain: list[dict[str, Any]] = [] + if flags["predecessor_present"]: + chain.append(predecessor) + if issuer_key_id == PARENT_KEY_ID: + chain.append(hierarchy(predecessor_issuer, PARENT_KEY_ID, PARENT)) + cursor = predecessor_hash + disclosures: list[dict[str, Any]] = [] + for index in range(run): + last = index == run - 1 + earlier_issuer = predecessor_issuer if predecessor_issuer in KEYS else KEY_ID + body_issuer = issuer_key_id if last else earlier_issuer + body_key = signing_key(body_issuer if body_issuer in KEYS else KEY_ID) + if not last: + item = disclosure_for(previous=cursor, issuer_key_id=earlier_issuer, key=KEYS[earlier_issuer]) + else: + estimate = source["receipts_lost_estimate"] if "receipts_lost_estimate" in source else 3 + signed_cause = "crash" if source.get("cause") == "shutdown" else source.get("cause", "crash") + item = disclosure_for( + previous=previous if run == 1 else cursor, + issuer_key_id=body_issuer, + key=body_key, + session_id=source.get("session_id", SESSION), + cause=signed_cause, + estimate=estimate, + type_name=source["type"] if "type" in source else None, + omit_estimate="receipts_lost_estimate" not in source, + ) + if source.get("signature") == b64u(bytes(32)): + item = {**item, "signature": b64u(bytes(32))} + elif source.get("cause") == "shutdown": + item = {**item, "cause": "shutdown"} + disclosures.append(item) + cursor = element_digest(item) + target = disclosures[-1] + chain.extend(disclosures) + if flags["claimed_absent_but_present"]: + inserted = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-present-inside-gap", + previous=predecessor_hash, + sequence=2, + ) + chain.insert(1 if flags["predecessor_present"] else 0, inserted) + if flags["successor_present"]: + fixture_seal = flags["successor_previous_receipt_hash"] + fixture_digest = element_digest(source) + if fixture_seal == fixture_digest: + seal = element_digest(target) + elif fixture_seal == flags["predecessor_hash"]: + seal = predecessor_hash + else: + seal = tail_flip(element_digest(target)) + chain.append( + receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-successor", + previous=seal, + sequence=9, + ) + ) + return target, chain, trusted + + +@pytest.fixture(scope="module") +def fixtures() -> list[tuple[str, dict[str, Any]]]: + return load_fixtures() + + +def test_fixture_corpus_is_the_twenty_vectors(fixtures: list[tuple[str, dict[str, Any]]]) -> None: + assert [name for name, _ in fixtures] == [ + "01-gap-disclosed-valid.json", + "02-gap-disclosure-dangling-predecessor.json", + "03-gap-disclosure-successor-does-not-link.json", + "04-gap-disclosure-contradicted.json", + "05-gap-disclosure-foreign-key.json", + "06-gap-disclosed-parent-key-null-estimate.json", + "07-gap-disclosure-unknown-key.json", + "08-gap-disclosure-tampered.json", + "09-gap-disclosure-key-case-variant.json", + "10-gap-disclosure-signature-malformed.json", + "11-gap-disclosure-confusable-ancestor-key.json", + "12-gap-disclosure-replayed-stream.json", + "13-gap-disclosure-stream-case-variant.json", + "14-gap-disclosure-predecessor-link-tail.json", + "15-gap-disclosure-seal-tail-mismatch.json", + "16-gap-disclosure-contradicted-at-tail.json", + "17-gap-disclosure-at-unsealed-tail.json", + "18-gap-disclosure-tail-with-stale-link.json", + "19-gap-disclosure-type-version-unknown.json", + "20-gap-disclosure-type-absent.json", + ] + for _, doc in fixtures: + assert doc["source"]["spec"] == "spec/trace-v0.2.md section 3.3.4" + assert doc["expected"]["controller_outcome"] == "unknown" + + +def test_generator_keys_match_the_vendored_trust_anchors() -> None: + doc = json.loads((FIXTURE_DIR / "01-gap-disclosed-valid.json").read_text(encoding="utf-8")) + for key_id, key in ((KEY_ID, KEY), (PARENT_KEY_ID, PARENT), (FOREIGN_KEY_ID, FOREIGN)): + assert doc["trusted_issuer_keys"][key_id] == jwk(key) + + +def test_every_registered_rule_has_two_fixture_vectors(fixtures: list[tuple[str, dict[str, Any]]]) -> None: + counts: dict[str, int] = {} + for _, doc in fixtures: + expected = doc["expected"] + for code in [*expected["failures"], *expected["warnings"]]: + if code != RECEIPT_GAP_DISCLOSED: + counts[code] = counts.get(code, 0) + 1 + assert set(counts) == { + "disclosure_type_unsupported", + "disclosure_issuer_not_chain_key", + "disclosure_stream_mismatch", + "disclosure_predecessor_absent", + "disclosure_contradicted", + "disclosure_not_sealed_by_successor", + "disclosure_signature_invalid", + "disclosure_key_unknown", + "disclosure_not_yet_sealed", + } + assert all(count >= 2 for count in counts.values()) + + +def test_live_tail_contrast_is_pinned_by_identical_fixture_disclosures() -> None: + sealed = json.loads((FIXTURE_DIR / "01-gap-disclosed-valid.json").read_text(encoding="utf-8")) + tail = json.loads((FIXTURE_DIR / "17-gap-disclosure-at-unsealed-tail.json").read_text(encoding="utf-8")) + assert sealed["gap_disclosure"] == tail["gap_disclosure"] + assert sealed["expected"]["status"] == RECEIPT_GAP_DISCLOSED + assert tail["expected"]["status"] == GAP_DISCLOSURE_UNVERIFIED + assert tail["expected"]["failures"] == [] + + +@pytest.mark.parametrize("name,doc", load_fixtures(), ids=lambda item: item if isinstance(item, str) else item["name"]) +def test_fixture_vector(name: str, doc: dict[str, Any]) -> None: + target, chain, trusted = rebuild(doc) + verdict = verify_disclosure( + target, + chain, + session_id=doc["context"]["session_id"], + trusted_issuer_keys=trusted, + ) + expected = doc["expected"] + assert verdict.status == expected["status"], name + assert verdict.failures == tuple(expected["failures"]), name + assert verdict.warnings == tuple(expected["warnings"]), name + assert verdict.consecutive_disclosures == expected["consecutive_disclosures"], name + assert verdict.controller_outcome == "unknown" + assert verdict.effect_status == EFFECT_UNKNOWN + assert verdict.retry_authorized is False + assert verdict.cause == target.get("cause") if isinstance(target.get("cause"), str) else None + assert verdict.linked_predecessor == target.get("previous_receipt_hash") + assert FORBIDDEN.isdisjoint(verdict.as_fixture_dict()) + + +@pytest.mark.parametrize("name,doc", load_fixtures(), ids=lambda item: item if isinstance(item, str) else "") +def test_fixture_assertion_object_is_not_derived_evidence(name: str, doc: dict[str, Any]) -> None: + hostile = dict(doc["context"]["chain"]) + verdict = verify_disclosure( + doc["gap_disclosure"], + [hostile, doc["gap_disclosure"]], + session_id=doc["context"]["session_id"], + trusted_issuer_keys=doc["trusted_issuer_keys"], + ) + assert verdict.status != RECEIPT_GAP_DISCLOSED, name + assert verdict.derived_predecessor_present is False + + +def test_public_api_rejects_fixture_assertion_parameters() -> None: + for function in (verify_disclosure, reconcile_chain): + assert FORBIDDEN.isdisjoint(inspect.signature(function).parameters) + with pytest.raises(TypeError): + reconcile_chain( # type: ignore[call-arg] + [], + session_id=SESSION, + trusted_issuer_keys={}, + predecessor_present=True, + ) + + +def _workflow( + *, + include_disclosure: bool, + seal: bool, + bind: bool, + inventory: list[str] | None, + cause: str = "crash", + estimate: int | None = 3, + fence: int | None = None, + signer: str = KEY_ID, + ancestor: bool = False, +) -> tuple[list[bytes], dict[str, dict[str, str]], str]: + first = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-0", + previous=None, + sequence=1, + ) + elements: list[dict[str, Any]] = [first] + if ancestor: + elements.append(hierarchy(KEY_ID, PARENT_KEY_ID, PARENT)) + previous = element_digest(first) + if include_disclosure: + gap = disclosure_for( + previous=previous, + issuer_key_id=signer, + key=signing_key(signer), + cause=cause, + estimate=estimate, + credential_id="cred-2" if bind else None, + ) + elements.append(gap) + previous = element_digest(gap) + if seal: + extra = {"cas_fence_epoch": fence} if fence is not None else {} + elements.append( + receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=previous, + sequence=4, + **extra, + ) + ) + trusted = trust(KEY_ID, PARENT_KEY_ID, FOREIGN_KEY_ID) + return [dumps(element) for element in elements], trusted, SESSION + + +def test_case_a_missing_hop_without_disclosure_is_not_gap_disclosed() -> None: + elements, trusted, session = _workflow(include_disclosure=False, seal=True, bind=False, inventory=["cred-0", "cred-1", "cred-2"]) + result = reconcile_chain( + elements, + session_id=session, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-1", "cred-2"], + ) + assert result.status == RECEIPT_MISSING_REQUIRED + assert result.credentials[-1].status == RECEIPT_MISSING_REQUIRED + assert result.accepted_as_complete is False + assert result.policy_accepted is False + assert result.retry_authorized is False + + +def test_case_b_two_sided_splice_is_gap_disclosed_not_execution() -> None: + elements, trusted, session = _workflow(include_disclosure=True, seal=True, bind=True, inventory=["cred-0", "cred-1", "cred-2"]) + result = reconcile_chain( + elements, + session_id=session, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-1", "cred-2"], + accept_disclosed_gaps=True, + ) + assert result.disclosures[0].status == RECEIPT_GAP_DISCLOSED + assert result.disclosures[0].derived_predecessor_present is True + assert result.disclosures[0].derived_successor_present is True + assert result.credentials[2].status == RECEIPT_GAP_DISCLOSED + assert result.status == RECEIPT_GAP_DISCLOSED + assert result.accepted_as_complete is False + assert result.effect_status == EFFECT_UNKNOWN + assert result.retry_authorized is False + assert result.policy_accepted is True + refused = reconcile_chain( + elements, + session_id=session, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-1", "cred-2"], + completeness_required=True, + accept_disclosed_gaps=True, + ) + assert refused.policy_accepted is False + assert refused.accepted_as_complete is False + + +def test_tail_disclosure_is_unverified_and_not_coverage() -> None: + elements, trusted, session = _workflow(include_disclosure=True, seal=False, bind=True, inventory=["cred-0", "cred-2"]) + result = reconcile_chain( + elements, + session_id=session, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-2"], + accept_disclosed_gaps=True, + ) + assert result.disclosures[0].status == GAP_DISCLOSURE_UNVERIFIED + assert result.disclosures[0].failures == () + assert result.disclosures[0].warnings == ("disclosure_not_yet_sealed",) + assert result.credentials[1].status == GAP_DISCLOSURE_UNVERIFIED + assert result.status == GAP_DISCLOSURE_UNVERIFIED + assert result.policy_accepted is False + assert result.accepted_as_complete is False + + +def test_truncated_chain_does_not_infer_the_omitted_credential() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + second = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(first), + sequence=2, + ) + chain = [dumps(first), dumps(second)] + trusted = trust(KEY_ID) + without_inventory = reconcile_chain(chain, session_id=SESSION, trusted_issuer_keys=trusted) + assert without_inventory.status == INVENTORY_NOT_SUPPLIED + assert without_inventory.credentials == () + with_inventory = reconcile_chain( + chain, + session_id=SESSION, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-1", "cred-2"], + ) + assert [item.status for item in with_inventory.credentials] == [ + RECEIPT_PRESENT, + RECEIPT_PRESENT, + RECEIPT_MISSING_REQUIRED, + ] + assert with_inventory.status == RECEIPT_MISSING_REQUIRED + + +def test_unbound_disclosure_does_not_cover_an_omitted_credential() -> None: + elements, trusted, session = _workflow( + include_disclosure=True, + seal=True, + bind=False, + inventory=["cred-0", "cred-1", "cred-2"], + ) + result = reconcile_chain( + elements, + session_id=session, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-1", "cred-2"], + ) + assert result.disclosures[0].status == RECEIPT_GAP_DISCLOSED + assert result.credentials[2].status == RECEIPT_MISSING_REQUIRED + assert result.status == RECEIPT_MISSING_REQUIRED + + +def test_cause_and_fence_epoch_do_not_change_the_outcome_or_authorize_retry() -> None: + baselines = [] + for cause, estimate, fence in ( + ("crash", 3, None), + ("delegation_revoked", 0, 1), + ("lease_id=lease-9", None, 4), + ("cas_fence_epoch=99", 99, 99), + ("lease_id=lease-9; cas_fence_epoch=100", -1, 100), + ): + elements, trusted, session = _workflow( + include_disclosure=True, + seal=True, + bind=True, + inventory=["cred-0", "cred-1", "cred-2"], + cause=cause, + estimate=estimate, + fence=fence, + ) + result = reconcile_chain( + elements, + session_id=session, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-1", "cred-2"], + ) + baselines.append( + ( + result.status, + result.disclosures[0].failures, + result.disclosures[0].warnings, + result.effect_status, + result.retry_authorized, + result.credentials[2].status, + ) + ) + assert result.disclosures[0].cause == cause + assert result.disclosures[0].receipts_lost_estimate == estimate + assert baselines == [baselines[0]] * len(baselines) + assert baselines[0][0] == RECEIPT_GAP_DISCLOSED + assert baselines[0][4] is False + + +def test_malformed_descriptive_fields_do_not_select_an_outcome_by_value() -> None: + statuses = [] + for cause in ({"lease_id": "lease-1"}, {"unrelated": True}, 5): + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + unsigned = { + "type": DISCLOSURE_TYPE, + "previous_receipt_hash": element_digest(first), + "session_id": SESSION, + "issuer_key_id": KEY_ID, + "cause": cause, + "receipts_lost_estimate": 3, + } + gap = sign(unsigned, KEY) + successor = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap), + sequence=3, + ) + verdict = verify_disclosure(gap, [first, gap, successor], session_id=SESSION, trusted_issuer_keys=trust(KEY_ID)) + statuses.append((verdict.status, verdict.failures, verdict.effect_status, verdict.retry_authorized)) + assert statuses == [(RECEIPT_INVALID, ("disclosure_descriptive_field_malformed",), EFFECT_UNKNOWN, False)] * 3 + + +def test_claimed_absent_record_inside_the_gap_impeaches_the_disclosure() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + hidden = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-hidden", previous=element_digest(first), sequence=2) + gap = disclosure_for(previous=element_digest(first), issuer_key_id=KEY_ID, key=KEY) + successor = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap), + sequence=6, + ) + verdict = verify_disclosure( + gap, + [first, hidden, gap, successor], + session_id=SESSION, + trusted_issuer_keys=trust(KEY_ID), + ) + assert verdict.status == RECEIPT_INVALID + assert verdict.failures == ("disclosure_contradicted",) + assert element_digest(hidden) in verdict.derived_contradicting_digests + + +def test_sequence_inside_the_splice_span_is_a_contradiction() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + gap = disclosure_for(previous=element_digest(first), issuer_key_id=KEY_ID, key=KEY) + successor = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap), + sequence=6, + ) + outside = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-late", + previous=element_digest(successor), + sequence=3, + ) + verdict = verify_disclosure( + gap, + [first, gap, successor, outside], + session_id=SESSION, + trusted_issuer_keys=trust(KEY_ID), + ) + assert "disclosure_contradicted" in verdict.failures + assert element_digest(outside) in verdict.derived_contradicting_digests + + +def test_unauthorized_and_confusable_ancestor_signers_are_rejected() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + foreign = disclosure_for(previous=element_digest(first), issuer_key_id=FOREIGN_KEY_ID, key=FOREIGN) + sealed = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(foreign), + sequence=4, + ) + trusted = trust(KEY_ID, FOREIGN_KEY_ID, PARENT_KEY_ID) + verdict = verify_disclosure(foreign, [first, foreign, sealed], session_id=SESSION, trusted_issuer_keys=trusted) + assert verdict.failures == ("disclosure_issuer_not_chain_key",) + + listed = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-0", + previous=None, + sequence=1, + permitted_ancestor_key_ids=[PARENT_KEY_ID], + ) + parent_signed = disclosure_for(previous=element_digest(listed), issuer_key_id=PARENT_KEY_ID, key=PARENT) + parent_seal = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(parent_signed), + sequence=4, + ) + unsigned_list = verify_disclosure( + parent_signed, + [listed, parent_signed, parent_seal], + session_id=SESSION, + trusted_issuer_keys=trusted, + ) + assert unsigned_list.failures == ("disclosure_issuer_not_chain_key",) + assert unsigned_list.derived_ancestor_key_ids == () + + statement = hierarchy(KEY_ID, PARENT_KEY_ID, PARENT) + authorized_gap = disclosure_for(previous=element_digest(first), issuer_key_id=PARENT_KEY_ID, key=PARENT) + authorized_seal = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(authorized_gap), + sequence=4, + ) + authorized = verify_disclosure( + authorized_gap, + [first, statement, authorized_gap, authorized_seal], + session_id=SESSION, + trusted_issuer_keys=trusted, + ) + assert authorized.status == RECEIPT_GAP_DISCLOSED + assert authorized.derived_ancestor_key_ids == (PARENT_KEY_ID,) + + +def test_duplicate_hop_is_not_a_fenced_retry() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + again = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-0", + previous=element_digest(first), + sequence=2, + cas_fence_epoch=8, + ) + result = reconcile_chain( + [dumps(first), dumps(again)], + session_id=SESSION, + trusted_issuer_keys=trust(KEY_ID), + expected_credential_ids=["cred-0"], + ) + assert result.credentials[0].status == RECEIPT_INVALID + assert result.retry_authorized is False + assert result.effect_status == EFFECT_UNKNOWN + + +def test_complete_inventory_is_accepted_only_without_a_gap() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + second = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(first), + sequence=2, + ) + result = reconcile_chain( + [dumps(first), dumps(second)], + session_id=SESSION, + trusted_issuer_keys=trust(KEY_ID), + expected_credential_ids=["cred-0", "cred-1"], + completeness_required=True, + ) + assert result.status == COMPLETE + assert result.accepted_as_complete is True + assert result.policy_accepted is True + + +@pytest.mark.parametrize( + "payload,message", + [ + (b'{"a":1,"a":2}', "duplicate JSON key"), + (b'{"a":NaN}', "non-finite JSON number"), + (b'{"a":Infinity}', "non-finite JSON number"), + (b'{"a":1.5}', "non-integral JSON number"), + (b"[1]", "untrusted JSON must be an object"), + (b'{"n":9007199254740993}', "integer outside the safe range"), + (b'{"d":' + b'{"x":' * 40 + b"1" + b"}" * 40 + b"}", "JSON nesting exceeds"), + ], +) +def test_bounded_parser_refuses_malformed_input(payload: bytes, message: str) -> None: + with pytest.raises(MalformedInput, match=message): + parse_untrusted_json(payload) + + +def test_oversize_element_is_refused() -> None: + with pytest.raises(MalformedInput, match="size bound"): + parse_untrusted_json(b'{"pad":"' + b"a" * 70_000 + b'"}') + + +def test_private_jwk_is_not_a_trust_anchor() -> None: + private = {**jwk(KEY), "d": b64u(bytes(range(32)))} + with pytest.raises(MalformedInput, match="private key material"): + reconcile_chain([], session_id=SESSION, trusted_issuer_keys={KEY_ID: private}) + + +def test_non_canonical_signature_is_invalid_not_an_exception() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + gap = disclosure_for(previous=element_digest(first), issuer_key_id=KEY_ID, key=KEY) + padded = {**gap, "signature": gap["signature"] + "="} + successor = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap), + sequence=3, + ) + verdict = verify_disclosure( + padded, + [first, padded, successor], + session_id=SESSION, + trusted_issuer_keys=trust(KEY_ID), + ) + assert verdict.failures[0] == "disclosure_signature_invalid" + + +def test_identical_disclosure_bytes_change_outcome_only_when_the_seal_exists() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + gap = disclosure_for(previous=element_digest(first), issuer_key_id=KEY_ID, key=KEY) + successor = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap), + sequence=3, + ) + trusted = trust(KEY_ID) + sealed = verify_disclosure(gap, [first, gap, successor], session_id=SESSION, trusted_issuer_keys=trusted) + tail = verify_disclosure(gap, [first, gap], session_id=SESSION, trusted_issuer_keys=trusted) + assert sealed.status == RECEIPT_GAP_DISCLOSED + assert tail.status == GAP_DISCLOSURE_UNVERIFIED + assert tail.failures == () + assert tail.warnings == ("disclosure_not_yet_sealed",) + + +def test_reconcile_chain_judges_a_typeless_disclosure() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + gap = disclosure_for( + previous=element_digest(first), + issuer_key_id=KEY_ID, + key=KEY, + type_name=None, + ) + assert "type" not in gap + successor = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap), + sequence=3, + ) + result = reconcile_chain( + [dumps(first), dumps(gap), dumps(successor)], + session_id=SESSION, + trusted_issuer_keys=trust(KEY_ID), + expected_credential_ids=["cred-0", "cred-1"], + ) + assert result.disclosures[0].failures == ("disclosure_type_unsupported",) + assert result.status == RECEIPT_INVALID From 0478f1c3a8e5994b0dfe3102b7d2b9eeab2889df Mon Sep 17 00:00:00 2001 From: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:42:57 -0600 Subject: [PATCH 2/2] fix(trace-adapters): authenticate successor seals, hop linkage, and credential conflicts - Require the sealing successor (and the terminal hop receipt after a consecutive disclosure run) to carry a valid signature in session_id under the chain key / authenticated ancestor with strictly increasing sequence before treating a GapDisclosure/1.0 as sealed. - Require hops in reconcile_chain to form a contiguous hash-linked, monotonically sequenced chain under the chain key / authorized ancestor; unlinked or foreign-key hops fail closed as receipt_invalid. - Reject disclosures that claim a credential_id also present as a hop receipt (or duplicated across disclosures) as disclosure_contradicted. Signed-off-by: Raghuvar Karthik Durga <177662415+drk-ram@users.noreply.github.com> --- .../src/agentrust_trace_adapters/__init__.py | 14 +- .../gap_reconciler.py | 176 +++++++++++++++--- .../tests/test_gap_reconciler.py | 108 ++++++++++- 3 files changed, 263 insertions(+), 35 deletions(-) diff --git a/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/__init__.py b/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/__init__.py index 3b71d7b7..fe8822c1 100644 --- a/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/__init__.py +++ b/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/__init__.py @@ -43,24 +43,24 @@ ) __all__ = [ - "AppraisalEvidence", "DIGEST_RE", - "DisclosureVerdict", "GAP_DISCLOSURE_UNVERIFIED", + "RECEIPT_GAP_DISCLOSED", + "RECEIPT_INVALID", + "RECEIPT_MISSING_REQUIRED", + "TRACE_PROFILE", + "AppraisalEvidence", + "DisclosureVerdict", "MalformedInput", "MissingEvidence", "OpenShellEvidence", "PolicyEvidence", - "RECEIPT_GAP_DISCLOSED", - "RECEIPT_INVALID", - "RECEIPT_MISSING_REQUIRED", "Reconciliation", "SourceSystem", - "TRACE_PROFILE", "appraisal_from_evidence", - "build_record", "build_openshell_record", "build_policy_bundle", + "build_record", "build_transcript", "digest_bytes", "reconcile_chain", diff --git a/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/gap_reconciler.py b/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/gap_reconciler.py index d3b1bdb3..56745af3 100644 --- a/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/gap_reconciler.py +++ b/packages/agentrust-trace-adapters/src/agentrust_trace_adapters/gap_reconciler.py @@ -48,18 +48,18 @@ __all__ = [ "COMPLETE", - "CredentialCoverage", "DISCLOSURE_TYPE", - "DisclosureVerdict", "EFFECT_UNKNOWN", "GAP_DISCLOSURE_UNVERIFIED", "HIERARCHY_TYPE", "INVENTORY_NOT_SUPPLIED", - "MalformedInput", "RECEIPT_GAP_DISCLOSED", "RECEIPT_INVALID", "RECEIPT_MISSING_REQUIRED", "RECEIPT_PRESENT", + "CredentialCoverage", + "DisclosureVerdict", + "MalformedInput", "Reconciliation", "element_digest", "parse_untrusted_json", @@ -313,7 +313,7 @@ def _judge_disclosure( predecessor = _element_by_digest(elements, disclosure.get("previous_receipt_hash"), disclosure_index) successor = _successor(elements, disclosure_index) ancestors = _authenticated_ancestors(elements, keys) - predecessor_issuer = _authenticated_issuer(predecessor, keys) + predecessor_issuer = _authenticated_issuer(predecessor, keys, session_id=session_id) derived_ancestors = ancestors.get(predecessor_issuer, ()) if predecessor_issuer else () contradicting = _contradicting( elements, @@ -321,6 +321,7 @@ def _judge_disclosure( successor, disclosure_index, digest, + disclosure.get("credential_id") if isinstance(disclosure.get("credential_id"), str) else None, ) failures: list[str] = [] @@ -345,7 +346,17 @@ def _judge_disclosure( failures.append("disclosure_contradicted") if successor is None: warnings.append("disclosure_not_yet_sealed") - elif successor.get("previous_receipt_hash") != digest: + elif not _seal_holds( + elements, + disclosure_index, + digest, + successor, + session_id, + predecessor, + predecessor_issuer, + derived_ancestors, + keys, + ): failures.append("disclosure_not_sealed_by_successor") if failures: @@ -374,7 +385,18 @@ def _judge_disclosure( receipts_lost_estimate=estimate if type(estimate) is int else None, bound_credential_id=bound if isinstance(bound, str) else None, derived_predecessor_present=predecessor is not None and predecessor_issuer is not None, - derived_successor_present=successor is not None, + derived_successor_present=successor is not None + and _seal_holds( + elements, + disclosure_index, + digest, + successor, + session_id, + predecessor, + predecessor_issuer, + derived_ancestors, + keys, + ), derived_ancestor_key_ids=tuple(derived_ancestors), derived_contradicting_digests=tuple(dict.fromkeys(contradicting)), ) @@ -389,29 +411,33 @@ def _cover_credentials( ) -> tuple[CredentialCoverage, ...]: if inventory is None: return () + valid_chain_hops = _valid_chain_hop_digests(elements, session_id, keys) + all_hops = [element for element in elements if not _skipped_for_coverage(element)] + broken_chain_exists = any(element_digest(element) not in valid_chain_hops for element in all_hops) coverage: list[CredentialCoverage] = [] for credential_id in inventory: hops = [ element - for element in elements - if element.get("credential_id") == credential_id and not _skipped_for_coverage(element) + for element in all_hops + if element.get("credential_id") == credential_id ] verified = [ element for element in hops - if element.get("session_id") == session_id - and _hop_signature_holds(element, keys) - ] - forged = [ - element - for element in hops - if isinstance(element.get("issuer_key_id"), str) - and element["issuer_key_id"] in keys - and not _signature_holds(element, keys[element["issuer_key_id"]]) + if element_digest(element) in valid_chain_hops ] + invalid_hop = any(element_digest(element) not in valid_chain_hops for element in hops) bound = [item for item in disclosures if item.bound_credential_id == credential_id] - if any(item.status == RECEIPT_INVALID for item in bound) or forged or len(verified) > 1: - # A second verified hop is not a fenced retry. Fence epochs are ignored. + if ( + any(item.status == RECEIPT_INVALID for item in bound) + or invalid_hop + or len(verified) > 1 + or len(bound) > 1 + or (bool(verified) and bool(bound)) + or (broken_chain_exists and bool(verified)) + ): + # A second verified hop is not a fenced retry; a broken link or + # simultaneous hop+disclosure for the same credential is invalid. status = RECEIPT_INVALID elif verified: status = RECEIPT_PRESENT @@ -501,9 +527,18 @@ def _authenticated_ancestors( def _authenticated_issuer( element: Mapping[str, Any] | None, keys: Mapping[str, Ed25519PublicKey], + *, + session_id: str | None = None, ) -> str | None: if element is None: return None + if element.get("type") == HIERARCHY_TYPE: + return None + if session_id is not None and _gap_type(element) is None and element.get("session_id") != session_id: + return None + raw_sig = _canonical_b64url(element.get("signature")) + if raw_sig is None or len(raw_sig) != 64: + return None issuer = element.get("issuer_key_id") if not isinstance(issuer, str) or not issuer: return None @@ -516,6 +551,87 @@ def _authenticated_issuer( return issuer +def _seal_holds( + elements: Sequence[Mapping[str, Any]], + disclosure_index: int | None, + disclosure_digest: str, + successor: Mapping[str, Any], + session_id: str, + predecessor: Mapping[str, Any] | None, + predecessor_issuer: str | None, + derived_ancestors: Sequence[str], + keys: Mapping[str, Ed25519PublicKey], +) -> bool: + if successor.get("previous_receipt_hash") != disclosure_digest: + return False + allowed_issuers = {predecessor_issuer, *derived_ancestors} if predecessor_issuer else set() + if disclosure_index is None: + return False + prev_digest = disclosure_digest + for candidate in elements[disclosure_index + 1 :]: + if candidate.get("type") == HIERARCHY_TYPE: + continue + if candidate.get("previous_receipt_hash") != prev_digest: + return False + if candidate.get("session_id") != session_id: + return False + cand_issuer = _authenticated_issuer(candidate, keys, session_id=session_id) + if cand_issuer is None: + return False + if predecessor_issuer in keys and cand_issuer not in allowed_issuers: + return False + if _gap_type(candidate) is not None or _is_disclosure_candidate(candidate): + prev_digest = element_digest(candidate) + continue + # Reached the terminal non-disclosure hop receipt that seals the splice. + if cand_issuer in keys and not _signature_holds(candidate, keys[cand_issuer]): + return False + pred_seq = _sequence(predecessor) + succ_seq = _sequence(candidate) + return not (pred_seq is not None and succ_seq is not None and succ_seq <= pred_seq) + return False + + +def _valid_chain_hop_digests( + elements: Sequence[Mapping[str, Any]], + session_id: str, + keys: Mapping[str, Ed25519PublicKey], +) -> set[str]: + ancestors = _authenticated_ancestors(elements, keys) + valid: set[str] = set() + prev_digest: str | None = None + last_hop_seq: int | None = None + chain_issuer: str | None = None + allowed_issuers: set[str] = set() + for element in elements: + if element.get("type") == HIERARCHY_TYPE: + continue + if element.get("previous_receipt_hash") != prev_digest: + return set() + if _gap_type(element) is not None or _is_disclosure_candidate(element): + prev_digest = element_digest(element) + continue + if element.get("session_id") != session_id: + return set() + if not _hop_signature_holds(element, keys): + return set() + issuer = element["issuer_key_id"] + if chain_issuer is None: + chain_issuer = issuer + allowed_issuers = {chain_issuer, *ancestors.get(chain_issuer, ())} + elif issuer not in allowed_issuers: + return set() + seq = _sequence(element) + if seq is not None and last_hop_seq is not None and seq <= last_hop_seq: + return set() + if seq is not None: + last_hop_seq = seq + digest = element_digest(element) + valid.add(digest) + prev_digest = digest + return valid + + def _element_by_digest( elements: Sequence[Mapping[str, Any]], digest: Any, @@ -570,6 +686,7 @@ def _contradicting( successor: Mapping[str, Any] | None, disclosure_index: int | None, disclosure_digest: str, + bound_credential_id: str | None = None, ) -> list[str]: if predecessor is None or disclosure_index is None: return [] @@ -577,6 +694,12 @@ def _contradicting( if predecessor_index is None: return [] hits: list[str] = [] + if bound_credential_id is not None: + for index, element in enumerate(elements): + if index == disclosure_index or element.get("type") == HIERARCHY_TYPE: + continue + if element.get("credential_id") == bound_credential_id: + hits.append(element_digest(element)) right = disclosure_index if successor is not None: successor_index = _index_of(elements, successor) @@ -604,9 +727,12 @@ def _contradicting( continue sequence = _sequence(element) digest = element_digest(element) - if sequence is not None and predecessor_sequence < sequence < successor_sequence: - if digest != disclosure_digest: - hits.append(digest) + if ( + sequence is not None + and predecessor_sequence < sequence < successor_sequence + and digest != disclosure_digest + ): + hits.append(digest) return hits @@ -709,9 +835,7 @@ def _descriptive_malformed(disclosure: Mapping[str, Any]) -> bool: estimate = disclosure.get("receipts_lost_estimate") if estimate is None: return False - if type(estimate) is not int or not -_SAFE_INT <= estimate <= _SAFE_INT: - return True - return False + return type(estimate) is not int or not -_SAFE_INT <= estimate <= _SAFE_INT def _chain_objects( @@ -781,7 +905,7 @@ def _trust_store(trusted: Mapping[str, Mapping[str, Any]]) -> dict[str, Ed25519P def _public_key(jwk: Mapping[str, Any]) -> Ed25519PublicKey: if not isinstance(jwk, Mapping): raise MalformedInput("trusted issuer key is not a JWK object") - if any(field in jwk for field in ("d", "priv", "p", "q")): + if any(field in jwk for field in ("d", "priv", "p", "q", "dp", "dq", "qi", "oth", "k")): raise MalformedInput("private key material is not a trust anchor") if jwk.get("kty") != "OKP" or jwk.get("crv") != "Ed25519": raise MalformedInput("trusted issuer key is not Ed25519") diff --git a/packages/agentrust-trace-adapters/tests/test_gap_reconciler.py b/packages/agentrust-trace-adapters/tests/test_gap_reconciler.py index 731cb55f..121cd137 100644 --- a/packages/agentrust-trace-adapters/tests/test_gap_reconciler.py +++ b/packages/agentrust-trace-adapters/tests/test_gap_reconciler.py @@ -219,7 +219,7 @@ def rebuild(doc: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, Any]], if not last: item = disclosure_for(previous=cursor, issuer_key_id=earlier_issuer, key=KEYS[earlier_issuer]) else: - estimate = source["receipts_lost_estimate"] if "receipts_lost_estimate" in source else 3 + estimate = source.get("receipts_lost_estimate", 3) signed_cause = "crash" if source.get("cause") == "shutdown" else source.get("cause", "crash") item = disclosure_for( previous=previous if run == 1 else cursor, @@ -228,7 +228,7 @@ def rebuild(doc: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, Any]], session_id=source.get("session_id", SESSION), cause=signed_cause, estimate=estimate, - type_name=source["type"] if "type" in source else None, + type_name=source.get("type"), omit_estimate="receipts_lost_estimate" not in source, ) if source.get("signature") == b64u(bytes(32)): @@ -850,3 +850,107 @@ def test_reconcile_chain_judges_a_typeless_disclosure() -> None: ) assert result.disclosures[0].failures == ("disclosure_type_unsupported",) assert result.status == RECEIPT_INVALID + + +def test_unauthenticated_or_foreign_or_wrong_session_successor_cannot_seal_disclosure() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + gap = disclosure_for( + previous=element_digest(first), + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-2", + ) + trusted = trust(KEY_ID, FOREIGN_KEY_ID) + + # 1. Tampered signature on successor + valid_succ = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap), + sequence=3, + ) + forged_succ = {**valid_succ, "signature": b64u(bytes(64))} + verdict_forged = verify_disclosure( + gap, [first, gap, forged_succ], session_id=SESSION, trusted_issuer_keys=trusted + ) + assert verdict_forged.status == RECEIPT_INVALID + assert "disclosure_not_sealed_by_successor" in verdict_forged.failures + assert verdict_forged.derived_successor_present is False + + # 2. Foreign-key-signed successor + foreign_succ = receipt( + issuer_key_id=FOREIGN_KEY_ID, + key=FOREIGN, + credential_id="cred-1", + previous=element_digest(gap), + sequence=3, + ) + verdict_foreign = verify_disclosure( + gap, [first, gap, foreign_succ], session_id=SESSION, trusted_issuer_keys=trusted + ) + assert verdict_foreign.status == RECEIPT_INVALID + assert "disclosure_not_sealed_by_successor" in verdict_foreign.failures + + # 3. Cross-session successor + other_session_succ = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap), + sequence=3, + session_id="other-session", + ) + verdict_session = verify_disclosure( + gap, [first, gap, other_session_succ], session_id=SESSION, trusted_issuer_keys=trusted + ) + assert verdict_session.status == RECEIPT_INVALID + assert "disclosure_not_sealed_by_successor" in verdict_session.failures + + +def test_unlinked_or_foreign_hops_and_contradicting_credential_disclosures_are_rejected() -> None: + first = receipt(issuer_key_id=KEY_ID, key=KEY, credential_id="cred-0", previous=None, sequence=1) + unlinked_second = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous="sha256:" + "00" * 32, + sequence=2, + ) + trusted = trust(KEY_ID, FOREIGN_KEY_ID) + res_unlinked = reconcile_chain( + [dumps(first), dumps(unlinked_second)], + session_id=SESSION, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-1"], + completeness_required=True, + ) + assert res_unlinked.status == RECEIPT_INVALID + assert res_unlinked.accepted_as_complete is False + assert res_unlinked.policy_accepted is False + + # Disclosure claiming a credential_id that is also present as a hop receipt + gap_same_cred = disclosure_for( + previous=element_digest(first), + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-0", + ) + valid_succ = receipt( + issuer_key_id=KEY_ID, + key=KEY, + credential_id="cred-1", + previous=element_digest(gap_same_cred), + sequence=3, + ) + res_contra = reconcile_chain( + [dumps(first), dumps(gap_same_cred), dumps(valid_succ)], + session_id=SESSION, + trusted_issuer_keys=trusted, + expected_credential_ids=["cred-0", "cred-1"], + accept_disclosed_gaps=True, + ) + assert res_contra.status == RECEIPT_INVALID + assert "disclosure_contradicted" in res_contra.failures + assert res_contra.policy_accepted is False +