cleanup warnings

This commit is contained in:
bunnie 2025-11-12 18:24:23 +08:00
parent 94964f12a2
commit 5f859e57fb
7 changed files with 182 additions and 81 deletions

View file

@ -18,7 +18,7 @@ xous-names = { package = "xous-api-names", version = "0.9.67" }
locales = { path = "../../locales" } locales = { path = "../../locales" }
pddb = { path = "../../services/pddb" } pddb = { path = "../../services/pddb" }
modals = { path = "../../services/modals", features = ["no-gam"] } modals = { path = "../../services/modals", features = ["no-gam"] }
# backup = { path = "libraries/backup" } backup = { path = "../../apps/vault/libraries/backup" }
byteorder = { version = "1.4.3", default-features = false } byteorder = { version = "1.4.3", default-features = false }
arrayref = "0.3.6" arrayref = "0.3.6"
subtle = { version = "2.5.0", features = ["core_hint_black_box"] } subtle = { version = "2.5.0", features = ["core_hint_black_box"] }

View file

@ -20,7 +20,7 @@ use ux_api::widgets::TextEntryPayload;
use vault2::env::xous::U2F_APP_DICT; use vault2::env::xous::U2F_APP_DICT;
use vault2::{ use vault2::{
AppInfo, VAULT_ALLOC_HINT, VAULT_PASSWORD_DICT, VAULT_TOTP_DICT, atime_to_str, basis_change, AppInfo, VAULT_ALLOC_HINT, VAULT_PASSWORD_DICT, VAULT_TOTP_DICT, atime_to_str, basis_change,
ctap::data_formats::PublicKeyCredentialSource, deserialize_app_info, serialize_app_info, utc_now, deserialize_app_info, serialize_app_info, utc_now,
}; };
use xous::{Message, send_message}; use xous::{Message, send_message};
@ -66,7 +66,6 @@ pub struct ActionManager {
pddb: RefCell<pddb::Pddb>, pddb: RefCell<pddb::Pddb>,
tt: ticktimer_server::Ticktimer, tt: ticktimer_server::Ticktimer,
action_active: Arc<AtomicBool>, action_active: Arc<AtomicBool>,
opensk_mutex: Arc<Mutex<i32>>,
mode_cache: VaultMode, mode_cache: VaultMode,
main_conn: xous::CID, main_conn: xous::CID,
keystore: Keystore, keystore: Keystore,
@ -77,7 +76,6 @@ impl ActionManager {
mode: Arc<Mutex<VaultMode>>, mode: Arc<Mutex<VaultMode>>,
item_lists: Arc<Mutex<ItemLists>>, item_lists: Arc<Mutex<ItemLists>>,
action_active: Arc<AtomicBool>, action_active: Arc<AtomicBool>,
opensk_mutex: Arc<Mutex<i32>>,
) -> ActionManager { ) -> ActionManager {
let xns = xous_names::XousNames::new().unwrap(); let xns = xous_names::XousNames::new().unwrap();
let storage_manager = storage::Manager::new(&xns); let storage_manager = storage::Manager::new(&xns);
@ -96,7 +94,6 @@ impl ActionManager {
pddb: RefCell::new(pddb::Pddb::new()), pddb: RefCell::new(pddb::Pddb::new()),
tt: ticktimer_server::Ticktimer::new().unwrap(), tt: ticktimer_server::Ticktimer::new().unwrap(),
action_active, action_active,
opensk_mutex,
main_conn, main_conn,
keystore: Keystore::new(&xns), keystore: Keystore::new(&xns),
} }
@ -1472,7 +1469,7 @@ pub(crate) fn heap_usage() -> usize {
} }
} }
fn make_pw_name(description: &str, username: &str, dest: &mut String) { fn make_pw_name(description: &str, _username: &str, dest: &mut String) {
dest.clear(); dest.clear();
dest.push_str(description); dest.push_str(description);
// dest.push_str("/"); // dest.push_str("/");
@ -1489,20 +1486,7 @@ fn make_u2f_item_from_record(guid: &str, ai: AppInfo) -> ListItem {
let desc: String = format!("{} (U2F)", ai.name); let desc: String = format!("{} (U2F)", ai.name);
ListItem::new(desc, extra, true, guid.to_owned(), ai.count, ai.atime) ListItem::new(desc, extra, true, guid.to_owned(), ai.count, ai.atime)
} }
fn make_fido_item_from_record(guid: &str, result: PublicKeyCredentialSource) -> ListItem {
let name = if let Some(display_name) = result.user_display_name {
display_name
} else {
String::from_utf8(result.user_handle).unwrap_or("".to_string())
};
let desc = format!(
"{} / {} (FIDO2)",
result.rp_id,
String::from_utf8(result.credential_id).unwrap_or("---".to_string())
);
let extra = format!("{}", name);
ListItem::new(desc, extra, true, guid.to_owned(), 0, 0)
}
fn make_totp_item_from_record(guid: &str, totp: TotpRecord) -> ListItem { fn make_totp_item_from_record(guid: &str, totp: TotpRecord) -> ListItem {
let extra = format!( let extra = format!(
"{}:{}:{}:{}:{}", "{}:{}:{}:{}:{}",

View file

@ -1,14 +1,3 @@
use core::sync::atomic::{AtomicBool, Ordering};
use std::cell::RefCell;
use std::sync::{Arc, Mutex};
use std::thread;
use num_traits::*;
use pddb::Pddb;
use totp::PumpOp;
use xous::msg_blocking_scalar_unpack;
use xous_ipc::Buffer;
mod ux; mod ux;
use ux::*; use ux::*;
mod itemcache; mod itemcache;
@ -18,8 +7,29 @@ use actions::ActionOp;
mod storage; mod storage;
mod submenu; mod submenu;
mod totp; mod totp;
pub(crate) mod vault_api; pub mod vault_api;
pub use vault_api::*;
mod vendor_commands;
use core::sync::atomic::{AtomicBool, Ordering};
use std::cell::RefCell;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Instant;
use locales::t; use locales::t;
use num_traits::*;
use pddb::Pddb;
use totp::PumpOp;
use vault2::Transport;
use vault2::ctap::main_hid::HidIterType;
use vault2::env::Env;
use vault2::env::xous::XousEnv;
use xous::msg_blocking_scalar_unpack;
use xous_ipc::Buffer;
use xous_usb_hid::device::fido::*;
use crate::vendor_commands::VendorSession;
/* /*
Dev status & notes -- Dev status & notes --
@ -119,26 +129,6 @@ necessarily listed in order of implementation:
pub(crate) const SERVER_NAME_VAULT2: &str = "_Vault2_"; pub(crate) const SERVER_NAME_VAULT2: &str = "_Vault2_";
/// Top level application events.
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub(crate) enum VaultOp {
/// Redraw the screen
Redraw = 0,
KeyPress,
/// Partial menu
MenuChangeFont,
MenuDeleteStage1,
MenuEditStage1,
MenuAutotype,
MenuReadoutMode,
MenuAutotypeRate,
MenuLeftyMode,
MenuDone,
MenuTotpMode,
MenuPwMode,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(Copy, Clone, PartialEq, Eq, Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub enum VaultMode { pub enum VaultMode {
Totp, Totp,
@ -170,6 +160,9 @@ fn main() -> ! {
let action_active = Arc::new(AtomicBool::new(false)); let action_active = Arc::new(AtomicBool::new(false));
// Protects access to the openSK PDDB entries from simultaneous readout on the UX while OpenSK is updating // Protects access to the openSK PDDB entries from simultaneous readout on the UX while OpenSK is updating
let opensk_mutex = Arc::new(Mutex::new(0)); let opensk_mutex = Arc::new(Mutex::new(0));
let allow_host = Arc::new(AtomicBool::new(false));
// storage for lefty mode
let lefty_mode = Arc::new(AtomicBool::new(false));
let mut vault_ui = VaultUi::new(&xns, conn, item_lists.clone(), mode.clone()); let mut vault_ui = VaultUi::new(&xns, conn, item_lists.clone(), mode.clone());
@ -193,10 +186,8 @@ fn main() -> ! {
let mode = mode.clone(); let mode = mode.clone();
let item_lists = item_lists.clone(); let item_lists = item_lists.clone();
let action_active = action_active.clone(); let action_active = action_active.clone();
let opensk_mutex = opensk_mutex.clone();
move || { move || {
let mut manager = let mut manager = crate::actions::ActionManager::new(main_conn, mode, item_lists, action_active);
crate::actions::ActionManager::new(main_conn, mode, item_lists, action_active, opensk_mutex);
loop { loop {
let msg = xous::receive_message(sid).unwrap(); let msg = xous::receive_message(sid).unwrap();
let opcode: Option<ActionOp> = FromPrimitive::from_usize(msg.body.id()); let opcode: Option<ActionOp> = FromPrimitive::from_usize(msg.body.id());
@ -282,6 +273,116 @@ fn main() -> ! {
let actions_conn = xous::connect(actions_sid).unwrap(); let actions_conn = xous::connect(actions_sid).unwrap();
// spawn the FIDO2 USB handler
let _ = thread::spawn({
let allow_host = allow_host.clone();
let opensk_mutex = opensk_mutex.clone();
let conn = conn.clone();
let lefty_mode = lefty_mode.clone();
move || {
let mut vendor_session = VendorSession::default();
// block until the PDDB is mounted
let pddb = pddb::Pddb::new();
pddb.is_mounted_blocking();
let env = XousEnv::new(conn, lefty_mode); // lefty_mode is now owned by env
let mut ctap = vault2::Ctap::new(env, Instant::now());
loop {
match ctap.env().main_hid_connection().u2f_wait_incoming() {
Ok(msg) => {
ctap.update_timeouts(Instant::now());
let mutex = opensk_mutex.lock().unwrap();
log::trace!("Received U2F packet");
let typed_reply =
ctap.process_hid_packet(&msg.packet, Transport::MainHid, Instant::now());
match typed_reply {
HidIterType::Ctap(reply) => {
for pkt_reply in reply {
let mut reply = RawFidoReport::default();
reply.packet.copy_from_slice(&pkt_reply);
let status = ctap.env().main_hid_connection().u2f_send(reply);
match status {
Ok(()) => {
log::trace!("Sent U2F packet");
}
Err(e) => {
log::error!("Error sending U2F packet: {:?}", e);
}
}
}
}
HidIterType::Vendor(msg) => {
let reply = match vendor_commands::handle_vendor_data(
msg.cmd as u8,
msg.cid,
msg.payload,
&mut vendor_session,
) {
Ok(return_payload) => {
// if None, this means we've finished parsing all that
// was needed, and we handle/respond with real data
match return_payload {
Some(data) => data,
None => {
log::debug!("starting processing of vendor data...");
let resp = vendor_commands::handle_vendor_command(
&mut vendor_session,
allow_host.load(Ordering::SeqCst),
);
log::debug!("finished processing of vendor data!");
match vendor_session.is_backup() {
true => {
if vendor_session.has_backup_data() {
resp
} else {
vendor_session = VendorSession::default();
resp
}
}
false => {
vendor_session = VendorSession::default();
resp
}
}
}
}
}
Err(session_error) => {
// reset the session
vendor_session = VendorSession::default();
session_error.ctaphid_error(msg.cid)
}
};
for pkt_reply in reply {
let mut reply = RawFidoReport::default();
reply.packet.copy_from_slice(&pkt_reply);
let status = ctap.env().main_hid_connection().u2f_send(reply);
match status {
Ok(()) => {
log::trace!("Sent U2F packet");
}
Err(e) => {
log::error!("Error sending U2F packet: {:?}", e);
}
}
}
}
}
drop(mutex);
}
Err(e) => match e {
_ => {
log::warn!("FIDO listener got an error: {:?}", e);
}
},
}
}
}
});
let menu_sid = xous::create_server().unwrap(); let menu_sid = xous::create_server().unwrap();
let menu_mgr = submenu::create_submenu(conn, actions_conn, menu_sid); let menu_mgr = submenu::create_submenu(conn, actions_conn, menu_sid);
let modals = modals::Modals::new(&xns).unwrap(); let modals = modals::Modals::new(&xns).unwrap();
@ -306,6 +407,15 @@ fn main() -> ! {
Some(VaultOp::Redraw) => { Some(VaultOp::Redraw) => {
vault_ui.redraw(); vault_ui.redraw();
} }
Some(VaultOp::ReloadDbAndFullRedraw) => {
xous::send_message(
actions_conn,
xous::Message::new_blocking_scalar(ActionOp::ReloadDb.to_usize().unwrap(), 0, 0, 0, 0),
)
.ok();
vault_ui.refresh_totp();
vault_ui.redraw();
}
Some(VaultOp::MenuDone) => { Some(VaultOp::MenuDone) => {
menu_active = false; menu_active = false;
// update the TOTP codes, in case there were changes // update the TOTP codes, in case there were changes
@ -404,6 +514,20 @@ fn main() -> ! {
} }
allow_totp_rendering.store(true, Ordering::SeqCst); allow_totp_rendering.store(true, Ordering::SeqCst);
} }
Some(VaultOp::BasisChange) => {
vault_ui.basis_change();
xous::send_message(
conn,
xous::Message::new_blocking_scalar(
VaultOp::ReloadDbAndFullRedraw.to_usize().unwrap(),
0,
0,
0,
0,
),
)
.ok();
}
_ => { _ => {
log::error!("Got unknown message: {:?}", msg); log::error!("Got unknown message: {:?}", msg);
} }

View file

@ -9,9 +9,8 @@ use chrono::{DateTime, NaiveDateTime, Utc};
use ctap_crypto::Hash256; use ctap_crypto::Hash256;
use crate::totp::TotpAlgorithm; use crate::totp::TotpAlgorithm;
use crate::vault_api::VAULT_PASSWORD_DICT;
const VAULT_PASSWORD_DICT: &'static str = "vault.passwords"; use crate::vault_api::VAULT_TOTP_DICT;
const VAULT_TOTP_DICT: &'static str = "vault.totp";
const VAULT_TOTP_ALLOC_HINT: usize = 128; const VAULT_TOTP_ALLOC_HINT: usize = 128;
const VAULT_PASSWORD_REC_VERSION: u32 = 1; const VAULT_PASSWORD_REC_VERSION: u32 = 1;

View file

@ -143,6 +143,11 @@ impl VaultUi {
} }
} }
pub(crate) fn basis_change(&mut self) {
self.item_lists.lock().unwrap().clear_all();
self.totp_list.clear();
}
pub(crate) fn store_glyph_style(&mut self, style: GlyphStyle) { pub(crate) fn store_glyph_style(&mut self, style: GlyphStyle) {
self.pddb self.pddb
.borrow() .borrow()
@ -213,7 +218,7 @@ impl VaultUi {
// to reduce locking thrash, we cache a copy of the current mode at the top of redraw. // to reduce locking thrash, we cache a copy of the current mode at the top of redraw.
let mode_at_entry = (*self.mode.lock().unwrap()).clone(); let mode_at_entry = (*self.mode.lock().unwrap()).clone();
self.gfx.clear().ok(); self.clear_area();
match mode_at_entry { match mode_at_entry {
VaultMode::Totp => { VaultMode::Totp => {
@ -337,7 +342,7 @@ impl VaultUi {
match self.storage_manager.get_record(&ContentKind::Password, guid) { match self.storage_manager.get_record(&ContentKind::Password, guid) {
Ok(record) => record, Ok(record) => record,
Err(error) => { Err(error) => {
log::error!("internal error rendering password"); log::error!("internal error rendering password: {:?}", error);
self.gfx.flush().ok(); self.gfx.flush().ok();
return; return;
} }

View file

@ -16,20 +16,13 @@ pub const VAULT_TOTP_DICT: &'static str = "vault.totp";
/// bytes to reserve for a key entry. Making this slightly larger saves on some churn as stuff gets updated /// bytes to reserve for a key entry. Making this slightly larger saves on some churn as stuff gets updated
pub const VAULT_ALLOC_HINT: usize = 256; pub const VAULT_ALLOC_HINT: usize = 256;
/// Top level application events.
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub enum VaultOp { pub(crate) enum VaultOp {
/// a line of text has arrived /// Redraw the screen
Line = 0, // make sure we occupy opcodes with discriminants < 1000, as the rest are used for callbacks Redraw = 0,
/// incremental line of text
IncrementalLine,
/// redraw our UI
Redraw,
/// ignore dirty rectangles and redraw everything
FullRedraw,
/// reload the database (slow), and ignore dirty rectangles and redraw everything
ReloadDbAndFullRedraw, ReloadDbAndFullRedraw,
/// change focus KeyPress,
ChangeFocus,
/// Partial menu /// Partial menu
MenuChangeFont, MenuChangeFont,
@ -39,15 +32,11 @@ pub enum VaultOp {
MenuReadoutMode, MenuReadoutMode,
MenuAutotypeRate, MenuAutotypeRate,
MenuLeftyMode, MenuLeftyMode,
MenuDone,
MenuTotpMode,
MenuPwMode,
/// PDDB basis change
BasisChange, BasisChange,
/// Nop while waiting for prerequisites to be filled
Nop,
/// exit the application
Quit,
} }
pub fn atime_to_str(req_atime: u64) -> String { pub fn atime_to_str(req_atime: u64) -> String {

View file

@ -2,8 +2,8 @@ use core::convert::TryFrom;
use cbor::reader::DecoderError; use cbor::reader::DecoderError;
use locales::t; use locales::t;
use vault::ctap::hid::{ChannelID, CtapHidCommand, Message, send::HidPacketIterator}; use vault2::ctap::hid::{ChannelID, CtapHidCommand, Message, send::HidPacketIterator};
use vault::vault_api::{COMMAND_BACKUP_TOTP_CODES, COMMAND_RESET_SESSION, COMMAND_RESTORE_TOTP_CODES}; use vault2::vault_api::{COMMAND_BACKUP_TOTP_CODES, COMMAND_RESET_SESSION, COMMAND_RESTORE_TOTP_CODES};
use crate::storage::{Error, PasswordRecord, TotpRecord}; use crate::storage::{Error, PasswordRecord, TotpRecord};
use crate::totp::TotpAlgorithm; use crate::totp::TotpAlgorithm;