progress on issue #223

This adds the abort flow to the U2F approvals. Needs more testing.
This commit is contained in:
bunnie 2022-09-23 00:27:14 +08:00
parent 13402b99b9
commit 278570d8d3
3 changed files with 57 additions and 26 deletions

View file

@ -318,10 +318,16 @@
"en-tts": "Host has requested a factory reset of FIDO/U2F credentials. This will permanently erase all registrations.\nPress 'y' to allow, any other key to abort."
},
"vault.u2f.authenticate": {
"en": "U2F Authentication Request\nPress any key to approve.",
"ja": "U2F 認証リクエスト\nいずれかのキーを押して承認します。",
"zh": "U2F 认证请求\n按任意键批准。",
"en-tts": "U2F Authentication Request\nPress any key to approve."
"en": "U2F Authentication Request\n",
"ja": "U2F 認証リクエスト\n",
"zh": "U2F 认证请求\n",
"en-tts": "U2F Authentication Request\n"
},
"vault.u2f.wait_abort": {
"en": "U2F request denied. Waiting for host to abort...\n",
"ja": "U2F リクエストが拒否されました。 ホストが中止するのを待っています...\n",
"zh": "U2F 请求被拒绝。 等待主机中止...\n",
"en-tts": "U2F request denied. Waiting for host to abort...\n"
},
"vault.u2f.newapphash": {
"en": "New registration request. Press any key to approve.\nHash: ",
@ -390,10 +396,10 @@
"en-tts": "U2F Registration Request"
},
"vault.u2freq": {
"en": "FIDO Request",
"ja": "FIDOリクエスト",
"zh": "FIDO 请求",
"en-tts": "FIDO Request"
"en": "FIDO Request.\n\nDENY the request by pressing F1.\nAPPROVE by pressing any other key.\n",
"ja": "FIDOリクエスト\n\nF1 を押して要求を拒否するか、その他のキーを押して承認します。\n",
"zh": "FIDO 请求\n\n按 F1 拒绝请求,或按任何其他键批准它。\n",
"en-tts": "FIDO Request.\n\nPress F1 to DENY the request.\nPress any other key to approve it.\n"
},
"vault.select_font": {
"en": "Select a font style",

View file

@ -169,8 +169,9 @@ fn main() -> ! {
let sid = xous::create_server().unwrap();
// TODO: fix this so there is a uniform public API for the time server
let time_conn = xous::connect(xous::SID::from_bytes(b"timeserverpublic").unwrap()).unwrap();
let conn = xous::connect(sid).unwrap();
start_fido_ux_thread();
start_fido_ux_thread(conn);
// global shared state between threads.
let mode = Arc::new(Mutex::new(VaultMode::Fido));
@ -182,7 +183,6 @@ fn main() -> ! {
// has to be in its own thread because it uses blocking modal calls that would cause
// redraws of the background list to block/fail.
let actions_sid = xous::create_server().unwrap();
let conn = xous::connect(sid).unwrap();
SELF_CONN.store(conn, Ordering::SeqCst);
start_actions_thread(conn, actions_sid, mode.clone(), item_list.clone(), action_active.clone());
let actions_conn = xous::connect(actions_sid).unwrap();

View file

@ -113,7 +113,7 @@ const DEFAULT_PRESENCE_TIMEOUT_MS: i64 = 30_000;
const DEFAULT_PROMPT_TIMEOUT_MS: i64 = 30_000;
const POLLED_PROMPT_TIMEOUT_MS: i64 = 1000; // how long the screen stays up after the host "gives up" polling
const KEEPALIVE_MS: usize = 100;
pub(crate) fn start_fido_ux_thread() {
pub(crate) fn start_fido_ux_thread(main_conn: xous::CID) {
let sid = xous::create_server().unwrap();
let cid = xous::connect(sid).expect("couldn't connect to UX thread server");
SELF_CID.store(cid, Ordering::SeqCst);
@ -380,7 +380,7 @@ pub(crate) fn start_fido_ux_thread() {
}
}
let key_hit = kbhit.load(Ordering::SeqCst);
if key_hit != 0 {
if key_hit != 0 && key_hit != 0x11 { // 0x11 is the F1 character
num_fido_auths += 1;
log::info!("got user presence! count: {}", num_fido_auths);
if let Some(mut msg) = deferred_req.take() {
@ -401,21 +401,35 @@ pub(crate) fn start_fido_ux_thread() {
).unwrap();
} else {
tt.sleep_ms(interval).unwrap();
// check if we timed out
if tt.elapsed_ms() as i64 >= prompt_expiration_ms {
num_fido_auths += 1; // bump it so we can pass the "don't touch it" test
log::info!("timed out");
ux_state = UxState::Idle;
modals.dynamic_notification_close().unwrap();
// unblock the listener with a `None` response
if let Some(mut msg) = deferred_req.take() {
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let mut fido_request = buffer.to_original::<FidoRequest, _>().unwrap();
fido_request.granted = None;
log::trace!("timeout returning {:?}", fido_request.granted);
buffer.replace(fido_request).unwrap();
if key_hit != 0x11 {
// check if we timed out
if tt.elapsed_ms() as i64 >= prompt_expiration_ms {
num_fido_auths += 1; // bump it so we can pass the "don't touch it" test
log::info!("timed out");
ux_state = UxState::Idle;
modals.dynamic_notification_close().unwrap();
// unblock the listener with a `None` response
if let Some(mut msg) = deferred_req.take() {
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let mut fido_request = buffer.to_original::<FidoRequest, _>().unwrap();
fido_request.granted = None;
log::trace!("timeout returning {:?}", fido_request.granted);
buffer.replace(fido_request).unwrap();
}
} else { // else pump the loop again
send_message(self_cid,
Message::new_scalar(UxOp::Pump.to_usize().unwrap(), KEEPALIVE_MS, 0, 0, 0)
).unwrap();
}
} else { // else pump the loop again
} else {
log::info!("aborted");
modals.dynamic_notification_close().unwrap();
tt.sleep_ms(interval).unwrap();
modals.dynamic_notification(
Some(t!("vault.u2f.wait_abort", xous::LANG)),
None,
).unwrap();
kbhit.store(0, Ordering::SeqCst); // reset the waiting key...
send_message(self_cid,
Message::new_scalar(UxOp::Pump.to_usize().unwrap(), KEEPALIVE_MS, 0, 0, 0)
).unwrap();
@ -486,6 +500,17 @@ pub(crate) fn start_fido_ux_thread() {
_ => log::error!("Error updating app atime"),
}
pddb.sync().ok();
// force a redraw of the screen so the new record is rendered,
// but for some reason this isn't working...
tt.sleep_ms(350).ok();
log::info!("sycing UI state...");
send_message(
main_conn,
Message::new_scalar(
crate::VaultOp::FullRedraw.to_usize().unwrap(),
0, 0, 0, 0)
).unwrap();
} else {
log::error!("Illegal state for U2F registration!");
}