Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.0] - 2026-11-27

### Added

- Receipt v3-core verification through the `v3` command and `pipelock_verify.v3` API.
Mixed legacy evidence returns `USE_HOST_VERIFIER` with an unsupported verdict;
use `pipelock verify-receipt --chain <dir>` for that evidence.

## [0.4.1] - 2026-10-12

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-include tests/conformance *
recursive-include tests/fixtures *
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ pip install pipelock-verify

Only one runtime dependency: [`cryptography`](https://cryptography.io) for the Ed25519 primitives.

## Receipt v3-core

Verify v3 evidence with a trusted signer key (repeat `--key` for multiple keys):

```bash
pipelock-verify v3 --key PUBLIC_KEY_HEX --output result -- evidence-directory
```

The Python API exposes the same verifier:

```python
from pathlib import Path
from pipelock_verify.v3 import Options, verify_paths

document, projection = verify_paths(
[Path("evidence-directory")], Options(keys=("PUBLIC_KEY_HEX",), directory=True)
)
print(document["verdict"], document["exit_code"])
```

If a directory or file list also contains legacy evidence, the v3-core verifier
returns `USE_HOST_VERIFIER` and an unsupported verdict (exit 3). Use
`pipelock verify-receipt --chain <dir>` to verify that evidence.

## Usage

### Single receipt (auto-detects v1 vs v2)
Expand Down
2 changes: 1 addition & 1 deletion pipelock_verify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
verify_chain,
)

__version__ = "0.4.1"
__version__ = "0.5.0"

