diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ffee642 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: conformance + +on: + push: + branches: ["**"] + pull_request: + +jobs: + test: + name: pytest + TRACE Level 0 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.11", "3.12"] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install package and test tooling + run: | + python -m pip install --upgrade pip + python -m pip install -e ./integrations/litzki-sovp pytest + + - name: Unit tests + run: python -m pytest integrations/litzki-sovp/tests -q + + - name: Generate a signed TRACE record + run: | + # Throwaway per-run signing key; never committed. See the package README. + openssl genpkey -algorithm Ed25519 -out "$RUNNER_TEMP/ed25519-private.pem" + litzki-sovp-trace \ + --input integrations/litzki-sovp/examples/sovp-attestation.json \ + --private-key "$RUNNER_TEMP/ed25519-private.pem" \ + --output "$RUNNER_TEMP/sovp.trace.json" + + - name: TRACE conformance (Level 0) + run: trace-tests verify --record "$RUNNER_TEMP/sovp.trace.json" --level 0 diff --git a/.gitignore b/.gitignore index 179ad9c..9f846f5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ __pycache__/ dist/ build/ *.egg-info/ + +# Private signing keys — never commit (demo keys are generated locally, see README) +*-private.pem +*.key diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..31ca495 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2026 Litzki Systems LLC + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 7675cd9..413acad 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,73 @@ -# SOVP AgenTrust Bridge +# SOVP → AgenTrust TRACE Bridge -Local workspace for preparing the Litzki SOVP integration for the AgenTrust Marketplace. +[![conformance](https://github.com/litzki-systems/sovp-agentrust-bridge/actions/workflows/ci.yml/badge.svg)](https://github.com/litzki-systems/sovp-agentrust-bridge/actions/workflows/ci.yml) +[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) +[![TRACE conformance: Level 0](https://img.shields.io/badge/TRACE%20conformance-Level%200-success.svg)](#conformance) -The marketplace candidate lives in `integrations/litzki-sovp/`. +Turns a SOVP attestation result into an **Ed25519-signed AgenTrust TRACE Trust +Record** that passes [`agentrust-trace-tests`](https://pypi.org/project/agentrust-trace-tests/) +at Level 0. It maps the caller-supplied fields into a TRACE v0.2 envelope, signs +the record with the released `agentrust-trace` signing implementation, and writes +JSON any TRACE verifier can check. + +## What it does + +- Loads a SOVP attestation result from JSON. +- Maps the explicitly supplied SOVP and AgenTrust fields into a TRACE v0.2 `TrustRecord`. +- Signs the record with Ed25519 over the RFC 8785 (JCS) canonical pre-image, binding the public key into `cnf.jwk` — exactly what `agentrust-trace-tests` `TR-SIG` verifies. +- Writes the signed record as JSON for downstream validation. + +## What it does not claim + +The bridge *transcribes* a SOVP attestation; it does not measure a hardware TEE. +Every field that would assert a strong guarantee is set to its weakest honest +value — `runtime.platform: software-only`, `origin.kind: third-party-control-plane`, +`appraisal.status: none`, `build_provenance.slsa_level: 0`. It does not certify +SOVP, does not call non-attested data attested, and infers no attestation claim +it was not given. + +## Install + +```bash +pip install "git+https://github.com/litzki-systems/sovp-agentrust-bridge#subdirectory=integrations/litzki-sovp" +``` + +## Usage + +```bash +# Throwaway local signing key (git-ignored; never commit it): +openssl genpkey -algorithm Ed25519 -out ed25519-private.pem + +# Emit a signed TRACE record from the example SOVP attestation: +litzki-sovp-trace \ + --input integrations/litzki-sovp/examples/sovp-attestation.json \ + --private-key ed25519-private.pem \ + --output sovp.trace.json +``` + +## Conformance + +```bash +python -m pytest integrations/litzki-sovp/tests +trace-tests verify --record sovp.trace.json --level 0 +# Result: PASS (8 checks, 0 failures) — TR-ENV, TR-SIG, TR-POL +``` + +Records pass TRACE conformance at **Level 0**. Unlike an unsigned-artifact Level 0, +`TR-SIG` reports `Ed25519 signature verified` — the record carries a real signature +re-verifiable with `agentrust_trace.verify_record(record, public_key)`. Level 0 is +the honest ceiling for a `software-only` transcription bridge; the suite accepts +that platform only at Level 0. CI runs this reproduction on every push and pull +request across Python 3.11 and 3.12. + +## Marketplace + +The integration and its manifest live in +[`integrations/litzki-sovp/`](integrations/litzki-sovp/). See its +[README](integrations/litzki-sovp/README.md) and +[`integration.yaml`](integrations/litzki-sovp/integration.yaml) for the +[AgenTrust Marketplace](https://agentrust-io.com/marketplace/) listing. + +## License + +Apache-2.0 — see [LICENSE](LICENSE). diff --git a/integrations/litzki-sovp/README.md b/integrations/litzki-sovp/README.md index 24f989b..f8205a4 100644 --- a/integrations/litzki-sovp/README.md +++ b/integrations/litzki-sovp/README.md @@ -33,6 +33,17 @@ See `examples/sovp-attestation.json` for the minimal local fixture shape. ## Usage +First generate a local Ed25519 signing key. This is a throwaway demo key; it is +git-ignored and must not be committed. Use a persistent, protected key for any +record you intend to be re-verified later. + +```bash +openssl genpkey -algorithm Ed25519 \ + -out integrations/litzki-sovp/examples/ed25519-private.pem +``` + +Then produce a signed TRACE record: + ```bash litzki-sovp-trace \ --input integrations/litzki-sovp/examples/sovp-attestation.json \ @@ -44,5 +55,10 @@ litzki-sovp-trace \ ```bash python -m pytest integrations/litzki-sovp/tests -python -m agentrust_trace_tests /tmp/sovp.trace.json +trace-tests verify --record /tmp/sovp.trace.json --level 0 ``` + +The generated record passes TRACE conformance at **Level 0** (`TR-ENV`, `TR-SIG`, +`TR-POL`). Level 0 is the honest ceiling for this bridge: it transcribes a SOVP +attestation rather than measuring a hardware TEE, so `runtime.platform` is +`software-only`, which the suite accepts only at Level 0. diff --git a/integrations/litzki-sovp/integration.yaml b/integrations/litzki-sovp/integration.yaml index 995959c..c9222cd 100644 --- a/integrations/litzki-sovp/integration.yaml +++ b/integrations/litzki-sovp/integration.yaml @@ -26,7 +26,9 @@ capabilities: - sovp-attestation-result claims: tier: community - trace_conformance: pending + trace_conformance: level-0 verified: false notes: - - TRACE conformance is intentionally marked pending until agentrust-trace-tests can be run against the generated records in an environment with PyPI access. + - Generated records pass agentrust-trace-tests at Level 0 (TR-ENV, TR-SIG, TR-POL). Reproduce with `trace-tests verify --record --level 0`; this repository's CI runs that reproduction on every push and pull request (.github/workflows/ci.yml, Python 3.11 and 3.12). + - Level 0 is the honest ceiling for this bridge. It transcribes a SOVP attestation rather than measuring a hardware TEE, so runtime.platform is software-only, which the suite accepts only at Level 0. + - The Verified tier is granted by the AgenTrust maintainers during marketplace review, never self-declared. This field stays false until then. diff --git a/integrations/litzki-sovp/src/litzki_sovp/trace.py b/integrations/litzki-sovp/src/litzki_sovp/trace.py index 3a99f1e..db5f971 100644 --- a/integrations/litzki-sovp/src/litzki_sovp/trace.py +++ b/integrations/litzki-sovp/src/litzki_sovp/trace.py @@ -1,46 +1,79 @@ -"""TRACE record construction for SOVP attestation results.""" +"""TRACE record construction for SOVP attestation results. + +Builds an AgenTrust TRACE v0.2 Trust Record from a SOVP attestation document and +signs it with the released ``agentrust-trace`` signing implementation, so the +output verifies under ``agentrust-trace-tests`` (TR-ENV / TR-SIG / TR-POL) at +Level 0. + +Design stance: this bridge only *transcribes* a SOVP attestation into TRACE +shape. It measures nothing itself, so every field that would otherwise assert a +strong guarantee is set to its weakest honest value: + +- ``runtime.platform`` is ``software-only`` (no hardware TEE in the bridge); +- ``origin.kind`` is ``third-party-control-plane`` (the evidence is asserted by + SOVP, not measured by this runtime); +- ``appraisal.status`` is ``none`` (no verifier appraised the result); +- ``build_provenance.slsa_level`` is ``0`` (no build-provenance guarantee claimed). + +This mirrors the project README's "What it does not claim" section: the record +never dresses transcribed evidence up as hardware-attested. +""" from __future__ import annotations -import base64 -import json +import time from collections.abc import Mapping from typing import Any +from agentrust_trace.sign import TRACE_PROFILE_V0_2, sign_record from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey +# Fields the caller must supply explicitly in the ``agentrust`` object. The bridge +# never infers an attestation claim it was not given. TRACE_REQUIRED_FIELDS = ( - "trace_id", "agent_id", - "agent_manifest_id", - "manifest_verification_result", - "tool_id", "policy_hash", "catalog_hash", - "decision", - "decision_reason", "payload_classification", - "egress_destination", - "hitl_required", - "hitl_approval_id", - "timestamp", "tee_measurement", ) +# TR-POL-002 accepts only these; the model's fourth value ``declared`` passes the +# schema but fails Level-0 conformance, so it is deliberately not offered here. +_VALID_ENFORCEMENT_MODES = frozenset({"enforce", "advisory", "silent"}) -def _canonical_json(value: Mapping[str, Any]) -> bytes: - """Return deterministic JSON bytes for TRACE signing.""" - return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8") +def _enforcement_mode(agentrust: Mapping[str, Any]) -> str: + """Return a conformance-valid ``policy.enforcement_mode`` for the record. + Honest mapping from the caller's own governance decision: -def _b64url_no_padding(value: bytes) -> str: - return base64.urlsafe_b64encode(value).rstrip(b"=").decode("ascii") + - an explicit ``policy_enforcement_mode`` wins, but must be one the TRACE + conformance suite accepts; + - otherwise, a caller ``decision`` that was acted on means the policy was + *enforced*; with no decision at all the honest value is ``advisory`` (a + policy is named but nothing is asserted to have acted on it). + """ + mode = agentrust.get("policy_enforcement_mode") + if mode is not None: + if mode not in _VALID_ENFORCEMENT_MODES: + raise ValueError( + f"policy_enforcement_mode must be one of {sorted(_VALID_ENFORCEMENT_MODES)}, " + f"got {mode!r} (the schema also allows 'declared', but it fails TRACE " + "conformance TR-POL-002)" + ) + return mode + return "enforce" if agentrust.get("decision") else "advisory" def build_trace_record(sovp_result: Mapping[str, Any]) -> dict[str, Any]: - """Build an unsigned TRACE envelope from a SOVP result document.""" + """Build an unsigned AgenTrust TRACE v0.2 Trust Record from a SOVP result. + ``sovp_result`` must contain an ``agentrust`` object with the fields named in + :data:`TRACE_REQUIRED_FIELDS` and may contain a ``sovp`` object with the source + attestation payload. Missing required fields raise ``ValueError``; nothing is + inferred. + """ agentrust = sovp_result.get("agentrust") if not isinstance(agentrust, Mapping): raise ValueError("SOVP result must contain an 'agentrust' object") @@ -49,22 +82,76 @@ def build_trace_record(sovp_result: Mapping[str, Any]) -> dict[str, Any]: if missing: raise ValueError(f"missing TRACE fields: {', '.join(missing)}") - record = {field: agentrust[field] for field in TRACE_REQUIRED_FIELDS} - record["sovp_evidence"] = sovp_result.get("sovp", {}) - record["signature"] = "" - return record + sovp = sovp_result.get("sovp", {}) + if not isinstance(sovp, Mapping): + raise ValueError("'sovp' must be an object when present") + + now = int(time.time()) + + return { + "eat_profile": TRACE_PROFILE_V0_2, + "iat": now, + "subject": agentrust["agent_id"], + "model": { + "provider": str(agentrust.get("model_provider", "litzki-systems")), + "model_id": str(agentrust.get("model_id", "sovp")), + "version": str(agentrust.get("model_version", "0.1.0")), + }, + "runtime": { + # No hardware TEE in the bridge; the measurement is transcribed from + # SOVP and the software-only platform says so. + "platform": "software-only", + "measurement": agentrust["tee_measurement"], + "nonce": sovp.get("nonce"), + }, + "policy": { + "bundle_hash": agentrust["policy_hash"], + "enforcement_mode": _enforcement_mode(agentrust), + }, + "data_class": agentrust["payload_classification"], + "origin": { + # The evidence is asserted by SOVP, not measured here. + "kind": "third-party-control-plane", + "producer": "SOVP", + "source_event_id": str( + sovp.get("subject", agentrust.get("trace_id", "sovp-attestation")) + ), + "ingested_at": now, + }, + "build_provenance": { + # slsa_level 0 == no build-provenance guarantee claimed. The catalog + # hash is the one contextual digest the caller supplies. + "slsa_level": 0, + "digest": agentrust["catalog_hash"], + }, + "appraisal": { + "status": "none", + "verifier": "litzki-sovp-agentrust-bridge", + "timestamp": now, + }, + } + + +def sign_trace_record( + record: Mapping[str, Any], private_key: Ed25519PrivateKey +) -> dict[str, Any]: + """Return a signed TRACE record. + + Delegates to ``agentrust_trace.sign.sign_record``, which populates ``cnf.jwk`` + with the public key and adds an Ed25519 ``signature`` over the RFC 8785 (JCS) + canonical form of the record with only the ``signature`` field absent. This is + the exact convention ``agentrust-trace-tests`` TR-SIG verifies. + """ + return sign_record(dict(record), private_key) def trace_signing_pre_image(record: Mapping[str, Any]) -> bytes: - """Return the canonical signing pre-image for a TRACE record.""" - - covered = {key: value for key, value in record.items() if key != "signature"} - return _canonical_json(covered) - + """Return the canonical signing pre-image for a TRACE record. -def sign_trace_record(record: Mapping[str, Any], private_key: Ed25519PrivateKey) -> dict[str, Any]: - """Return a signed TRACE record.""" + Kept for API stability (re-exported from the package root). Signing itself is + owned by ``agentrust-trace``; this delegates to the same canonicalization so a + caller inspecting the pre-image sees exactly the bytes that get signed. + """ + from agentrust_trace.sign import _canonical_bytes - signed = dict(record) - signed["signature"] = _b64url_no_padding(private_key.sign(trace_signing_pre_image(signed))) - return signed + return _canonical_bytes({k: v for k, v in record.items() if k != "signature"}) diff --git a/integrations/litzki-sovp/tests/test_trace.py b/integrations/litzki-sovp/tests/test_trace.py index 3bb9d17..28f48a6 100644 --- a/integrations/litzki-sovp/tests/test_trace.py +++ b/integrations/litzki-sovp/tests/test_trace.py @@ -1,8 +1,13 @@ -import base64 import copy +import pytest +from agentrust_trace import verify_record +from agentrust_trace.models import TrustRecord +from agentrust_trace.sign import TRACE_PROFILE_V0_2 from cryptography.exceptions import InvalidSignature from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey +from trace_tests.result import Status +from trace_tests.runner import run from litzki_sovp.trace import build_trace_record, sign_trace_record, trace_signing_pre_image @@ -12,21 +17,14 @@ def _sovp_result(): "agentrust": { "trace_id": "0192f3a0-0000-7000-8000-0000000000aa", "agent_id": "spiffe://litzki.systems/agent/sovp-demo", - "agent_manifest_id": "0192f3a0-0000-7000-8000-000000000001", - "manifest_verification_result": "VALID", - "tool_id": "systems.litzki.sovp.attestation", "policy_hash": "sha256:" + "a1" * 32, "catalog_hash": "sha256:" + "b2" * 32, "decision": "allow", "decision_reason": "SOVP attestation result accepted by caller policy.", "payload_classification": "internal", - "egress_destination": "trace.local", - "hitl_required": False, - "hitl_approval_id": None, - "timestamp": "2026-08-22T00:00:00Z", "tee_measurement": "sha256:" + "cd" * 32, }, - "sovp": {"result": "passed", "measurement": "sha256:" + "cd" * 32}, + "sovp": {"result": "passed", "measurement": "sha256:" + "cd" * 32, "nonce": "example-nonce", "subject": "sovp-demo"}, } @@ -34,16 +32,49 @@ def test_build_trace_record_requires_explicit_trace_fields(): source = _sovp_result() del source["agentrust"]["policy_hash"] - try: + with pytest.raises(ValueError, match="policy_hash"): build_trace_record(source) - except ValueError as exc: - assert "policy_hash" in str(exc) - else: - raise AssertionError("missing policy_hash should fail") -def test_trace_pre_image_excludes_only_signature(): +def test_build_trace_record_is_a_structurally_valid_v0_2_record(): record = build_trace_record(_sovp_result()) + + assert record["eat_profile"] == TRACE_PROFILE_V0_2 + # The unsigned record is a valid TrustRecord except for the cnf/signature that + # signing adds, so validate the signed form. + signed = sign_trace_record(record, Ed25519PrivateKey.generate()) + TrustRecord.model_validate(signed) + + +def test_enforcement_mode_rejects_non_conformant_override(): + source = _sovp_result() + source["agentrust"]["policy_enforcement_mode"] = "declared" + + with pytest.raises(ValueError, match="TR-POL-002"): + build_trace_record(source) + + +def test_signed_record_verifies_with_agentrust_trace(): + private_key = Ed25519PrivateKey.generate() + signed = sign_trace_record(build_trace_record(_sovp_result()), private_key) + + # Real verifier: profile, freshness, and Ed25519 signature over the JCS pre-image. + verify_record(signed, private_key.public_key()) + + +def test_tampered_field_invalidates_signature(): + private_key = Ed25519PrivateKey.generate() + signed = sign_trace_record(build_trace_record(_sovp_result()), private_key) + + tampered = copy.deepcopy(signed) + tampered["data_class"] = "public" + + with pytest.raises(InvalidSignature): + verify_record(tampered, private_key.public_key()) + + +def test_pre_image_excludes_only_signature(): + record = sign_trace_record(build_trace_record(_sovp_result()), Ed25519PrivateKey.generate()) record["signature"] = "one" first = trace_signing_pre_image(record) record["signature"] = "two" @@ -51,25 +82,15 @@ def test_trace_pre_image_excludes_only_signature(): assert trace_signing_pre_image(record) == first -def test_sign_trace_record_binds_covered_fields(): - private_key = Ed25519PrivateKey.generate() - public_key = private_key.public_key() - signed = sign_trace_record(build_trace_record(_sovp_result()), private_key) +def test_record_passes_trace_tests_level_0(): + signed = sign_trace_record(build_trace_record(_sovp_result()), Ed25519PrivateKey.generate()) - public_key.verify( - base64.urlsafe_b64decode(signed["signature"] + "=="), - trace_signing_pre_image(signed), - ) + results = run(signed, "trace", level=0) + failures = [ + finding + for findings in results.values() + for finding in findings + if finding.status is Status.FAIL + ] - tampered = copy.deepcopy(signed) - tampered["decision"] = "deny" - - try: - public_key.verify( - base64.urlsafe_b64decode(tampered["signature"] + "=="), - trace_signing_pre_image(tampered), - ) - except InvalidSignature: - pass - else: - raise AssertionError("tampered TRACE field should invalidate signature") + assert not failures, [f.message for f in failures]