use crate::attestation::report::AttestationReport;
use crate::attestation::verifier::{AttestationVerifier, VerifiedAttestation};
use crate::config::TeeProvider;
use crate::errors::TeeError;
pub struct NitroVerifier {
pub expected_pcr0: Option<String>,
pub allow_debug: bool,
}
impl NitroVerifier {
pub fn new() -> Self {
Self {
expected_pcr0: None,
allow_debug: false,
}
}
pub fn with_expected_pcr0(mut self, pcr0: impl Into<String>) -> Self {
self.expected_pcr0 = Some(pcr0.into());
self
}
pub fn allow_debug(mut self, allow: bool) -> Self {
self.allow_debug = allow;
self
}
}
impl Default for NitroVerifier {
fn default() -> Self {
Self::new()
}
}
impl AttestationVerifier for NitroVerifier {
fn verify(&self, report: &AttestationReport) -> Result<VerifiedAttestation, TeeError> {
if report.provider != TeeProvider::AwsNitro {
return Err(TeeError::AttestationVerification(format!(
"expected AWS Nitro provider, got {}",
report.provider
)));
}
if report.claims.debug_mode && !self.allow_debug {
return Err(TeeError::AttestationVerification(
"debug mode enclaves are not permitted".to_string(),
));
}
if let Some(expected) = &self.expected_pcr0 {
if report.measurement.digest != *expected {
return Err(TeeError::MeasurementMismatch {
expected: expected.clone(),
actual: report.measurement.digest.clone(),
});
}
}
tracing::debug!(
"structural validation only — cryptographic signature verification requires aws-nitro-enclaves-cose"
);
Ok(VerifiedAttestation::new(
report.clone(),
TeeProvider::AwsNitro,
))
}
fn supported_provider(&self) -> TeeProvider {
TeeProvider::AwsNitro
}
}