@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
1111use thiserror:: Error ;
1212use x509_parser:: prelude:: * ;
1313
14- use crate :: attestation:: dcap:: verify_dcap_attestation;
14+ use crate :: attestation:: { dcap:: verify_dcap_attestation, measurements :: MultiMeasurements } ;
1515
1616/// The attestation evidence payload that gets sent over the channel
1717#[ derive( Debug , Serialize , Deserialize ) ]
@@ -77,7 +77,7 @@ pub async fn verify_azure_attestation(
7777 input : Vec < u8 > ,
7878 expected_input_data : [ u8 ; 64 ] ,
7979 pccs_url : Option < String > ,
80- ) -> Result < super :: measurements:: Measurements , MaaError > {
80+ ) -> Result < super :: measurements:: MultiMeasurements , MaaError > {
8181 let now = std:: time:: SystemTime :: now ( )
8282 . duration_since ( std:: time:: UNIX_EPOCH )
8383 . expect ( "Time went backwards" )
@@ -93,7 +93,7 @@ async fn verify_azure_attestation_with_given_timestamp(
9393 expected_input_data : [ u8 ; 64 ] ,
9494 pccs_url : Option < String > ,
9595 now : u64 ,
96- ) -> Result < super :: measurements:: Measurements , MaaError > {
96+ ) -> Result < super :: measurements:: MultiMeasurements , MaaError > {
9797 let attestation_document: AttestationDocument = serde_json:: from_slice ( & input) ?;
9898 tracing:: info!( "Attempting to verifiy azure attestation: {attestation_document:?}" ) ;
9999
@@ -108,7 +108,7 @@ async fn verify_azure_attestation_with_given_timestamp(
108108
109109 // Do DCAP verification
110110 let tdx_quote_bytes = BASE64_URL_SAFE . decode ( attestation_document. tdx_quote_base64 ) ?;
111- let measurements =
111+ let _dcap_measurements =
112112 verify_dcap_attestation ( tdx_quote_bytes, expected_tdx_input_data, pccs_url) . await ?;
113113
114114 let hcl_ak_pub = hcl_report. ak_pub ( ) ?;
@@ -142,7 +142,7 @@ async fn verify_azure_attestation_with_given_timestamp(
142142 let pub_key = PKey :: public_key_from_der ( & hcl_ak_pub_der) ?;
143143 vtpm_quote. verify ( & pub_key, & expected_input_data[ ..32 ] ) ?;
144144
145- let _pcrs = vtpm_quote. pcrs_sha256 ( ) ;
145+ let pcrs = vtpm_quote. pcrs_sha256 ( ) ;
146146
147147 // Parse AK certificate
148148 let ( _type_label, ak_certificate_der) = pem_rfc7468:: decode_vec (
@@ -171,7 +171,7 @@ async fn verify_azure_attestation_with_given_timestamp(
171171 // Verify the AK certificate against microsoft root cert
172172 verify_ak_cert_with_azure_roots ( ak_certificate_der_without_trailing_data, now) ?;
173173
174- Ok ( measurements )
174+ Ok ( MultiMeasurements :: from_pcrs ( pcrs ) )
175175}
176176
177177/// JSON Web Key used in [HclRuntimeClaims]
@@ -299,6 +299,8 @@ pub enum MaaError {
299299
300300#[ cfg( test) ]
301301mod tests {
302+ use crate :: attestation:: measurements:: MeasurementPolicy ;
303+
302304 use super :: * ;
303305
304306 #[ tokio:: test]
@@ -329,13 +331,37 @@ mod tests {
329331 // timestamp
330332 let now = 1764621240 ;
331333
332- verify_azure_attestation_with_given_timestamp (
334+ let measurements_json = br#"
335+ [{
336+ "measurement_id": "cvm-image-azure-tdx.rootfs-20241107200854.wic.vhd",
337+ "attestation_type": "azure-tdx",
338+ "measurements": {
339+ "4": {
340+ "expected": "c4a25a6d7704629f63db84d20ea8db0e9ce002b2801be9a340091fe7ac588699"
341+ },
342+ "9": {
343+ "expected": "9f4a5775122ca4703e135a9ae6041edead0064262e399df11ca85182b0f1541d"
344+ },
345+ "11": {
346+ "expected": "abd7c695ffdb6081e99636ee016d1322919c68d049b698b399d22ae215a121bf"
347+ }
348+ }
349+ }]
350+ "# ;
351+
352+ let measurement_policy = MeasurementPolicy :: from_json_bytes ( measurements_json. to_vec ( ) )
353+ . await
354+ . unwrap ( ) ;
355+
356+ let measurements = verify_azure_attestation_with_given_timestamp (
333357 attestation_bytes. to_vec ( ) ,
334358 [ 0 ; 64 ] , // Input data
335359 None ,
336360 now,
337361 )
338362 . await
339363 . unwrap ( ) ;
364+
365+ measurement_policy. check_measurement ( & measurements) . unwrap ( ) ;
340366 }
341367}
0 commit comments