mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-22 09:23:16 +00:00
add a method to force-rewrite keys
This is useful in CI to test various stages of dev-key signed image vs secret key erase without having to go through a complete suicide cycle on the chip. This command is gated behind a feature flag that would only be invoked for beta testing. I think it's still safe to have even as a beta-signed feature because the worst you can do with this is replace existing keys - so it could be used to DoS/brick, but not leak secrets.
This commit is contained in:
parent
0529a10eb8
commit
0aeb9daa37
5 changed files with 68 additions and 40 deletions
|
|
@ -29,6 +29,7 @@ efuse = []
|
|||
policy-menu = []
|
||||
|
||||
gen2 = []
|
||||
key-testing = []
|
||||
|
||||
std = ["derive-rkyv", "xous-names", "xous-ipc", "locales"]
|
||||
derive-rkyv = ["rkyv"]
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ pub enum Opcode {
|
|||
// ----- below are non-cryptographic opcodes but used to manipulate sensitive state -----
|
||||
/// Set bootwait parameters
|
||||
Bootwait = 4096,
|
||||
/// For testing only: overwrite secret keys
|
||||
#[cfg(feature = "key-testing")]
|
||||
OverwriteKeys = 4097,
|
||||
|
||||
/// Used to map unknown opcodes
|
||||
InvalidCall = 65535,
|
||||
|
|
|
|||
|
|
@ -108,8 +108,13 @@ board-dabao = [
|
|||
] # Dev board form factor
|
||||
loader-dabao = []
|
||||
|
||||
hazardous-debug = [
|
||||
] # this feature enables the printing of secret materials for debug purposes
|
||||
tts = []
|
||||
efuse = []
|
||||
# this feature enables the printing of secret materials for debug purposes
|
||||
hazardous-debug = []
|
||||
|
||||
# this feature indicates the system is being booted to do keying testing.
|
||||
# it enables some features that allows the keystore to be overwritten
|
||||
# so that we can rapidly iterate through various combinations of boot
|
||||
# signatures
|
||||
key-testing = ["keystore-api/key-testing"]
|
||||
|
||||
default = []
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ pub fn keystore(sid: SID) -> ! {
|
|||
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
// as_flat saves a copy step, but we have to deserialize some enums manually
|
||||
let mut aes_op = buffer.to_original::<AesOp, _>().unwrap();
|
||||
// TODO: add hardening checks to the deserialization of AesOp. Can't assume the
|
||||
// values are correct coming into this server.
|
||||
store.aes_op(&mut aes_op).expect("couldn't perform AES op");
|
||||
buffer.replace(aes_op).unwrap();
|
||||
}
|
||||
|
|
@ -45,6 +47,8 @@ pub fn keystore(sid: SID) -> ! {
|
|||
let mut buffer =
|
||||
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut kwp = buffer.to_original::<KeyWrapper, _>().unwrap();
|
||||
// TODO: add hardening checks to the deserialization of AesOp. Can't assume the
|
||||
// values are correct coming into this server.
|
||||
store.aes_kwp(&mut kwp).expect("couldn't wrap key");
|
||||
buffer.replace(kwp).unwrap();
|
||||
}
|
||||
|
|
@ -71,6 +75,10 @@ pub fn keystore(sid: SID) -> ! {
|
|||
Opcode::InvalidCall => {
|
||||
log::error!("Invalid call in keystore: {:?}", opcode);
|
||||
}
|
||||
#[cfg(feature = "key-testing")]
|
||||
Opcode::OverwriteKeys => {
|
||||
store.force_system_init(&mut rram);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,24 +35,10 @@ impl KeyStore {
|
|||
Self { slot_mgr, owc, master_key: None }
|
||||
}
|
||||
|
||||
pub fn ensure_system_init(&mut self, rram: &mut Reram) {
|
||||
// debug coreuser status
|
||||
/*
|
||||
let coreuser_range = xous::map_memory(
|
||||
xous::MemoryAddress::new(utralib::utra::coreuser::HW_COREUSER_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("Couldn't map coreuser range");
|
||||
let coreuser = utralib::CSR::new(coreuser_range.as_mut_ptr() as *mut u32);
|
||||
log::info!("coreuser status: {:x}", coreuser.r(utralib::utra::coreuser::STATUS));
|
||||
*/
|
||||
|
||||
fn system_init_inner(&mut self, rram: &mut Reram) {
|
||||
// one routine works for both dabao and baosec
|
||||
let board_type = self.owc.get_decoded::<BoardTypeCoding>().unwrap();
|
||||
if self.owc.get(bao1x_api::IN_SYSTEM_BOOT_SETUP_DONE).unwrap() == 0 {
|
||||
log::info!("System setup not yet done. Initializing secret identifiers...");
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let mut trng = bao1x_hal_service::trng::Trng::new(&xns).unwrap();
|
||||
// generate all the keys
|
||||
|
|
@ -87,6 +73,31 @@ impl KeyStore {
|
|||
log::info!("Secret ID init done.");
|
||||
log::info!("{}KEYSTORE.INITDONE,{}", BOOKEND_START, BOOKEND_END);
|
||||
}
|
||||
|
||||
pub fn ensure_system_init(&mut self, rram: &mut Reram) {
|
||||
log::info!("System setup not yet done. Initializing secret identifiers...");
|
||||
// debug coreuser status
|
||||
/*
|
||||
let coreuser_range = xous::map_memory(
|
||||
xous::MemoryAddress::new(utralib::utra::coreuser::HW_COREUSER_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("Couldn't map coreuser range");
|
||||
let coreuser = utralib::CSR::new(coreuser_range.as_mut_ptr() as *mut u32);
|
||||
log::info!("coreuser status: {:x}", coreuser.r(utralib::utra::coreuser::STATUS));
|
||||
*/
|
||||
|
||||
if self.owc.get(bao1x_api::IN_SYSTEM_BOOT_SETUP_DONE).unwrap() == 0 {
|
||||
self.system_init_inner(rram);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "key-testing")]
|
||||
pub fn force_system_init(&mut self, rram: &mut Reram) {
|
||||
self.system_init_inner(rram);
|
||||
log::info!("{}KEYSTORE.FORCEINIT,{}", BOOKEND_START, BOOKEND_END);
|
||||
}
|
||||
|
||||
/// returns `true` if collateral is erased
|
||||
|
|
|
|||
Loading…
Reference in a new issue