You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2285a77
Browse filesBrowse the repository at this point in the historyBrowse files
feat(attestation): hash intent and evidence as JCS and bind them on verify (#247)
Stacked PR D of the estate-format series:
- A: `.kyaml` loaders
- B: example profiles
- C: JCS reports
- E: KYAML output (#248)
A, B, C and E are merged. This PR builds on `crate::json` from the
JCS-reports PR.
## What changes
- **JCS hashing.** `assail --attest` hashes the intent and evidence
records as their JCS (RFC 8785) bytes via the new
`crate::json::to_canonical_bytes`. It previously hashed
`serde_json::to_vec` struct order. The `.attestation.json` sidecar
itself is now written as I-JSON/JCS (J-1).
- **Content binding on verify (a fix).** `attest verify` used to
recompute only `chain_hash` from the three *stored* digests, so the
embedded intent and evidence could be edited after sealing without
detection. It now rehashes both from the file and fails on a mismatch.
It hashes the parsed JSON tree rather than the typed structs, so fields
this build doesn't know about stay inside the hash.
- **`hash_scheme` on the seal** (`jcs-sha256`). The scheme is prefixed
into the chain hash: `SHA-256(hash_scheme || intent_hash ||
evidence_hash || report_hash)`. Any Ed25519 signature therefore covers
it too.
- **Fixed-width digests (Codex P1, fixed in d88ccd9).** `attest verify`
rejects any digest field that isn't exactly 64 lowercase hex characters.
Without that check, an attacker could move the scheme name into
`intent_hash` and drop `hash_scheme`. That reproduced the signed bytes
on the legacy path, which skips the content rehash. With fixed widths,
the legacy chain input (192 bytes) and the scheme-prefixed one (202
bytes) can't coincide.
- **Legacy sidecars.** Sidecars with no `hash_scheme` deserialise as
`serde-json-sha256`, use the old chain-hash formula, and verify as
before, reported as `Content: not rehashed (legacy hash scheme)`. An
unknown scheme fails.
## Validation
- `cargo fmt --check`, plus `cargo clippy --all-targets -D warnings`
both with `--all-features` and without: clean.
- `cargo test --all-features`: all suites green after merging main (lib:
509 passed).
- New tests in `src/attestation/mod.rs`:
- A fresh sidecar verifies with content bound.
- `intent_hash` equals SHA-256 of a **hand-written** JCS string.
- Pretty-printing the sidecar keeps it valid.
- Editing intent or evidence is detected.
- A genuine legacy seal verifies but is unbound.
- Relabelling a seal as legacy breaks the chain hash.
- The scheme-shift attack is rejected. That test reported *no* failures
before d88ccd9.
- An unknown scheme fails.
- End-to-end with the built binary, cross-checked with tools that share
no code with the crate:
- `jq -cjS .attestation.intent | sha256sum` and the same for evidence
match the seal.
- `sha256sum report.json` matches `report_hash`.
- `printf 'jcs-sha256%s%s%s' I E R | sha256sum` matches `chain_hash`.
- Editing the evidence fails verification.
- Downgrade plus edit fails with a chain mismatch.
- On a signed sidecar, the signature verifies, a downgrade fails, and
the scheme-shift attack fails (`intent_hash is not a SHA-256 digest`).
## Proof angle
`src/abi/AttestationUnforgeability.idr` is parametric in `chainHash`
under the `chainCR` (injectivity) hypothesis. Its doc now states the
scope: the model covers **one scheme at a time**, and `integrity`,
`authenticity` and `nonRepudiation` hold per scheme.
Scheme binding (no downgrade) is not modelled. In the code it rests on
the fixed-width digest check. The Codex P1 was a failure of exactly the
injectivity `chainCR` assumes: the bug was in the encoding, not in
SHA-256.
The model can be extended with a fourth `chainHash` input and a
no-downgrade lemma. That needs an Idris2 type-check, which this
environment couldn't run, and no workflow here type-checks `src/abi/`.
The open review thread on `seal.rs` holds that decision for the owner.
## Follow-ups (outside this PR)
- `attest verify --report <file>` to recompute `report_hash` from the
report itself; today it is only cross-checked against `decision_hash`.
- A `--require-bound` mode (or a policy default) that rejects legacy,
unbound seals.
- An Idris2 type-check job for `src/abi/` in CI.
- `evidence.evidence_hash` hashes `usize::to_le_bytes`, whose width
depends on the platform. That is harmless for the seal, which uses JCS,
but not portable.
- Consumers that parse the sidecar (DYADT / K9 contractiles) should read
`hash_scheme`. That work is in other repositories.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01PFaqv6iBXrt3W5Akd1Fq5k
---------
Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments