@@ -24,44 +24,45 @@ pub async fn verify_dcap_attestation(
2424 expected_input_data : [ u8 ; 64 ] ,
2525 pccs_url : Option < String > ,
2626) -> Result < MultiMeasurements , DcapVerificationError > {
27- let measurements = if cfg ! ( not( test) ) {
28- let now = std:: time:: SystemTime :: now ( )
29- . duration_since ( std:: time:: UNIX_EPOCH ) ?
30- . as_secs ( ) ;
31- let quote = Quote :: parse ( & input) ?;
32- tracing:: info!( "Verifying DCAP attestation: {quote:?}" ) ;
27+ let now = std:: time:: SystemTime :: now ( )
28+ . duration_since ( std:: time:: UNIX_EPOCH ) ?
29+ . as_secs ( ) ;
30+ let quote = Quote :: parse ( & input) ?;
31+ tracing:: info!( "Verifying DCAP attestation: {quote:?}" ) ;
3332
34- let ca = quote. ca ( ) ?;
35- let fmspc = hex:: encode_upper ( quote. fmspc ( ) ?) ;
36- let collateral = get_collateral_for_fmspc (
37- & pccs_url. clone ( ) . unwrap_or ( PCS_URL . to_string ( ) ) ,
38- fmspc,
39- ca,
40- false , // Indicates not SGX
41- )
42- . await ?;
43-
44- let _verified_report = dcap_qvl:: verify:: verify ( & input, & collateral, now) ?;
33+ let ca = quote. ca ( ) ?;
34+ let fmspc = hex:: encode_upper ( quote. fmspc ( ) ?) ;
35+ let collateral = get_collateral_for_fmspc (
36+ & pccs_url. clone ( ) . unwrap_or ( PCS_URL . to_string ( ) ) ,
37+ fmspc,
38+ ca,
39+ false , // Indicates not SGX
40+ )
41+ . await ?;
4542
46- let measurements = MultiMeasurements :: from_dcap_qvl_quote ( & quote ) ?;
43+ let _verified_report = dcap_qvl :: verify :: verify ( & input , & collateral , now ) ?;
4744
48- if get_quote_input_data ( quote. report ) != expected_input_data {
49- return Err ( DcapVerificationError :: InputMismatch ) ;
50- }
51- measurements
52- } else {
53- // In tests we use mock quotes which will fail to verify
54- let quote = tdx_quote:: Quote :: from_bytes ( & input) ?;
55- if quote. report_input_data ( ) != expected_input_data {
56- return Err ( DcapVerificationError :: InputMismatch ) ;
57- }
45+ let measurements = MultiMeasurements :: from_dcap_qvl_quote ( & quote) ?;
5846
59- MultiMeasurements :: from_tdx_quote ( & quote)
60- } ;
47+ if get_quote_input_data ( quote. report ) != expected_input_data {
48+ return Err ( DcapVerificationError :: InputMismatch ) ;
49+ }
6150
6251 Ok ( measurements)
6352}
6453
54+ pub fn mock_verify_dcap (
55+ input : Vec < u8 > ,
56+ expected_input_data : [ u8 ; 64 ] ,
57+ ) -> Result < MultiMeasurements , DcapVerificationError > {
58+ // In tests we use mock quotes which will fail to verify
59+ let quote = tdx_quote:: Quote :: from_bytes ( & input) ?;
60+ if quote. report_input_data ( ) != expected_input_data {
61+ return Err ( DcapVerificationError :: InputMismatch ) ;
62+ }
63+ Ok ( MultiMeasurements :: from_tdx_quote ( & quote) )
64+ }
65+
6566/// Create a mock quote for testing on non-confidential hardware
6667#[ cfg( test) ]
6768fn generate_quote ( input : [ u8 ; 64 ] ) -> Result < Vec < u8 > , QuoteGenerationError > {
0 commit comments