catch and handle fat-finger UX events better

they used to panic, now they just print a warning
This commit is contained in:
bunnie 2022-02-04 18:22:17 +08:00
parent 43a5749ee1
commit b35f2a1d3e
3 changed files with 50 additions and 42 deletions

View file

@ -96,7 +96,7 @@ fn xmain() -> ! {
RendererOp::Gutter.to_u32().unwrap() RendererOp::Gutter.to_u32().unwrap()
); );
gutter.set_manual_dismiss(false); gutter.set_manual_dismiss(false);
let mut progress_action = Slider::new(renderer_cid, RendererOp::NotificationReturn.to_u32().unwrap(), let mut progress_action = Slider::new(renderer_cid, RendererOp::Gutter.to_u32().unwrap(),
0, 100, 1, Some("%"), 0, true, true 0, 100, 1, Some("%"), 0, true, true
); );
let mut last_percentage = 0; let mut last_percentage = 0;
@ -299,7 +299,7 @@ fn xmain() -> ! {
*mutex_op = RendererState::ResponseText(text); *mutex_op = RendererState::ResponseText(text);
} }
} }
RendererState::None => log::info!("Text entry got multiple key hits to close the dialog box"), RendererState::None => log::warn!("Text entry detected a fat finger event, ignoring."),
_ => { _ => {
log::error!("UX return opcode does not match our current operation in flight. This is a serious internal error."); log::error!("UX return opcode does not match our current operation in flight. This is a serious internal error.");
panic!("UX return opcode does not match our current operation in flight. This is a serious internal error."); panic!("UX return opcode does not match our current operation in flight. This is a serious internal error.");
@ -310,7 +310,7 @@ fn xmain() -> ! {
let mut mutex_op = op.lock().unwrap(); let mut mutex_op = op.lock().unwrap();
match *mutex_op { match *mutex_op {
RendererState::RunNotification(_) => *mutex_op = RendererState::None, RendererState::RunNotification(_) => *mutex_op = RendererState::None,
RendererState::None => log::info!("Notification got multiple key hits to close the dialog box"), RendererState::None => log::warn!("Notification detected a fat finger event, ignoring."),
_ => { _ => {
log::error!("UX return opcode does not match our current operation in flight: {:?}", mutex_op); log::error!("UX return opcode does not match our current operation in flight: {:?}", mutex_op);
panic!("UX return opcode does not match our current operation in flight. This is a serious internal error."); panic!("UX return opcode does not match our current operation in flight. This is a serious internal error.");
@ -333,6 +333,8 @@ fn xmain() -> ! {
let item = buffer.to_original::<RadioButtonPayload, _>().unwrap(); let item = buffer.to_original::<RadioButtonPayload, _>().unwrap();
*mutex_op = RendererState::ResponseRadio(item.0); *mutex_op = RendererState::ResponseRadio(item.0);
} }
RendererState::ResponseRadio(_) => log::warn!("Radio buttons detected a fat finger event, ignoring."),
RendererState::None => log::warn!("Radio buttons detected a fat finger event, ignoring."),
_ => { _ => {
log::error!("UX return opcode does not match our current operation in flight. This is a serious internal error."); log::error!("UX return opcode does not match our current operation in flight. This is a serious internal error.");
panic!("UX return opcode does not match our current operation in flight. This is a serious internal error."); panic!("UX return opcode does not match our current operation in flight. This is a serious internal error.");
@ -347,6 +349,8 @@ fn xmain() -> ! {
let item = buffer.to_original::<CheckBoxPayload, _>().unwrap(); let item = buffer.to_original::<CheckBoxPayload, _>().unwrap();
*mutex_op = RendererState::ResponseCheckBox(item); *mutex_op = RendererState::ResponseCheckBox(item);
} }
RendererState::ResponseCheckBox(_) => log::warn!("Check boxes detected a fat finger event, ignoring."),
RendererState::None => log::warn!("Check boxes detected a fat finger event, ignoring."),
_ => { _ => {
log::error!("UX return opcode does not match our current operation in flight. This is a serious internal error."); log::error!("UX return opcode does not match our current operation in flight. This is a serious internal error.");
panic!("UX return opcode does not match our current operation in flight. This is a serious internal error."); panic!("UX return opcode does not match our current operation in flight. This is a serious internal error.");

View file

@ -125,14 +125,18 @@ pub(crate) fn password_ux_manager(
pddb_modal.activate(); pddb_modal.activate();
} }
Some(PwRendererOpcode::PwReturn) => { Some(PwRendererOpcode::PwReturn) => {
let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; if renderer_active.load(Ordering::SeqCst) {
let mut pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap(); let mut buf = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let mut pw = buf.to_original::<gam::modal::TextEntryPayload, _>().unwrap();
plaintext_pw.lock().unwrap().clear(); plaintext_pw.lock().unwrap().clear();
write!(plaintext_pw.lock().unwrap(), "{}", pw.as_str()).expect("couldn't transfer password to local buffer"); write!(plaintext_pw.lock().unwrap(), "{}", pw.as_str()).expect("couldn't transfer password to local buffer");
pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave pw.volatile_clear(); // ensure the data is destroyed after sending to the keys enclave
buf.volatile_clear(); buf.volatile_clear();
} else {
log::warn!("Fat finger event received from Ux, ignoring");
}
// this resumes the waiting Ux Manager thread // this resumes the waiting Ux Manager thread
renderer_active.store(false, Ordering::SeqCst); renderer_active.store(false, Ordering::SeqCst);
@ -142,10 +146,10 @@ pub(crate) fn password_ux_manager(
}, },
Some(PwRendererOpcode::ModalKeypress) => msg_scalar_unpack!(msg, k1, k2, k3, k4, { Some(PwRendererOpcode::ModalKeypress) => msg_scalar_unpack!(msg, k1, k2, k3, k4, {
let keys = [ let keys = [
if let Some(a) = core::char::from_u32(k1 as u32) {a} else {'\u{0000}'}, core::char::from_u32(k1 as u32).unwrap_or('\u{0000}'),
if let Some(a) = core::char::from_u32(k2 as u32) {a} else {'\u{0000}'}, core::char::from_u32(k2 as u32).unwrap_or('\u{0000}'),
if let Some(a) = core::char::from_u32(k3 as u32) {a} else {'\u{0000}'}, core::char::from_u32(k3 as u32).unwrap_or('\u{0000}'),
if let Some(a) = core::char::from_u32(k4 as u32) {a} else {'\u{0000}'}, core::char::from_u32(k4 as u32).unwrap_or('\u{0000}'),
]; ];
pddb_modal.key_event(keys); pddb_modal.key_event(keys);
}), }),

View file

@ -896,38 +896,38 @@ fn xmain() -> ! {
rootkeys_modal.activate(); rootkeys_modal.activate();
}, },
Some(Opcode::UxAesEnsureReturn) => { Some(Opcode::UxAesEnsureReturn) => {
#[cfg(feature = "policy-menu")]
{ // 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));
}
keys.set_ux_password_type(None);
if let Some(sender) = aes_sender.take() { if let Some(sender) = aes_sender.take() {
xous::return_scalar(sender, 1).unwrap(); xous::return_scalar(sender, 1).unwrap();
#[cfg(feature = "policy-menu")]
{ // 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));
}
keys.set_ux_password_type(None);
} else { } else {
log::error!("entered a UxAesEnsureReturn but the flow was not set up correctly!"); xous::return_scalar(msg.sender, 0).unwrap();
panic!("entered a UxAesEnsureReturn but the flow was not set up correctly!") log::warn!("UxAesEnsureReturn detected a fat-finger event. Ignoring.");
} }
} }
Some(Opcode::AesOracle) => { Some(Opcode::AesOracle) => {