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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
screenshots, typed values, URLs or page text.
- `openadapt flow encrypt` replaces `flow seal` (a hidden alias for one release).
Desktop's "Seal and encrypt version" is now "Encrypt version".
- Each run also writes `receipt.card.json`, its public card. Transaction and
write receipts in a run folder become lines of the run's receipt, by digest.
`local-seal anchor` logs the receipt in Rekor too, and `openadapt verify`
then says "Logged publicly at <time>". The offline receipt page checks
`receipt.json` first.
- The run summary (`run-receipt/v2`) moves from `receipt.json` to
`run-summary.json`, `.md` and `.png`. Older run folders still read.

Expand Down
41 changes: 41 additions & 0 deletions openadapt/seal_view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,37 @@ def local_keys(home: Optional[Path] = None) -> list[dict[str, str]]:
return [public_key_entry(home or seal_home())]


def receipt_registry(keys: Any, *, own: bool = False) -> Optional[dict[str, Any]]:
"""The keys as an ``openadapt.receipt-keys/v1`` registry for the receipt check.

A registry that already names roles is used as it is. An older Seal key
registry names no role. Only this computer's own key (``own``) becomes
``this_computer``; for any other older registry there is no role to give,
so the receipt isn't checked against it (None), never labelled as this
computer's (trust-label class).
"""

if isinstance(keys, Mapping) and keys.get("schema") == "openadapt.receipt-keys/v1":
return dict(keys)
if not own:
return None
entries = keys.get("keys") if isinstance(keys, Mapping) else keys
out = []
for entry in entries or []:
if not isinstance(entry, Mapping):
continue
item = {
"key_id": entry.get("key_id"),
"public_key": entry.get("public_key"),
"role": "this_computer",
"status": entry.get("status", "active"),
}
if item["status"] == "revoked":
item["revoked_at"] = entry.get("revoked_at")
out.append(item)
return {"schema": "openadapt.receipt-keys/v1", "keys": out}


def page_data(
run_dir: Path,
*,
Expand All @@ -202,6 +233,7 @@ def page_data(
about: Optional[Mapping[str, Any]] = None,
host: Optional[Mapping[str, Any]] = None,
commands: Optional[str] = None,
own_keys: bool = False,
) -> dict[str, Any]:
"""What the viewer reads: the run's files exactly as they are on disk."""

Expand All @@ -211,13 +243,20 @@ def page_data(
if seal is None:
raise SealViewError(f"{run_dir} has no seal.json")
present = [name for name in RUN_FILES if (run_dir / name).is_file()]
receipt = _text(run_dir / "receipt.json")
if receipt is not None and '"payloadType"' not in receipt:
receipt = None # an older run summary under the receipt's name
return {
"report_b64": base64.b64encode(report).decode("ascii"),
"seal_text": seal,
"anchor_text": _text(run_dir / "seal.anchor.json"),
"tsa_text": _text(run_dir / "seal.tsa.json"),
"tsr_b64": _b64(run_dir / "seal.tsr"),
"keys": keys,
# The receipt (record/run/v1), checked first; seal.json is the older format.
"receipt_text": receipt,
"receipt_anchor_text": _text(run_dir / "receipt.anchor.json"),
"receipt_keys": receipt_registry(keys, own=own_keys),
"program": {"spec": dict(program)},
"about": dict(about or {}),
"host": {"files": present, **dict(host or {})},
Expand Down Expand Up @@ -265,6 +304,7 @@ def write_seal_page(
report = json.loads(report_path.read_bytes())
except (OSError, ValueError) as exc:
raise SealViewError(f"{report_path} can't be read") from exc
own_keys = keys is None
if keys is None:
keys = local_keys()
# A page forwarded to someone else stays a local check, not third-party proof.
Expand All @@ -282,6 +322,7 @@ def write_seal_page(
about=about,
host=dict(host or {}),
commands=commands,
own_keys=own_keys,
)
target = Path(out) if out else run_dir / PAGE_NAME
target.write_text(render_page(data), encoding="utf-8")
Expand Down
14 changes: 7 additions & 7 deletions openadapt/seal_view/viewer.html

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions packages/flow/docs/RECEIPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ two files beside `report.json` when the run ends, whatever its outcome:
|---|---|---|
| `receipt.json` | The receipt: a DSSE envelope over an in-toto statement, predicate type `https://openadapt.ai/record/run/v1`, signed with this computer's key | Yes, as a public card (below) |
| `receipt.private.json` | The salts and values behind the receipt's commitments (`openadapt.receipt-openings/v1`, mode 0600) | No. It never leaves the computer |
| `receipt.card.json` | The public card (`openadapt.receipt-card/v1`): the same signed envelope with only the Flow version opened (and the program name, for the synthetic tutorial) | Yes |

A stopped run gets a receipt too. The outcome (`VERIFIED`, `STOPPED`,
`UNKNOWN` or `FAILED`) is copied from the run and never upgraded: signing
Expand All @@ -24,7 +25,9 @@ changes the run's exit code and calls no model.
- the program's id (a hash, never its name) and version digest;
- the hour the run started;
- the outcome and a reason code;
- one line per write, with where it went (`gui` or `api`), the operation,
- one line per write, and one per transaction or write receipt in the run
folder (`tx-receipt.cose`, `*.receipt.cbor`), named by that file's SHA-256
so it verifies on its own; each line has where it went (`gui` or `api`), the operation,
its check (`confirmed`, `refuted` or `not_checked`), the check's strength
(`read_back`, `same_screen` or `none`), and what it didn't check;
- check counts;
Expand Down Expand Up @@ -94,8 +97,11 @@ Older files still verify, labelled "older format": `seal.json`
(`local-seal/v1`), `public-seal.json` (`public-seal/v1`), Cloud-signed
Execute receipts (`seal-signature/v1`), run summaries (`run-receipt/v2`),
write receipts (`write-receipt/v1`) and transaction receipts
(`tx-receipt/v1` to `v3`, with `--public-key`). For one release Flow also
writes `seal.json` beside `receipt.json`; see
(`tx-receipt/v1` to `v3`, with `--public-key`). `openadapt-flow local-seal anchor RUN_DIR` logs the receipt
in Rekor too (`receipt.anchor.json`, over the payload's SHA-256, so a later
countersignature doesn't change it), and a verifier then adds "Logged publicly
at <time>". For one release Flow also writes `seal.json` beside
`receipt.json`; see
[OFFLINE_SEALS.md](OFFLINE_SEALS.md) for that format, its keys and its
public-log anchor.

Expand Down
16 changes: 16 additions & 0 deletions packages/flow/openadapt_flow/cli_local_seal.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,22 @@ def _cmd_anchor(args: argparse.Namespace) -> int:
f"entry {entry['uuid']}, log index {entry['logIndex']}, at {_utc(entry['integratedTime'])}"
)
print(f"{args.log_url.rstrip('/')}/api/v1/log/entries/{entry['uuid']}")
receipt_path = seal_path.with_name("receipt.json")
if target.is_dir() and receipt_path.is_file():
# The run's receipt, signed by the same key, is anchored with it.
from openadapt_flow.seal_anchor import anchor_receipt

try:
receipt_anchor = anchor_receipt(
receipt_path, signer, log_url=args.log_url, log_keys=log_keys
)
except (AnchorError, OSError, ValueError) as exc:
print(f"receipt not anchored: {exc}", file=sys.stderr)
return 1
print(
f"anchored: {anchor_path(receipt_path)} "
f"(entry {receipt_anchor['entry']['uuid']})"
)
return 0


Expand Down
Loading
Loading