11use super :: { check_quote_header, converge_tcb_status_with_qe_tcb, verify_quote_common, Result } ;
22use crate :: {
3- cert:: { get_sgx_tdx_fmspc_tcbstatus_v3 , merge_advisory_ids} ,
3+ cert:: { get_sgx_tdx_tcb_status_v3 , merge_advisory_ids} ,
44 collaterals:: IntelCollateral ,
55 crypto:: sha256sum,
6- tdx_module:: { converge_tcb_status_with_tdx_module_tcb , get_tdx_module_identity_and_tcb } ,
6+ tdx_module:: { check_tdx_module_tcb_status , converge_tcb_status_with_tdx_module_tcb } ,
77 verifier:: QuoteVerificationOutput ,
88 VERIFIER_VERSION ,
99} ;
@@ -12,7 +12,7 @@ use core::cmp::min;
1212use dcap_types:: {
1313 quotes:: { body:: QuoteBody , version_4:: QuoteV4 , CertDataType } ,
1414 tcbinfo:: TcbInfo ,
15- TcbInfoV3TcbStatus , TdxModuleTcbValidationStatus , SGX_TEE_TYPE ,
15+ TdxModuleTcbValidationStatus , SGX_TEE_TYPE , TDX_TEE_TYPE ,
1616} ;
1717
1818/// Verify the given DCAP quote v4 and return the verification output.
@@ -58,61 +58,63 @@ pub fn verify_quote_v4(
5858
5959 let TcbInfo :: V3 ( tcb_info_v3) = tcb_info;
6060 let ( quote_tdx_body, tee_tcb_svn) = if let QuoteBody :: TD10QuoteBody ( body) = & quote. quote_body {
61- ( Some ( body) , body. tee_tcb_svn )
61+ ( Some ( body) , Some ( body. tee_tcb_svn ) )
6262 } else {
63- // SGX does not produce tee_tcb_svns
64- ( None , [ 0 ; 16 ] )
63+ // SGX does not produce tee_tcb_svn
64+ ( None , None )
6565 } ;
6666
67- // check TCB level
68-
6967 let tee_type = quote. header . tee_type ;
7068 let ( sgx_tcb_status, tdx_tcb_status, tcb_advisory_ids) =
71- get_sgx_tdx_fmspc_tcbstatus_v3 ( tee_type, Some ( tee_tcb_svn) , & sgx_extensions, & tcb_info_v3) ?;
69+ get_sgx_tdx_tcb_status_v3 ( tee_type, tee_tcb_svn, & sgx_extensions, & tcb_info_v3) ?;
7270
73- let mut advisory_ids = merge_advisory_ids ( tcb_advisory_ids, qe_tcb. advisory_ids ) ;
74- let mut tcb_status: TcbInfoV3TcbStatus ;
75- if quote. header . tee_type == SGX_TEE_TYPE {
76- tcb_status = sgx_tcb_status;
77- } else {
78- tcb_status = tdx_tcb_status. context ( "TDX TCB Status not found" ) ?;
71+ let advisory_ids = merge_advisory_ids ( tcb_advisory_ids, qe_tcb. advisory_ids ) ;
72+
73+ let ( tcb_status, advisory_ids) = if tee_type == TDX_TEE_TYPE {
74+ let tdx_tcb_status = tdx_tcb_status. context ( "TDX TCB Status not found" ) ?;
7975
8076 // Fetch TDXModule TCB and TDXModule Identity
8177 let (
8278 tdx_module_tcb_status,
8379 tdx_module_advisory_ids,
8480 tdx_module_mrsigner,
8581 tdx_module_attributes,
86- ) = get_tdx_module_identity_and_tcb ( & tee_tcb_svn, & tcb_info_v3) ?;
82+ ) = check_tdx_module_tcb_status ( & tee_tcb_svn. unwrap_or_default ( ) , & tcb_info_v3) ?;
8783 if tdx_module_tcb_status == TdxModuleTcbValidationStatus :: TcbNotSupported
8884 || tdx_module_tcb_status == TdxModuleTcbValidationStatus :: TdxModuleMismatch
8985 {
90- // NOTE: early return - modify from the original
86+ // NOTE: early return - different from the original code
9187 bail ! ( "TDX Module TCB not supported or out of date" ) ;
9288 }
9389
9490 // check TDX module
95- let ( tdx_report_mrsigner, tdx_report_attributes) = if let Some ( tdx_body) = quote_tdx_body {
96- ( tdx_body. mrsignerseam , tdx_body. seam_attributes )
97- } else {
98- unreachable ! ( ) ;
99- } ;
91+ let ( tdx_report_mrsigner, tdx_report_attributes) = quote_tdx_body
92+ . map ( |tdx_body| ( tdx_body. mrsignerseam , tdx_body. seam_attributes ) )
93+ . context ( "TDX Quote Body not found" ) ?;
10094
101- // TODO check if these validations are correct
102- let mr_signer_matched = tdx_module_mrsigner == tdx_report_mrsigner;
103- let attributes_matched = tdx_module_attributes == tdx_report_attributes;
104- if !mr_signer_matched || !attributes_matched {
105- bail ! ( "TDX module values mismatch" ) ;
95+ // ref. https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/7e5b2a13ca5472de8d97dd7d7024c2ea5af9a6ba/Src/AttestationLibrary/src/Verifiers/QuoteVerifier.cpp#L181
96+ if tdx_module_mrsigner != tdx_report_mrsigner {
97+ bail ! ( "TDX module mrsigner mismatch" ) ;
98+ }
99+ // ref. https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/7e5b2a13ca5472de8d97dd7d7024c2ea5af9a6ba/Src/AttestationLibrary/src/Verifiers/QuoteVerifier.cpp#L200
100+ if tdx_module_attributes != tdx_report_attributes {
101+ bail ! ( "TDX module attributes mismatch" ) ;
106102 }
107103
108- tcb_status = converge_tcb_status_with_tdx_module_tcb ( tcb_status, tdx_module_tcb_status) ;
109- advisory_ids = merge_advisory_ids ( advisory_ids, tdx_module_advisory_ids) ;
110- }
104+ (
105+ converge_tcb_status_with_tdx_module_tcb ( tdx_tcb_status, tdx_module_tcb_status) ,
106+ merge_advisory_ids ( advisory_ids, tdx_module_advisory_ids) ,
107+ )
108+ } else if tee_type == SGX_TEE_TYPE {
109+ ( sgx_tcb_status, advisory_ids)
110+ } else {
111+ bail ! ( "Unsupported TEE type: {}" , tee_type) ;
112+ } ;
111113
112114 Ok ( QuoteVerificationOutput {
113115 version : VERIFIER_VERSION ,
114116 quote_version : quote. header . version ,
115- tee_type : quote . header . tee_type ,
117+ tee_type,
116118 tcb_status : converge_tcb_status_with_qe_tcb ( tcb_status, qe_tcb. tcb_status ) ,
117119 min_tcb_evaluation_data_number : min (
118120 qe_tcb. tcb_evaluation_data_number ,
0 commit comments