Skip to content

Commit 2b7617c

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 a157fc7 commit 2b7617c

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

verifier-cli/src/main.rs

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

verifier/src/lib.rs

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

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

0 commit comments

Comments
 (0)