mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
simplify keystore setup
The TL;DR is this now treats dabao exactly the same as baosec in terms of keystore setup from the security flow perspective. baosec & dabao were different originally because baosec would rely upon the Avalanche generator TRNG as supplemental randomness and dabao would not. This special case had to be handled in the bootloader and propagated through. However, in a previous commit, the keystore setup was moved to the OS *anyways* - thus making this difference moot. This patch backs out the one-way counters that would track the dabao initialization state. It also doesn't fail the boot on the erase key proof check failing if the keystores aren't initialized yet. This creates yet another condition that could be glitched over to bypass the erase check but it is checked twice indepedently.
This commit is contained in:
parent
bcc4702602
commit
9093bb4ed7
5 changed files with 23 additions and 44 deletions
|
|
@ -428,23 +428,11 @@ impl Repl {
|
|||
crate::println!("== CP SETUP FAILED ==");
|
||||
secure = false;
|
||||
}
|
||||
if (boardtype == BoardTypeCoding::Baosec && owc.get(IN_SYSTEM_BOOT_SETUP_DONE).unwrap() == 0)
|
||||
|| (boardtype == BoardTypeCoding::Dabao && owc.get(DABAO_KEY_SETUP_DONE).unwrap() == 0)
|
||||
{
|
||||
if owc.get(IN_SYSTEM_BOOT_SETUP_DONE).unwrap() == 0 {
|
||||
crate::println!("In-system keys have NOT been generated");
|
||||
secure = false;
|
||||
} else {
|
||||
if boardtype == BoardTypeCoding::Baosec {
|
||||
crate::println!("In-system keys have been generated");
|
||||
} else {
|
||||
// assume dabao-type board
|
||||
if owc.get(INVOKE_DABAO_KEY_SETUP).unwrap() != 0 {
|
||||
crate::println!("In-system keys have been generated");
|
||||
} else {
|
||||
crate::println!("In-system key generation is still pending");
|
||||
secure = false
|
||||
}
|
||||
}
|
||||
crate::println!("In-system keys have been generated");
|
||||
}
|
||||
if !secure {
|
||||
crate::println!("** System did not meet minimum requirements for security **");
|
||||
|
|
|
|||
|
|
@ -152,16 +152,6 @@ pub const OEM_MODE: usize = 86;
|
|||
/// the data store.
|
||||
pub const BOOT0_PUBKEY_FAIL: usize = 87;
|
||||
|
||||
/// This pair of counters is used to invoke the key setup for dabao. It's not done until
|
||||
/// a Xous environment is loaded onto a dabao *and* the dabao is rebooted the first time.
|
||||
/// The reason it's not done all the time is that baosec boards want to set up their secure
|
||||
/// keys using the TRNG avalanche generator - which is not available on dabao. Thus we have
|
||||
/// to differentiate the two cases, because when a chip is "born" it thinks it's a "dabao",
|
||||
/// and has to be told it's a "baosec". This is the analogous path, but for dabaos that
|
||||
/// want the key store.
|
||||
pub const INVOKE_DABAO_KEY_SETUP: usize = 88;
|
||||
pub const DABAO_KEY_SETUP_DONE: usize = 89;
|
||||
|
||||
encode_oneway! {
|
||||
#[offset = 90]
|
||||
/// When set, the system will prefer to present generic, fixed identifiers when challenged
|
||||
|
|
|
|||
|
|
@ -274,6 +274,7 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32)
|
|||
let backup = bao1x_hal::buram::BackupManager::new();
|
||||
let (paranoid1, paranoid2) = owc.hardened_get2(PARANOID_MODE, PARANOID_MODE_DUPE).unwrap();
|
||||
let (dev_mode1, dev_mode2) = owc.hardened_get(bao1x_api::DEVELOPER_MODE).unwrap();
|
||||
let (init1, init2) = owc.hardened_get(bao1x_api::IN_SYSTEM_BOOT_SETUP_DONE).unwrap();
|
||||
csprng.random_delay();
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
// validate using the bao1x signature scheme
|
||||
|
|
@ -298,8 +299,10 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32)
|
|||
// developer image.
|
||||
csprng.random_delay();
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
if tag == *bao1x_api::pubkeys::KEYSLOT_INITIAL_TAGS[bao1x_api::pubkeys::DEVELOPER_KEY_SLOT]
|
||||
|| key == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT
|
||||
// this has to gate on keys being initialized, because without key setup nothing gets erased
|
||||
if (tag == *bao1x_api::pubkeys::KEYSLOT_INITIAL_TAGS[bao1x_api::pubkeys::DEVELOPER_KEY_SLOT]
|
||||
|| key == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT)
|
||||
&& (init1 != 0)
|
||||
{
|
||||
csprng.random_delay();
|
||||
let erase_proof: &[u8; 32] =
|
||||
|
|
@ -319,7 +322,7 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32)
|
|||
// this consumes dev_mode2 & !k2 - the alternate version - preventing the check from being
|
||||
// optimized out
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
if !key_inv == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT {
|
||||
if (!key_inv == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT) && (init2 != 0) {
|
||||
csprng.random_delay();
|
||||
let erase_proof: &[u8; 32] =
|
||||
backup.get_slice(ERASURE_PROOF_RANGE_BYTES).try_into().unwrap();
|
||||
|
|
@ -375,9 +378,10 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32)
|
|||
}
|
||||
csprng.random_delay();
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
if tag
|
||||
if (tag
|
||||
== *bao1x_api::pubkeys::KEYSLOT_INITIAL_TAGS[bao1x_api::pubkeys::DEVELOPER_KEY_SLOT]
|
||||
|| key == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT
|
||||
|| key == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT)
|
||||
&& (init1 != 0)
|
||||
{
|
||||
let erase_proof: &[u8; 32] =
|
||||
backup.get_slice(ERASURE_PROOF_RANGE_BYTES).try_into().unwrap();
|
||||
|
|
@ -398,7 +402,7 @@ pub unsafe extern "C" fn rust_entry(signed_buffer: *const usize, signature: u32)
|
|||
}
|
||||
csprng.random_delay();
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
if !key_inv == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT {
|
||||
if (!key_inv == bao1x_api::pubkeys::DEVELOPER_KEY_SLOT) && (init2 != 0) {
|
||||
let erase_proof: &[u8; 32] =
|
||||
backup.get_slice(ERASURE_PROOF_RANGE_BYTES).try_into().unwrap();
|
||||
if dev_mode2 == 0 || erase_proof != &[ERASE_VALUE; 32] {
|
||||
|
|
|
|||
|
|
@ -188,12 +188,6 @@ pub fn early_init_hw() -> u32 {
|
|||
if one_way.get(bao1x_api::BootWaitCoding::OFFSET).unwrap() == 0 {
|
||||
one_way.inc_coded::<bao1x_api::BootWaitCoding>().ok();
|
||||
}
|
||||
// set invoke_dabao_key_setup exactly once. On the next reboot, the keys
|
||||
// for the dabao environment will be created using the on-chip TRNG.
|
||||
if one_way.get(bao1x_api::INVOKE_DABAO_KEY_SETUP).unwrap() == 0 {
|
||||
// safety: the argument is from a checked constant
|
||||
unsafe { one_way.inc(bao1x_api::INVOKE_DABAO_KEY_SETUP).ok() };
|
||||
}
|
||||
}
|
||||
|
||||
// Setup some global control registers that will allow the TRNG to operate once the kernel is
|
||||
|
|
@ -234,7 +228,7 @@ pub fn setup_console<T: IoSetup + IoGpio>(
|
|||
udma_global.map_event(uart_id, PeriphEventType::Uart(EventUartOffset::Tx), EventChannel::Channel1);
|
||||
|
||||
let baudrate: u32 = bao1x_api::UART_BAUD;
|
||||
let freq: u32 = perclk / 2;
|
||||
let freq: u32 = perclk;
|
||||
|
||||
// the address of the UART buffer is "hard-allocated" at an offset one page from the top of
|
||||
// IFRAM0. This is a convention that must be respected by the UDMA UART library implementation
|
||||
|
|
|
|||
|
|
@ -285,12 +285,15 @@ impl SwapHal {
|
|||
}
|
||||
let backup = bao1x_hal::buram::BackupManager::new();
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
let erase_proof: &[u8; 32] = backup
|
||||
.get_slice(bao1x_hal::buram::ERASURE_PROOF_RANGE_BYTES)
|
||||
.try_into()
|
||||
.unwrap();
|
||||
if erase_proof != &[ERASE_VALUE; 32] {
|
||||
bao1x_hal::sigcheck::die_no_std();
|
||||
let owc = bao1x_hal::acram::OneWayCounter::new();
|
||||
if owc.get(bao1x_api::IN_SYSTEM_BOOT_SETUP_DONE).unwrap() != 0 {
|
||||
let erase_proof: &[u8; 32] = backup
|
||||
.get_slice(bao1x_hal::buram::ERASURE_PROOF_RANGE_BYTES)
|
||||
.try_into()
|
||||
.unwrap();
|
||||
if erase_proof != &[ERASE_VALUE; 32] {
|
||||
bao1x_hal::sigcheck::die_no_std();
|
||||
}
|
||||
}
|
||||
bollard!(bao1x_hal::sigcheck::die_no_std, 4);
|
||||
}
|
||||
|
|
@ -508,7 +511,7 @@ pub fn userspace_maps(cfg: &mut BootConfig) {
|
|||
|
||||
let baudrate: u32 = 1_000_000;
|
||||
let perclk = 100_000_000; // TODO: turn this into a symbolic const, or better yet, pass in from the loader
|
||||
let freq: u32 = perclk / 2;
|
||||
let freq: u32 = perclk;
|
||||
|
||||
// the address of the UART buffer is "hard-allocated" at an offset one page from the top of
|
||||
// IFRAM0. This is a convention that must be respected by the UDMA UART library implementation
|
||||
|
|
|
|||
Loading…
Reference in a new issue