README.md
219 lines · 9421 bytes
13 symbols in this file
1# evidence-seal
2
3[](LICENSE)
4[]()
5
6Tamper-evident seals and chain of custody for audit evidence packages.
7
8Every Audit Labs tool assumes the evidence it handles is authentic. `evidence-seal`
9is what makes that assumption checkable. Point it at a directory of evidence — an
10[audit-tools](https://github.com/audit-labs/audit-tools) package, a folder of
11exported screenshots, anything — and it writes a `manifest.json` that pins every
12file's SHA-256 into a single Merkle fingerprint. Later, `verify` proves the
13directory is byte-for-byte what was sealed, and names anything that changed.
14
15- **Integrity** — detect any modified, added, or removed file.
16- **Chain of custody** — link sequential seals so a series of dated packages
17 forms an append-only history; reordering or removing one is detectable.
18- **Attribution** *(optional)* — sign a manifest with an ed25519 key so a named
19 party attests "I collected this," not just "it is unchanged."
20- **Trusted time** *(optional)* — obtain an RFC 3161 timestamp from an
21 independent authority so the seal is provably *not backdated*.
22
23The core (`seal`, `verify`, `chain`) is **pure standard library** — no
24dependencies. Signing needs `cryptography` (`evidence-seal[sign]`) and
25timestamping needs `asn1crypto` (`evidence-seal[timestamp]`).
26
27## Install
28
29```bash
30# Core is pure standard library; extras add signing + timestamping.
31pip install "evidence-seal[sign,timestamp]"
32
33# Or, for the zero-dependency core, drop the extras:
34pip install evidence-seal
35```
36
37To hack on it from a clone instead, see [Development](#development).
38
39## Usage
40
41```bash
42# Seal a package (manifest written to <dir>.manifest.json alongside it)
43evidence-seal seal ./output/aws_audit_prod_2026-01-01 \
44 --meta engagement=ACME-2026 --meta collector="Christian Cleberg"
45
46# Later, prove nothing changed
47evidence-seal verify ./output/aws_audit_prod_2026-01-01
48# -> intact — 8 files match the seal (exit 0)
49# -> TAMPERED … MODIFIED iam_users.csv (exit 1)
50```
51
52### Chain of custody
53
54Seal each new package against the previous manifest to build a verifiable
55timeline:
56
57```bash
58evidence-seal seal ./pkg_jan --out seals/jan.json
59evidence-seal seal ./pkg_feb --out seals/feb.json --prev seals/jan.json
60evidence-seal seal ./pkg_mar --out seals/mar.json --prev seals/feb.json
61
62evidence-seal chain seals/jan.json seals/feb.json seals/mar.json
63# -> chain intact — 3 seals link correctly
64```
65
66Each manifest's `id` is the hash of its own canonical contents, and `previous`
67holds the prior manifest's id — so a broken, reordered, or spliced-out link is
68caught.
69
70### Signing (attribution)
71
72```bash
73evidence-seal keygen --private acme.key --public acme.pub # once
74evidence-seal seal ./pkg --sign acme.key # seal + sign
75evidence-seal verify ./pkg --pubkey acme.pub # require this signer
76```
77
78Without `--pubkey`, a present signature is still checked for validity; with it,
79the signer's key must also match, proving *identity* and not just integrity.
80
81### Sign-offs (who reviewed what)
82
83An engagement can carry a firm-signed team roster and signed preparer/reviewer
84statements (written by audit-workbench). Verify them offline, trusting the firm
85key by a fingerprint you obtained outside the folder:
86
87```bash
88evidence-seal signoffs ./deliverable --trust SHA256:Xm2…firm-key-fingerprint
89```
90
91The folder holds `team.json` (members, roles, and `ssh-ed25519` keys),
92`team.json.sig` (SSH signature by the firm key, namespace
93`audit-roster@audit-labs`), and `signoffs.jsonl` (one signed statement per line,
94namespace `audit-signoff@audit-labs`). Signatures use the OpenSSH `SSHSIG`
95format, so `ssh-keygen -Y verify` can check them too. An item counts as reviewed
96only when a reviewer who is a different roster member from the preparer signed
97the same content. Exit code 1 if the roster or any statement fails.
98
99### Timestamping (trusted time)
100
101A signature says *who*; a timestamp says *when*, attested by an independent
102Time-Stamp Authority rather than the sealer's own clock. The TSA timestamps the
103manifest `id`, so one token vouches for the whole package.
104
105```bash
106# One step: request, POST to a TSA, and bind the token in
107evidence-seal timestamp submit pkg.manifest.json --tsa https://freetsa.org/tsr
108
109# Or split it — build a request, submit it however you like, then apply
110evidence-seal timestamp request pkg.manifest.json --out pkg.tsq
111curl -sS -H 'Content-Type: application/timestamp-query' \
112 --data-binary @pkg.tsq https://freetsa.org/tsr -o pkg.tsr
113evidence-seal timestamp apply pkg.manifest.json --token pkg.tsr
114
115evidence-seal timestamp verify pkg.manifest.json
116# -> timestamp OK: timestamped at 2026-08-06T09:00:00Z
117
118# Full verification: also check the token's CMS signature against the TSA cert
119evidence-seal timestamp verify pkg.manifest.json --tsa-cert freetsa.pem
120# -> timestamp OK: timestamped at 2026-08-06T09:00:00Z; TSA signature valid (CN=…)
121evidence-seal verify ./pkg --tsa-cert freetsa.pem # same check inside a full verify
122```
123
124`apply` refuses any token whose imprint is not this manifest's `id`. Because the
125`id` moves if a single byte changes, a token can never be transplanted onto
126tampered evidence — re-sealing after a change orphans the timestamp. A present
127timestamp is checked automatically during `verify`.
128
129With `--tsa-cert`, the token's RFC 3161 CMS signature is verified against the
130supplied certificate: the certificate must carry the timeStamping extended key
131usage, identify the token's signer, be valid at `gen_time`, and its key must
132verify the signature over the timestamped content. This authenticates the token
133against a TSA certificate you trust; establishing that the certificate itself
134chains to a known root is left to you (supply a cert you already trust).
135
136## The manifest
137
138Canonical JSON, sorted keys — diff-friendly and reproducible:
139
140```json
141{
142 "algorithm": "sha256",
143 "created_at": "2026-08-06T08:06:05Z",
144 "subject": "aws_audit_prod_2026-01-01",
145 "previous": null,
146 "metadata": { "collector": "Christian Cleberg", "engagement": "ACME-2026" },
147 "root": "23fdf7eb…",
148 "file_count": 8,
149 "files": [ { "path": "iam_users.csv", "sha256": "309b0e45…", "bytes": 412 } ],
150 "id": "08b846a0…",
151 "signature": { "algorithm": "ed25519", "public_key": "1bea5f1d…", "value": "2d7c2d63…" },
152 "timestamp": { "format": "rfc3161", "gen_time": "2026-08-06T09:00:00Z", "imprint": "08b846a0…", "token": "MIIB…" }
153}
154```
155
156- **`root`** — Merkle root over all `(path, sha256)` leaves; one value that
157 changes if any file, name, or byte changes.
158- **`id`** — SHA-256 of the manifest's canonical form (excluding `id`,
159 `signature`, and `timestamp`); makes it self-verifying and chainable. Because
160 the signature and the timestamp both attest *to* the id, they sit outside it
161 and compose in any order.
162- **`ignore`** — glob patterns skipped at seal time; `verify` reuses them so it
163 never false-flags an intentionally excluded file.
164
165## Exit codes
166
167| Code | Meaning |
168| --- | --- |
169| `0` | Intact / valid. |
170| `1` | Tamper detected, chain broken, or signature invalid. |
171| `2` | Usage error (missing directory, bad `--meta`, missing optional dependency). |
172
173Fail a pipeline on `1`; treat `2` as a misconfiguration to fix.
174
175## Threat model
176
177`evidence-seal` proves a directory matches a manifest, who produced it (when
178signed), and that it existed by a given time (when timestamped). An *unsigned,
179untimestamped* manifest can be regenerated by anyone with the files, and its
180`created_at` is self-reported. For a strong "sealed at time T by party P"
181guarantee, **sign** the manifest (retain the public key out of band) and
182**timestamp** it with a trusted TSA.
183
184**What a seal does not prove.** A seal proves the *package* is unchanged since it
185was sealed — nothing more. It says nothing about whether the collection faithfully
186represented the system at collection time: whether the right scope was captured,
187whether a query was complete, or whether the evidence was gathered from the
188production system at all. That is the question an auditor actually asks, and it is
189answered by collection controls and re-performance, not by this tool. Seal the
190evidence; don't mistake an intact seal for a trustworthy collection.
191
192Further limits to be honest about:
193
194- **`timestamp verify` checks the binding; `--tsa-cert` adds signature
195 verification but not chain-of-trust.** Without a cert, verification proves the
196 stored token timestamps this manifest's `id`. With `--tsa-cert`, it also
197 verifies the token's CMS signature, the timeStamping EKU, the signer match,
198 and validity at `gen_time`. It does **not** verify that the certificate chains
199 to a trusted root — supply a TSA certificate you already trust.
200- Private keys are written **unencrypted** — store them accordingly.
201
202## Stability
203
204`evidence-seal` is stable as of **v1.0.0** and follows [semantic versioning](https://semver.org).
205The `manifest.json` schema (`manifest_version`) and the CLI exit codes are a
206committed contract — neither changes in a breaking way without a major-version bump.
207
208## Development
209
210```bash
211pip install -e ".[dev]"
212pytest
213ruff check .
214./scripts/e2e.sh # every feature end-to-end through the CLI, offline
215```
216
217## License
218
219GPL-3.0-or-later. See [LICENSE](LICENSE).