Skip to content

Commit

Permalink
feat: add negative unit tests for debug unlock
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Heymans <arthur.heymans@9elements.com>
  • Loading branch information
ArthurHeymans committed Jan 13, 2025
1 parent 671c275 commit 3aeb731
Show file tree
Hide file tree
Showing 3 changed files with 498 additions and 18 deletions.
4 changes: 3 additions & 1 deletion error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,9 @@ impl CaliptraError {
CaliptraError::new_const(0xa0000004);
pub const ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_MBOX_CMD: CaliptraError =
CaliptraError::new_const(0xa0000005);
pub const ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN: CaliptraError =
pub const ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_WRONG_PUBLIC_KEYS: CaliptraError =
CaliptraError::new_const(0xa0000006);
pub const ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_INVALID_SIGNATURE: CaliptraError =
CaliptraError::new_const(0xa0000006);
}

Expand Down
12 changes: 6 additions & 6 deletions rom/dev/src/flow/debug_unlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ fn handle_production_token(
if payload_length(token.length)
!= size_of::<ProductionAuthDebugUnlockToken>() - size_of::<MailboxReqHeader>()
{
Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN)?
Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_INVALID_SIGNATURE)?
}

// Debug level
if payload_length(token.unlock_category) != payload_length(request.unlock_category) {
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN);
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_INVALID_SIGNATURE);
}
if cfi_launder(token.challenge) != challenge.challenge {
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN);
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_INVALID_SIGNATURE);
} else {
caliptra_cfi_lib::cfi_assert_eq_12_words(
&Array4x12::from(token.challenge).0,
Expand Down Expand Up @@ -262,7 +262,7 @@ fn handle_production_token(
if cfi_launder(request_digest) != fuse_digest {
env.soc_ifc.finish_ss_dbg_unluck(false);
txn.set_uc_tap_unlock(false);
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_MANUF_INVALID_TOKEN);
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_WRONG_PUBLIC_KEYS);
} else {
caliptra_cfi_lib::cfi_assert_eq_12_words(
&request_digest.0[..12].try_into().unwrap(),
Expand All @@ -289,7 +289,7 @@ fn handle_production_token(
if result == Ecc384Result::SigVerifyFailed {
env.soc_ifc.finish_ss_dbg_unluck(false);
txn.set_uc_tap_unlock(false);
Err(CaliptraError::ROM_SS_DBG_UNLOCK_MANUF_INVALID_TOKEN)?;
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_INVALID_SIGNATURE);
}

let mut digest_op = env.sha2_512_384.sha512_digest_init()?;
Expand All @@ -306,7 +306,7 @@ fn handle_production_token(
)?;

if result == Mldsa87Result::SigVerifyFailed {
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_MANUF_INVALID_TOKEN);
return Err(CaliptraError::ROM_SS_DBG_UNLOCK_PROD_INVALID_TOKEN_INVALID_SIGNATURE);
}
Ok(())
}
Expand Down
Loading

0 comments on commit 3aeb731

Please sign in to comment.