Skip to content

fix(attestation): hash evidence counts as u64 on every platform - #262

Merged
hyperpolymath merged 2 commits into
mainfrom
claude/gallant-bell-4bo4oy-i-evidence-u64
Nov 5, 2026
Merged

hyperpolymath merged 2 commits into
mainfrom
claude/gallant-bell-4bo4oy-i-evidence-u64

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Closes the "evidence_hash hashes usize::to_le_bytes" follow-up from #247.

Problem

EvidenceAccumulator::finalize fed files_read to SHA-256 as usize::to_le_bytes. A 32-bit build hashed 4 bytes where a 64-bit build hashed 8, so the same scan produced different evidence hashes on different platforms, and a verifier on another platform couldn't recompute them.

Fix

  • files_read is widened to u64 before hashing, like bytes_read and wall_clock_ms already are.
  • On 64-bit platforms the hashed bytes are identical, so every existing evidence hash is unchanged. 32-bit builds now agree with them.
  • The computation moves to a public attestation::evidence::evidence_hash function, so a verifier can recompute it, and the doc comment now states the encoding.

Validation

  • New test evidence_hash_known_answer. The expected value comes from coreutils, not the crate:
    printf 'nonce\002\0\0\0\0\0\0\0\350\003\0\0\0\0\0\0rolling\007\0\0\0\0\0\0\0' | sha256sum
    
  • cargo fmt --check, plus cargo clippy --locked --all-targets -D warnings with and without --all-features: clean.
  • cargo test --locked --all-features: all suites green (lib: 524 passed).

Generated by Claude Code

The evidence hash fed files_read to SHA-256 as usize::to_le_bytes, so a
32-bit build hashed 4 bytes where a 64-bit build hashed 8, and the same
scan produced different evidence hashes. files_read is now widened to
u64 like bytes_read and wall_clock_ms. On 64-bit platforms the bytes,
and so every existing hash, are unchanged.

The computation moves to a pub evidence_hash function with a
known-answer test whose expected value comes from coreutils sha256sum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PFaqv6iBXrt3W5Akd1Fq5k
Copilot AI balanced review requested due to automatic review settings November 5, 2026 00:05
@hyperpolymath
hyperpolymath enabled auto-merge (squash) November 5, 2026 00:05
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T15:43:29.643426Z ee6f284 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 15:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@hyperpolymath
hyperpolymath merged commit 0a4159b into main Nov 5, 2026
28 of 29 checks passed
@hyperpolymath
hyperpolymath deleted the claude/gallant-bell-4bo4oy-i-evidence-u64 branch November 5, 2026 15:42
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

hyperpolymath added a commit that referenced this pull request Nov 5, 2026
Closes two follow-ups from #247.

## Problem

`attest verify` checks that the seal's three stored digests chain
together, and that `decision_hash` equals `report_hash`. Both of those
values are stored inside the sidecar. **Nothing rehashed the report
itself**, so a report edited after sealing still verified:

```
$ attest verify r.attestation.json        # r.json edited after sealing
  [OK] Attestation verified
```

Legacy seals (no `hash_scheme`) also verify without binding their intent
and evidence, and there was no way to require binding.

## Change

- **`--report <REPORT>`** rehashes the report file and fails with
`report_hash mismatch: stored=… computed=…` if the hashes differ.
- **`--require-bound`** fails on legacy seals with `legacy hash scheme:
intent and evidence are not bound to the seal`.
- The output now has a `Report:` line: `rehashed, matches the seal` or
`not checked (pass --report)`.
- **Library:**
- `VerifyOptions { report, require_bound }`, used with new
`verify_attestation_file_with` / `verify_attestation_str_with`.
- The existing `verify_attestation_file` / `verify_attestation_str` keep
their behaviour; they call the new functions with default options.
- `VerifyResult::Ok` gains `report_checked`, so a caller can't mistake
an unchecked report for a verified one.

## Validation

- **New tests:**
- `the_sealed_report_verifies`: `report_checked` is true with `--report`
and false without it.
  - `an_edited_report_is_detected`
- `require_bound_rejects_legacy_seals_only`: a genuine legacy seal
fails, a JCS seal passes.
- **End to end with the built CLI** (`assail examples --attest`):
  - The genuine report verifies (`Report: rehashed, matches the seal`).
- A report edited after sealing fails with `report_hash mismatch`; the
same file without `--report` still says `[OK]`, which is the gap this
closes.
- A legacy sidecar, rebuilt with `jq` plus a `sha256sum` chain hash,
passes by default and fails with `--require-bound`.
- A missing report file gives a clear `reading …: No such file or
directory`.
- `cargo fmt --check`, plus `cargo clippy --locked --all-targets -D
warnings` with and without `--all-features`: clean.
- `cargo test --locked --all-features`: all suites green (lib: 526
passed).

This touches `CHANGELOG.adoc` like the other open PRs (#261, #262).
Whichever merges later needs a trivial merge of main, and I'll handle
it.

---
_Generated by [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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants