Skip to content

Conversation

@imlk0
Copy link
Collaborator

@imlk0 imlk0 commented Dec 22, 2025

This commit introduces a new verity subcommand to support content integrity verification of data directories using cryptographic hashing (SHA-256).

The verity command includes three subcommands:

  • format: Scans a data directory, computes SHA-256 hashes for all files, generates metadata (JSON), and outputs a root hash representing the entire directory state.
  • verify: Validates the integrity of a data directory against a known root hash and metadata file, ensuring no files have been modified.
  • dump: Extracts and displays either the full metadata or the root hash from an existing metadata file.

Metadata is saved as a JSON file (cryptpilot.metadata.json by default), listing each file path and its corresponding hash. The root hash is derived from the serialized metadata, enabling secure anchoring in trusted environments.

Implementation details:

  • New CLI structures added in cli.rs with proper argument parsing.
  • Modular command implementation under src/cmd/verity/.
  • Integration into the global command dispatch via IntoCommand.
  • Files are processed asynchronously using tokio and async_walkdir.
  • Excludes metadata file during scanning to prevent self-inclusion.

This feature is useful for verifying system-critical directories during boot or in security-sensitive workflows.

This commit introduces a new `verity` subcommand to support content integrity
verification of data directories using cryptographic hashing (SHA-256).

The `verity` command includes three subcommands:
- `format`: Scans a data directory, computes SHA-256 hashes for all files,
  generates metadata (JSON), and outputs a root hash representing the entire
  directory state.
- `verify`: Validates the integrity of a data directory against a known root
  hash and metadata file, ensuring no files have been modified.
- `dump`: Extracts and displays either the full metadata or the root hash from
  an existing metadata file.

Metadata is saved as a JSON file (`cryptpilot.metadata.json` by default),
listing each file path and its corresponding hash. The root hash is derived
from the serialized metadata, enabling secure anchoring in trusted environments.

Implementation details:
- New CLI structures added in `cli.rs` with proper argument parsing.
- Modular command implementation under `src/cmd/verity/`.
- Integration into the global command dispatch via `IntoCommand`.
- Files are processed asynchronously using `tokio` and `async_walkdir`.
- Excludes metadata file during scanning to prevent self-inclusion.

This feature is useful for verifying system-critical directories during boot
or in security-sensitive workflows.

Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
@imlk0 imlk0 merged commit c749d65 into master Dec 25, 2025
8 checks passed
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.

2 participants