mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add a command for setting the bootwait flag
The keystore is a sensitive server, and the one-way counters have security-critical propoerties. So instead of revealing a generic one-way counter API to the world, specific, limited requests to do things are going to be created for the keystore. In this case, the bootwait flag would be convenient to be able to set from userspace. The motivation for this requirement is actually continuous integration - a normal human could just hold down a button while turning on power, but in CI, I don't have a robotic thumb (or an alternative electrical signal) to simulate the nerve-pinch on boot. Previously I was "cheating" and simulating this by nuking the loader, which effectively forces a bootwait. However, in production, this is *not possible* because the JTAG port is sealed off. Thus, this may be the first of a series of small PRs to incorporate CI tooling that clears up tech debt like nuking the loader to get into boot wait.
This commit is contained in:
parent
81f35b17be
commit
2b19c4bd21
4 changed files with 60 additions and 1 deletions
|
|
@ -18,6 +18,10 @@ pub enum Opcode {
|
|||
/// Ephemeral secret operations
|
||||
EphemeralOp = 256,
|
||||
|
||||
// ----- below are non-cryptographic opcodes but used to manipulate sensitive state -----
|
||||
/// Set bootwait parameters
|
||||
Bootwait = 4096,
|
||||
|
||||
/// Used to map unknown opcodes
|
||||
InvalidCall = 65535,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,6 +169,29 @@ impl Keystore {
|
|||
|
||||
#[inline(always)]
|
||||
pub(crate) fn get_dec_backend(&self) -> KeystoreDec<'_> { KeystoreDec(self) }
|
||||
|
||||
/// Returns the previous bootwait state
|
||||
pub fn bootwait(&self, enable: Option<bool>) -> Result<bool, xous::Error> {
|
||||
match xous::send_message(
|
||||
self.conn,
|
||||
xous::Message::new_blocking_scalar(
|
||||
Opcode::Bootwait.to_usize().unwrap(),
|
||||
if enable.is_some() { 1 } else { 0 },
|
||||
if enable.unwrap_or(false) { 1 } else { 0 },
|
||||
0,
|
||||
0,
|
||||
),
|
||||
)? {
|
||||
xous::Result::Scalar5(_, last, _, _, _) => {
|
||||
if last != 0 {
|
||||
Ok(true)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
|
|
|
|||
|
|
@ -44,6 +44,22 @@ pub fn keystore(sid: SID) -> ! {
|
|||
// this will use the backup_mgr to store ephemeral secrets
|
||||
todo!()
|
||||
}
|
||||
Opcode::Bootwait => {
|
||||
if let Some(scalar) = msg.body.scalar_message_mut() {
|
||||
let is_some = scalar.arg1 != 0;
|
||||
let enable = scalar.arg2 != 0;
|
||||
match store.set_bootwait(if is_some { Some(enable) } else { None }) {
|
||||
Ok(last) => {
|
||||
if last {
|
||||
scalar.arg1 = 1;
|
||||
} else {
|
||||
scalar.arg1 = 0;
|
||||
}
|
||||
}
|
||||
_ => panic!("Couldn't set bootwait"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Opcode::InvalidCall => {
|
||||
log::error!("Invalid call in keystore: {:?}", opcode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
use aes::Aes256;
|
||||
use aes::cipher::{BlockDecrypt, BlockEncrypt, KeyInit, generic_array::GenericArray};
|
||||
use bao1x_api::{
|
||||
BOOT0_PUBKEY_FAIL, BoardTypeCoding, CP_ID, DEVELOPER_MODE, OEM_MODE, SLOT_ELEMENT_LEN_BYTES, UUID,
|
||||
BOOT0_PUBKEY_FAIL, BoardTypeCoding, BootWaitCoding, CP_ID, DEVELOPER_MODE, OEM_MODE,
|
||||
SLOT_ELEMENT_LEN_BYTES, UUID,
|
||||
};
|
||||
use bao1x_hal::board::{BOOKEND_END, BOOKEND_START};
|
||||
use bao1x_hal::{
|
||||
|
|
@ -356,4 +357,19 @@ impl KeyStore {
|
|||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_bootwait(&self, enable: Option<bool>) -> Result<bool, xous::Error> {
|
||||
let previous = self.owc.get_decoded::<bao1x_api::BootWaitCoding>().expect("couldn't fetch flag");
|
||||
if let Some(enable) = enable {
|
||||
while self.owc.get_decoded::<bao1x_api::BootWaitCoding>().expect("couldn't fetch flag")
|
||||
!= if enable { bao1x_api::BootWaitCoding::Enable } else { bao1x_api::BootWaitCoding::Disable }
|
||||
{
|
||||
self.owc.inc_coded::<bao1x_api::BootWaitCoding>().unwrap();
|
||||
}
|
||||
}
|
||||
match previous {
|
||||
BootWaitCoding::Enable => Ok(true),
|
||||
BootWaitCoding::Disable => Ok(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue