22mod ak_certificate;
33mod nv_index;
44use ak_certificate:: { read_ak_certificate_from_tpm, verify_ak_cert_with_azure_roots} ;
5- use std:: string:: FromUtf8Error ;
65
76use az_tdx_vtpm:: { hcl, imds, report, vtpm} ;
87use base64:: { engine:: general_purpose:: URL_SAFE as BASE64_URL_SAFE , Engine as _} ;
@@ -12,11 +11,7 @@ use serde::{Deserialize, Serialize};
1211use thiserror:: Error ;
1312use x509_parser:: prelude:: * ;
1413
15- use crate :: attestation:: {
16- self ,
17- dcap:: get_quote_input_data,
18- measurements:: { CvmImageMeasurements , Measurements , PlatformMeasurements } ,
19- } ;
14+ use crate :: attestation:: dcap:: verify_dcap_attestation;
2015
2116/// The attestation evidence payload that gets sent over the channel
2217#[ derive( Debug , Serialize , Deserialize ) ]
@@ -100,25 +95,6 @@ async fn verify_azure_attestation_with_given_timestamp(
10095) -> Result < super :: measurements:: Measurements , MaaError > {
10196 let attestation_document: AttestationDocument = serde_json:: from_slice ( & input) ?;
10297
103- // Verify TDX quote (same as with DCAP) - TODO deduplicate this code
104- let tdx_quote_bytes = BASE64_URL_SAFE . decode ( attestation_document. tdx_quote_base64 ) ?;
105-
106- let quote = dcap_qvl:: quote:: Quote :: parse ( & tdx_quote_bytes) ?;
107-
108- let ca = quote. ca ( ) ?;
109- let fmspc = hex:: encode_upper ( quote. fmspc ( ) ?) ;
110- let collateral = dcap_qvl:: collateral:: get_collateral_for_fmspc (
111- & pccs_url
112- . clone ( )
113- . unwrap_or ( attestation:: dcap:: PCS_URL . to_string ( ) ) ,
114- fmspc,
115- ca,
116- false , // Indicates not SGX
117- )
118- . await ?;
119-
120- let _verified_report = dcap_qvl:: verify:: verify ( & tdx_quote_bytes, & collateral, now) ?;
121-
12298 let hcl_report_bytes = BASE64_URL_SAFE . decode ( attestation_document. hcl_report_base64 ) ?;
12399
124100 let hcl_report = hcl:: HclReport :: new ( hcl_report_bytes) ?;
@@ -127,9 +103,11 @@ async fn verify_azure_attestation_with_given_timestamp(
127103 // Check that HCL var data hash matches TDX quote report data
128104 let mut expected_tdx_input_data = [ 0u8 ; 64 ] ;
129105 expected_tdx_input_data[ ..32 ] . copy_from_slice ( & var_data_hash) ;
130- if get_quote_input_data ( quote. report . clone ( ) ) != expected_tdx_input_data {
131- return Err ( MaaError :: TdxQuoteInputMismatch ) ;
132- }
106+
107+ // Do DCAP verification
108+ let tdx_quote_bytes = BASE64_URL_SAFE . decode ( attestation_document. tdx_quote_base64 ) ?;
109+ let measurements =
110+ verify_dcap_attestation ( tdx_quote_bytes, expected_tdx_input_data, pccs_url) . await ?;
133111
134112 let hcl_ak_pub = hcl_report. ak_pub ( ) ?;
135113
@@ -191,12 +169,7 @@ async fn verify_azure_attestation_with_given_timestamp(
191169 // Verify the AK certificate against microsoft root cert
192170 verify_ak_cert_with_azure_roots ( ak_certificate_der_without_trailing_data, now) ?;
193171
194- Ok ( Measurements {
195- platform : PlatformMeasurements :: from_dcap_qvl_quote ( & quote)
196- . map_err ( |_| MaaError :: CannotExtractMeasurementsFromQuote ) ?,
197- cvm_image : CvmImageMeasurements :: from_dcap_qvl_quote ( & quote)
198- . map_err ( |_| MaaError :: CannotExtractMeasurementsFromQuote ) ?,
199- } )
172+ Ok ( measurements)
200173}
201174
202175/// JSON Web Key used in [HclRuntimeClaims]
@@ -272,8 +245,6 @@ impl RsaPubKey {
272245
273246#[ derive( Error , Debug ) ]
274247pub enum MaaError {
275- #[ error( "Failed to build input data: {0}" ) ]
276- InputData ( String ) ,
277248 #[ error( "Report: {0}" ) ]
278249 Report ( #[ from] az_tdx_vtpm:: report:: ReportError ) ,
279250 #[ error( "IMDS: {0}" ) ]
@@ -284,12 +255,6 @@ pub enum MaaError {
284255 Hcl ( #[ from] hcl:: HclError ) ,
285256 #[ error( "JSON: {0}" ) ]
286257 Json ( #[ from] serde_json:: Error ) ,
287- #[ error( "HTTP Client: {0}" ) ]
288- HttpClient ( #[ from] reqwest:: Error ) ,
289- #[ error( "MAA provider response: {0} - {1}" ) ]
290- MaaProvider ( http:: StatusCode , String ) ,
291- #[ error( "Token is bad UTF8: {0}" ) ]
292- BadUtf8 ( #[ from] FromUtf8Error ) ,
293258 #[ error( "vTPM quote: {0}" ) ]
294259 VtpmQuote ( #[ from] vtpm:: QuoteError ) ,
295260 #[ error( "AK public key: {0}" ) ]
@@ -300,8 +265,6 @@ pub enum MaaError {
300265 TssEsapi ( #[ from] tss_esapi:: Error ) ,
301266 #[ error( "PEM encode: {0}" ) ]
302267 Pem ( #[ from] pem_rfc7468:: Error ) ,
303- #[ error( "TDX quote input does not match hashed HCL var data" ) ]
304- TdxQuoteInputMismatch ,
305268 #[ error( "TD report input does not match hashed HCL var data" ) ]
306269 TdReportInputMismatch ,
307270 #[ error( "Base64 decode: {0}" ) ]
@@ -312,27 +275,11 @@ pub enum MaaError {
312275 AkFromClaimsNotEqualAkFromCertificate ,
313276 #[ error( "WebPKI: {0}" ) ]
314277 WebPki ( #[ from] webpki:: Error ) ,
315- #[ error( "Certificate chain is empty" ) ]
316- NoCertificate ,
317278 #[ error( "X509 parse: {0}" ) ]
318279 X509Parse ( #[ from] x509_parser:: asn1_rs:: Err < x509_parser:: error:: X509Error > ) ,
319280 #[ error( "X509: {0}" ) ]
320281 X509 ( #[ from] x509_parser:: error:: X509Error ) ,
321- #[ error( "Quote input is not as expected" ) ]
322- InputMismatch ,
323- #[ error( "Configuration mismatch - expected no remote attestation" ) ]
324- AttestationGivenWhenNoneExpected ,
325- #[ error( "Configfs-tsm quote generation: {0}" ) ]
326- QuoteGeneration ( #[ from] configfs_tsm:: QuoteGenerationError ) ,
327- #[ error( "SGX quote given when TDX quote expected" ) ]
328- SgxNotSupported ,
329- #[ error( "Platform measurements do not match any accepted values" ) ]
330- UnacceptablePlatformMeasurements ,
331- #[ error( "OS image measurements do not match any accepted values" ) ]
332- UnacceptableOsImageMeasurements ,
333- #[ error( "DCAP quote verification: {0}" ) ]
334- DcapQvl ( #[ from] anyhow:: Error ) ,
335- #[ error( "Cannot convert JSON web key to der" ) ]
282+ #[ error( "Cannot encode JSON web key as DER" ) ]
336283 JwkConversion ,
337284 #[ error( "OpenSSL: {0}" ) ]
338285 OpenSSL ( #[ from] ErrorStack ) ,
@@ -344,6 +291,8 @@ pub enum MaaError {
344291 JwkParse ,
345292 #[ error( "HCL runtime claims is missing HCLAkPub field" ) ]
346293 ClaimsMissingHCLAkPub ,
294+ #[ error( "DCAP verification: {0}" ) ]
295+ DcapVerification ( #[ from] crate :: attestation:: dcap:: DcapVerificationError ) ,
347296}
348297
349298#[ cfg( test) ]
@@ -352,7 +301,7 @@ mod tests {
352301
353302 #[ tokio:: test]
354303 async fn test_decode_hcl ( ) {
355- // from cvm-reverse-proxy/internal/attestation/azure/tdx/testdata/hclreport.bin
304+ // From cvm-reverse-proxy/internal/attestation/azure/tdx/testdata/hclreport.bin
356305 let hcl_bytes: & ' static [ u8 ] = include_bytes ! ( "../../../test-assets/hclreport.bin" ) ;
357306
358307 let hcl_report = hcl:: HclReport :: new ( hcl_bytes. to_vec ( ) ) . unwrap ( ) ;
0 commit comments