mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
Merge branch 'main' into rustls-exp2
This commit is contained in:
commit
a8f2c99b6c
11 changed files with 281 additions and 92 deletions
|
|
@ -240,6 +240,9 @@ perform the Xous firmware upgrade. This requires running manual update commands,
|
|||
- iterator form for PNG decoding (thanks to nworbnhoj for a ton of work to get that together)
|
||||
- memory usage is well-constrained now, and suitable for everyday use
|
||||
- primary limit to PNG decode speed is read speed over e.g. TCP
|
||||
- Feature #211 (change unlock PIN) implemented
|
||||
- The menu item is in the PDDB Submenu->Change unlock PIN
|
||||
- The redundant boot PIN setting during first power on setup is also removed. Only the one you set when you init the PDDB matters.
|
||||
|
||||
## Roadmap to 1.0
|
||||
|
||||
|
|
|
|||
|
|
@ -108,28 +108,28 @@
|
|||
"en-tts": "No"
|
||||
},
|
||||
"pddb.badpass": {
|
||||
"en": "Incorrect password.\n\nTry again?\n",
|
||||
"en": "Incorrect PIN.\n\nTry again?\n",
|
||||
"ja": "パスワードを認証失敗でした。\n\nもう一度実行しませんか。\n",
|
||||
"zh": "密码错误。 再试一次?",
|
||||
"en-tts": "Incorrect password. Try again?"
|
||||
"en-tts": "Incorrect PIN. Try again?"
|
||||
},
|
||||
"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": "任意キーを押して、パスワードを再入力してセットアップを確認してください。",
|
||||
"zh": "第一次使用,再次输入密码",
|
||||
"en-tts": "First-time setup: Enter password again."
|
||||
"en-tts": "First-time setup: Enter PIN again."
|
||||
},
|
||||
"pddb.checkpass_fail": {
|
||||
"en": "Password mismatch!\n\nPlease try again.",
|
||||
"en": "PIN mismatch!\n\nPlease try again.",
|
||||
"ja": "パスワード一致していません!\n\nもう一度実行しください。",
|
||||
"zh": "密码不匹配,请重试.",
|
||||
"en-tts": "Password mismatch! Please try again."
|
||||
"en-tts": "PIN mismatch! Please try again."
|
||||
},
|
||||
"pddb.badpass_infallible": {
|
||||
"en": "Incorrect password.\n\nPlease try again.",
|
||||
"en": "Incorrect PIN.\n\nPlease try again.",
|
||||
"ja": "パスワードを認証失敗でした。\n\nもう一度実行しください。",
|
||||
"zh": "密码错误。",
|
||||
"en-tts": "Incorrect password. Please try again."
|
||||
"en-tts": "Incorrect PIN. Please try again."
|
||||
},
|
||||
"pddb.requestformat": {
|
||||
"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": "基础姓名: ",
|
||||
"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": {
|
||||
"en": "List unlocked bases",
|
||||
"ja": "ロック解除されたベースをー覧表します",
|
||||
|
|
|
|||
|
|
@ -210,6 +210,9 @@ pub(crate) enum Opcode {
|
|||
/// Optimized key listing
|
||||
ListKeyV2 = 45,
|
||||
|
||||
/// change unlock PIN
|
||||
MenuChangePin = 46,
|
||||
|
||||
/// This key type could not be decoded
|
||||
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)]
|
||||
enum DnaMode {
|
||||
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
|
||||
/// 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
|
||||
|
|
@ -1572,31 +1637,7 @@ impl PddbOs {
|
|||
}
|
||||
// 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 {
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
self.pw_check(modals)?;
|
||||
}
|
||||
|
||||
// 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");
|
||||
},
|
||||
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 => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().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,
|
||||
}
|
||||
);
|
||||
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 {
|
||||
name: String::from_str(t!("mainmenu.closemenu", xous::LANG)),
|
||||
action_conn: None,
|
||||
|
|
|
|||
|
|
@ -95,18 +95,24 @@
|
|||
"zh": "执行备份的内部错误。 进程中止。",
|
||||
"en-tts": "Internal error performing backup. Process aborted."
|
||||
},
|
||||
"rootkeys.bootpass": {
|
||||
"en": "Create a PIN code for device unlock.",
|
||||
"ja": "デバイスのロックを解除するためのPINコードを作成します。",
|
||||
"zh": "输入密码 解锁 安全含义:低",
|
||||
"en-tts": "Enter unlock password"
|
||||
},
|
||||
"rootkeys.updatepass": {
|
||||
"rootkeys.updatefirstpass": {
|
||||
"en": "⚠ Critical Password ⚠\nCreate a strong root password for authorizing system updates.",
|
||||
"ja": "重要なパスワード\nシステムアップデートを認証するための強力なパスフレーズを作成します。",
|
||||
"zh": "输入密码 软件更新 安全含义:至关重要 ",
|
||||
"en-tts": "Enter a root password. This should be a strong password."
|
||||
},
|
||||
"rootkeys.updatepass": {
|
||||
"en": "⚠ Critical Password ⚠\nPlease confirm the root password.",
|
||||
"ja": "ルートパスワードを確認してください。",
|
||||
"zh": "请确认root密码。",
|
||||
"en-tts": "Please confirm the root password."
|
||||
},
|
||||
"rootkeys.updatepass_fail": {
|
||||
"en": "Passwords did not match. Try again?",
|
||||
"ja": "パスワードが間違っています。 再試行?",
|
||||
"zh": "密码不匹配。 再试一次?",
|
||||
"en-tts": "Passwords did not match. Try again?"
|
||||
},
|
||||
"rootkeys.blind_update": {
|
||||
"en": "No device keys detected. Shall we copy the staged gateware anyways, overwriting the current image?",
|
||||
"ja": "ルートキーが検出されませんでした。 とにかくステージングされたゲートウェアをコピーして、現在のイメージを上書きしませんか?",
|
||||
|
|
@ -126,10 +132,10 @@
|
|||
"en-tts": "Device keys already initialized."
|
||||
},
|
||||
"rootkeys.confirm": {
|
||||
"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": "Setup passwords for Precursor. You will create two passwords, a PIN code, and a root password."
|
||||
"en": "🔐 Setup passwords for Precursor 🔐\n\nYou will be prompted for a root passphrase that must be secure and cannot be changed.\n\nAre you ready?",
|
||||
"ja": "🔐 Precursor のパスワードを設定する 🔐\n\nルート パスフレーズの入力を求めるメッセージが表示されます。ルート パスフレーズは安全である必要があり、変更することはできません。\n\n準備はできていますか?",
|
||||
"zh": "🔐 为 Precursor 设置密码 🔐\n\n系统将提示您输入必须安全且无法更改的根密码。\n\n您准备好了吗?",
|
||||
"en-tts": "Setup passwords for Precursor\n\nYou will be prompted for a root passphrase that must be secure and cannot be changed.\n\nAre you ready?"
|
||||
},
|
||||
"rootkeys.confirm.yes": {
|
||||
"en": "I'm ready!",
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ pub(crate) enum Opcode {
|
|||
|
||||
/// attempt to initialize keys on a brand new system. Does nothing if the keys are already provisioned.
|
||||
UxTryInitKeys = 9,
|
||||
UxInitBootPasswordReturn = 10,
|
||||
UxInitUpdateFirstPasswordReturn = 10,
|
||||
UxInitUpdatePasswordReturn = 11,
|
||||
|
||||
/// provision a gateware update with our secret data
|
||||
|
|
|
|||
|
|
@ -722,12 +722,12 @@ impl<'a> RootKeys {
|
|||
|
||||
/// Plaintext password is passed as a &str. Any copies internally are destroyed. Caller is responsible for destroying the &str original.
|
||||
/// Performs a bcrypt hash of the password, with the currently set salt; does not store the plaintext after exit.
|
||||
pub fn hash_and_save_password(&mut self, pw: &str) {
|
||||
pub fn hash_and_save_password(&mut self, pw: &str, verify: bool) -> bool {
|
||||
let pw_type = if let Some(cur_type) = self.cur_password_type {
|
||||
cur_type
|
||||
} else {
|
||||
log::error!("got an unexpected password from the UX");
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
let mut hashed_password: [u8; 24] = [0; 24];
|
||||
let mut salt = self.get_salt();
|
||||
|
|
@ -751,19 +751,51 @@ impl<'a> RootKeys {
|
|||
let digest = hasher.finalize();
|
||||
|
||||
let pcache_ptr: *mut PasswordCache = self.pass_cache.as_mut_ptr() as *mut PasswordCache;
|
||||
unsafe {
|
||||
match pw_type {
|
||||
PasswordType::Boot => {
|
||||
for (&src, dst) in digest.iter().zip((*pcache_ptr).hashed_boot_pw.iter_mut()) {
|
||||
*dst = src;
|
||||
if !verify {
|
||||
unsafe {
|
||||
match pw_type {
|
||||
PasswordType::Boot => {
|
||||
for (&src, dst) in digest.iter().zip((*pcache_ptr).hashed_boot_pw.iter_mut()) {
|
||||
*dst = src;
|
||||
}
|
||||
(*pcache_ptr).hashed_boot_pw_valid = 1;
|
||||
}
|
||||
PasswordType::Update => {
|
||||
for (&src, dst) in digest.iter().zip((*pcache_ptr).hashed_update_pw.iter_mut()) {
|
||||
*dst = src;
|
||||
}
|
||||
(*pcache_ptr).hashed_update_pw_valid = 1;
|
||||
}
|
||||
(*pcache_ptr).hashed_boot_pw_valid = 1;
|
||||
}
|
||||
PasswordType::Update => {
|
||||
for (&src, dst) in digest.iter().zip((*pcache_ptr).hashed_update_pw.iter_mut()) {
|
||||
*dst = src;
|
||||
}
|
||||
true
|
||||
} else {
|
||||
unsafe {
|
||||
match pw_type {
|
||||
PasswordType::Boot => {
|
||||
if (*pcache_ptr).hashed_boot_pw_valid == 1 {
|
||||
for (&src, &dst) in digest.iter().zip((*pcache_ptr).hashed_boot_pw.iter()) {
|
||||
if dst != src {
|
||||
return false
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
PasswordType::Update => {
|
||||
if (*pcache_ptr).hashed_update_pw_valid == 1 {
|
||||
for (&src, &dst) in digest.iter().zip((*pcache_ptr).hashed_update_pw.iter()) {
|
||||
if dst != src {
|
||||
return false
|
||||
}
|
||||
}
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
(*pcache_ptr).hashed_update_pw_valid = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1063,7 +1095,6 @@ impl<'a> RootKeys {
|
|||
// extract the update password key from the cache, and apply it to the private key
|
||||
#[cfg(feature = "hazardous-debug")]
|
||||
{
|
||||
log::debug!("cached boot passwords {:x?}", pcache.hashed_boot_pw);
|
||||
log::debug!("cached update password: {:x?}", pcache.hashed_update_pw);
|
||||
}
|
||||
// private key must XOR with password before storing
|
||||
|
|
@ -1081,30 +1112,28 @@ impl<'a> RootKeys {
|
|||
.zip(self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[KeyRomLocs::SELFSIGN_PRIVKEY as usize..KeyRomLocs::SELFSIGN_PRIVKEY as usize + 256/(size_of::<u32>()*8)].iter_mut()) {
|
||||
*dst = u32::from_be_bytes(src.try_into().unwrap())
|
||||
}
|
||||
#[cfg(feature = "hazardous-debug")]
|
||||
log::debug!("private_key_enc: {:?}", private_key_enc);
|
||||
|
||||
pb.set_percentage(10);
|
||||
|
||||
// generate and store a root key (aka boot key), this is what is unlocked by the "boot password"
|
||||
// ironically, it's a "lower security" key because it just acts as a gatekeeper to further
|
||||
// keys that would have a stronger password applied to them, based upon the importance of the secret
|
||||
// think of this more as a user PIN login confirmation, than as a significant cryptographic event
|
||||
// generate the "boot key". This is just a random number that eventually gets XOR'd with a PIN
|
||||
// by the PDDB to derive the final PDDB .System unlock key.
|
||||
let mut boot_key_enc: [u8; 32] = [0; 32];
|
||||
for (dst, key) in
|
||||
boot_key_enc.chunks_mut(4).into_iter()
|
||||
.zip(pcache.hashed_boot_pw.chunks(4).into_iter()) {
|
||||
for dst in
|
||||
boot_key_enc.chunks_mut(4).into_iter() {
|
||||
let key_word = self.trng.get_u32().unwrap().to_be_bytes();
|
||||
// just unroll this loop, it's fast and easy enough
|
||||
(*dst)[0] = key[0] ^ key_word[0];
|
||||
(*dst)[1] = key[1] ^ key_word[1];
|
||||
(*dst)[2] = key[2] ^ key_word[2];
|
||||
(*dst)[3] = key[3] ^ key_word[3];
|
||||
// also note that interestingly, we don't have to XOR it with the hashed boot password --
|
||||
// this key isn't used by this routine, just initialized, so really, it only matters to
|
||||
// XOR it with the password when you use it the first time to encrypt something.
|
||||
(*dst)[0] = key_word[0];
|
||||
(*dst)[1] = key_word[1];
|
||||
(*dst)[2] = key_word[2];
|
||||
(*dst)[3] = key_word[3];
|
||||
}
|
||||
#[cfg(feature = "hazardous-debug")]
|
||||
log::debug!("boot_key_enc: {:?}", boot_key_enc);
|
||||
|
||||
// store the boot key to the keyrom staging area
|
||||
for (src, dst) in private_key_enc.chunks(4).into_iter()
|
||||
for (src, dst) in boot_key_enc.chunks(4).into_iter()
|
||||
.zip(self.sensitive_data.borrow_mut().as_slice_mut::<u32>()[KeyRomLocs::USER_KEY as usize..KeyRomLocs::USER_KEY as usize + 256/(size_of::<u32>()*8)].iter_mut()) {
|
||||
*dst = u32::from_be_bytes(src.try_into().unwrap())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,8 +147,9 @@ mod implementation {
|
|||
pub fn update_policy(&mut self, policy: Option<PasswordRetentionPolicy>) {
|
||||
log::info!("policy updated: {:?}", policy);
|
||||
}
|
||||
pub fn hash_and_save_password(&mut self, pw: &str) {
|
||||
pub fn hash_and_save_password(&mut self, pw: &str, _verify: bool) -> bool {
|
||||
log::info!("got password plaintext: {}", pw);
|
||||
true
|
||||
}
|
||||
pub fn set_ux_password_type(&mut self, cur_type: Option<PasswordType>) {
|
||||
self.password_type = cur_type;
|
||||
|
|
@ -197,6 +198,7 @@ mod implementation {
|
|||
}
|
||||
pub fn purge_password(&mut self, _ptype: PasswordType) {}
|
||||
pub fn purge_user_password(&mut self, _ptype: AesRootkeyType) {}
|
||||
pub fn purge_sensitive_data(&mut self) {}
|
||||
|
||||
pub fn get_ux_password_type(&self) -> Option<PasswordType> {self.password_type}
|
||||
pub fn finish_key_init(&mut self) {}
|
||||
|
|
@ -470,7 +472,7 @@ fn main() -> ! {
|
|||
true,
|
||||
TextEntryVisibility::LastChars,
|
||||
main_cid,
|
||||
Opcode::UxInitBootPasswordReturn.to_u32().unwrap(),
|
||||
Opcode::UxInitUpdateFirstPasswordReturn.to_u32().unwrap(),
|
||||
vec![TextEntryPayload::new()],
|
||||
None,
|
||||
);
|
||||
|
|
@ -481,7 +483,7 @@ fn main() -> ! {
|
|||
let mut rootkeys_modal = Modal::new(
|
||||
gam::ROOTKEY_MODAL_NAME,
|
||||
ActionType::TextEntry(password_action.clone()),
|
||||
Some(t!("rootkeys.bootpass", xous::LANG)),
|
||||
Some(t!("rootkeys.updatefirstpass", xous::LANG)),
|
||||
None,
|
||||
GlyphStyle::Regular,
|
||||
8
|
||||
|
|
@ -624,29 +626,29 @@ fn main() -> ! {
|
|||
}
|
||||
// setup_key_init() prepares the salt and other items necessary to receive a password safely
|
||||
keys.setup_key_init();
|
||||
// request the boot password first
|
||||
keys.set_ux_password_type(Some(PasswordType::Boot));
|
||||
// request the update password first
|
||||
keys.set_ux_password_type(Some(PasswordType::Update));
|
||||
// pop up our private password dialog box
|
||||
password_action.set_action_opcode(Opcode::UxInitBootPasswordReturn.to_u32().unwrap());
|
||||
password_action.set_action_opcode(Opcode::UxInitUpdateFirstPasswordReturn.to_u32().unwrap());
|
||||
rootkeys_modal.modify(
|
||||
Some(ActionType::TextEntry(password_action.clone())),
|
||||
Some(t!("rootkeys.bootpass", xous::LANG)), false,
|
||||
Some(t!("rootkeys.updatefirstpass", xous::LANG)), false,
|
||||
None, true, None
|
||||
);
|
||||
#[cfg(feature="tts")]
|
||||
tts.tts_blocking(t!("rootkeys.bootpass", xous::LANG)).unwrap();
|
||||
log::info!("{}ROOTKEY.BOOTPW,{}", xous::BOOKEND_START, xous::BOOKEND_END);
|
||||
tts.tts_blocking(t!("rootkeys.updatefirstpass", xous::LANG)).unwrap();
|
||||
log::info!("{}ROOTKEY.UPDPW,{}", xous::BOOKEND_START, xous::BOOKEND_END);
|
||||
rootkeys_modal.activate();
|
||||
}
|
||||
},
|
||||
Some(Opcode::UxInitBootPasswordReturn) => {
|
||||
Some(Opcode::UxInitUpdateFirstPasswordReturn) => {
|
||||
// assume:
|
||||
// - setup_key_init has also been called (exactly once, before anything happens)
|
||||
// - set_ux_password_type has been called already
|
||||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str(), false);
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
|
||||
|
|
@ -667,7 +669,56 @@ fn main() -> ! {
|
|||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
if !keys.hash_and_save_password(plaintext_pw.first().as_str(), true) {
|
||||
// password did not verify
|
||||
modals.add_list_item(t!("rootkeys.gwup.yes", xous::LANG)).expect("modals error");
|
||||
modals.add_list_item(t!("rootkeys.gwup.no", xous::LANG)).expect("modals error");
|
||||
match modals.get_radiobutton(t!("rootkeys.updatepass_fail", xous::LANG)) {
|
||||
Ok(response) => {
|
||||
if response == t!("rootkeys.gwup.yes", xous::LANG) {
|
||||
keys.purge_password(PasswordType::Update);
|
||||
// request the update password first
|
||||
keys.set_ux_password_type(Some(PasswordType::Update));
|
||||
// pop up our private password dialog box
|
||||
password_action.set_action_opcode(Opcode::UxInitUpdateFirstPasswordReturn.to_u32().unwrap());
|
||||
rootkeys_modal.modify(
|
||||
Some(ActionType::TextEntry(password_action.clone())),
|
||||
Some(t!("rootkeys.updatefirstpass", xous::LANG)), false,
|
||||
None, true, None
|
||||
);
|
||||
#[cfg(feature="tts")]
|
||||
tts.tts_blocking(t!("rootkeys.updatefirstpass", xous::LANG)).unwrap();
|
||||
log::info!("{}ROOTKEY.UPDPW,{}", xous::BOOKEND_START, xous::BOOKEND_END);
|
||||
rootkeys_modal.activate();
|
||||
continue;
|
||||
} else {
|
||||
// abort
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
keys.purge_password(PasswordType::Update);
|
||||
keys.purge_sensitive_data();
|
||||
susres.set_suspendable(true).expect("couldn't unblock suspend/resume");
|
||||
if let Some(dr) = deferred_response.take() {
|
||||
xous::return_scalar(dr, 0).unwrap();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
log::error!("get_radiobutton failed");
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
keys.purge_password(PasswordType::Update);
|
||||
keys.purge_sensitive_data();
|
||||
susres.set_suspendable(true).expect("couldn't unblock suspend/resume");
|
||||
if let Some(dr) = deferred_response.take() {
|
||||
xous::return_scalar(dr, 0).unwrap();
|
||||
}
|
||||
continue;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
|
||||
|
|
@ -946,7 +997,7 @@ fn main() -> ! {
|
|||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str(), false);
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
// indicate that there should be no change to the policy
|
||||
|
|
@ -1034,7 +1085,7 @@ fn main() -> ! {
|
|||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str(), false);
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
|
||||
|
|
@ -1130,7 +1181,7 @@ fn main() -> ! {
|
|||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str(), false);
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
|
||||
|
|
@ -1170,7 +1221,7 @@ fn main() -> ! {
|
|||
{
|
||||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str(), false);
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
|
||||
|
|
@ -1259,7 +1310,7 @@ fn main() -> ! {
|
|||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str(), false);
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
send_message(main_cid,
|
||||
|
|
@ -1373,7 +1424,7 @@ fn main() -> ! {
|
|||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str(), false);
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
keys.set_ux_password_type(None);
|
||||
|
|
@ -1554,7 +1605,7 @@ fn main() -> ! {
|
|||
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
|
||||
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str());
|
||||
keys.hash_and_save_password(plaintext_pw.first().as_str(), false);
|
||||
plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
|
||||
buf.volatile_clear();
|
||||
keys.set_ux_password_type(None);
|
||||
|
|
|
|||
|
|
@ -192,6 +192,7 @@ def main():
|
|||
bcrypter = bcrypt.BCrypt()
|
||||
# logging.debug("{}".format(boot_pw_array[:pw_len]))
|
||||
logging.debug("user_key_enc: {}".format(list(user_key_enc)))
|
||||
logging.debug("private_key_enc: {}".format(list(get_key(8, keyrom, 32))))
|
||||
logging.debug("salt: {}".format(list(pepper)))
|
||||
hashed_pw = bcrypter.crypt_raw(boot_pw_array[:pw_len], pepper, 7)
|
||||
logging.debug("hashed_pw: {}".format(list(hashed_pw)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue