1- use az_tdx_vtpm:: { hcl, imds, report, tdx , vtpm} ;
1+ use az_tdx_vtpm:: { hcl, imds, report, vtpm} ;
22use tokio_rustls:: rustls:: pki_types:: CertificateDer ;
33// use openssl::pkey::{PKey, Public};
44use base64:: prelude:: * ;
@@ -7,24 +7,26 @@ use serde::Serialize;
77
88use crate :: attestation:: { compute_report_input, AttestationError , AttestationType , QuoteGenerator } ;
99
10+ use super :: QuoteVerifier ;
11+
1012#[ derive( Clone ) ]
11- pub struct MaaQuoteGenerator {
13+ pub struct MaaGenerator {
1214 maa_endpoint : String ,
1315 aad_access_token : String ,
1416}
1517
16- impl QuoteGenerator for MaaQuoteGenerator {
18+ impl QuoteGenerator for MaaGenerator {
1719 /// Type of attestation used
1820 fn attestation_type ( & self ) -> AttestationType {
1921 AttestationType :: AzureTdx
2022 }
2123
22- fn create_attestation (
24+ async fn create_attestation (
2325 & self ,
2426 cert_chain : & [ CertificateDer < ' _ > ] ,
2527 exporter : [ u8 ; 32 ] ,
2628 ) -> Result < Vec < u8 > , AttestationError > {
27- let quote_input = compute_report_input ( cert_chain, exporter) ?;
29+ let input_data = compute_report_input ( cert_chain, exporter) ?;
2830
2931 let td_report = report:: get_report ( ) . unwrap ( ) ;
3032
@@ -37,7 +39,7 @@ impl QuoteGenerator for MaaQuoteGenerator {
3739 // This makes a request to Azure Instance metadata service and gives us a binary response
3840 let td_quote_bytes = imds:: get_td_quote ( & td_report) . unwrap ( ) ;
3941
40- let hcl_report_bytes = vtpm:: get_report_with_report_data ( & quote_input ) . unwrap ( ) ;
42+ let hcl_report_bytes = vtpm:: get_report_with_report_data ( & input_data ) . unwrap ( ) ;
4143 let hcl_report = hcl:: HclReport :: new ( hcl_report_bytes) . unwrap ( ) ;
4244 let hcl_var_data = hcl_report. var_data ( ) ;
4345
@@ -61,19 +63,19 @@ impl QuoteGenerator for MaaQuoteGenerator {
6163
6264 let body = TdxVmRequest {
6365 quote : quote_b64,
64- runtimeData : Some ( RuntimeData {
66+ runtime_data : Some ( RuntimeData {
6567 data : runtime_b64,
6668 data_type : "Binary" ,
6769 } ) ,
6870 nonce : Some ( "my-app-nonce-or-session-id" . to_string ( ) ) ,
6971 } ;
7072 let body_bytes = serde_json:: to_vec ( & body) . unwrap ( ) ;
71- let jwt_token = self . call_tdxvm_attestation ( body_bytes) . await ;
72- todo ! ( )
73+ let jwt_token = self . call_tdxvm_attestation ( body_bytes) . await . unwrap ( ) ;
74+ Ok ( jwt_token . as_bytes ( ) . to_vec ( ) )
7375 }
7476}
7577
76- impl MaaQuoteGenerator {
78+ impl MaaGenerator {
7779 /// Get a signed JWT from the azure API
7880 async fn call_tdxvm_attestation (
7981 & self ,
@@ -107,6 +109,25 @@ impl MaaQuoteGenerator {
107109 }
108110}
109111
112+ #[ derive( Clone ) ]
113+ pub struct MaaVerifier ;
114+
115+ impl QuoteVerifier for MaaVerifier {
116+ fn attestation_type ( & self ) -> AttestationType {
117+ AttestationType :: AzureTdx
118+ }
119+
120+ async fn verify_attestation (
121+ & self ,
122+ input : Vec < u8 > ,
123+ cert_chain : & [ CertificateDer < ' _ > ] ,
124+ exporter : [ u8 ; 32 ] ,
125+ ) -> Result < Option < super :: measurements:: Measurements > , AttestationError > {
126+ let input_data = compute_report_input ( cert_chain, exporter) ?;
127+ todo ! ( )
128+ }
129+ }
130+
110131#[ derive( Serialize ) ]
111132struct RuntimeData < ' a > {
112133 data : String , // base64url of VarData bytes
@@ -116,9 +137,9 @@ struct RuntimeData<'a> {
116137
117138#[ derive( Serialize ) ]
118139struct TdxVmRequest < ' a > {
119- quote : String , // base64url (TDX quote)
120- #[ serde( skip_serializing_if = "Option::is_none" ) ]
121- runtimeData : Option < RuntimeData < ' a > > ,
140+ quote : String , // base64 (TDX quote)
141+ #[ serde( rename = "runtimeData" , skip_serializing_if = "Option::is_none" ) ]
142+ runtime_data : Option < RuntimeData < ' a > > ,
122143 #[ serde( skip_serializing_if = "Option::is_none" ) ]
123144 nonce : Option < String > ,
124145}
0 commit comments