tighten up the on-boarding password flow

- check the password with a double-entry on the first boot
- if we see a blank disk, bypass the usual checks and allow the mount
to fail, then, enter the setup routine.
This commit is contained in:
bunnie 2022-01-06 22:13:00 +08:00
parent 4c927f2c99
commit c046422746
3 changed files with 65 additions and 12 deletions

View file

@ -24,6 +24,16 @@
"zh": "密码错误。 再试一次?",
"en-audio": "Incorrect password. Try again?"
},
"pddb.checkpass": {
"en": "Press any key, then\nre-enter your password\nfor setup confirmation.",
"zh": "第一次使用,再次输入密码",
"en-audio": "First-time setup: Enter password again."
},
"pddb.checkpass_fail": {
"en": "Password mismatch!\nPlease try again.",
"zh": "密码不匹配,请重试.",
"en-audio": "Password mismatch! Please try again."
},
"pddb.badpass_infallible": {
"en": "Incorrect password.\n\nPlease try again.",
"zh": "密码错误。",

View file

@ -498,7 +498,13 @@ impl PddbOs {
}
success
} else {
true // the first password entered is always correct. If you made a typo, nothing we can do about it...
// the system is in a blank state -- use the bogus key so that the later test for
// mounting the PDDB doesn't fail on account of a lack of key matter. We'll deal
// with setting the key correctly later.
self.system_basis_key = Some(system_key);
let cipher = Aes256::new(GenericArray::from_slice(&system_key));
self.cipher_ecb = Some(cipher);
true
}
} else {
true
@ -1189,6 +1195,27 @@ impl PddbOs {
if !self.rootkeys.is_initialized().unwrap() {
return Err(Error::new(ErrorKind::Unsupported, "Root keys are not initialized; cannot format a PDDB without root keys!"));
}
// step 0. If we have a modal, confirm that the password entered was correct with a double-entry.
if let Some(modals) = progress {
let mut success = false;
while !success {
let mut checkblock_a = [0u8; BLOCK_SIZE];
self.rootkeys.decrypt_block(GenericArray::from_mut_slice(&mut checkblock_a));
modals.show_notification(t!("pddb.checkpass", xous::LANG)).expect("notification failed");
self.clear_password();
let mut checkblock_b = [0u8; BLOCK_SIZE];
self.rootkeys.decrypt_block(GenericArray::from_mut_slice(&mut checkblock_b));
if checkblock_a == checkblock_b {
success = true;
} else {
modals.show_notification(t!("pddb.checkpass_fail", xous::LANG)).expect("notification failed");
self.clear_password();
}
}
}
// step 1. Erase the entire PDDB region - leaves the state in all 1's
if !fast {
log::info!("Erasing the PDDB region");

View file

@ -992,7 +992,8 @@ fn xmain() -> ! {
aes_sender = Some(msg.sender);
}
keys.set_ux_password_type(Some(PasswordType::Boot));
password_action.set_action_opcode(Opcode::UxAesPasswordPolicy.to_u32().unwrap());
//password_action.set_action_opcode(Opcode::UxAesPasswordPolicy.to_u32().unwrap()); // skip policy question. it's annoying.
password_action.set_action_opcode(Opcode::UxAesEnsureReturn.to_u32().unwrap());
rootkeys_modal.modify(
Some(ActionType::TextEntry(password_action)),
Some(t!("rootkeys.get_login_password", xous::LANG)), false,
@ -1018,7 +1019,7 @@ fn xmain() -> ! {
xous::return_scalar(msg.sender, 0).unwrap();
}
}),
Some(Opcode::UxAesPasswordPolicy) => {
Some(Opcode::UxAesPasswordPolicy) => { // this is bypassed, it's not useful. You basically always only want to retain the password until sleep.
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap();
@ -1041,17 +1042,32 @@ fn xmain() -> ! {
rootkeys_modal.activate();
},
Some(Opcode::UxAesEnsureReturn) => {
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
if payload.as_str() == t!("rootkeys.policy_keep", xous::LANG) {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep));
} else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) {
/*
{ // in case we want to bring back the policy check
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
if payload.as_str() == t!("rootkeys.policy_keep", xous::LANG) {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep));
} else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) {
keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend));
} else if payload.as_str() == "no change" {
// don't change the policy
} else {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level
}
}*/
{
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear();
// this is a reasonable default policy -- don't bother the user to answer this question all the time.
keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend));
} else if payload.as_str() == "no change" {
// don't change the policy
} else {
keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level
}
keys.set_ux_password_type(None);
if let Some(sender) = aes_sender.take() {
xous::return_scalar(sender, 1).unwrap();