Skip to content
295 changes: 288 additions & 7 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions crates/attestation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pccs = { workspace = true }
mock-tdx = { workspace = true, optional = true }
tokio = { workspace = true, features = ["fs"] }
tokio-rustls = { workspace = true, default-features = false }
attest-types = { git = "https://github.com/easy-tee/attest.git", branch = "ah/better-interface" }
attest-measure = {git = "https://github.com/easy-tee/attest.git", branch = "ah/better-interface" }

anyhow = "1.0.100"
pem-rfc7468 = { version = "0.7.0", features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/attestation/src/azure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ mod tests {
.unwrap();

assert_eq!(async_measurements, sync_measurements);
measurement_policy.check_measurement(&async_measurements).unwrap();
measurement_policy.check_measurement(&async_measurements, None).unwrap();
}

/// Verify a complete observed Azure attestation payload that includes
Expand Down
32 changes: 19 additions & 13 deletions crates/attestation/src/dcap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Data Center Attestation Primitives (DCAP) evidence generation and
//! verification
use attest_types::AttestationEvidence;
use dcap_qvl::{
QuoteCollateralV3,
collateral::get_collateral_for_fmspc,
Expand All @@ -21,10 +22,12 @@ const AZURE_BAD_FMSPC: &str = "90C06F000000";
pub const PCS_URL: &str = "https://api.trustedservices.intel.com";

/// Generate a TDX quote
pub fn create_dcap_attestation(input_data: [u8; 64]) -> Result<Vec<u8>, AttestationError> {
let quote = generate_quote(input_data)?;
tracing::info!("Generated TDX quote of {} bytes", quote.len());
Ok(quote)
pub fn create_dcap_attestation(
input_data: [u8; 64],
) -> Result<AttestationEvidence, AttestationError> {
let attestation_evidence = generate_quote(input_data)?;
tracing::info!("Generated TDX quote of {} bytes", attestation_evidence.quote.len());
Ok(attestation_evidence)
}

/// Verify a DCAP TDX quote, and return the measurement values
Expand Down Expand Up @@ -254,16 +257,19 @@ pub fn verify_dcap_attestation_sync(

/// Create a mock quote for testing on non-confidential hardware
#[cfg(any(test, feature = "mock"))]
fn generate_quote(input: [u8; 64]) -> Result<Vec<u8>, tdx_attest::TdxAttestError> {
generate_mock_tdx_quote(input).map_err(|error| {
tdx_attest::TdxAttestError::QuoteFailure(format!("mock-tdx quote generation: {error}"))
})
fn generate_quote(input: [u8; 64]) -> Result<AttestationEvidence, AttestationError> {
generate_mock_tdx_quote(input).map_err(|error| AttestationError::Mock(format!("{error}")))
}

/// Create a quote
#[cfg(not(any(test, feature = "mock")))]
fn generate_quote(input: [u8; 64]) -> Result<Vec<u8>, tdx_attest::TdxAttestError> {
tdx_attest::get_quote(&input)
fn generate_quote(input: [u8; 64]) -> Result<AttestationEvidence, AttestationError> {
use attest_measure::platform;

Ok(AttestationEvidence {
quote: tdx_attest::get_quote(&input)?,
platform: platform::metadata_for(attest_types::AttestationType::GcpTdx)?,
})
}

/// Given a [Report] get the input data regardless of report type
Expand Down Expand Up @@ -363,7 +369,7 @@ mod tests {
.unwrap();

assert_eq!(async_measurements, sync_measurements);
measurement_policy.check_measurement(&async_measurements).unwrap();
measurement_policy.check_measurement(&async_measurements, None).unwrap();
}

// This specifically tests a quote which has outdated TCB level from Azure
Expand Down Expand Up @@ -407,10 +413,10 @@ mod tests {
.unwrap();
let pccs = Pccs::new(Some(mock_pcs.base_url.clone()));
let expected_input_data = [0xA5; 64];
let attestation_bytes = create_dcap_attestation(expected_input_data).unwrap();
let attestation = create_dcap_attestation(expected_input_data).unwrap();

let measurements =
verify_dcap_attestation(attestation_bytes, expected_input_data, Some(pccs))
verify_dcap_attestation(attestation.quote, expected_input_data, Some(pccs))
.await
.unwrap();

Expand Down
Loading
Loading