mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
add debug telemetry to the keystore
this is constructed in a way such that 1. it's gated off in production builds 2. if it was accidentally gated on, there is some security impact but not a significant loss of security We do need the telemetry so that during CI we can confirm that things are actually working. I think the risk of being too buttoned-up and then accidentally doing something like accidentally never initializing keys and leaving them all zero is greater than the risk of accidental partial leakage of information due to a procedural mix-up in the image signing ceremony.
This commit is contained in:
parent
145c2e37b2
commit
22f44f82b9
1 changed files with 22 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ use aes::cipher::{BlockDecrypt, BlockEncrypt, KeyInit, generic_array::GenericArr
|
||||||
use bao1x_api::{
|
use bao1x_api::{
|
||||||
BOOT0_PUBKEY_FAIL, BoardTypeCoding, CP_ID, DEVELOPER_MODE, OEM_MODE, SLOT_ELEMENT_LEN_BYTES, UUID,
|
BOOT0_PUBKEY_FAIL, BoardTypeCoding, CP_ID, DEVELOPER_MODE, OEM_MODE, SLOT_ELEMENT_LEN_BYTES, UUID,
|
||||||
};
|
};
|
||||||
|
use bao1x_hal::board::{BOOKEND_END, BOOKEND_START};
|
||||||
use bao1x_hal::{
|
use bao1x_hal::{
|
||||||
acram::{OneWayCounter, SlotManager},
|
acram::{OneWayCounter, SlotManager},
|
||||||
board::{CHAFF_KEYS, NUISANCE_KEYS_0, NUISANCE_KEYS_1, ROOT_SEED},
|
board::{CHAFF_KEYS, NUISANCE_KEYS_0, NUISANCE_KEYS_1, ROOT_SEED},
|
||||||
|
|
@ -102,6 +103,23 @@ impl KeyStore {
|
||||||
|
|
||||||
// read key material
|
// read key material
|
||||||
ikm.extend_from_slice(self.slot_mgr.read(&ROOT_SEED).unwrap());
|
ikm.extend_from_slice(self.slot_mgr.read(&ROOT_SEED).unwrap());
|
||||||
|
#[cfg(feature = "hazardous-debug")]
|
||||||
|
{
|
||||||
|
// analyze part of the key and print some informative statements during hazardous-debug
|
||||||
|
// we want to make sure that keys are actually being initialized, erased, or denied
|
||||||
|
// look at only 64 bits out of the 256 bit key - it's enough that it's highly unlikely that
|
||||||
|
// these 64 bits would match any of the zero/erased values, but not so much that if a
|
||||||
|
// dev image is accidentally signed & released that it'd be a serious threat to security
|
||||||
|
// as you'd still have 192 bits of secret material
|
||||||
|
let root_seed = self.slot_mgr.read(&ROOT_SEED).unwrap();
|
||||||
|
if root_seed[..8] == [0u8; 8] {
|
||||||
|
log::info!("{}KEYSTORE.ZERO,{}", BOOKEND_START, BOOKEND_END);
|
||||||
|
} else if root_seed[..8] == [bao1x_hal::sigcheck::ERASE_VALUE; 8] {
|
||||||
|
log::info!("{}KEYSTORE.ERASED,{}", BOOKEND_START, BOOKEND_END);
|
||||||
|
} else {
|
||||||
|
log::info!("{}KEYSTORE.KEYPASS,{}", BOOKEND_START, BOOKEND_END);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// build nuisance key offsets - this is direct readout hardening
|
// build nuisance key offsets - this is direct readout hardening
|
||||||
let nk0 = NUISANCE_KEYS_0.try_into_data_iter().unwrap();
|
let nk0 = NUISANCE_KEYS_0.try_into_data_iter().unwrap();
|
||||||
|
|
@ -175,7 +193,7 @@ impl KeyStore {
|
||||||
#[cfg(feature = "hazardous-debug")]
|
#[cfg(feature = "hazardous-debug")]
|
||||||
// leak only part of the chaff, see below comment about hedging against accidental signing of a debug
|
// leak only part of the chaff, see below comment about hedging against accidental signing of a debug
|
||||||
// image
|
// image
|
||||||
log::info!("chaff: {:x?}", chaff_xor[..8]);
|
log::info!("chaff: {:x?}", &chaff_xor[..8]);
|
||||||
ikm.extend_from_slice(&chaff_xor);
|
ikm.extend_from_slice(&chaff_xor);
|
||||||
assert!(ikm.len() == (nk_len + 1 + 1) * KEY_LEN); // sanity check that all keys were in fact added
|
assert!(ikm.len() == (nk_len + 1 + 1) * KEY_LEN); // sanity check that all keys were in fact added
|
||||||
|
|
||||||
|
|
@ -220,11 +238,14 @@ impl KeyStore {
|
||||||
// do something with ct_xor that guarantees it's never optimized out
|
// do something with ct_xor that guarantees it's never optimized out
|
||||||
if ct_xor.iter().all(|&cx| cx == 0) {
|
if ct_xor.iter().all(|&cx| cx == 0) {
|
||||||
log::warn!("Chaff result is all-0. Confirming that we're in developer mode");
|
log::warn!("Chaff result is all-0. Confirming that we're in developer mode");
|
||||||
|
log::info!("{}KEYSTORE.ZEROCHAFF,{}", BOOKEND_START, BOOKEND_END);
|
||||||
// panic if we're not in developer mode
|
// panic if we're not in developer mode
|
||||||
assert!(
|
assert!(
|
||||||
self.owc.get(DEVELOPER_MODE).unwrap() != 0,
|
self.owc.get(DEVELOPER_MODE).unwrap() != 0,
|
||||||
"Either we have the most improbable chaff, or (more likely) the chaff is set to all 0's"
|
"Either we have the most improbable chaff, or (more likely) the chaff is set to all 0's"
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
log::info!("{}KEYSTORE.OKCHAFF,{}", BOOKEND_START, BOOKEND_END);
|
||||||
}
|
}
|
||||||
self.master_key = Some(master_key);
|
self.master_key = Some(master_key);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue