-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding command to get owner pub key hash received with image bundle
- Loading branch information
Showing
11 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed under the Apache-2.0 license | ||
|
||
use crate::Drivers; | ||
|
||
use caliptra_cfi_derive_git::cfi_impl_fn; | ||
use caliptra_cfi_lib_git::cfi_launder; | ||
|
||
use caliptra_common::{ | ||
cprintln, | ||
mailbox_api::{GetOwnerPubKeyHashReq, GetOwnerPubKeyHashResp, MailboxResp, MailboxRespHeader}, | ||
}; | ||
use caliptra_error::{CaliptraError, CaliptraResult}; | ||
|
||
use zerocopy::{AsBytes, FromBytes}; | ||
|
||
pub struct GetOwnerPubKeyHashCmd; | ||
impl GetOwnerPubKeyHashCmd { | ||
#[cfg_attr(not(feature = "no-cfi"), cfi_impl_fn)] | ||
#[inline(never)] | ||
pub(crate) fn execute(drivers: &mut Drivers, cmd_args: &[u8]) -> CaliptraResult<MailboxResp> { | ||
if let Some(cmd) = GetOwnerPubKeyHashReq::read_from(cmd_args) { | ||
let mut resp = GetOwnerPubKeyHashResp::default(); | ||
|
||
// Copy the pub key hash from the last cold boot from the data vault | ||
resp.key_hash | ||
.copy_from_slice(drivers.data_vault.owner_pk_hash().as_bytes()); | ||
|
||
Ok(MailboxResp::GetOwnerPubKeyHash(resp)) | ||
} else { | ||
Err(CaliptraError::RUNTIME_INSUFFICIENT_MEMORY) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
runtime/tests/runtime_integration_tests/test_get_owner_pub_key_hash.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Licensed under the Apache-2.0 license | ||
|
||
use caliptra_api::mailbox::GetOwnerPubKeyHashResp; | ||
use caliptra_common::mailbox_api::{CommandId, MailboxReqHeader}; | ||
use caliptra_hw_model::HwModel; | ||
use zerocopy::{AsBytes, FromBytes}; | ||
|
||
use crate::common::{run_rt_test, RuntimeTestArgs}; | ||
|
||
#[test] | ||
fn test_get_owner_pub_key_hash() { | ||
let mut model = run_rt_test(RuntimeTestArgs::default()); | ||
|
||
let payload = MailboxReqHeader { | ||
chksum: caliptra_common::checksum::calc_checksum( | ||
u32::from(CommandId::GET_OWNER_PUB_KEY_HASH), | ||
&[], | ||
), | ||
}; | ||
|
||
let result = | ||
model.mailbox_execute(CommandId::GET_OWNER_PUB_KEY_HASH.into(), payload.as_bytes()); | ||
|
||
let response = result.unwrap().unwrap(); | ||
|
||
let get_owner_pub_key_hash_resp = | ||
GetOwnerPubKeyHashResp::read_from(response.as_bytes()).unwrap(); | ||
|
||
// Check against our fake owner public key hash | ||
let mut exp_pub_key_hash = | ||
openssl::sha::sha384(caliptra_image_fake_keys::OWNER_PUBLIC_KEYS.as_bytes()); | ||
// FLip endianness by each dword for the hash | ||
for dword in exp_pub_key_hash.chunks_exact_mut(4) { | ||
dword.reverse(); | ||
} | ||
assert_eq!(exp_pub_key_hash, get_owner_pub_key_hash_resp.key_hash); | ||
} |