@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
66use std:: {
77 fmt:: { self , Display , Formatter } ,
88 sync:: Arc ,
9- time:: SystemTimeError ,
9+ time:: { SystemTime , SystemTimeError , UNIX_EPOCH } ,
1010} ;
1111
1212use configfs_tsm:: QuoteGenerationError ;
@@ -148,6 +148,8 @@ pub struct AttestationVerifier {
148148 pub accepted_measurements : Vec < MeasurementRecord > ,
149149 /// A PCCS service to use - defaults to Intel PCS
150150 pub pccs_url : Option < String > ,
151+ /// Whether to log quotes to a file
152+ pub log_dcap_quote : bool ,
151153}
152154
153155impl AttestationVerifier {
@@ -156,6 +158,7 @@ impl AttestationVerifier {
156158 Self {
157159 accepted_measurements : Vec :: new ( ) ,
158160 pccs_url : None ,
161+ log_dcap_quote : false ,
159162 }
160163 }
161164
@@ -179,6 +182,7 @@ impl AttestationVerifier {
179182 } ,
180183 } ] ,
181184 pccs_url : None ,
185+ log_dcap_quote : false ,
182186 }
183187 }
184188
@@ -190,6 +194,11 @@ impl AttestationVerifier {
190194 exporter : [ u8 ; 32 ] ,
191195 ) -> Result < Option < Measurements > , AttestationError > {
192196 let attestation_type = attestation_exchange_message. attestation_type ;
197+ tracing:: debug!( "Verifing {attestation_type} attestation" ) ;
198+
199+ if self . log_dcap_quote {
200+ log_attestation ( & attestation_exchange_message) . await ;
201+ }
193202
194203 let measurements = match attestation_type {
195204 AttestationType :: DcapTdx => {
@@ -222,6 +231,7 @@ impl AttestationVerifier {
222231 . find ( |a| a. attestation_type == attestation_type && a. measurements == measurements)
223232 . ok_or ( AttestationError :: MeasurementsNotAccepted ) ?;
224233
234+ tracing:: debug!( "Verification successful" ) ;
225235 Ok ( Some ( measurements) )
226236 }
227237
@@ -384,6 +394,21 @@ fn get_pki_hash_from_certificate_chain(
384394 Ok ( hasher. finalize ( ) . into ( ) )
385395}
386396
397+ /// Write attestation data to a log file
398+ async fn log_attestation ( attestation : & AttestationExchangeMessage ) {
399+ if attestation. attestation_type != AttestationType :: None {
400+ let timestamp = SystemTime :: now ( )
401+ . duration_since ( UNIX_EPOCH )
402+ . expect ( "Time went backwards" )
403+ . as_nanos ( ) ;
404+
405+ let filename = format ! ( "quotes/{}-{}" , attestation. attestation_type, timestamp) ;
406+ if let Err ( err) = tokio:: fs:: write ( & filename, attestation. attestation . clone ( ) ) . await {
407+ tracing:: warn!( "Failed to write {filename}: {err}" ) ;
408+ }
409+ }
410+ }
411+
387412/// An error when generating or verifying an attestation
388413#[ derive( Error , Debug ) ]
389414pub enum AttestationError {
0 commit comments