From cd0269036d20f2478a34fe5aa956559b0b4e91b4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 24 Mar 2023 23:08:50 +0800 Subject: [PATCH] WIP: #334 I don't have a way to test this, but maybe you can give it a try and see if it fixes as described in the issue. --- apps/vault/src/env/xous/mod.rs | 132 +++++++++++++++++---------------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/apps/vault/src/env/xous/mod.rs b/apps/vault/src/env/xous/mod.rs index 97ec8e68c..6d404bfdf 100644 --- a/apps/vault/src/env/xous/mod.rs +++ b/apps/vault/src/env/xous/mod.rs @@ -307,81 +307,85 @@ impl XousEnv { }; let update = buf.to_original::().unwrap(); let app_id_str = hex::encode(update.app_id); - // note the access - let mut info = { - // fetch the application info, if it exists - log::info!("Updating U2F record {}", app_id_str); - // add code to query the PDDB here to look for the k/v mapping of this app ID - match pddb.get( - U2F_APP_DICT, - &app_id_str, - None, true, false, - Some(256), Some(basis_change) - ) { - Ok(mut app_data) => { - let app_attr = app_data.attributes().unwrap(); - if app_attr.len != 0 { - let mut descriptor = Vec::::new(); - match app_data.read_to_end(&mut descriptor) { - Ok(_) => { - deserialize_app_info(descriptor) + if update.app_id != [0u8; 32] { + // note the access + let mut info = { + // fetch the application info, if it exists + log::info!("Updating U2F record {}", app_id_str); + // add code to query the PDDB here to look for the k/v mapping of this app ID + match pddb.get( + U2F_APP_DICT, + &app_id_str, + None, true, false, + Some(256), Some(basis_change) + ) { + Ok(mut app_data) => { + let app_attr = app_data.attributes().unwrap(); + if app_attr.len != 0 { + let mut descriptor = Vec::::new(); + match app_data.read_to_end(&mut descriptor) { + Ok(_) => { + deserialize_app_info(descriptor) + } + Err(e) => {log::error!("Couldn't read app info: {:?}", e); None} } - Err(e) => {log::error!("Couldn't read app info: {:?}", e); None} + } else { + None } - } else { + } + _ => { + log::info!("couldn't find key {}", app_id_str); None } } - _ => { - log::info!("couldn't find key {}", app_id_str); - None - } - } - }.unwrap_or_else( - || { - // otherwise, create it - match modals - .alert_builder(t!("vault.u2f.give_app_name", xous::LANG)) - .field(None, None) - .build() - { - Ok(name) => { - let info = AppInfo { - name: name.content()[0].content.to_string(), - notes: t!("vault.notes", xous::LANG).to_string(), - id: update.app_id, - ctime: crate::utc_now().timestamp() as u64, - atime: 0, - count: 0, - }; - info - } - _ => { - log::error!("couldn't get name for app"); - panic!("couldn't get name for app"); + }.unwrap_or_else( + || { + // otherwise, create it + match modals + .alert_builder(t!("vault.u2f.give_app_name", xous::LANG)) + .field(None, None) + .build() + { + Ok(name) => { + let info = AppInfo { + name: name.content()[0].content.to_string(), + notes: t!("vault.notes", xous::LANG).to_string(), + id: update.app_id, + ctime: crate::utc_now().timestamp() as u64, + atime: 0, + count: 0, + }; + info + } + _ => { + log::error!("couldn't get name for app"); + panic!("couldn't get name for app"); + } } } - } - ); + ); - info.atime = crate::utc_now().timestamp() as u64; - info.count = info.count.saturating_add(1); - let ser = serialize_app_info(&info); + info.atime = crate::utc_now().timestamp() as u64; + info.count = info.count.saturating_add(1); + let ser = serialize_app_info(&info); - // update the access time, by deleting the key and writing it back into the PDDB - pddb.delete_key(U2F_APP_DICT, &app_id_str, None).ok(); - match pddb.get( - U2F_APP_DICT, - &app_id_str, - None, true, true, - Some(256), Some(basis_change) - ) { - Ok(mut app_data) => { - app_data.write(&ser).expect("couldn't update atime"); + // update the access time, by deleting the key and writing it back into the PDDB + pddb.delete_key(U2F_APP_DICT, &app_id_str, None).ok(); + match pddb.get( + U2F_APP_DICT, + &app_id_str, + None, true, true, + Some(256), Some(basis_change) + ) { + Ok(mut app_data) => { + app_data.write(&ser).expect("couldn't update atime"); + } + _ => log::error!("Error updating app atime"), } - _ => log::error!("Error updating app atime"), + pddb.sync().ok(); + } else { + log::warn!("app_id is all 0's; bypassing name association"); } - pddb.sync().ok(); log::debug!("sycing UI state..."); xous::send_message(