@@ -115,18 +115,50 @@ impl Verifier for Tdx {
115115 }
116116 } ) ?;
117117
118- let claims = verify_evidence ( expected_report_data, expected_init_data_hash, tdx_evidence)
119- . await
120- . context ( "TDX verifier" ) ?;
118+ let claims = verify_evidence (
119+ expected_report_data,
120+ expected_init_data_hash,
121+ tdx_evidence,
122+ None ,
123+ )
124+ . await
125+ . context ( "TDX verifier" ) ?;
121126
122127 Ok ( ( claims, "cpu" . to_string ( ) ) )
123128 }
129+
130+ /// Verify with attest-supplied DCAP collateral (skip PCCS fetch).
131+ #[ cfg( feature = "tdx-dcap-rust" ) ]
132+ async fn evaluate_with_collateral (
133+ & self ,
134+ evidence : TeeEvidence ,
135+ expected_report_data : & ReportData ,
136+ expected_init_data_hash : & InitDataHash ,
137+ collateral : & serde_json:: Value ,
138+ ) -> Result < ( TeeEvidenceParsedClaim , TeeClass ) > {
139+ let tdx_evidence = serde_json:: from_value :: < TdxEvidence > ( evidence) . map_err ( |source| {
140+ VerifierError :: InvalidEvidenceFormat {
141+ field : "evidence" ,
142+ source : source. into ( ) ,
143+ }
144+ } ) ?;
145+ let claims = verify_evidence (
146+ expected_report_data,
147+ expected_init_data_hash,
148+ tdx_evidence,
149+ Some ( collateral) ,
150+ )
151+ . await
152+ . context ( "TDX verifier" ) ?;
153+ Ok ( ( claims, "cpu" . to_string ( ) ) )
154+ }
124155}
125156
126157async fn verify_evidence (
127158 expected_report_data : & ReportData < ' _ > ,
128159 expected_init_data_hash : & InitDataHash < ' _ > ,
129160 evidence : TdxEvidence ,
161+ collateral : Option < & serde_json:: Value > ,
130162) -> Result < TeeEvidenceParsedClaim > {
131163 if evidence. quote . is_empty ( ) {
132164 return Err ( VerifierError :: InvalidEvidenceFormat {
@@ -147,7 +179,17 @@ async fn verify_evidence(
147179 } ) ?;
148180
149181 // Verify TD quote ECDSA signature.
150- let tcb_verification_result = ecdsa_quote_verification ( quote_bin. as_slice ( ) ) . await ?;
182+ let tcb_verification_result = {
183+ #[ cfg( feature = "tdx-dcap-rust" ) ]
184+ {
185+ ecdsa_quote_verification ( quote_bin. as_slice ( ) , collateral) . await ?
186+ }
187+ #[ cfg( feature = "tdx-dcap-ffi" ) ]
188+ {
189+ let _ = collateral;
190+ ecdsa_quote_verification ( quote_bin. as_slice ( ) ) . await ?
191+ }
192+ } ;
151193
152194 info ! (
153195 "Quote DCAP check succeeded. TCB status: {}" ,
@@ -418,6 +460,29 @@ mod tests {
418460 ) ) ;
419461 }
420462
463+ /// evaluate_with_collateral uses the caller-supplied DCAP collateral
464+ /// (from test_data/tdx_collateral.json, fetched from PCCS for the
465+ /// prerecorded tdx_quote_4.dat) instead of contacting a PCCS.
466+ #[ cfg( feature = "tdx-dcap-rust" ) ]
467+ #[ tokio:: test]
468+ async fn evaluate_with_collateral_uses_supplied ( ) {
469+ let quote_bin = std:: fs:: read ( "./test_data/tdx_quote_4.dat" ) . expect ( "read quote" ) ;
470+ let quote_b64 = STANDARD . encode ( & quote_bin) ;
471+ let collateral_json =
472+ std:: fs:: read ( "./test_data/tdx_collateral.json" ) . expect ( "read collateral" ) ;
473+ let collateral: serde_json:: Value =
474+ serde_json:: from_slice ( & collateral_json) . expect ( "parse collateral" ) ;
475+ let result = Tdx :: default ( )
476+ . evaluate_with_collateral (
477+ json ! ( { "quote" : quote_b64 } ) ,
478+ & ReportData :: NotProvided ,
479+ & InitDataHash :: NotProvided ,
480+ & collateral,
481+ )
482+ . await ;
483+ assert ! ( result. is_ok( ) , "evaluate_with_collateral failed: {:?}" , result. err( ) ) ;
484+ }
485+
421486 #[ test]
422487 fn test_generate_parsed_claim ( ) {
423488 let ccel_bin = fs:: read ( "./test_data/CCEL_data" ) . unwrap ( ) ;
0 commit comments