Skip to content
Open
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
39 changes: 39 additions & 0 deletions verifier-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ enum AttestCommand {
#[clap(env)]
corpus: PathBuf,
},
/// Show the set of measurements currently on the RoT. This includes
/// the cert chain and the measurement log
MeasurementSet,
}

/// An enum of the possible routes to the `Attest` task.
Expand Down Expand Up @@ -209,6 +212,7 @@ fn main() -> Result<()> {
let cert_chain = attest
.get_certificates()
.context("Getting attestation certificate chain")?;

for cert in cert_chain {
let cert = cert
.to_pem(LineEnding::default())
Expand Down Expand Up @@ -299,11 +303,46 @@ fn main() -> Result<()> {
} => {
verify_measurements(&cert_chain, &log, &corpus)?;
}
AttestCommand::MeasurementSet => {
let set = measurement_set(attest.as_ref())?;
for item in set.into_iter() {
println!("* {item}");
}
}
}

Ok(())
}

fn measurement_set(attest: &dyn Attest) -> Result<MeasurementSet> {
// get log
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: probably don't need this comment

info!("getting measurement log");
let log = attest
.get_measurement_log()
.context("Get measurement log from attestor")?;
let mut cert_chain = Vec::new();

let certs = attest
.get_certificates()
.context("Get certificate chain from attestor")?;

for (index, cert) in certs.iter().enumerate() {
info!("writing cert[{index}]");
let pem = cert
.to_pem(LineEnding::default())
.context(format!("Encode cert {index} as PEM"))?;
cert_chain
.write_all(pem.as_bytes())
.context(format!("Write cert {index}",))?;
}

let cert_chain: PkiPath = Certificate::load_pem_chain(&cert_chain)
.context("loading PkiPath from PEM cert chain")?;

MeasurementSet::from_artifacts(&cert_chain, &log)
.context("MeasurementSet from PkiPath")
}

// Check that the measurments in `cert_chain` and `log` are all present in
// the `corpus`.
// NOTE: The output of this function is only as trustworthy as its inputs.
Expand Down
9 changes: 9 additions & 0 deletions verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ impl MeasurementSet {
}
}

impl std::iter::IntoIterator for MeasurementSet {
type Item = Measurement;
type IntoIter = <std::collections::HashSet<attest_data::Measurement> as std::iter::IntoIterator>::IntoIter;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what rust suggested, it's possible I could do this in a less obfuscated way

Copy link
Contributor

Choose a reason for hiding this comment

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

Another way is to define an Iterator for MeasurementSet and then impl IntoIterator in terms of that. This seems fine though, and is less code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

HashSet is already in scope here so you save some characters by dropping the std::collections


fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

/// A collection of measurement values that is used as a source of truth when
/// appraising the set of measurements derived from an attestation.
pub struct ReferenceMeasurements(pub(crate) HashSet<Measurement>);
Expand Down
Loading