fix password entry to work with the new return type

also requires a call to `reset_action_payloads` for the
number of field elements to be recorded correctly!
This commit is contained in:
bunnie 2022-04-22 17:43:26 +08:00
parent 55197e97f4
commit 34c2ffe1a3
2 changed files with 32 additions and 30 deletions

View file

@ -64,7 +64,7 @@ pub(crate) fn password_ux_manager(
let ux_cid = xous::connect(ux_sid).unwrap(); let ux_cid = xous::connect(ux_sid).unwrap();
// create a thread that just handles the redrawing requests // create a thread that just handles the redrawing requests
// build the core data structure here // build the core data structure here
let password_action = TextEntry::new( let mut password_action = TextEntry::new(
true, true,
TextEntryVisibility::LastChars, TextEntryVisibility::LastChars,
ux_cid, ux_cid,
@ -72,6 +72,7 @@ pub(crate) fn password_ux_manager(
vec![TextEntryPayload::new()], vec![TextEntryPayload::new()],
None, None,
); );
password_action.reset_action_payloads(1, None);
let mut pddb_modal = let mut pddb_modal =
Modal::new( Modal::new(
@ -112,12 +113,12 @@ pub(crate) fn password_ux_manager(
}, },
Some(PwManagerOpcode::PwReturn) => { Some(PwManagerOpcode::PwReturn) => {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
if let Some(mut response) = dr.take() { if let Some(mut response) = dr.take() {
let mut buffer = unsafe { Buffer::from_memory_message_mut(response.body.memory_message_mut().unwrap()) }; let mut buffer = unsafe { Buffer::from_memory_message_mut(response.body.memory_message_mut().unwrap()) };
let mut request = buffer.to_original::<BasisRequestPassword, _>().unwrap(); let mut request = buffer.to_original::<BasisRequestPassword, _>().unwrap();
request.plaintext_pw = Some(xous_ipc::String::from_str(pw.as_str())); request.plaintext_pw = Some(xous_ipc::String::from_str(pw.first().as_str()));
// return the password to the caller // return the password to the caller
buffer.replace(request).unwrap(); buffer.replace(request).unwrap();
// response goes out of scope here and calls Drop which returns the message // response goes out of scope here and calls Drop which returns the message
@ -125,7 +126,7 @@ pub(crate) fn password_ux_manager(
log::error!("Password return received, but no deferred response on record"); log::error!("Password return received, but no deferred response on record");
} }
pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
}, },
Some(PwManagerOpcode::ModalRedraw) => { Some(PwManagerOpcode::ModalRedraw) => {

View file

@ -196,6 +196,7 @@ mod implementation {
false false
} }
pub fn is_pcache_boot_password_valid(&self) -> bool { pub fn is_pcache_boot_password_valid(&self) -> bool {
// set this to `false` to test password boxes in hosted mode
true true
} }
pub fn fpga_key_source(&self) -> FpgaKeySource { pub fn fpga_key_source(&self) -> FpgaKeySource {
@ -370,6 +371,7 @@ fn xmain() -> ! {
vec![TextEntryPayload::new()], vec![TextEntryPayload::new()],
None, None,
); );
password_action.reset_action_payloads(1, None);
let mut dismiss_modal_action = Notification::new(main_cid, Opcode::UxGutter.to_u32().unwrap()); let mut dismiss_modal_action = Notification::new(main_cid, Opcode::UxGutter.to_u32().unwrap());
dismiss_modal_action.set_is_password(true); dismiss_modal_action.set_is_password(true);
@ -506,10 +508,10 @@ fn xmain() -> ! {
// - setup_key_init has also been called (exactly once, before anything happens) // - setup_key_init has also been called (exactly once, before anything happens)
// - set_ux_password_type has been called already // - set_ux_password_type has been called already
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str()); keys.hash_and_save_password(plaintext_pw.first().as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
keys.set_ux_password_type(Some(PasswordType::Update)); keys.set_ux_password_type(Some(PasswordType::Update));
@ -526,10 +528,10 @@ fn xmain() -> ! {
}, },
Some(Opcode::UxInitUpdatePasswordReturn) => { Some(Opcode::UxInitUpdatePasswordReturn) => {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str()); keys.hash_and_save_password(plaintext_pw.first().as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
keys.set_ux_password_type(None); keys.set_ux_password_type(None);
@ -723,10 +725,10 @@ fn xmain() -> ! {
} }
Some(Opcode::UxUpdateGwPasswordReturn) => { Some(Opcode::UxUpdateGwPasswordReturn) => {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str()); keys.hash_and_save_password(plaintext_pw.first().as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
// indicate that there should be no change to the policy // indicate that there should be no change to the policy
let payload = gam::RadioButtonPayload::new(t!("rootkeys.policy_suspend", xous::LANG)); let payload = gam::RadioButtonPayload::new(t!("rootkeys.policy_suspend", xous::LANG));
@ -800,10 +802,10 @@ fn xmain() -> ! {
}, },
Some(Opcode::UxSignXousPasswordReturn) => { Some(Opcode::UxSignXousPasswordReturn) => {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str()); keys.hash_and_save_password(plaintext_pw.first().as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
let payload = gam::RadioButtonPayload::new(t!("rootkeys.policy_suspend", xous::LANG)); let payload = gam::RadioButtonPayload::new(t!("rootkeys.policy_suspend", xous::LANG));
@ -892,10 +894,10 @@ fn xmain() -> ! {
}), }),
Some(Opcode::UxAesPasswordPolicy) => { // this is bypassed, it's not useful. You basically always only want to retain the password until sleep. 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 buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str()); keys.hash_and_save_password(plaintext_pw.first().as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
let mut confirm_radiobox = gam::modal::RadioButtons::new( let mut confirm_radiobox = gam::modal::RadioButtons::new(
@ -933,10 +935,9 @@ fn xmain() -> ! {
} }
{ {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().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.as_str()); plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
// this is a reasonable default policy -- don't bother the user to answer this question all the time. // this is a reasonable default policy -- don't bother the user to answer this question all the time.
@ -994,10 +995,10 @@ fn xmain() -> ! {
} }
Some(Opcode::UxBbramCheckReturn) => { Some(Opcode::UxBbramCheckReturn) => {
let buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let console_text = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let console_text = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
log::info!("got console text:{}", console_text.as_str()); log::info!("got console text:{}", console_text.first().as_str());
if console_text.as_str().starts_with("HELPER_OK") { if console_text.first().as_str().starts_with("HELPER_OK") {
log::info!("got '{}', moving on", console_text.as_str()); log::info!("got '{}', moving on", console_text.first().as_str());
// proceed // proceed
if keys.is_pcache_update_password_valid() || !keys.is_initialized() { if keys.is_pcache_update_password_valid() || !keys.is_initialized() {
send_message(main_cid, send_message(main_cid,
@ -1022,10 +1023,10 @@ fn xmain() -> ! {
} }
Some(Opcode::UxBbramPasswordReturn) => { Some(Opcode::UxBbramPasswordReturn) => {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut plaintext_pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let plaintext_pw = buf.to_original::<gam::modal::TextEntryPayloads, _>().unwrap();
keys.hash_and_save_password(plaintext_pw.as_str()); keys.hash_and_save_password(plaintext_pw.first().as_str());
plaintext_pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave plaintext_pw.first().volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
send_message(main_cid, send_message(main_cid,
xous::Message::new_scalar(Opcode::UxBbramRun.to_usize().unwrap(), 0, 0, 0, 0) xous::Message::new_scalar(Opcode::UxBbramRun.to_usize().unwrap(), 0, 0, 0, 0)