Skip to content

Commit 33c733d

Browse files
committed
Begin verification fn
1 parent 739507f commit 33c733d

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

src/attestation/azure.rs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use az_tdx_vtpm::{hcl, imds, report, tdx, vtpm};
1+
use az_tdx_vtpm::{hcl, imds, report, vtpm};
22
use tokio_rustls::rustls::pki_types::CertificateDer;
33
// use openssl::pkey::{PKey, Public};
44
use base64::prelude::*;
@@ -7,24 +7,26 @@ use serde::Serialize;
77

88
use 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)]
111132
struct RuntimeData<'a> {
112133
data: String, // base64url of VarData bytes
@@ -116,9 +137,9 @@ struct RuntimeData<'a> {
116137

117138
#[derive(Serialize)]
118139
struct 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
}

src/attestation/dcap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl QuoteGenerator for DcapTdxQuoteGenerator {
1919
self.attestation_type
2020
}
2121

22-
fn create_attestation(
22+
async fn create_attestation(
2323
&self,
2424
cert_chain: &[CertificateDer<'_>],
2525
exporter: [u8; 32],

src/attestation/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Display for AttestationType {
5454
}
5555
}
5656

57-
/// Defines how to generate a quote
57+
/// Defines how to generate an attestation
5858
pub trait QuoteGenerator: Clone + Send + 'static {
5959
/// Type of attestation used
6060
fn attestation_type(&self) -> AttestationType;
@@ -64,7 +64,7 @@ pub trait QuoteGenerator: Clone + Send + 'static {
6464
&self,
6565
cert_chain: &[CertificateDer<'_>],
6666
exporter: [u8; 32],
67-
) -> Result<Vec<u8>, AttestationError>;
67+
) -> impl Future<Output = Result<Vec<u8>, AttestationError>> + Send;
6868
}
6969

7070
/// Defines how to verify a quote
@@ -114,7 +114,7 @@ impl QuoteGenerator for NoQuoteGenerator {
114114
}
115115

116116
/// Create an empty attestation
117-
fn create_attestation(
117+
async fn create_attestation(
118118
&self,
119119
_cert_chain: &[CertificateDer<'_>],
120120
_exporter: [u8; 32],

src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ impl<L: QuoteGenerator, R: QuoteVerifier> ProxyServer<L, R> {
193193
let remote_cert_chain = connection.peer_certificates().map(|c| c.to_owned());
194194

195195
let attestation = if local_quote_generator.attestation_type() != AttestationType::None {
196-
local_quote_generator.create_attestation(&cert_chain, exporter)?
196+
local_quote_generator
197+
.create_attestation(&cert_chain, exporter)
198+
.await?
197199
} else {
198200
Vec::new()
199201
};
@@ -508,7 +510,8 @@ impl<L: QuoteGenerator, R: QuoteVerifier> ProxyClient<L, R> {
508510

509511
let attestation = if local_quote_generator.attestation_type() != AttestationType::None {
510512
local_quote_generator
511-
.create_attestation(&cert_chain.ok_or(ProxyError::NoClientAuth)?, exporter)?
513+
.create_attestation(&cert_chain.ok_or(ProxyError::NoClientAuth)?, exporter)
514+
.await?
512515
} else {
513516
Vec::new()
514517
};

0 commit comments

Comments
 (0)