Physically move the pure-code subtrees out of .specify into the package, leaving compat symlinks at the old .specify/<dir> paths so every existing reference (internal CASAN_HARNESS_ROOT + external CI/docker/mjs) keeps resolving. Runtime state stays put. Moved (git mv): scripts/ tests/ security/ templates/ config/ governance/ memory/ .specify/<dir> -> packages/casan-harness/<dir> (+ .specify/<dir> symlink) Stays in .specify (state/governance/domain, handled later): logs/ agentops/ level5/ init-options.json traceability-map.json Python `.resolve()` self-location followed the compat symlink into packages and lost the app root; generate-casan-demo-context.py, generate-agentops-dashboard.py and dashboard-server.py now walk UP for the `.specify` state marker instead of a fixed parent depth (fixes "missing trace files" in run-casan4). Full gate: PASS=64 FAIL=0 SKIP=3 (CASAN_CI_STEP_TIMEOUT_SEC=1200 — track-a ~450s runs close to the 600s default and can tip over under load; this is timing variance, not a regression — it passed cleanly with headroom). Runtime log/audit artifacts kept unstaged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
74 lines
2.5 KiB
Python
Executable File
74 lines
2.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""CASAN Plan-09 — Evidence Pack verifier (MVP).
|
|
|
|
Recomputes the hash of every file in a pack and compares it to the stored
|
|
artifact-manifest.json. Any change to any packed file flips a hash and fails
|
|
verification. (The bash wrapper additionally verifies the RSA signature over
|
|
manifest-head.txt, which stops an attacker who rewrites the manifest too.)
|
|
|
|
Argv: <pack_dir>
|
|
Exit: 0 intact, 1 tamper detected / manifest missing.
|
|
"""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
|
|
def main():
|
|
pack_dir = sys.argv[1]
|
|
manifest_path = os.path.join(pack_dir, "artifact-manifest.json")
|
|
if not os.path.isfile(manifest_path):
|
|
sys.stderr.write("EVIDENCE_PACK_NO_MANIFEST\n")
|
|
return 1
|
|
try:
|
|
manifest = json.load(open(manifest_path, encoding="utf-8"))
|
|
except ValueError:
|
|
sys.stderr.write("EVIDENCE_PACK_MANIFEST_CORRUPT\n")
|
|
return 1
|
|
|
|
stored = manifest.get("files", {})
|
|
mismatches = []
|
|
|
|
# Every file recorded in the manifest must still hash to the same value.
|
|
for fn, want in stored.items():
|
|
path = os.path.join(pack_dir, fn)
|
|
if not os.path.isfile(path):
|
|
mismatches.append(f"{fn}:missing")
|
|
continue
|
|
with open(path, "rb") as f:
|
|
got = hashlib.sha256(f.read()).hexdigest()
|
|
if got != want:
|
|
mismatches.append(f"{fn}:hash_changed")
|
|
|
|
# A new unmanifested file (except sig/head) is also tampering.
|
|
for fn in os.listdir(pack_dir):
|
|
if fn in ("artifact-manifest.json", "evidence-pack.sig", "manifest-head.txt"):
|
|
continue
|
|
if os.path.isfile(os.path.join(pack_dir, fn)) and fn not in stored:
|
|
mismatches.append(f"{fn}:unexpected_file")
|
|
|
|
# The stored manifest_head must match the recomputed head of `stored`.
|
|
canonical = json.dumps(stored, sort_keys=True, separators=(",", ":"))
|
|
head_now = hashlib.sha256(canonical.encode()).hexdigest()
|
|
if head_now != manifest.get("manifest_head"):
|
|
mismatches.append("manifest_head:mismatch")
|
|
|
|
if mismatches:
|
|
sys.stderr.write("EVIDENCE_PACK_TAMPERED " + " ".join(mismatches) + "\n")
|
|
return 1
|
|
|
|
cert = "unknown"
|
|
rs = os.path.join(pack_dir, "run-summary.json")
|
|
if os.path.isfile(rs):
|
|
try:
|
|
cert = str(json.load(open(rs, encoding="utf-8")).get("certified"))
|
|
except ValueError:
|
|
pass
|
|
print(f"EVIDENCE_PACK_INTACT files={len(stored)} certified={cert} head={head_now}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|