reset "don't ask again" flag for password creation during factory test

this facility is necessary in case a worker accidentally picks
the wrong setting, disabling the feature for the device. When
the factory test completes, a call is made to reset the parameter.

This was a slightly complicated affair because the the don't ask
flag is contained within the rootkeys enclave itself, and we can't
just give access to rootkeys willy-nilly. So the flag is passed
through the PDDB and then to the rootkeys enclave. It's not harmful
to have it reset by an unauthorized actor; the pop-up will not
happen if passwords are, in fact, already set.
This commit is contained in:
bunnie 2022-07-19 23:57:25 +08:00
parent 593928bd75
commit 6f10061653
10 changed files with 44 additions and 2 deletions

View file

@ -201,6 +201,9 @@ pub(crate) enum Opcode {
/// Rekey the PDDB
RekeyPddb = 42,
/// Reset "don't ask to init root keys" flag - pass-through to root keys object - for end of OQC test
ResetDontAskInit = 43,
/// This key type could not be decoded
InvalidOpcode = u32::MAX as _,
}

View file

@ -2302,6 +2302,9 @@ impl PddbOs {
}
}
pub(crate) fn reset_dont_ask_init(&self) {
self.rootkeys.do_reset_dont_ask_init();
}
//-------------------------------- TESTING -----------------------------------------
// always gated behind a feature flag. Includes routines that are nonsensicle in normal operation at best,
// and very dangerous from a security perspective at worst.

View file

@ -628,6 +628,13 @@ impl Pddb {
panic!("Internal error: wrong return code for is_efuse_secured()");
}
}
/// Reset the "don't ask to init root keys" flag. Used primarily by the OQC test routine to reset this in case
/// a worker accidentally set it during testing.
pub fn reset_dont_ask_init(&self) {
send_message(self.conn,
Message::new_blocking_scalar(Opcode::ResetDontAskInit.to_usize().unwrap(), 0, 0, 0, 0)
).expect("couldn't send ResetDontAskInit");
}
/// Rekey the PDDB. This can be a very long-running blocking operation that will definitely.
/// interrupt normal user flow.
pub fn rekey_pddb(&self, op: PddbRekeyOp) -> Result<()> {

View file

@ -1396,6 +1396,10 @@ fn wrapped_main() -> ! {
let result = basis_cache.rekey(&mut pddb_os, rekey_op);
buffer.replace(result).unwrap();
}
Opcode::ResetDontAskInit => {
pddb_os.reset_dont_ask_init();
xous::return_scalar(msg.sender, 1).ok();
}
#[cfg(not(any(target_os = "none", target_os = "xous")))]
Opcode::DangerousDebug => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };

View file

@ -126,10 +126,10 @@
"en-tts": "Device keys already initialized."
},
"rootkeys.confirm": {
"en": "🔐 Create passwords for Precursor 🔐\n\nYou will be prompted for two passwords:\n\t1. Device unlock PIN code\n\t2. Root passphrase.\n\nAre you ready?",
"en": "🔐 Setup passwords for Precursor 🔐\n\nYou will be prompted for two passwords:\n\t1. Device unlock PIN code\n\t2. Root passphrase.\n\nAre you ready?",
"ja": "これにより、Precursorデバイスのルートキーが初期化されます。\n\n2つのパスワードの入力を求められます。\n\t1.デバイスのロック解除PINコード\n\t2.システムアップデートパスフレーズ。\n\n準備はいいですか?",
"zh": "仅当您准备好信 任此设备时才 应继续",
"en-tts": "Create passwords for Precursor. You will create two passwords, a PIN code, and a root password."
"en-tts": "Setup passwords for Precursor. You will create two passwords, a PIN code, and a root password."
},
"rootkeys.confirm.yes": {
"en": "I'm ready!",

View file

@ -99,6 +99,8 @@ pub(crate) enum Opcode {
EraseBackupBlock = 45,
/// Checks to see if "don't ask me about updates" is set
IsDontAskSet = 46,
/// Resets the dont ask bit. Mainly for use by the OQC testing routine
ResetDontAsk = 47,
}
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive, PartialEq, Eq)]

View file

@ -2552,6 +2552,14 @@ impl<'a> RootKeys {
self.gateware().len() as u32 - 4,
).expect("couldn't erase backup region");
}
pub fn reset_dont_ask_init(&mut self) {
self.spinor.patch(
self.gateware(),
self.gateware_base(),
&[0xffu8; 4],
self.gateware().len() as u32 - 4,
).expect("couldn't erase backup region");
}
pub fn read_backup_header(&mut self) -> Option<BackupHeader> {
let kernel = self.kernel();
let backup = &kernel[KERNEL_BACKUP_OFFSET as usize..KERNEL_BACKUP_OFFSET as usize + size_of::<BackupHeader>()];

View file

@ -153,6 +153,12 @@ impl RootKeys {
0, 0, 0, 0)
).expect("couldn't send message to root keys");
}
pub fn do_reset_dont_ask_init(&self) {
send_message(self.conn,
Message::new_blocking_scalar(Opcode::ResetDontAsk.to_usize().unwrap(),
0, 0, 0, 0)
).expect("couldn't send message to root keys");
}
/// Returns the raw, unchecked restore header. Further checking may be done at the restore point,
/// but the purpose of this is to just decide if we should even try to initiate a restore.
pub fn get_restore_header(&self) -> Result<Option<BackupHeader>, xous::Error> {

View file

@ -371,6 +371,7 @@ mod implementation {
}
pub fn is_dont_ask_init_set(&self) -> bool {false}
pub fn set_dont_ask_init(&self) {}
pub fn reset_dont_ask_init(&mut self) {}
}
}
@ -1664,6 +1665,10 @@ fn main() -> ! {
xous::return_scalar(msg.sender, 0).ok();
}
}),
Some(Opcode::ResetDontAsk) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
keys.reset_dont_ask_init();
xous::return_scalar(msg.sender, 1).ok();
}),
Some(Opcode::TestUx) => msg_blocking_scalar_unpack!(msg, _arg, _, _, _, {
// dummy test for now
xous::return_scalar(msg.sender, 1234).unwrap();

View file

@ -581,6 +581,10 @@ impl<'a> ShellCmdApi<'a> for Test {
wifi_tries += 1;
}
log::info!("Resetting the don't ask flag for initializing root keys");
let pddb = pddb::Pddb::new();
pddb.reset_dont_ask_init();
AUDIO_OQC.store(true, Ordering::Relaxed);
self.freq = 659.25;
self.left_play = true;