Skip to content

Commit

Permalink
Merge branch 'main' into rtool57
Browse files Browse the repository at this point in the history
  • Loading branch information
korran authored Sep 13, 2024
2 parents c9f5606 + 1075491 commit f485e00
Show file tree
Hide file tree
Showing 47 changed files with 3,844 additions and 146 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@ on:
- cron: '11 10 * * 2-6'

jobs:
rtl-repo-sync:
name: RTL Repo Sync
uses: ./.github/workflows/rtl-repo-sync.yml
permissions:
contents: write
pull-requests: write

find-latest-release:
name: Find Latest Release
needs: rtl-repo-sync
runs-on: ubuntu-22.04
outputs:
create_release: ${{ steps.find.outputs.create_release }}
Expand Down
67 changes: 67 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ exclude = [

members = [
"api",
"auth-manifest/app",
"auth-manifest/gen",
"auth-manifest/types",
"builder",
"cfi/lib",
"cfi/derive",
Expand Down Expand Up @@ -90,6 +93,8 @@ bitfield = "0.14.0"
bitflags = "2.4.0"
bit-vec = "0.6.3"
caliptra-api = { path = "api" }
caliptra-auth-man-gen = { path = "auth-manifest/gen", default-features = false }
caliptra-auth-man-types = { path = "auth-manifest/types", default-features = false }
caliptra-cfi-lib = { path = "cfi/lib", default-features = false, features = ["cfi", "cfi-counter" ] }
caliptra-cfi-derive = { path = "cfi/derive" }
caliptra-cfi-lib-git = { git = "https://github.com/chipsalliance/caliptra-cfi.git", package = "caliptra-cfi-lib-git", rev = "a98e499d279e81ae85881991b1e9eee354151189", default-features = false, features = ["cfi", "cfi-counter" ] }
Expand Down Expand Up @@ -141,6 +146,7 @@ dpe = { path = "dpe/dpe", default-features = false, features = ["dpe_profile_p38
crypto = { path = "dpe/crypto", default-features = false }
platform = { path = "dpe/platform", default-features = false }
elf = "0.7.2"
fips204 = "0.2.1"
gdbstub = "0.6.3"
gdbstub_arch = "0.2.4"
getrandom = "0.2"
Expand Down
129 changes: 129 additions & 0 deletions api/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ impl CommandId {

// The capabilities command.
pub const CAPABILITIES: Self = Self(0x4341_5053); // "CAPS"

// The authorization manifest set command.
pub const SET_AUTH_MANIFEST: Self = Self(0x4154_4D4E); // "ATMN"

// The authorize and stash command.
pub const AUTHORIZE_AND_STASH: Self = Self(0x4154_5348); // "ATSH"
}

impl From<u32> for CommandId {
Expand Down Expand Up @@ -140,6 +146,7 @@ pub enum MailboxResp {
GetRtAliasCert(GetRtAliasCertResp),
QuotePcrs(QuotePcrsResp),
CertifyKeyExtended(CertifyKeyExtendedResp),
AuthorizeAndStash(AuthorizeAndStashResp),
}

impl MailboxResp {
Expand All @@ -159,6 +166,7 @@ impl MailboxResp {
MailboxResp::GetRtAliasCert(resp) => resp.as_bytes_partial(),
MailboxResp::QuotePcrs(resp) => Ok(resp.as_bytes()),
MailboxResp::CertifyKeyExtended(resp) => Ok(resp.as_bytes()),
MailboxResp::AuthorizeAndStash(resp) => Ok(resp.as_bytes()),
}
}

Expand All @@ -178,6 +186,7 @@ impl MailboxResp {
MailboxResp::GetRtAliasCert(resp) => resp.as_bytes_partial_mut(),
MailboxResp::QuotePcrs(resp) => Ok(resp.as_bytes_mut()),
MailboxResp::CertifyKeyExtended(resp) => Ok(resp.as_bytes_mut()),
MailboxResp::AuthorizeAndStash(resp) => Ok(resp.as_bytes_mut()),
}
}

Expand Down Expand Up @@ -236,6 +245,8 @@ pub enum MailboxReq {
ExtendPcr(ExtendPcrReq),
AddSubjectAltName(AddSubjectAltNameReq),
CertifyKeyExtended(CertifyKeyExtendedReq),
SetAuthManifest(SetAuthManifestReq),
AuthorizeAndStash(AuthorizeAndStashReq),
}

impl MailboxReq {
Expand All @@ -259,6 +270,8 @@ impl MailboxReq {
MailboxReq::ExtendPcr(req) => Ok(req.as_bytes()),
MailboxReq::AddSubjectAltName(req) => req.as_bytes_partial(),
MailboxReq::CertifyKeyExtended(req) => Ok(req.as_bytes()),
MailboxReq::SetAuthManifest(req) => Ok(req.as_bytes()),
MailboxReq::AuthorizeAndStash(req) => Ok(req.as_bytes()),
}
}

Expand All @@ -282,6 +295,8 @@ impl MailboxReq {
MailboxReq::ExtendPcr(req) => Ok(req.as_bytes_mut()),
MailboxReq::AddSubjectAltName(req) => req.as_bytes_partial_mut(),
MailboxReq::CertifyKeyExtended(req) => Ok(req.as_bytes_mut()),
MailboxReq::SetAuthManifest(req) => Ok(req.as_bytes_mut()),
MailboxReq::AuthorizeAndStash(req) => Ok(req.as_bytes_mut()),
}
}

Expand All @@ -305,6 +320,8 @@ impl MailboxReq {
MailboxReq::ExtendPcr(_) => CommandId::EXTEND_PCR,
MailboxReq::AddSubjectAltName(_) => CommandId::ADD_SUBJECT_ALT_NAME,
MailboxReq::CertifyKeyExtended(_) => CommandId::CERTIFY_KEY_EXTENDED,
MailboxReq::SetAuthManifest(_) => CommandId::SET_AUTH_MANIFEST,
MailboxReq::AuthorizeAndStash(_) => CommandId::AUTHORIZE_AND_STASH,
}
}

Expand Down Expand Up @@ -918,6 +935,118 @@ impl Request for QuotePcrsReq {
type Resp = QuotePcrsResp;
}

// SET_AUTH_MANIFEST
#[repr(C)]
#[derive(Debug, AsBytes, FromBytes, PartialEq, Eq)]
pub struct SetAuthManifestReq {
pub hdr: MailboxReqHeader,
pub manifest_size: u32,
pub manifest: [u8; SetAuthManifestReq::MAX_MAN_SIZE],
}
impl SetAuthManifestReq {
pub const MAX_MAN_SIZE: usize = 8192;

pub fn as_bytes_partial(&self) -> CaliptraResult<&[u8]> {
if self.manifest_size as usize > Self::MAX_MAN_SIZE {
return Err(CaliptraError::RUNTIME_MAILBOX_API_REQUEST_DATA_LEN_TOO_LARGE);
}
let unused_byte_count = Self::MAX_MAN_SIZE - self.manifest_size as usize;
Ok(&self.as_bytes()[..size_of::<Self>() - unused_byte_count])
}

pub fn as_bytes_partial_mut(&mut self) -> CaliptraResult<&mut [u8]> {
if self.manifest_size as usize > Self::MAX_MAN_SIZE {
return Err(CaliptraError::RUNTIME_MAILBOX_API_REQUEST_DATA_LEN_TOO_LARGE);
}
let unused_byte_count = Self::MAX_MAN_SIZE - self.manifest_size as usize;
Ok(&mut self.as_bytes_mut()[..size_of::<Self>() - unused_byte_count])
}
}
impl Default for SetAuthManifestReq {
fn default() -> Self {
Self {
hdr: MailboxReqHeader::default(),
manifest_size: 0,
manifest: [0u8; SetAuthManifestReq::MAX_MAN_SIZE],
}
}
}

#[repr(u32)]
#[derive(Debug, PartialEq, Eq)]
pub enum ImageHashSource {
Invalid = 0,
InRequest,
ShaAcc,
}

impl From<u32> for ImageHashSource {
fn from(val: u32) -> Self {
match val {
1_u32 => ImageHashSource::InRequest,
2_u32 => ImageHashSource::ShaAcc,
_ => ImageHashSource::Invalid,
}
}
}

bitflags::bitflags! {
pub struct AuthAndStashFlags : u32 {
const SKIP_STASH = 0x1;
}
}

impl From<u32> for AuthAndStashFlags {
/// Converts to this type from the input type.
fn from(value: u32) -> Self {
AuthAndStashFlags::from_bits_truncate(value)
}
}

impl AuthAndStashFlags {
pub fn set_skip_stash(&mut self, skip_stash: bool) {
self.set(AuthAndStashFlags::SKIP_STASH, skip_stash);
}
}

// AUTHORIZE_AND_STASH
#[repr(C)]
#[derive(Debug, AsBytes, FromBytes, PartialEq, Eq)]
pub struct AuthorizeAndStashReq {
pub hdr: MailboxReqHeader,
pub metadata: [u8; 4],
pub measurement: [u8; 48],
pub context: [u8; 48],
pub svn: u32,
pub flags: u32,
pub source: u32,
}
impl Default for AuthorizeAndStashReq {
fn default() -> Self {
Self {
hdr: Default::default(),
metadata: Default::default(),
measurement: [0u8; 48],
context: [0u8; 48],
svn: Default::default(),
flags: AuthAndStashFlags::SKIP_STASH.bits(),
source: ImageHashSource::InRequest as u32,
}
}
}
impl Request for AuthorizeAndStashReq {
const ID: CommandId = CommandId::AUTHORIZE_AND_STASH;
type Resp = StashMeasurementResp;
}

#[repr(C)]
#[derive(Debug, Default, AsBytes, FromBytes, PartialEq, Eq)]
pub struct AuthorizeAndStashResp {
pub hdr: MailboxRespHeader,
pub auth_req_result: u32,
}
impl Response for AuthorizeAndStashResp {}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
39 changes: 39 additions & 0 deletions auth-manifest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## SOC Manifest

The Caliptra SOC manifest has two main components:

- ### **Preamble**
The Preamble section contains the authorization manifest ECC and LMS public keys of the vendor and the owner. These public keys correspond to the private keys that sign the Image Metadata Collection (IMC) section. These signatures are included in the Preamble. The Caliptra firmware’s ECC and LMS private keys endorse the manifest’s public keys, and these endorsements (signatures) are part of the Preamble as well.

*Note: All fields are little endian unless specified*

| Field | Size (bytes) | Description|
|-------|--------|------------|
| Manifest Marker | 4 | Magic Number marking the start of the manifest. The value must be 0x41544D4E (‘ATMN’ in ASCII)|
| Manifest Size | 4 | Size of the full manifest structure |
| Version | 4 | Manifest version |
| Flags | 4 | Feature flags. <br> **Bit0:** - Vendor Signature Required. If set, verify the vendor IMC signature(s) <br>**Bit1-Bit31:** Reserved |
| Vendor ECC Public Key | 96 | ECC P-384 public key used to verify the IMC Signature. <br> **X-Coordinate:** Public Key X-Coordinate (48 bytes) <br> **Y-Coordinate:** Public Key Y-Coordinate (48 bytes) |
| Vendor LMS Public Key | 48 | LMS public key used to verify the IMC Signature. <br> **tree_type:** LMS Algorithm Type (4 bytes) <br> **otstype:** LMS Ots Algorithm Type (4 bytes) <br> **id:** (16 bytes) <br> **digest:** (24 bytes) <br> Note: If LMS validation is not required, this should field should be zeroed out.|
| Vendor ECC Signature | 96 | Vendor ECDSA P-384 signature of the Version, Flags, Vendor ECC and LMS public keys, hashed using SHA2-384. <br> **R-Coordinate:** Random Point (48 bytes) <br> **S-Coordinate:** Proof (48 bytes) |
| Vendor LMS Signature | 1620 | Vendor LMS signature of the Version, Flags, Vendor ECC and LMS public keys, hashed using SHA2-384. <br> **q:** Leaf of the Merkle tree where the OTS public key appears (4 bytes) <br> **ots:** Lmots Signature (1252 bytes) <br> **tree_type:** Lms Algorithm Type (4 bytes) <br> **tree_path:** Path through the tree from the leaf associated with the LM-OTS signature to the root. (360 bytes) <br> Note: If LMS validation is not required, this should field should be zeroed out.|
| Owner ECC Public Key | 96 | ECC P-384 public key used to verify the IMC Signature. <br> **X-Coordinate:** Public Key X-Coordinate (48 bytes) <br> **Y-Coordinate:** Public Key Y-Coordinate (48 bytes) |
| Owner LMS Public Key | 48 | LMS public key used to verify the IMC Signature. <br> **tree_type:** LMS Algorithm Type (4 bytes) <br> **otstype:** LMS Ots Algorithm Type (4 bytes) <br> **id:** (16 bytes) <br> **digest:** (24 bytes) <br> Note: If LMS validation is not required, this should field should be zeroed out.|
| Owner ECC Signature | 96 | Owner ECDSA P-384 signature of the Version, Flags, Owner ECC and LMS public keys, hashed using SHA2-384. <br> **R-Coordinate:** Random Point (48 bytes) <br> **S-Coordinate:** Proof (48 bytes) |
| Owner LMS Signature | 1620 | Owner LMS signature of the Version, Flags, Owner ECC and LMS public keys, hashed using SHA2-384. <br> **q:** Leaf of the Merkle tree where the OTS public key appears (4 bytes) <br> **ots:** Lmots Signature (1252 bytes) <br> **tree_type:** Lms Algorithm Type (4 bytes) <br> **tree_path:** Path through the tree from the leaf associated with the LM-OTS signature to the root. (360 bytes) <br> Note: If LMS validation is not required, this should field should be zeroed out.|

- ### **Image Metadata Entry**
| Field | Size (bytes) | Description|
|-------|--------|------------|
| Image Hash | 48 | SHA2-384 hash of a SOC image |
| Image Source | 4 | <TBD> |

- ### **Image Metadata Collection**
The Image Metadata Collection (IMC) is a collection of Image Metadata entries (IME). Each IME has a hash that matches a SOC images. The manifest vendor and owner private keys sign the IMC. The Preamble holds the IMC signatures. The manifest IMC vendor signatures are optional and are validated only if the FLAGS field Bit 0 = 1. Up to sixteen image hashes are supported.

| Field | Size (bytes) | Description|
|-------|--------|------------|
| Revision | 4 | Version of the IMC structure |
| Reserved | 4 | Reserved |
| Image Metadata Entry (IME) Count | 4 | Number of IME(s) in the IMC |
| Image Metadata Entry (N) | Variable | List of Image Metadata Entry structures |
Loading

0 comments on commit f485e00

Please sign in to comment.