"""Standalone verifier for the CAIN-42 governance-data-plane bundles. Python standard library only; imports nothing from CAIN. Usage: python3 verify_dataplane.py.txt Checks: 1. every file in MANIFEST.json exists and hashes to its recorded sha256; no unlisted files 2. the RFC 6962 inclusion proof of a fast-path decision (from the live run) recomputes to the Merkle root that the live cluster committed at the recorded sequence 3. the verdict is consistent with the gates: PRODUCTION READY / a_plus_plus_plus=true only if every gate is PASS; no gate without evidence is PASS 4. no implementation source is published (only .json/.md/.txt and this verifier) The QC signatures themselves are checkable at /api/v1/live-cluster/qc/{sequence} with the published cluster keys; this script does not fetch them (it runs offline). """ import hashlib import json import sys from pathlib import Path def rfc6962_verify(leaf: bytes, index: int, size: int, path, root: str) -> bool: if not 0 <= index < size: return False fn, sn = index, size - 1 r = hashlib.sha256(b"\x00" + leaf).digest() for p in path: pb = bytes.fromhex(p) if sn == 0: return False if fn & 1 or fn == sn: r = hashlib.sha256(b"\x01" + pb + r).digest() if not fn & 1: while fn and not fn & 1: fn >>= 1 sn >>= 1 else: r = hashlib.sha256(b"\x01" + r + pb).digest() fn >>= 1 sn >>= 1 return sn == 0 and r.hex() == root def main(d: Path) -> int: results = [] def check(name, ok, detail=""): results.append((name, bool(ok), detail)) man = json.loads((d / "MANIFEST.json").read_text()) bad = [f for f, h in man["files"].items() if not (d / f).is_file() or hashlib.sha256((d / f).read_bytes()).hexdigest() != h] extra = [str(p.relative_to(d)) for p in d.rglob("*") if p.is_file() and p.name != "MANIFEST.json" and str(p.relative_to(d)) not in man["files"] and p.name != "index.html"] check("manifest_hashes", not bad, f"mismatched: {bad}") check("no_unlisted_files", not extra, f"unlisted: {extra}") live = d / "governance/live_run.json" if live.exists(): lr = json.loads(live.read_text()) e = (lr.get("evidence_anchor") or {}).get("one_decision_end_to_end") or {} p = e.get("proof") check("anchor_inclusion_proof", p and rfc6962_verify(p["leaf"].encode(), p["leaf_index"], p["tree_size"], p["audit_path"], p["root"]), f"root {p and p['root'][:16]} at sequence {p and p['sequence']}") check("anchor_root_matches_committed_result", p and lr["evidence_anchor"]["result"].get("root") == p["root"]) check("snapshot_qc_reverified_offline", lr["snapshot_commit"].get("offline_reverify") is True) gates = json.loads((d / "GATES.json").read_text()) check("no_pass_without_evidence", all(g["evidence"] for g in gates.values() if g["status"] == "PASS")) all_pass = all(g["status"] == "PASS" for g in gates.values()) vname = man["verdict_file"] v = json.loads((d / vname).read_text()) if vname == "final-verdict.json": check("verdict_consistent", (v["production_status"] == "PRODUCTION READY") == all_pass, v["production_status"]) else: check("verdict_consistent", v["a_plus_plus_plus"] is all_pass and (v["production_status"] == "PASS") == all_pass, v["verdict"]) check("blockers_listed_for_every_non_pass", {b["blocker"] for b in v["blockers"]} == {k for k, g in gates.items() if g["status"] != "PASS"}) code = [f for f in man["files"] if not f.endswith((".json", ".md", ".txt"))] check("no_implementation_source_published", not code, f"{code}") for name, ok, detail in results: print(f"{'PASS' if ok else 'FAIL'} {name} {detail}") ok = all(r[1] for r in results) print("ALL_CHECKS_PASSED" if ok else "VERIFICATION_FAILED") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main(Path(sys.argv[1] if len(sys.argv) > 1 else ".")))