diff --git a/src/lib.rs b/src/lib.rs index e6a1c2bc..178ed282 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,13 +112,19 @@ use certs::sev::sev; #[cfg(all(feature = "sev", feature = "openssl"))] use certs::sev::ca::{Certificate, Chain as CertSevCaChain}; +#[cfg(all(not(feature = "sev"), feature = "snp", feature = "openssl"))] +use certs::snp::ca::Chain as CertSnpCaChain; + #[cfg(all(feature = "sev", feature = "openssl"))] use certs::sev::builtin as SevBuiltin; +#[cfg(all(not(feature = "sev"), feature = "snp", feature = "openssl"))] +use certs::snp::builtin as SnpBuiltin; + #[cfg(feature = "sev")] use crate::{certs::sev::sev::Certificate as SevCertificate, error::Indeterminate, launch::sev::*}; -#[cfg(all(feature = "sev", feature = "openssl"))] +#[cfg(any(feature = "sev", feature = "snp"))] use std::convert::TryFrom; use std::io::{Read, Write}; @@ -282,6 +288,24 @@ impl From for CertSevCaChain { } } +#[cfg(all(not(feature = "sev"), feature = "snp", feature = "openssl"))] +impl From for CertSnpCaChain { + fn from(gen: Generation) -> CertSnpCaChain { + let (ark, ask) = match gen { + Generation::Milan => ( + SnpBuiltin::milan::ark().unwrap(), + SnpBuiltin::milan::ask().unwrap(), + ), + Generation::Genoa => ( + SnpBuiltin::genoa::ark().unwrap(), + SnpBuiltin::genoa::ask().unwrap(), + ), + }; + + CertSnpCaChain { ark, ask } + } +} + #[cfg(all(feature = "sev", feature = "openssl"))] impl TryFrom<&sev::Chain> for Generation { type Error = (); @@ -308,6 +332,55 @@ impl TryFrom<&sev::Chain> for Generation { } } +#[cfg(any(feature = "sev", feature = "snp"))] +impl TryFrom for Generation { + type Error = (); + + fn try_from(val: String) -> Result { + match &val.to_lowercase()[..] { + #[cfg(feature = "sev")] + "naples" => Ok(Self::Naples), + + #[cfg(feature = "sev")] + "rome" => Ok(Self::Rome), + + #[cfg(any(feature = "sev", feature = "snp"))] + "milan" => Ok(Self::Milan), + + #[cfg(any(feature = "sev", feature = "snp"))] + "genoa" => Ok(Self::Genoa), + + #[cfg(any(feature = "sev", feature = "snp"))] + "bergamo" => Ok(Self::Genoa), + + #[cfg(any(feature = "sev", feature = "snp"))] + "siena" => Ok(Self::Genoa), + + _ => Err(()), + } + } +} + +#[cfg(any(feature = "sev", feature = "snp"))] +impl Generation { + /// Create a title-cased string identifying the SEV generation. + pub fn titlecase(&self) -> String { + match self { + #[cfg(feature = "sev")] + Self::Naples => "Naples".to_string(), + + #[cfg(feature = "sev")] + Self::Rome => "Rome".to_string(), + + #[cfg(any(feature = "sev", feature = "snp"))] + Self::Milan => "Milan".to_string(), + + #[cfg(any(feature = "sev", feature = "snp"))] + Self::Genoa => "Genoa".to_string(), + } + } +} + // The C FFI interface to the library. #[cfg(feature = "sev")] diff --git a/src/measurement/mod.rs b/src/measurement/mod.rs index 424ebf80..612ca357 100644 --- a/src/measurement/mod.rs +++ b/src/measurement/mod.rs @@ -3,7 +3,7 @@ //! Everything one needs to calculate a launch measurement for a SEV encrypted confidential guest. //! This includes, GCTX, SEV-HASHES, VMSA and OVMF pages. -#[cfg(all(any(feature = "sev", feature = "snp"), feature = "openssl"))] +#[cfg(all(feature = "snp", feature = "openssl"))] pub mod gctx; #[cfg(any(feature = "sev", feature = "snp"))]