Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions crates/attestation/src/dcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn verify_dcap_attestation(
input: Vec<u8>,
expected_input_data: [u8; 64],
pccs: Option<Pccs>,
) -> Result<MultiMeasurements, DcapVerificationError> {
) -> Result<(MultiMeasurements, Quote), DcapVerificationError> {
let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)?.as_secs();
let override_azure_outdated_tcb = false;
verify_dcap_attestation_with_given_timestamp(
Expand All @@ -59,7 +59,7 @@ pub fn verify_dcap_attestation_sync(
input: Vec<u8>,
expected_input_data: [u8; 64],
pccs: Pccs,
) -> Result<MultiMeasurements, DcapVerificationError> {
) -> Result<(MultiMeasurements, Quote), DcapVerificationError> {
let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)?.as_secs();
let override_azure_outdated_tcb = false;
verify_dcap_attestation_with_timestamp_sync(
Expand All @@ -85,7 +85,7 @@ pub fn verify_dcap_attestation_with_timestamp_sync(
collateral: Option<QuoteCollateralV3>,
now: u64,
override_azure_outdated_tcb: bool,
) -> Result<MultiMeasurements, DcapVerificationError> {
) -> Result<(MultiMeasurements, Quote), DcapVerificationError> {
let quote = Quote::parse(&input)?;

let ca = quote_ca(&quote)?.as_id_str();
Expand Down Expand Up @@ -119,7 +119,7 @@ pub async fn verify_dcap_attestation_with_given_timestamp(
collateral: Option<QuoteCollateralV3>,
now: u64,
override_azure_outdated_tcb: bool,
) -> Result<MultiMeasurements, DcapVerificationError> {
) -> Result<(MultiMeasurements, Quote), DcapVerificationError> {
let quote = Quote::parse(&input)?;

let ca = quote_ca(&quote)?.as_id_str();
Expand Down Expand Up @@ -153,7 +153,7 @@ fn verify_dcap_attestation_with_collateral_and_timestamp(
collateral: QuoteCollateralV3,
now: u64,
override_azure_outdated_tcb: bool,
) -> Result<MultiMeasurements, DcapVerificationError> {
) -> Result<(MultiMeasurements, Quote), DcapVerificationError> {
tracing::info!("Verifying DCAP attestation: {quote:?}");

let fmspc = hex::encode_upper(quote_fmspc(&quote)?);
Expand Down Expand Up @@ -194,19 +194,19 @@ fn verify_dcap_attestation_with_collateral_and_timestamp(

let measurements = MultiMeasurements::from_dcap_qvl_quote(&quote)?;

if get_quote_input_data(quote.report) != expected_input_data {
if get_quote_input_data(&quote.report) != expected_input_data {
return Err(DcapVerificationError::InputMismatch);
}

Ok(measurements)
Ok((measurements, quote))
}

#[cfg(any(test, feature = "mock"))]
pub async fn verify_dcap_attestation(
input: Vec<u8>,
expected_input_data: [u8; 64],
pccs: Option<Pccs>,
) -> Result<MultiMeasurements, DcapVerificationError> {
) -> Result<(MultiMeasurements, Quote), DcapVerificationError> {
let quote = Quote::parse(&input)?;
let ca = quote_ca(&quote)?.as_id_str();
let fmspc = hex::encode_upper(quote_fmspc(&quote)?);
Expand All @@ -221,19 +221,19 @@ pub async fn verify_dcap_attestation(
verifier.verify(&input, &collateral, now)?;

let measurements = MultiMeasurements::from_dcap_qvl_quote(&quote)?;
if get_quote_input_data(quote.report) != expected_input_data {
if get_quote_input_data(&quote.report) != expected_input_data {
return Err(DcapVerificationError::InputMismatch);
}

Ok(measurements)
Ok((measurements, quote))
}

#[cfg(any(test, feature = "mock"))]
pub fn verify_dcap_attestation_sync(
input: Vec<u8>,
expected_input_data: [u8; 64],
pccs: Pccs,
) -> Result<MultiMeasurements, DcapVerificationError> {
) -> Result<(MultiMeasurements, Quote), DcapVerificationError> {
let quote = Quote::parse(&input)?;
let ca = quote_ca(&quote)?.as_id_str();
let fmspc = hex::encode_upper(quote_fmspc(&quote)?);
Expand All @@ -243,10 +243,10 @@ pub fn verify_dcap_attestation_sync(
verifier.verify(&input, &collateral, now)?;

let measurements = MultiMeasurements::from_dcap_qvl_quote(&quote)?;
if get_quote_input_data(quote.report.clone()) != expected_input_data {
if get_quote_input_data(&quote.report) != expected_input_data {
return Err(DcapVerificationError::InputMismatch);
}
Ok(measurements)
Ok((measurements, quote))
}

/// Create a mock quote for testing on non-confidential hardware
Expand All @@ -262,7 +262,7 @@ fn generate_quote(input: [u8; 64]) -> Result<Vec<u8>, AttestationError> {
}

/// Given a [Report] get the input data regardless of report type
pub fn get_quote_input_data(report: Report) -> [u8; 64] {
pub fn get_quote_input_data(report: &Report) -> [u8; 64] {
match report {
Report::TD10(r) => r.report_data,
Report::TD15(r) => r.base.report_data,
Expand Down Expand Up @@ -326,7 +326,7 @@ mod tests {
let async_collateral = serde_saphyr::from_slice(collateral_bytes).unwrap();
let sync_collateral = serde_saphyr::from_slice(collateral_bytes).unwrap();

let async_measurements = verify_dcap_attestation_with_given_timestamp(
let (async_measurements, _) = verify_dcap_attestation_with_given_timestamp(
attestation_bytes.to_vec(),
[
116, 39, 106, 100, 143, 31, 212, 145, 244, 116, 162, 213, 44, 114, 216, 80, 227,
Expand All @@ -342,7 +342,7 @@ mod tests {
.await
.unwrap();

let sync_measurements = verify_dcap_attestation_with_timestamp_sync(
let (sync_measurements, _) = verify_dcap_attestation_with_timestamp_sync(
attestation_bytes.to_vec(),
[
116, 39, 106, 100, 143, 31, 212, 145, 244, 116, 162, 213, 44, 114, 216, 80, 227,
Expand Down Expand Up @@ -404,7 +404,7 @@ mod tests {
let expected_input_data = [0xA5; 64];
let quote = create_dcap_attestation(expected_input_data).unwrap();

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

assert_eq!(measurements, crate::measurements::mock_dcap_measurements());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Google Cloud Platform specific attestation logic

//! On GCP check MRTD values map to Google endorsed firmware

@ameba23 ameba23 Aug 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is mostly unchanged from main - i just refactored it into a separate file to avoid having both provenance and firmware stuff together in one file.

use std::{
collections::HashMap,
sync::{Arc, RwLock},
Expand Down Expand Up @@ -76,10 +75,11 @@ mod tests {
use attest_types::{AcpiHashes, DcapImageHashes};
use dcap_qvl::quote::Quote;

use super::GcpFirmwareCache;
use crate::{
AttestationType,
PlatformMetadata,
dcap::{get_quote_input_data, verify_dcap_attestation_with_given_timestamp},
gcp::GcpFirmwareCache,
measurements::{ExpectedMeasurements, MeasurementPolicy, MeasurementRecord},
};

Expand All @@ -97,7 +97,6 @@ mod tests {
hex::decode(input).unwrap().try_into().unwrap()
}

/// Image hashes associated with test fixture
fn gcp_portable_image_hashes() -> DcapImageHashes {
DcapImageHashes {
uki_authenticode: decode_dcap_hash(
Expand Down Expand Up @@ -141,20 +140,20 @@ mod tests {
#[tokio::test]
async fn test_gcp_tdx_portable_policy_with_stored_collateral() {
let attestation_bytes: &'static [u8] =
include_bytes!("../test-assets/gcp-tdx-1782809233226668671");
include_bytes!("../../test-assets/gcp-tdx-1782809233226668671");
let collateral_bytes: &'static [u8] =
include_bytes!("../test-assets/gcp-tdx-collateral-1782809233226668671.yaml");
include_bytes!("../../test-assets/gcp-tdx-collateral-1782809233226668671.yaml");
let firmware_bytes: &'static [u8] =
include_bytes!("../test-assets/gcp-tdx-firmware-1782809233226668671.yaml");
include_bytes!("../../test-assets/gcp-tdx-firmware-1782809233226668671.yaml");

let expected_input_data = {
let quote = Quote::parse(attestation_bytes).unwrap();
get_quote_input_data(quote.report)
get_quote_input_data(&quote.report)
};

let collateral = serde_saphyr::from_slice(collateral_bytes).unwrap();
let firmware = serde_saphyr::from_slice(firmware_bytes).unwrap();
let measurements = verify_dcap_attestation_with_given_timestamp(
let (measurements, _) = verify_dcap_attestation_with_given_timestamp(
attestation_bytes.to_vec(),
expected_input_data,
None,
Expand All @@ -168,6 +167,7 @@ mod tests {
let measurement_policy = MeasurementPolicy {
accepted_measurements: vec![MeasurementRecord {
measurement_id: "gcp-tdx-portable-image-hashes".to_string(),
attestation_type: AttestationType::GcpTdx,
measurements: ExpectedMeasurements::Image(gcp_portable_image_hashes()),
}],
};
Expand Down
6 changes: 6 additions & 0 deletions crates/attestation/src/gcp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Google Cloud Platform related attestation verification logic
mod firmware;
mod provenance;

pub(crate) use firmware::{GcpFirmwareCache, fetch_firmware};
pub(crate) use provenance::{GcpProvenanceChecker, GcpProvenanceError};
Loading
Loading