@@ -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.
0 commit comments