Watch
1
0
Fork
You've already forked souveraine
0
souveraine/packaging/souveraine-verify-trail
Fimeg 8f42fc953d publish: the public projection begins here
This is a projection, not a development branch. The tree above was constructed
from the internal source named below under a manifest that decides which paths
may leave, then scanned as a whole tree rather than as a series of patches, and
only then published.

Public history starts here because the history before it was not admissible,
and neither was the tree. What used to stand in this repository included a
rescue copy of another machine, a directory of phone handoffs, deployment
wired to one house, and a submodule pointing at a forge no stranger can reach.
None of that was ever the product. It stays in the private forge, which is
allowed to hold the whole working organism, and this is what was deliberately
sent out instead.

Three mechanisms produced this tree, in decreasing order of trust. A top-level
path the manifest does not name never arrives at all, which is the one that
catches directories nobody has thought of yet. Named internal files inside
admitted roots are dropped. A short, reviewed table replaces deployment
defaults that a public build must not carry -- an endpoint aimed at one LAN, a
VPN profile belonging to one phone, packaging built from one checkout path.

Everything after this commit is an ordinary publication with the same three
trailers, so a force push stops being routine and starts meaning that
something deliberate happened. The trailers bind the projection to its source
without pretending the public SHA is the private one: same lineage, different
tree, and the record says so.

Source-Sha: 8f27b1e76a8fef560a336aba18e6990713ff1047
Policy-Sha: 6b261d2f3e6e1fb19874846ba4bb1dfe15565d25b8618c1c1afba0419c101d27
Tree-Digest: 18ec3563c5e5ef9a414993a9f6734b251ff9ed3cd56eebdd6cac01e45c6e3067
2026-09-04 15:55:48 -04:00

73 lines
2.7 KiB
Python
Executable file

#!/usr/bin/env python3
"""Verify a Souveraine hash-chained JSONL trail.
Reads the forensic trail (or SessionAudit's — same contract) and checks that
every entry's hash covers its own body and that each `prev` is the previous
entry's hash. DEVICE-STATE-MACHINE.md §11 called the trail tamper-evident and
listed this as owed: evidence nobody checks is not evidence.
The contract, in one sentence: strip the trailing `,"hash":"<hex>"`, close the
object, SHA-256 what is left.
Rotation is expected, not an error — the live file's first entry chains onto
the last entry of `.jsonl.1`, so a single file verified alone opens with a
`prev` it cannot see. Pass the generations oldest-first to check across them.
souveraine-verify-trail # the default trail
souveraine-verify-trail f.jsonl.2 f.jsonl.1 f.jsonl
"""
import hashlib
import json
import os
import sys
DEFAULT = os.path.join(
os.environ.get("XDG_STATE_HOME", os.path.expanduser("~/.local/state")),
"souveraine",
"forensic.jsonl",
)
def verify(paths):
prev = None # None = first file, accept whatever prev it opens with
seq = None
checked = 0
for path in paths:
try:
lines = open(path).read().splitlines()
except OSError as e:
print(f"cannot read {path}: {e}", file=sys.stderr)
return 2
for n, line in enumerate(lines, 1):
if not line.strip():
continue
cut = line.rfind(',"hash":')
if cut < 0:
print(f"{path}:{n}: no hash field")
return 1
want = hashlib.sha256((line[:cut] + "}").encode()).hexdigest()
try:
entry = json.loads(line)
except json.JSONDecodeError as e:
print(f"{path}:{n}: not JSON ({e})")
return 1
if entry.get("hash") != want:
print(f"{path}:{n}: seq {entry.get('seq')} hash does not cover its body")
return 1
if prev is not None and entry.get("prev", "") != prev:
print(f"{path}:{n}: seq {entry.get('seq')} does not chain onto the entry before it")
return 1
if seq is not None and entry.get("seq") != seq + 1:
# A gap is not tampering by itself — a rotated generation may be
# gone — but it is worth naming, because the chain cannot span
# what is not on disk.
print(f"{path}:{n}: sequence jumps {seq} -> {entry.get('seq')}")
prev = entry["hash"]
seq = entry.get("seq")
checked += 1
print(f"chain verifies: {checked} entries")
return 0
if __name__ == "__main__":
sys.exit(verify(sys.argv[1:] or [DEFAULT]))