__all__ = [
"PAYLOAD_AUTHORITY",
Expand Down
8 changes: 7 additions & 1 deletion pipelock_verify/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def _print_chain(result: ChainResult, path: Path) -> None:


def main(argv: Sequence[str] | None = None) -> int:
arguments = list(sys.argv[1:] if argv is None else argv)
if arguments and arguments[0] == "v3":
from .v3.cli import run

return run(arguments[1:])

parser = argparse.ArgumentParser(
prog="pipelock_verify",
description=(
Expand Down Expand Up @@ -132,7 +138,7 @@ def main(argv: Sequence[str] | None = None) -> int:
version=f"pipelock-verify {__version__}",
)

args = parser.parse_args(argv)
args = parser.parse_args(arguments)
path: Path = args.path

if not path.exists():
Expand Down
9 changes: 9 additions & 0 deletions pipelock_verify/v3/SOURCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Pipelock commit 89ba9038a; sdk/verifiers/python/src/pipelock_aarp_verify/v3/
Files: __init__.py, cli.py, cutover.py, decision.py, verify.py, wire.py, registry.json
Only parent helper imports are redirected to _helpers.py.
Local changes (behaviour-preserving, for CodeQL): decision.py no longer imports verify (its Verification and
_Stream annotations are aliased to Any), removing the import cycle; verify.py drops the type-checking sqlite3
import and annotates the scratch database as Any, keeping the deferred runtime import as the only one;
verify.py head_expectation's empty except carries a comment; verify.py _accepted and wire.py _match_string
return False after the match instead of in a catch-all case.
Local change: wire.py _time() passes +00:00 instead of the trailing Z to datetime.fromisoformat, which rejects Z before Python 3.11.
9 changes: 9 additions & 0 deletions pipelock_verify/v3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2026 Pipelab
# SPDX-License-Identifier: Apache-2.0

"""Receipt v3 verification library."""

from .verify import Options, claims_input, projection, verify_paths
from .wire import canonical

__all__ = ["Options", "canonical", "claims_input", "projection", "verify_paths"]
40 changes: 40 additions & 0 deletions pipelock_verify/v3/_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2026 Pipelock contributors
# SPDX-License-Identifier: Apache-2.0

"""Helpers copied from the Pipelock Python verifier at 89ba9038a."""

from __future__ import annotations

import os
import stat
from pathlib import Path
from typing import BinaryIO


def _open_regular_input(path: str | Path) -> BinaryIO:
fd = os.open(path, os.O_RDONLY | getattr(os, "O_NONBLOCK", 0))
try:
if not stat.S_ISREG(os.fstat(fd).st_mode):
raise OSError("input must be a regular file")
return os.fdopen(fd, "rb")
except BaseException:
os.close(fd)
raise


def _parse_evidence_filename(name: str) -> tuple[str, int] | None:
"""Match evidencename.Parse, including its legacy sequence-zero fallback."""
if not name.startswith("evidence-") or not name.endswith(".jsonl"):
return None
stem = name[len("evidence-") : -len(".jsonl")]
found_session, separator, start_text = stem.rpartition("-")
if not separator:
return None
if start_text and all("0" <= char <= "9" for char in start_text):
# A uint64 needs at most 20 digits once leading zeros are removed.
trimmed = start_text.lstrip("0") or "0"
if len(trimmed) <= 20:
start = int(trimmed)
if start <= (1 << 64) - 1:
return found_session, start
return found_session, 0
91 changes: 91 additions & 0 deletions pipelock_verify/v3/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2026 Pipelab
# SPDX-License-Identifier: Apache-2.0

"""The receipt v3 installed-package command."""

from __future__ import annotations

import argparse
import sys
from pathlib import Path

from ._helpers import _open_regular_input
from .verify import Options, claims_input, verify_paths
from .wire import canonical


class _Parser(argparse.ArgumentParser):
def error(self, message: str) -> None:
raise ValueError(message)


def run(argv: list[str]) -> int:
parser = _Parser(prog="pipelock_aarp_verify v3", allow_abbrev=False)
parser.add_argument("--key", action="append", default=[])
parser.add_argument("--allow-unpinned", action="store_true")
parser.add_argument("--allow-prefix", action="store_true")
parser.add_argument("--accept-discontinuity", action="append", default=[])
parser.add_argument("--allow-partial-history", action="append", default=[])
parser.add_argument("--expect-lineage", default="")
parser.add_argument("--expect-head", action="append", default=[])
parser.add_argument("--expect-seq", action="append", default=[])
parser.add_argument("--format", choices=("v3",))
parser.add_argument("--output", choices=("result", "projection"))
parser.add_argument("--claims", action="store_true")
parser.add_argument("paths", nargs="*", type=Path)
try:
args = parser.parse_intermixed_args(argv)
if args.claims:
if len(args.paths) != 1 or any(
(
args.key,
args.allow_unpinned,
args.allow_prefix,
args.accept_discontinuity,
args.allow_partial_history,
args.expect_lineage,
args.expect_head,
args.expect_seq,
args.format,
args.output,
)
):
raise ValueError(
"--claims requires exactly one file and no other options"
)
with _open_regular_input(args.paths[0]):
pass
sys.stdout.write("true\n" if claims_input(args.paths[0]) else "false\n")
return 0
directory = len(args.paths) == 1 and args.paths[0].is_dir()
options = Options(
keys=tuple(args.key),
allow_unpinned=args.allow_unpinned,
allow_prefix=args.allow_prefix,
accept_discontinuities=tuple(args.accept_discontinuity),
allow_partial_histories=tuple(args.allow_partial_history),
expect_lineage=args.expect_lineage,
expect_heads=tuple(args.expect_head),
expect_sequences=tuple(args.expect_seq),
directory=directory,
explicit_v3=args.format == "v3",
)
result, projection = verify_paths(args.paths, options)
if any(
finding["code"] == "USE_HOST_VERIFIER" for finding in result["findings"]
):
sys.stderr.write(
"Use pipelock verify-receipt --chain <dir> for this evidence.\n"
)
sys.stdout.write(
canonical(projection if args.output == "projection" else result).decode(
"utf-8"
)
+ "\n"
)
return result["exit_code"]
except (OSError, ValueError) as exc:
sys.stderr.write(" ".join(str(exc).splitlines()) + "\n")
return 2
except SystemExit as exc:
return int(exc.code or 0)
60 changes: 60 additions & 0 deletions pipelock_verify/v3/cutover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2026 Pipelab
# SPDX-License-Identifier: Apache-2.0

"""Name-only old evidence detection and empty cutover validation."""

from ._helpers import _parse_evidence_filename
from ._helpers import _open_regular_input
from .wire import digest

_EMPTY_BYTES = b'{"chains":[],"v":1}'
EMPTY_INVENTORY = digest(_EMPTY_BYTES)


# Go discovery: internal/receipt/v3/legacy.go:43, internal/receipt/chain_set.go:358,
# internal/ael/emitter.go:138 and internal/receipt/group_inventory.go:83.
def legacy_candidate(name: str) -> bool:
return bool(
_parse_evidence_filename(name)
or name == "ael"
or name.startswith("chain-link-")
and name.endswith(".json")
or name.startswith("receipt-group-")
and name.endswith(".json")
or name
in (
"activation-receipts.jsonl",
"redaction-receipts.jsonl",
"ratification-receipts.jsonl",
)
)


def _empty_inventory(path):
with _open_regular_input(path) as source:
return source.read(len(_EMPTY_BYTES) + 1) == _EMPTY_BYTES


def verify_empty_cutover(v, inventories, claimed):
if not claimed:
return {}
checked = set()
for stream in v.streams.values():
cutover = stream.body.get("legacy_cutover")
opener = stream.opening
if not cutover or opener is None:
continue
pin, count = cutover["inventory"], cutover["chains"]
checked.add(pin)
paths = inventories.get(pin, ())
if paths:
for path in paths:
if count != 0 or not _empty_inventory(path):
v.add("CUTOVER_INVENTORY_MISMATCH", record=opener)
elif count != 0:
v.add("CUTOVER_INVENTORY_MISMATCH", record=opener)
for pin in sorted(inventories.keys() - checked):
for path in inventories[pin]:
if not _empty_inventory(path):
v.add("CUTOVER_INVENTORY_MISMATCH")
return {}
Loading
Loading