upgrade audit routines to use the new signature checking API

This commit is contained in:
bunnie 2025-12-05 23:16:04 +08:00
parent 8be0f1004b
commit 50d32ecb42
No known key found for this signature in database

View file

@ -4,7 +4,7 @@ use alloc::string::{String, ToString};
use alloc::vec::Vec; use alloc::vec::Vec;
use core::convert::TryInto; use core::convert::TryInto;
use bao1x_api::signatures::FunctionCode; use bao1x_api::pubkeys::{BOOT0_SELF_CHECK, BOOT0_TO_BOOT1, BOOT1_TO_LOADER_OR_BAREMETAL};
#[allow(unused_imports)] #[allow(unused_imports)]
use bao1x_api::*; use bao1x_api::*;
use bao1x_hal::acram::OneWayCounter; use bao1x_hal::acram::OneWayCounter;
@ -357,58 +357,33 @@ impl Repl {
crate::println!(""); crate::println!("");
} }
match bao1x_hal::sigcheck::validate_image( match bao1x_hal::sigcheck::validate_image(BOOT0_SELF_CHECK, None, None) {
bao1x_api::BOOT0_START as *const u32, Ok((k, k2, tag, target)) => crate::println!(
bao1x_api::BOOT0_START as *const u32, "Boot0: key {}/{} ({}) -> {:x}",
bao1x_api::BOOT0_REVOCATION_OFFSET,
&[FunctionCode::Boot0 as u32],
false,
None,
None,
) {
Ok((k, k2, tag)) => crate::println!(
"Boot0: key {}/{} ({})",
k, k,
k2, !k2,
core::str::from_utf8(&tag).unwrap_or("invalid tag") core::str::from_utf8(&tag).unwrap_or("invalid tag"),
target ^ u32::from_le_bytes(tag)
), ),
Err(e) => crate::println!("Boot0 did not validate: {:?}", e), Err(e) => crate::println!("Boot0 did not validate: {:?}", e),
} }
match bao1x_hal::sigcheck::validate_image( match bao1x_hal::sigcheck::validate_image(BOOT0_TO_BOOT1, None, None) {
bao1x_api::BOOT1_START as *const u32, Ok((k, k2, tag, target)) => crate::println!(
bao1x_api::BOOT0_START as *const u32, "Boot1: key {}/{} ({}) -> {:x}",
bao1x_api::BOOT0_REVOCATION_OFFSET,
&[
FunctionCode::Boot1 as u32,
FunctionCode::UpdatedBoot1 as u32,
FunctionCode::Developer as u32,
],
false,
None,
None,
) {
Ok((k, k2, tag)) => crate::println!(
"Boot1: key {}/{} ({})",
k, k,
k2, !k2,
core::str::from_utf8(&tag).unwrap_or("invalid tag") core::str::from_utf8(&tag).unwrap_or("invalid tag"),
target ^ u32::from_le_bytes(tag)
), ),
Err(e) => crate::println!("Boot1 did not validate: {:?}", e), Err(e) => crate::println!("Boot1 did not validate: {:?}", e),
} }
match bao1x_hal::sigcheck::validate_image( match bao1x_hal::sigcheck::validate_image(BOOT1_TO_LOADER_OR_BAREMETAL, None, None) {
bao1x_api::LOADER_START as *const u32, Ok((k, k2, tag, target)) => crate::println!(
bao1x_api::BOOT1_START as *const u32, "Next stage: key {}/{} ({}) -> {:x}",
bao1x_api::BOOT1_REVOCATION_OFFSET,
&crate::secboot::ALLOWED_FUNCTIONS,
false,
None,
None,
) {
Ok((k, k2, tag)) => crate::println!(
"Next stage: key {}/{} ({})",
k, k,
k2, !k2,
core::str::from_utf8(&tag).unwrap_or("invalid tag") core::str::from_utf8(&tag).unwrap_or("invalid tag"),
target ^ u32::from_le_bytes(tag)
), ),
Err(e) => crate::println!("Next stage did not validate: {:?}", e), Err(e) => crate::println!("Next stage did not validate: {:?}", e),
} }
@ -475,25 +450,10 @@ impl Repl {
crate::println!("** System did not meet minimum requirements for security **"); crate::println!("** System did not meet minimum requirements for security **");
} }
} }
"lockdown" => { "lockdown" => match bao1x_hal::sigcheck::validate_image(BOOT0_TO_BOOT1, None, None) {
match bao1x_hal::sigcheck::validate_image( Ok((k, _k2, _tag, _target)) => {
bao1x_api::BOOT1_START as *const u32,
bao1x_api::BOOT0_START as *const u32,
bao1x_api::BOOT0_REVOCATION_OFFSET,
&[
FunctionCode::Boot1 as u32,
FunctionCode::UpdatedBoot1 as u32,
FunctionCode::Developer as u32,
],
false,
None,
None,
) {
Ok((k, _k2, _tag)) => {
if k != bao1x_api::pubkeys::DEVELOPER_KEY_SLOT { if k != bao1x_api::pubkeys::DEVELOPER_KEY_SLOT {
crate::println!( crate::println!("This will permanently disable developer mode. It cannot be undone!");
"This will permanently disable developer mode. It cannot be undone!"
);
crate::println!("Proceed? (type 'YES' in all caps to proceed)"); crate::println!("Proceed? (type 'YES' in all caps to proceed)");
self.lockdown_armed = true; self.lockdown_armed = true;
} else { } else {
@ -505,8 +465,7 @@ impl Repl {
Err(_e) => { Err(_e) => {
crate::println!("Boot1 has no valid signature, lockdown would brick the chip.") crate::println!("Boot1 has no valid signature, lockdown would brick the chip.")
} }
} },
}
"baosec-init" => { "baosec-init" => {
// this routine is used to initialize baosec products - sets the board type and // this routine is used to initialize baosec products - sets the board type and
// erases the off-chip FLASH // erases the off-chip FLASH