Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include ueid actual size in DPE Platform to support variable sized ueids #385

Merged
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
1 change: 1 addition & 0 deletions dpe/src/commands/derive_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ impl CommandExecution for DeriveContextCmd {
cfg_if! {
if #[cfg(not(feature = "disable_export_cdi"))] {
let ueid = &env.platform.get_ueid()?;
let ueid = ueid.get()?;
let args = CreateDpeCertArgs {
handle: &self.handle,
locality,
Expand Down
10 changes: 8 additions & 2 deletions platform/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub const VENDOR_ID: u32 = 0;
pub const VENDOR_SKU: u32 = 0;
pub const NOT_BEFORE: &str = "20230227000000Z";
pub const NOT_AFTER: &str = "99991231235959Z";
pub const TEST_UEID: Ueid = [0xA; 17];
pub const TEST_UEID: [u8; 17] = [0xA; 17];

// Run ./generate.sh to generate all test certs and test private keys
#[cfg(feature = "dpe_profile_p256_sha256")]
Expand Down Expand Up @@ -203,6 +203,12 @@ impl Platform for DefaultPlatform {
Err(PlatformError::NotImplemented)
}
fn get_ueid(&mut self) -> Result<Ueid, PlatformError> {
Ok(TEST_UEID)
let buf_size = TEST_UEID.len() as u32;
let mut ueid = Ueid::default();

ueid.buf[..buf_size as usize].clone_from_slice(&TEST_UEID);
ueid.buf_size = buf_size;

Ok(ueid)
}
}
28 changes: 27 additions & 1 deletion platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,32 @@ pub const MAX_SN_SIZE: usize = 20;
pub const MAX_KEY_IDENTIFIER_SIZE: usize = 20;
pub const MAX_VALIDITY_SIZE: usize = 24;
pub const MAX_OTHER_NAME_SIZE: usize = 128;
// Hash size of the SHA-384 DPE profile
pub const MAX_UEID_SIZE: usize = 48;

pub type Ueid = [u8; 17];
pub struct Ueid {
pub buf: [u8; MAX_UEID_SIZE],
pub buf_size: u32,
}

impl Ueid {
pub fn get(&self) -> Result<&[u8], PlatformError> {
let ueid = self
.buf
.get(..self.buf_size as usize)
.ok_or(PlatformError::InvalidUeidError)?;
Ok(ueid)
}
}

impl Default for Ueid {
fn default() -> Self {
Self {
buf: [0; MAX_UEID_SIZE],
buf_size: 0,
}
}
}

#[derive(Debug, PartialEq, Eq)]
pub enum SignerIdentifier {
Expand Down Expand Up @@ -64,6 +88,7 @@ pub enum PlatformError {
IssuerKeyIdentifierError(u32) = 0x8,
SubjectAlternativeNameError(u32) = 0x9,
MissingUeidError = 0xA,
InvalidUeidError = 0xB,
}

impl PlatformError {
Expand All @@ -79,6 +104,7 @@ impl PlatformError {
PlatformError::CertificateChainError => None,
PlatformError::NotImplemented => None,
PlatformError::MissingUeidError => None,
PlatformError::InvalidUeidError => None,
PlatformError::IssuerNameError(code) => Some(*code),
PlatformError::PrintError(code) => Some(*code),
PlatformError::SerialNumberError(code) => Some(*code),
Expand Down