mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add PIN change to the PDDB
This commit is contained in:
parent
7aca2d64b3
commit
4ae3308fbe
5 changed files with 132 additions and 33 deletions
|
|
@ -108,28 +108,28 @@
|
||||||
"en-tts": "No"
|
"en-tts": "No"
|
||||||
},
|
},
|
||||||
"pddb.badpass": {
|
"pddb.badpass": {
|
||||||
"en": "Incorrect password.\n\nTry again?\n",
|
"en": "Incorrect PIN.\n\nTry again?\n",
|
||||||
"ja": "パスワードを認証失敗でした。\n\nもう一度実行しませんか。\n",
|
"ja": "パスワードを認証失敗でした。\n\nもう一度実行しませんか。\n",
|
||||||
"zh": "密码错误。 再试一次?",
|
"zh": "密码错误。 再试一次?",
|
||||||
"en-tts": "Incorrect password. Try again?"
|
"en-tts": "Incorrect PIN. Try again?"
|
||||||
},
|
},
|
||||||
"pddb.checkpass": {
|
"pddb.checkpass": {
|
||||||
"en": "Press any key, then re-enter your password to confirm.",
|
"en": "Press any key, then re-enter your PIN to confirm.",
|
||||||
"ja": "任意キーを押して、パスワードを再入力してセットアップを確認してください。",
|
"ja": "任意キーを押して、パスワードを再入力してセットアップを確認してください。",
|
||||||
"zh": "第一次使用,再次输入密码",
|
"zh": "第一次使用,再次输入密码",
|
||||||
"en-tts": "First-time setup: Enter password again."
|
"en-tts": "First-time setup: Enter PIN again."
|
||||||
},
|
},
|
||||||
"pddb.checkpass_fail": {
|
"pddb.checkpass_fail": {
|
||||||
"en": "Password mismatch!\n\nPlease try again.",
|
"en": "PIN mismatch!\n\nPlease try again.",
|
||||||
"ja": "パスワード一致していません!\n\nもう一度実行しください。",
|
"ja": "パスワード一致していません!\n\nもう一度実行しください。",
|
||||||
"zh": "密码不匹配,请重试.",
|
"zh": "密码不匹配,请重试.",
|
||||||
"en-tts": "Password mismatch! Please try again."
|
"en-tts": "PIN mismatch! Please try again."
|
||||||
},
|
},
|
||||||
"pddb.badpass_infallible": {
|
"pddb.badpass_infallible": {
|
||||||
"en": "Incorrect password.\n\nPlease try again.",
|
"en": "Incorrect PIN.\n\nPlease try again.",
|
||||||
"ja": "パスワードを認証失敗でした。\n\nもう一度実行しください。",
|
"ja": "パスワードを認証失敗でした。\n\nもう一度実行しください。",
|
||||||
"zh": "密码错误。",
|
"zh": "密码错误。",
|
||||||
"en-tts": "Incorrect password. Please try again."
|
"en-tts": "Incorrect PIN. Please try again."
|
||||||
},
|
},
|
||||||
"pddb.requestformat": {
|
"pddb.requestformat": {
|
||||||
"en": "The PDDB needs to be cryptographically formatted. This takes about 15 minutes and can't be interrupted.\n\nProceed?",
|
"en": "The PDDB needs to be cryptographically formatted. This takes about 15 minutes and can't be interrupted.\n\nProceed?",
|
||||||
|
|
@ -203,6 +203,36 @@
|
||||||
"zh": "基础姓名: ",
|
"zh": "基础姓名: ",
|
||||||
"en-tts": "For basis: "
|
"en-tts": "For basis: "
|
||||||
},
|
},
|
||||||
|
"pddb.changepin.mountfirst": {
|
||||||
|
"en": "Unlock the device before changing the PIN",
|
||||||
|
"ja": "PIN を変更する前にデバイスのロックを解除してください",
|
||||||
|
"zh": "在更改 PIN 之前解锁设备",
|
||||||
|
"en-tts": "Unlock the device before changing the PIN"
|
||||||
|
},
|
||||||
|
"pddb.changepin.enter_new_pin": {
|
||||||
|
"en": "Enter your new PIN in the next dialog box.",
|
||||||
|
"ja": "次のダイアログ ボックスに新しい PIN を入力します。",
|
||||||
|
"zh": "在下一个对话框中输入您的新 PIN。",
|
||||||
|
"en-tts": "Enter your new PIN in the next dialog box."
|
||||||
|
},
|
||||||
|
"pddb.changepin.success": {
|
||||||
|
"en": "PIN updated!",
|
||||||
|
"ja": "PIN が更新されました。",
|
||||||
|
"zh": "PIN 已更新!",
|
||||||
|
"en-tts": "PIN updated!"
|
||||||
|
},
|
||||||
|
"pddb.changepin.nochange": {
|
||||||
|
"en": "PIN unchanged.",
|
||||||
|
"ja": "PIN は変更されていません",
|
||||||
|
"zh": "PIN 未更改",
|
||||||
|
"en-tts": "PIN unchanged."
|
||||||
|
},
|
||||||
|
"pddb.menu.change_unlock_pin": {
|
||||||
|
"en": "Change unlock PIN",
|
||||||
|
"ja": "ロック解除暗証番号の変更",
|
||||||
|
"zh": "更改解锁密码",
|
||||||
|
"en-tts": "Change unlock PIN"
|
||||||
|
},
|
||||||
"pddb.menu.listbasis": {
|
"pddb.menu.listbasis": {
|
||||||
"en": "List unlocked bases",
|
"en": "List unlocked bases",
|
||||||
"ja": "ロック解除されたベースをー覧表します",
|
"ja": "ロック解除されたベースをー覧表します",
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,9 @@ pub(crate) enum Opcode {
|
||||||
/// Optimized key listing
|
/// Optimized key listing
|
||||||
ListKeyV2 = 45,
|
ListKeyV2 = 45,
|
||||||
|
|
||||||
|
/// change unlock PIN
|
||||||
|
MenuChangePin = 46,
|
||||||
|
|
||||||
/// This key type could not be decoded
|
/// This key type could not be decoded
|
||||||
InvalidOpcode = u32::MAX as _,
|
InvalidOpcode = u32::MAX as _,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,14 @@ impl Deref for StaticCryptoData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl DerefMut for StaticCryptoData {
|
||||||
|
fn deref_mut(&mut self) -> &mut [u8] {
|
||||||
|
unsafe {
|
||||||
|
core::slice::from_raw_parts_mut(self as *mut StaticCryptoData as *mut u8, size_of::<StaticCryptoData>())
|
||||||
|
as &mut [u8]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(Eq, PartialEq)]
|
||||||
enum DnaMode {
|
enum DnaMode {
|
||||||
Normal,
|
Normal,
|
||||||
|
|
@ -1562,6 +1570,63 @@ impl PddbOs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pw_check(&self, modals: &modals::Modals) -> Result<()> {
|
||||||
|
let mut success = false;
|
||||||
|
while !success {
|
||||||
|
// the "same password check" is accomplished by just encrypting the all-zeros block twice
|
||||||
|
// with the cipher after clearing the password and re-entering it, and then comparing that
|
||||||
|
// the results are identical. The test blocks are never committed or stored anywhere.
|
||||||
|
// The actual creation of the "real" key material is done in step 3.
|
||||||
|
let mut checkblock_a = [0u8; BLOCK_SIZE];
|
||||||
|
self.rootkeys.decrypt_block(GenericArray::from_mut_slice(&mut checkblock_a));
|
||||||
|
|
||||||
|
log::info!("{}PDDB.CHECKPASS,{}", xous::BOOKEND_START, xous::BOOKEND_END);
|
||||||
|
#[cfg(any(target_os = "none", target_os = "xous"))] // skip this dialog in hosted mode
|
||||||
|
modals.show_notification(t!("pddb.checkpass", xous::LANG), None).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 {
|
||||||
|
log::info!("{}PDDB.PWFAIL,{}", xous::BOOKEND_START, xous::BOOKEND_END);
|
||||||
|
modals.show_notification(t!("pddb.checkpass_fail", xous::LANG), None).expect("notification failed");
|
||||||
|
self.clear_password();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if success {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(Error::new(ErrorKind::PermissionDenied, "Password entry failed"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// this function attempts to change the PIN. returns Ok() if changed, error if not.
|
||||||
|
pub(crate) fn pddb_change_pin(&mut self, modals: &modals::Modals) -> Result<()> {
|
||||||
|
if let Some(system_keys) = &self.system_basis_key {
|
||||||
|
// get the new password
|
||||||
|
self.clear_password();
|
||||||
|
modals.show_notification(t!("pddb.changepin.enter_new_pin", xous::LANG), None)
|
||||||
|
.map_err(|_| Error::new(ErrorKind::Other, "Internal error"))?;
|
||||||
|
self.pw_check(modals)?;
|
||||||
|
|
||||||
|
// wrap keys in the new password, and store them to disk
|
||||||
|
let wrapped_key = self.rootkeys.wrap_key(&system_keys.data).expect("Internal error wrapping our encryption key");
|
||||||
|
let wrapped_key_pt = self.rootkeys.wrap_key(&system_keys.pt).expect("Internal error wrapping our encryption key");
|
||||||
|
let mut crypto_keys = StaticCryptoData::default();
|
||||||
|
crypto_keys.deref_mut().copy_from_slice(&self.static_crypto_data_get().deref());
|
||||||
|
assert!(wrapped_key_pt.len() == 40);
|
||||||
|
assert!(wrapped_key.len() == 40);
|
||||||
|
crypto_keys.system_key_pt.copy_from_slice(&wrapped_key_pt);
|
||||||
|
crypto_keys.system_key.copy_from_slice(&wrapped_key);
|
||||||
|
self.patch_keys(crypto_keys.deref(), 0);
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(Error::new(ErrorKind::PermissionDenied, "System basis keys not unlocked"))
|
||||||
|
}
|
||||||
|
}
|
||||||
/// this function is dangerous in that calling it will completely erase all of the previous data
|
/// this function is dangerous in that calling it will completely erase all of the previous data
|
||||||
/// in the PDDB an replace it with a brand-spanking new, blank PDDB.
|
/// in the PDDB an replace it with a brand-spanking new, blank PDDB.
|
||||||
/// The number of servers that can connect to the Spinor crate is strictly tracked, so we borrow a reference
|
/// The number of servers that can connect to the Spinor crate is strictly tracked, so we borrow a reference
|
||||||
|
|
@ -1572,31 +1637,7 @@ impl PddbOs {
|
||||||
}
|
}
|
||||||
// step 0. If we have a modal, confirm that the password entered was correct with a double-entry.
|
// step 0. If we have a modal, confirm that the password entered was correct with a double-entry.
|
||||||
if let Some(modals) = progress {
|
if let Some(modals) = progress {
|
||||||
let mut success = false;
|
self.pw_check(modals)?;
|
||||||
while !success {
|
|
||||||
// the "same password check" is accomplished by just encrypting the all-zeros block twice
|
|
||||||
// with the cipher after clearing the password and re-entering it, and then comparing that
|
|
||||||
// the results are identical. The test blocks are never committed or stored anywhere.
|
|
||||||
// The actual creation of the "real" key material is done in step 3.
|
|
||||||
let mut checkblock_a = [0u8; BLOCK_SIZE];
|
|
||||||
self.rootkeys.decrypt_block(GenericArray::from_mut_slice(&mut checkblock_a));
|
|
||||||
|
|
||||||
log::info!("{}PDDB.CHECKPASS,{}", xous::BOOKEND_START, xous::BOOKEND_END);
|
|
||||||
#[cfg(any(target_os = "none", target_os = "xous"))] // skip this dialog in hosted mode
|
|
||||||
modals.show_notification(t!("pddb.checkpass", xous::LANG), None).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 {
|
|
||||||
log::info!("{}PDDB.PWFAIL,{}", xous::BOOKEND_START, xous::BOOKEND_END);
|
|
||||||
modals.show_notification(t!("pddb.checkpass_fail", xous::LANG), None).expect("notification failed");
|
|
||||||
self.clear_password();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 1. Erase the entire PDDB region - leaves the state in all 1's
|
// step 1. Erase the entire PDDB region - leaves the state in all 1's
|
||||||
|
|
|
||||||
|
|
@ -1419,6 +1419,22 @@ fn wrapped_main() -> ! {
|
||||||
}
|
}
|
||||||
modals.show_notification(¬e, None).expect("couldn't show basis list");
|
modals.show_notification(¬e, None).expect("couldn't show basis list");
|
||||||
},
|
},
|
||||||
|
Opcode::MenuChangePin => {
|
||||||
|
if basis_cache.basis_count() == 0 {
|
||||||
|
modals.show_notification(t!("pddb.changepin.mountfirst", xous::LANG), None)
|
||||||
|
.expect("couldn't show notification");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
match pddb_os.pddb_change_pin(&modals) {
|
||||||
|
Ok(_) => modals.show_notification(t!("pddb.changepin.success", xous::LANG), None)
|
||||||
|
.expect("couldn't show notification"),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Error changing PIN: {:?}", e);
|
||||||
|
modals.show_notification(t!("pddb.changepin.nochange", xous::LANG), None)
|
||||||
|
.expect("couldn't show notification");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
Opcode::RekeyPddb => {
|
Opcode::RekeyPddb => {
|
||||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
let rekey_op = buffer.to_original::<PddbRekeyOp, _>().unwrap();
|
let rekey_op = buffer.to_original::<PddbRekeyOp, _>().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,15 @@ pub(crate) fn pddb_menu(conn: xous::CID) {
|
||||||
close_on_select: true,
|
close_on_select: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
menu_items.push(
|
||||||
|
MenuItem {
|
||||||
|
name: String::from_str(t!("pddb.menu.change_unlock_pin", xous::LANG)),
|
||||||
|
action_conn: Some(conn),
|
||||||
|
action_opcode: Opcode::MenuChangePin.to_u32().unwrap(),
|
||||||
|
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||||
|
close_on_select: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
menu_items.push(MenuItem {
|
menu_items.push(MenuItem {
|
||||||
name: String::from_str(t!("mainmenu.closemenu", xous::LANG)),
|
name: String::from_str(t!("mainmenu.closemenu", xous::LANG)),
|
||||||
action_conn: None,
|
action_conn: None,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue