11//! Attestation functions
22
3- use anyhow:: { anyhow, Context , Result } ;
3+ use anyhow:: { anyhow, bail , Context , Result } ;
44use dcap_qvl:: quote:: Quote ;
5- use qvl:: { quote:: Report , verify:: VerifiedReport } ;
5+ use qvl:: {
6+ quote:: { EnclaveReport , Report , TDReport10 , TDReport15 } ,
7+ verify:: VerifiedReport ,
8+ } ;
69use serde:: Serialize ;
710use sha2:: { Digest as _, Sha384 } ;
811use x509_parser:: parse_x509_certificate;
@@ -77,7 +80,7 @@ impl QuoteContentType<'_> {
7780 "keccak384" => do_hash ! ( sha3:: Keccak384 ) ,
7881 "keccak512" => do_hash ! ( sha3:: Keccak512 ) ,
7982 "raw" => content. try_into ( ) . ok ( ) . context ( "invalid content length" ) ?,
80- _ => anyhow :: bail!( "invalid hash algorithm" ) ,
83+ _ => bail ! ( "invalid hash algorithm" ) ,
8184 } ;
8285 Ok ( output)
8386 }
@@ -289,7 +292,7 @@ impl Attestation {
289292 ) -> Result < VerifiedAttestation > {
290293 let quote = & self . quote ;
291294 if & self . decode_report_data ( ) ? != report_data {
292- anyhow :: bail!( "report data mismatch" ) ;
295+ bail ! ( "report data mismatch" ) ;
293296 }
294297 let report = qvl:: collateral:: get_collateral_and_verify ( quote, pccs_url)
295298 . await
@@ -300,9 +303,10 @@ impl Attestation {
300303 . replay_event_logs ( None )
301304 . context ( "Failed to replay event logs" ) ?;
302305 if rtmrs != [ report. rt_mr0 , report. rt_mr1 , report. rt_mr2 , report. rt_mr3 ] {
303- anyhow :: bail!( "RTMR mismatch" ) ;
306+ bail ! ( "RTMR mismatch" ) ;
304307 }
305308 }
309+ validate_tcb ( & report) ?;
306310 Ok ( VerifiedAttestation {
307311 quote : self . quote ,
308312 raw_event_log : self . raw_event_log ,
@@ -314,6 +318,47 @@ impl Attestation {
314318
315319impl Attestation < VerifiedReport > { }
316320
321+ /// Validate the TCB attributes
322+ pub fn validate_tcb ( report : & VerifiedReport ) -> Result < ( ) > {
323+ fn validate_td10 ( report : & TDReport10 ) -> Result < ( ) > {
324+ let is_debug = report. td_attributes [ 0 ] & 0x01 != 0 ;
325+ if is_debug {
326+ bail ! ( "Debug mode is not allowed" ) ;
327+ }
328+ if report. mr_signer_seam != [ 0u8 ; 48 ] {
329+ bail ! ( "Invalid mr signer seam" ) ;
330+ }
331+ if report. mr_config_id != [ 0u8 ; 48 ] {
332+ bail ! ( "Invalid mr config id" ) ;
333+ }
334+ if report. mr_owner != [ 0u8 ; 48 ] {
335+ bail ! ( "Invalid mr owner" ) ;
336+ }
337+ if report. mr_owner_config != [ 0u8 ; 48 ] {
338+ bail ! ( "Invalid mr owner config" ) ;
339+ }
340+ Ok ( ( ) )
341+ }
342+ fn validate_td15 ( report : & TDReport15 ) -> Result < ( ) > {
343+ if report. mr_service_td != [ 0u8 ; 48 ] {
344+ bail ! ( "Invalid mr service td" ) ;
345+ }
346+ validate_td10 ( & report. base )
347+ }
348+ fn validate_sgx ( report : & EnclaveReport ) -> Result < ( ) > {
349+ let is_debug = report. attributes [ 0 ] & 0x02 != 0 ;
350+ if is_debug {
351+ bail ! ( "Debug mode is not allowed" ) ;
352+ }
353+ Ok ( ( ) )
354+ }
355+ match & report. report {
356+ Report :: TD15 ( report) => validate_td15 ( report) ,
357+ Report :: TD10 ( report) => validate_td10 ( report) ,
358+ Report :: SgxEnclave ( report) => validate_sgx ( report) ,
359+ }
360+ }
361+
317362/// Information about the app extracted from event log
318363#[ derive( Debug , Clone , Serialize ) ]
319364pub struct AppInfo {
0 commit comments