Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename "root hash" to "fingerprint" #74

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ Lofty Ambitions

`filepack` has lofty ambitions!

- Definition of a "root" hash, likely just the hash of the manifest itself, so
that as long as the root hash is received from a trusted source the manifest
itself does not need to be trusted.
- Definition of a "fingerprint" hash, likely just the hash of the manifest
itself, so that as long as the fingerprint is received from a trusted source
the manifest itself does not need to be trusted.

- Creation and verification of signatures over the root hash, so that
- Creation and verification of signatures over the fingerprint, so that
developers and packagers can vouch for the correctness of the contents of a
manifest, and users can verify that a manifest was signed by a trusted public
key.
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ pub(crate) enum Error {
backtrace: Option<Backtrace>,
path: DisplayPath,
},
#[snafu(display("root hash mismatch"))]
RootHashMismatch { backtrace: Option<Backtrace> },
#[snafu(display("fingerprint mismatch"))]
FingerprintMismatch { backtrace: Option<Backtrace> },
#[snafu(display("manifest has already been signed by public key `{public_key}`"))]
SignatureAlreadyExists {
backtrace: Option<Backtrace>,
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) struct Manifest {
impl Manifest {
pub(crate) const FILENAME: &'static str = "filepack.json";

pub(crate) fn root_hash(&self) -> Hash {
pub(crate) fn fingerprint(&self) -> Hash {
let canonical = Self {
files: self.files.clone(),
signatures: BTreeMap::new(),
Expand Down
2 changes: 1 addition & 1 deletion src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod tests {
<dd>1</dd>
<dt>total size</dt>
<dd>1 KiB</dd>
<dt>root hash</dt>
<dt>fingerprint</dt>
<dd class=monospace>2e2f6ca534371afe8783a9bcace2237a7611e2e5aa87eb272782b563f70d14ac</dd>
<dt>signatures</dt>
<dd class=monospace>3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29</dd>
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Create {
let private_key_path = options.key_dir()?.join(MASTER_PRIVATE_KEY);

let (public_key, signature) =
PrivateKey::load_and_sign(&private_key_path, manifest.root_hash().as_bytes())?;
PrivateKey::load_and_sign(&private_key_path, manifest.fingerprint().as_bytes())?;

manifest.signatures.insert(public_key, signature);
}
Expand Down
6 changes: 3 additions & 3 deletions src/subcommand/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ impl Sign {

let mut manifest = Manifest::load(&path)?;

let root_hash = manifest.root_hash();
let fingerprint = manifest.fingerprint();

for (public_key, signature) in &manifest.signatures {
public_key.verify(root_hash.as_bytes(), signature)?;
public_key.verify(fingerprint.as_bytes(), signature)?;
}

if !self.force {
Expand All @@ -43,7 +43,7 @@ impl Sign {
let private_key_path = options.key_dir()?.join(MASTER_PRIVATE_KEY);

let (public_key, signature) =
PrivateKey::load_and_sign(&private_key_path, root_hash.as_bytes())?;
PrivateKey::load_and_sign(&private_key_path, fingerprint.as_bytes())?;

manifest.signatures.insert(public_key, signature);

Expand Down
22 changes: 11 additions & 11 deletions src/subcommand/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::*;

#[derive(Parser)]
pub(crate) struct Verify {
#[arg(help = "Verify manifest root hash is <HASH>", long)]
hash: Option<Hash>,
#[arg(help = "Verify manifest fingerprint is <FINGERPRINT>", long)]
fingerprint: Option<Hash>,
#[arg(help = "Ignore missing files", long)]
ignore_missing: bool,
#[arg(help = "Verify that manifest has been signed by <KEY>", long)]
Expand Down Expand Up @@ -45,20 +45,20 @@ impl Verify {
path: Manifest::FILENAME,
})?;

let root_hash = manifest.root_hash();
let fingerprint = manifest.fingerprint();

if let Some(expected) = self.hash {
if root_hash != expected {
if let Some(expected) = self.fingerprint {
if fingerprint != expected {
let style = Style::stderr();
eprintln!(
"\
root hash mismatch: `{source}`
expected: {}
actual: {}",
fingerprint mismatch: `{source}`
expected: {}
actual: {}",
expected.style(style.good()),
root_hash.style(style.bad()),
fingerprint.style(style.bad()),
);
return Err(error::RootHashMismatch.build());
return Err(error::FingerprintMismatch.build());
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ mismatched file: `{path}`
}

for (public_key, signature) in &manifest.signatures {
public_key.verify(root_hash.as_bytes(), signature)?;
public_key.verify(fingerprint.as_bytes(), signature)?;
}

if let Some(key) = self.key {
Expand Down
4 changes: 2 additions & 2 deletions templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ <h1>{{ metadata.title }}</h1>
<dd>{{ self.manifest.files.len() }}</dd>
<dt>total size</dt>
<dd>{{ Bytes(self.manifest.total_size()) }}</dd>
<dt>root hash</dt>
<dd class=monospace>{{ self.manifest.root_hash() }}</dd>
<dt>fingerprint</dt>
<dd class=monospace>{{ self.manifest.fingerprint() }}</dd>
<dt>signatures</dt>
%% for key in self.manifest.signatures.keys() {
<dd class=monospace>{{ key }}</dd>
Expand Down
4 changes: 2 additions & 2 deletions tests/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ fn sign_creates_valid_signature() {
ed25519_dalek::VerifyingKey::from_bytes(&hex::decode(public_key).unwrap().try_into().unwrap())
.unwrap();

let root_hash = blake3::hash(r#"{"files":{"bar":{"hash":"af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262","size":0}}}"#.as_bytes());
let fingerprint = blake3::hash(r#"{"files":{"bar":{"hash":"af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262","size":0}}}"#.as_bytes());

public_key
.verify_strict(root_hash.as_bytes(), &signature)
.verify_strict(fingerprint.as_bytes(), &signature)
.unwrap();

Command::cargo_bin("filepack")
Expand Down
14 changes: 7 additions & 7 deletions tests/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ fn signature_verification_success() {
}

#[test]
fn verify_hash() {
fn verify_fingerprint() {
let dir = TempDir::new().unwrap();

dir.child("foo").touch().unwrap();
Expand All @@ -640,7 +640,7 @@ fn verify_hash() {
.unwrap()
.args([
"verify",
"--hash",
"--fingerprint",
"74ddbe0dcf48c634aca1d90f37defd60b230fc52857ffa4b6c956583e8a4daaf",
])
.current_dir(&dir)
Expand All @@ -651,17 +651,17 @@ fn verify_hash() {
.unwrap()
.args([
"verify",
"--hash",
"--fingerprint",
"0000000000000000000000000000000000000000000000000000000000000000",
])
.current_dir(&dir)
.assert()
.stderr(is_match(
"\
root hash mismatch: `.*filepack\\.json`
expected: 0000000000000000000000000000000000000000000000000000000000000000
actual: 74ddbe0dcf48c634aca1d90f37defd60b230fc52857ffa4b6c956583e8a4daaf
error: root hash mismatch\n",
fingerprint mismatch: `.*filepack\\.json`
expected: 0000000000000000000000000000000000000000000000000000000000000000
actual: 74ddbe0dcf48c634aca1d90f37defd60b230fc52857ffa4b6c956583e8a4daaf
error: fingerprint mismatch\n",
))
.failure();
}
Expand Down