Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
232 changes: 228 additions & 4 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion crates/attestation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ tokio = { workspace = true, features = ["fs"] }
tokio-rustls = { workspace = true, default-features = false }

anyhow = "1.0.100"
coset = "0.4.2"
nsm-nitro-enclave-utils = { version = "0.1.3", default-features = false, features = ["nitro", "verify"] }
nsm-nitro-enclave-utils-keygen = { version = "=0.1.3", optional = true }
pem-rfc7468 = { version = "0.7.0", features = ["std"] }
tdx-attest = { git = "https://github.com/Dstack-TEE/dstack.git", rev = "4f602dddc0542cd34da031c90ac0b3a560f316ed" }
base64 = "0.22.1"
Expand All @@ -41,6 +44,8 @@ openssl = { version = "0.10.79", optional = true }

[dev-dependencies]
mock-tdx = { workspace = true }
nsm-nitro-enclave-utils = { version = "0.1.3", default-features = false, features = ["nitro", "pki", "seed", "verify"] }
nsm-nitro-enclave-utils-keygen = "=0.1.3"
tempfile = "3.23.0"
tokio-rustls = { workspace = true, default-features = true }

Expand All @@ -53,7 +58,12 @@ default = []
azure = ["tss-esapi", "az-tdx-vtpm", "openssl"]

# Allows mock quotes used in tests and exposes related functions for testing
mock = ["dep:mock-tdx"]
mock = [
"dep:mock-tdx",
"dep:nsm-nitro-enclave-utils-keygen",
"nsm-nitro-enclave-utils/pki",
"nsm-nitro-enclave-utils/seed",
]

[lints]
workspace = true
Binary file not shown.
25 changes: 21 additions & 4 deletions crates/attestation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub mod azure;
pub mod dcap;
pub mod measurements;
pub mod nitro;

use std::{
fmt::{self, Display, Formatter},
Expand All @@ -18,7 +19,7 @@ use pccs::{Pccs, PccsError};
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::{dcap::DcapVerificationError, measurements::MeasurementPolicy};
use crate::{dcap::DcapVerificationError, measurements::MeasurementPolicy, nitro::NitroError};

/// Used in attestation type detection to check if we are on GCP
const GCP_METADATA_API: &str = "http://metadata.google.internal";
Expand Down Expand Up @@ -60,6 +61,7 @@ impl AttestationExchangeMessage {
.map_err(DcapVerificationError::from)?;
Ok(Some(MultiMeasurements::from_dcap_qvl_quote(&quote)?))
}
AttestationType::AwsNitro => Ok(Some(nitro::get_measurements(&self.attestation)?)),
}
}
}
Expand All @@ -79,6 +81,8 @@ pub enum AttestationType {
QemuTdx,
/// DCAP TDX
DcapTdx,
/// AWS Nitro Enclaves
AwsNitro,
}

impl AttestationType {
Expand All @@ -90,6 +94,7 @@ impl AttestationType {
AttestationType::QemuTdx => "qemu-tdx",
AttestationType::GcpTdx => "gcp-tdx",
AttestationType::DcapTdx => "dcap-tdx",
AttestationType::AwsNitro => "aws-nitro",
}
}

Expand All @@ -102,6 +107,9 @@ impl AttestationType {
return Ok(AttestationType::AzureTdx);
}
}
if nitro::running_on_nitro() {
return Ok(AttestationType::AwsNitro);
}
// Otherwise try DCAP quote - this internally checks that the quote provider
// is `tdx_guest`
if tdx_attest::get_quote(&[0; 64]).is_ok() {
Expand Down Expand Up @@ -235,6 +243,7 @@ impl AttestationGenerator {
AttestationType::DcapTdx | AttestationType::GcpTdx | AttestationType::QemuTdx => {
dcap::create_dcap_attestation(input_data)
}
AttestationType::AwsNitro => Ok(nitro::create_nitro_attestation(input_data)?),
}
}

Expand Down Expand Up @@ -272,9 +281,7 @@ impl AttestationGenerator {
pub struct AttestationVerifier {
/// The measurement policy with accepted values and attestation types
pub measurement_policy: MeasurementPolicy,
/// If this is empty, anything will be accepted - but measurements are
/// always injected into HTTP headers, so that they can be verified
/// upstream A PCCS service to use - defaults to Intel PCS
/// A PCCS service to use - defaults to Intel PCS
pub pccs_url: Option<String>,
/// Whether to write quotes to files on disk
pub dump_dcap_quotes: bool,
Expand Down Expand Up @@ -406,6 +413,10 @@ impl AttestationVerifier {
)
.await?
}
AttestationType::AwsNitro => nitro::verify_nitro_attestation(
attestation_exchange_message.attestation,
expected_input_data,
)?,
};

// Do a measurement / attestation type policy check
Expand Down Expand Up @@ -467,6 +478,10 @@ impl AttestationVerifier {
pccs,
)?
}
AttestationType::AwsNitro => nitro::verify_nitro_attestation(
attestation_exchange_message.attestation,
expected_input_data,
)?,
};

// Do a measurement / attestation type policy check
Expand Down Expand Up @@ -586,6 +601,8 @@ pub enum AttestationError {
QuoteGeneration(#[from] tdx_attest::TdxAttestError),
#[error("DCAP verification: {0}")]
DcapVerification(#[from] DcapVerificationError),
#[error("Nitro attestation: {0}")]
Nitro(#[from] NitroError),
#[error("Attestation type not supported")]
AttestationTypeNotSupported,
#[error("Attestation type not accepted")]
Expand Down
Loading
Loading