forked from sigstore/sigstore-rs
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added merkle proof examples, fixed some bugs, reduced repetition and …
…added some functionality. Relates to: sigstore#283 Signed-off-by: Victor Embacher <victor@embacher.xyz>
- Loading branch information
Showing
9 changed files
with
174 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use clap::Parser; | ||
use sigstore::crypto::CosignVerificationKey; | ||
use sigstore::rekor::apis::configuration::Configuration; | ||
use sigstore::rekor::apis::tlog_api::{get_log_info, get_log_proof}; | ||
use std::fs::read_to_string; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Parser)] | ||
struct Args { | ||
#[arg(long, value_name = "REKOR PUBLIC KEY")] | ||
rekor_key: PathBuf, | ||
#[arg(long, value_name = "HEX ENCODED HASH")] | ||
old_root: String, | ||
#[arg(long)] | ||
old_size: usize, | ||
#[arg(long, value_name = "TREE ID")] | ||
tree_id: Option<String>, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let args = Args::parse(); | ||
let tree_id = args.tree_id.as_ref().map(|s| s.as_str()); | ||
// read verification key | ||
let rekor_key = read_to_string(&args.rekor_key) | ||
.map_err(Into::into) | ||
.and_then(|k| CosignVerificationKey::from_pem(k.as_bytes(), &Default::default()))?; | ||
|
||
// fetch log info | ||
let rekor_config = Configuration::default(); | ||
let log_info = get_log_info(&rekor_config).await?; | ||
|
||
let proof = get_log_proof( | ||
&rekor_config, | ||
log_info.tree_size as _, | ||
Some(&args.old_size.to_string()), | ||
tree_id, | ||
) | ||
.await?; | ||
|
||
log_info | ||
.verify_consistency(args.old_size, &args.old_root, &proof, &rekor_key) | ||
.expect("failed to verify log consistency"); | ||
println!("Successfully verified consistency"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use clap::Parser; | ||
use sigstore::crypto::CosignVerificationKey; | ||
use sigstore::rekor::apis::configuration::Configuration; | ||
use sigstore::rekor::apis::entries_api::get_log_entry_by_index; | ||
use std::fs::read_to_string; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Parser)] | ||
struct Args { | ||
#[arg(long, value_name = "INDEX")] | ||
log_index: usize, | ||
#[arg(long, value_name = "REKOR PUBLIC KEY")] | ||
rekor_key: PathBuf, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let args = Args::parse(); | ||
|
||
// read verification key | ||
let rekor_key = read_to_string(&args.rekor_key) | ||
.map_err(Into::into) | ||
.and_then(|k| CosignVerificationKey::from_pem(k.as_bytes(), &Default::default()))?; | ||
|
||
// fetch entry from log | ||
let rekor_config = Configuration::default(); | ||
let log_entry = get_log_entry_by_index(&rekor_config, args.log_index as i32).await?; | ||
|
||
// verify inclusion with key | ||
log_entry | ||
.verify_inclusion(&rekor_key) | ||
.expect("failed to verify log inclusion"); | ||
println!("Successfully verified inclusion."); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
pub mod proof_verification; | ||
pub mod rfc6962; | ||
|
||
use crate::errors::SigstoreError; | ||
use crate::errors::SigstoreError::UnexpectedError; | ||
use digest::Output; | ||
pub use proof_verification::MerkleProofError; | ||
pub(crate) use proof_verification::MerkleProofVerifier; | ||
pub(crate) use rfc6962::{Rfc6269Default, Rfc6269HasherTrait}; | ||
|
||
/// Many rekor models have hex-encoded hashes, this functions helps to avoid repetition. | ||
pub(crate) fn hex_to_hash_output( | ||
h: impl AsRef<[u8]>, | ||
) -> Result<Output<Rfc6269Default>, SigstoreError> { | ||
hex::decode(h) | ||
.map_err(Into::into) | ||
.and_then(|h| { | ||
<[u8; 32]>::try_from(h.as_slice()).map_err(|err| UnexpectedError(format!("{err:?}"))) | ||
}) | ||
.map(Into::into) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters