Skip to content

Commit

Permalink
Add SignWithExported message types.
Browse files Browse the repository at this point in the history
  • Loading branch information
clundin25 committed Jan 13, 2025
1 parent d71e867 commit f4dd360
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions api/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ impl CommandId {

// The get IDevID CSR command.
pub const GET_IDEV_CSR: Self = Self(0x4944_4352); // "IDCR"

pub const SIGN_WITH_EXPORTED: Self = Self(0x5357_4554); // "SWET"
}

impl From<u32> for CommandId {
Expand Down Expand Up @@ -153,6 +155,7 @@ pub enum MailboxResp {
CertifyKeyExtended(CertifyKeyExtendedResp),
AuthorizeAndStash(AuthorizeAndStashResp),
GetIdevCsr(GetIdevCsrResp),
SignWithExported(SignWithExportedResp),
}

impl MailboxResp {
Expand All @@ -174,6 +177,7 @@ impl MailboxResp {
MailboxResp::CertifyKeyExtended(resp) => Ok(resp.as_bytes()),
MailboxResp::AuthorizeAndStash(resp) => Ok(resp.as_bytes()),
MailboxResp::GetIdevCsr(resp) => Ok(resp.as_bytes()),
MailboxResp::SignWithExported(resp) => Ok(resp.as_bytes()),
}
}

Expand All @@ -195,6 +199,7 @@ impl MailboxResp {
MailboxResp::CertifyKeyExtended(resp) => Ok(resp.as_mut_bytes()),
MailboxResp::AuthorizeAndStash(resp) => Ok(resp.as_mut_bytes()),
MailboxResp::GetIdevCsr(resp) => Ok(resp.as_mut_bytes()),
MailboxResp::SignWithExported(resp) => Ok(resp.as_mut_bytes()),
}
}

Expand Down Expand Up @@ -253,6 +258,7 @@ pub enum MailboxReq {
CertifyKeyExtended(CertifyKeyExtendedReq),
SetAuthManifest(SetAuthManifestReq),
AuthorizeAndStash(AuthorizeAndStashReq),
SignWithExported(SignWithExportedResp),
}

impl MailboxReq {
Expand All @@ -278,6 +284,7 @@ impl MailboxReq {
MailboxReq::CertifyKeyExtended(req) => Ok(req.as_bytes()),
MailboxReq::SetAuthManifest(req) => Ok(req.as_bytes()),
MailboxReq::AuthorizeAndStash(req) => Ok(req.as_bytes()),
MailboxReq::SignWithExported(req) => Ok(req.as_bytes()),
}
}

Expand All @@ -303,6 +310,7 @@ impl MailboxReq {
MailboxReq::CertifyKeyExtended(req) => Ok(req.as_mut_bytes()),
MailboxReq::SetAuthManifest(req) => Ok(req.as_mut_bytes()),
MailboxReq::AuthorizeAndStash(req) => Ok(req.as_mut_bytes()),
MailboxReq::SignWithExported(req) => Ok(req.as_mut_bytes()),
}
}

Expand All @@ -328,6 +336,7 @@ impl MailboxReq {
MailboxReq::CertifyKeyExtended(_) => CommandId::CERTIFY_KEY_EXTENDED,
MailboxReq::SetAuthManifest(_) => CommandId::SET_AUTH_MANIFEST,
MailboxReq::AuthorizeAndStash(_) => CommandId::AUTHORIZE_AND_STASH,
MailboxReq::SignWithExported(_) => CommandId::SIGN_WITH_EXPORTED,
}
}

Expand Down Expand Up @@ -1010,6 +1019,60 @@ impl Default for GetIdevCsrResp {
}
}

// SIGN_WITH_EXPORTED
#[repr(C)]
#[derive(Debug, IntoBytes, FromBytes, KnownLayout, Immutable, PartialEq, Eq)]
pub struct SignWithExportedReq {
pub hdr: MailboxReqHeader,
pub exported_cdi: [u8; Self::EXPORTED_CDI_MAX_SIZE],
pub digest: [u8; Self::MAX_DIGEST_SIZE],
}

impl Default for SignWithExportedReq {
fn default() -> Self {
Self {
hdr: MailboxReqHeader::default(),
exported_cdi: [0u8; Self::EXPORTED_CDI_MAX_SIZE],
digest: [0u8; Self::MAX_DIGEST_SIZE],
}
}
}

impl SignWithExportedReq {
pub const EXPORTED_CDI_MAX_SIZE: usize = 512;
pub const MAX_DIGEST_SIZE: usize = 64; // TODO(clundin): Is this a reasonable max size? This accommodates
// SHA-512 but DPE only supports SHA-384.
}

impl Request for SignWithExportedReq {
const ID: CommandId = CommandId::SIGN_WITH_EXPORTED;
type Resp = SignWithExportedResp;
}

#[repr(C)]
#[derive(Debug, IntoBytes, FromBytes, KnownLayout, Immutable, PartialEq, Eq)]
pub struct SignWithExportedResp {
pub hdr: MailboxRespHeader,
pub signature_size: u32,
pub signature: [u8; Self::DATA_MAX_SIZE],
}

impl SignWithExportedResp {
pub const DATA_MAX_SIZE: usize = 512;
}

impl ResponseVarSize for SignWithExportedResp {}

impl Default for SignWithExportedResp {
fn default() -> Self {
Self {
hdr: MailboxRespHeader::default(),
signature_size: 0,
signature: [0u8; Self::DATA_MAX_SIZE],
}
}
}

#[repr(u32)]
#[derive(Debug, PartialEq, Eq)]
pub enum ImageHashSource {
Expand Down

0 comments on commit f4dd360

Please sign in to comment.