Skip to content

Commit ac70b56

Browse files
Laura Abbottlabbott
authored andcommitted
Add measurement-set command
It's useful to see what the current set of measurements is on device
1 parent 10952e8 commit ac70b56

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

verifier-cli/src/main.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ enum AttestCommand {
144144
#[clap(env)]
145145
corpus: PathBuf,
146146
},
147+
/// Show the set of measurements currently on the RoT. This includes
148+
/// the cert chain and the measurement log
149+
MeasurementSet,
147150
}
148151

149152
/// An enum of the possible routes to the `Attest` task.
@@ -209,6 +212,7 @@ fn main() -> Result<()> {
209212
let cert_chain = attest
210213
.get_certificates()
211214
.context("Getting attestation certificate chain")?;
215+
212216
for cert in cert_chain {
213217
let cert = cert
214218
.to_pem(LineEnding::default())
@@ -299,11 +303,46 @@ fn main() -> Result<()> {
299303
} => {
300304
verify_measurements(&cert_chain, &log, &corpus)?;
301305
}
306+
AttestCommand::MeasurementSet => {
307+
let set = measurement_set(attest.as_ref())?;
308+
for item in set.into_iter() {
309+
println!("* {item}");
310+
}
311+
}
302312
}
303313

304314
Ok(())
305315
}
306316

317+
fn measurement_set(attest: &dyn Attest) -> Result<MeasurementSet> {
318+
// get log
319+
info!("getting measurement log");
320+
let log = attest
321+
.get_measurement_log()
322+
.context("Get measurement log from attestor")?;
323+
let mut cert_chain = Vec::new();
324+
325+
let certs = attest
326+
.get_certificates()
327+
.context("Get certificate chain from attestor")?;
328+
329+
for (index, cert) in certs.iter().enumerate() {
330+
info!("writing cert[{index}]");
331+
let pem = cert
332+
.to_pem(LineEnding::default())
333+
.context(format!("Encode cert {index} as PEM"))?;
334+
cert_chain
335+
.write_all(pem.as_bytes())
336+
.context(format!("Write cert {index}",))?;
337+
}
338+
339+
let cert_chain: PkiPath = Certificate::load_pem_chain(&cert_chain)
340+
.context("loading PkiPath from PEM cert chain")?;
341+
342+
MeasurementSet::from_artifacts(&cert_chain, &log)
343+
.context("MeasurementSet from PkiPath")
344+
}
345+
307346
// Check that the measurments in `cert_chain` and `log` are all present in
308347
// the `corpus`.
309348
// NOTE: The output of this function is only as trustworthy as its inputs.

verifier/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,16 @@ impl MeasurementSet {
448448
}
449449
}
450450

451+
impl std::iter::IntoIterator for MeasurementSet {
452+
type Item = Measurement;
453+
type IntoIter = <std::collections::HashSet<attest_data::Measurement> as std::iter::IntoIterator>::IntoIter;
454+
455+
fn into_iter(self) -> Self::IntoIter {
456+
self.0.into_iter()
457+
}
458+
}
459+
460+
451461
/// A collection of measurement values that is used as a source of truth when
452462
/// appraising the set of measurements derived from an attestation.
453463
pub struct ReferenceMeasurements(pub(crate) HashSet<Measurement>);

0 commit comments

Comments
 (0)