port apps/vault to use xous-ipc 0.10

This commit is contained in:
bunnie 2024-09-23 14:19:13 +08:00
parent cdc841124d
commit e5bd1cffb9
3 changed files with 42 additions and 43 deletions

View file

@ -3,8 +3,8 @@ use std::cell::RefCell;
use std::io::ErrorKind; use std::io::ErrorKind;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::sync::{ use std::sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex, Arc, Mutex,
atomic::{AtomicBool, Ordering},
}; };
use gam::TextEntryPayload; use gam::TextEntryPayload;
@ -17,15 +17,15 @@ use perflib::*;
use persistent_store::store::OPENSK2_DICT; use persistent_store::store::OPENSK2_DICT;
use vault::env::xous::U2F_APP_DICT; use vault::env::xous::U2F_APP_DICT;
use vault::{ use vault::{
atime_to_str, basis_change, ctap::data_formats::PublicKeyCredentialSource, deserialize_app_info, AppInfo, VAULT_ALLOC_HINT, VAULT_PASSWORD_DICT, VAULT_TOTP_DICT, atime_to_str, basis_change,
serialize_app_info, utc_now, AppInfo, VAULT_ALLOC_HINT, VAULT_PASSWORD_DICT, VAULT_TOTP_DICT, ctap::data_formats::PublicKeyCredentialSource, deserialize_app_info, serialize_app_info, utc_now,
}; };
use xous::{send_message, Message}; use xous::{Message, send_message};
use crate::storage::{self, PasswordRecord, StorageContent}; use crate::storage::{self, PasswordRecord, StorageContent};
use crate::totp::TotpAlgorithm; use crate::totp::TotpAlgorithm;
use crate::{storage::TotpRecord, ListItem, ListKey};
use crate::{ItemLists, SelectedEntry, VaultMode}; use crate::{ItemLists, SelectedEntry, VaultMode};
use crate::{ListItem, ListKey, storage::TotpRecord};
#[cfg(feature = "vaultperf")] #[cfg(feature = "vaultperf")]
const FILE_ID_APPS_VAULT_SRC_ACTIONS: u32 = 1; const FILE_ID_APPS_VAULT_SRC_ACTIONS: u32 = 1;
@ -164,7 +164,7 @@ impl<'a> ActionManager<'a> {
.field(None, Some(password_validator)) .field(None, Some(password_validator))
.build() .build()
{ {
Ok(text) => text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string(), Ok(text) => &text.content()[0].content,
_ => { _ => {
log::error!("Name entry failed"); log::error!("Name entry failed");
self.action_active.store(false, Ordering::SeqCst); self.action_active.store(false, Ordering::SeqCst);
@ -179,7 +179,7 @@ impl<'a> ActionManager<'a> {
.field(None, Some(password_validator)) .field(None, Some(password_validator))
.build() .build()
{ {
Ok(text) => text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string(), Ok(text) => &text.content()[0].content,
_ => { _ => {
log::error!("Name entry failed"); log::error!("Name entry failed");
self.action_active.store(false, Ordering::SeqCst); self.action_active.store(false, Ordering::SeqCst);
@ -246,7 +246,7 @@ impl<'a> ActionManager<'a> {
.field(Some(password), Some(password_validator)) .field(Some(password), Some(password_validator))
.build() .build()
{ {
Ok(text) => text.content()[0].content, Ok(text) => &text.content()[0].content,
_ => { _ => {
log::error!("Name entry failed"); log::error!("Name entry failed");
self.action_active.store(false, Ordering::SeqCst); self.action_active.store(false, Ordering::SeqCst);
@ -322,7 +322,7 @@ impl<'a> ActionManager<'a> {
#[cfg(feature = "ux-swap-delay")] #[cfg(feature = "ux-swap-delay")]
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
let pg2 = PasswordGenerator { let pg2 = PasswordGenerator {
length: length as usize, length: *length as usize,
numbers: number, numbers: number,
lowercase_letters: lower, lowercase_letters: lower,
uppercase_letters: upper, uppercase_letters: upper,
@ -342,13 +342,13 @@ impl<'a> ActionManager<'a> {
} }
} else { } else {
approved = true; approved = true;
maybe_password maybe_password.to_string()
}; };
} }
let mut record = storage::PasswordRecord { let mut record = storage::PasswordRecord {
version: VAULT_PASSWORD_REC_VERSION, version: VAULT_PASSWORD_REC_VERSION,
description, description: description.to_string(),
username, username: username.to_string(),
password, password,
notes: if bip39 { notes: if bip39 {
"bip39".to_string() "bip39".to_string()
@ -382,7 +382,7 @@ impl<'a> ActionManager<'a> {
.field(None, Some(password_validator)) .field(None, Some(password_validator))
.build() .build()
{ {
Ok(text) => text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string(), Ok(text) => &text.content()[0].content,
_ => { _ => {
log::error!("Name entry failed"); log::error!("Name entry failed");
self.action_active.store(false, Ordering::SeqCst); self.action_active.store(false, Ordering::SeqCst);
@ -422,7 +422,7 @@ impl<'a> ActionManager<'a> {
.field(None, Some(totp_ss_validator)) .field(None, Some(totp_ss_validator))
.build() .build()
{ {
Ok(text) => text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string(), Ok(text) => &text.content()[0].content,
_ => { _ => {
log::error!("TOTP ss entry failed"); log::error!("TOTP ss entry failed");
self.action_active.store(false, Ordering::SeqCst); self.action_active.store(false, Ordering::SeqCst);
@ -460,7 +460,7 @@ impl<'a> ActionManager<'a> {
.field(Some("0".to_string()), Some(count_validator)) .field(Some("0".to_string()), Some(count_validator))
.build() .build()
{ {
Ok(entry) => &(entry.content()[0].content).parse::<u64>().unwrap(), Ok(entry) => (entry.content()[0].content).parse::<u64>().unwrap(),
_ => { _ => {
log::error!("Count entry failed"); log::error!("Count entry failed");
self.action_active.store(false, Ordering::SeqCst); self.action_active.store(false, Ordering::SeqCst);
@ -475,7 +475,7 @@ impl<'a> ActionManager<'a> {
// record after entering it. // record after entering it.
let mut totp = storage::TotpRecord { let mut totp = storage::TotpRecord {
version: VAULT_TOTP_REC_VERSION, version: VAULT_TOTP_REC_VERSION,
name: description, name: description.to_string(),
secret: validated_secret, secret: validated_secret,
algorithm: TotpAlgorithm::HmacSha1, algorithm: TotpAlgorithm::HmacSha1,
digits: 6, digits: 6,
@ -512,20 +512,19 @@ impl<'a> ActionManager<'a> {
if choice.is_none() { if choice.is_none() {
// we're dealing with FIDO stuff, use the custom code path // we're dealing with FIDO stuff, use the custom code path
let dictionary = let dictionary = match usize::from_str_radix(entry.key_guid.as_str(), 10) {
match usize::from_str_radix(entry.key_guid.as_str().unwrap_or("UTF8-error"), 10) { Ok(fido_key) => {
Ok(fido_key) => { if vault::ctap::storage::key::CREDENTIALS.contains(&fido_key) {
if vault::ctap::storage::key::CREDENTIALS.contains(&fido_key) { persistent_store::store::OPENSK2_DICT // heuristic: all fido2 keys are simple integers
persistent_store::store::OPENSK2_DICT // heuristic: all fido2 keys are simple integers } else {
} else { U2F_APP_DICT
U2F_APP_DICT
}
} }
Err(_) => U2F_APP_DICT, // u2f keys are long hex strings }
}; Err(_) => U2F_APP_DICT, // u2f keys are long hex strings
};
match self.pddb.borrow().get( match self.pddb.borrow().get(
dictionary, dictionary,
entry.key_guid.as_str().unwrap_or("UTF8-error"), entry.key_guid.as_str(),
None, None,
false, false,
false, false,
@ -536,7 +535,7 @@ impl<'a> ActionManager<'a> {
let attr = candidate.attributes().expect("couldn't get key attributes"); let attr = candidate.attributes().expect("couldn't get key attributes");
match self.pddb.borrow().delete_key( match self.pddb.borrow().delete_key(
dictionary, dictionary,
entry.key_guid.as_str().unwrap_or("UTF8-error"), entry.key_guid.as_str(),
Some(&attr.basis), Some(&attr.basis),
) { ) {
Ok(_) => { Ok(_) => {
@ -556,7 +555,7 @@ impl<'a> ActionManager<'a> {
} else { } else {
// we're deleting either a password, or a totp // we're deleting either a password, or a totp
let choice = choice.unwrap(); let choice = choice.unwrap();
let guid = entry.key_guid.as_str().unwrap_or("UTF8-error"); let guid = entry.key_guid.as_str();
if entry.mode == VaultMode::Password { if entry.mode == VaultMode::Password {
// self.modals.show_notification(&format!("deleting key {}", guid), None).ok(); // self.modals.show_notification(&format!("deleting key {}", guid), None).ok();
// if it's a password, we have to pull the full record, and then reconstitute the // if it's a password, we have to pull the full record, and then reconstitute the
@ -604,7 +603,7 @@ impl<'a> ActionManager<'a> {
match entry.mode { match entry.mode {
VaultMode::Password => { VaultMode::Password => {
let choice = storage::ContentKind::Password; let choice = storage::ContentKind::Password;
let guid = entry.key_guid.as_str().unwrap_or("UTF8-error"); let guid = entry.key_guid.as_str();
let storage = self.storage.borrow_mut(); let storage = self.storage.borrow_mut();
let pw: storage::PasswordRecord = match storage.get_record(&choice, guid) { let pw: storage::PasswordRecord = match storage.get_record(&choice, guid) {
Ok(record) => record, Ok(record) => record,
@ -1438,7 +1437,7 @@ impl<'a> ActionManager<'a> {
.field(None, Some(name_validator)) .field(None, Some(name_validator))
.build() .build()
{ {
Ok(text) => text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string(), Ok(text) => &text.content()[0].content,
_ => { _ => {
log::error!("Name entry failed"); log::error!("Name entry failed");
self.action_active.store(false, Ordering::SeqCst); self.action_active.store(false, Ordering::SeqCst);
@ -1492,7 +1491,7 @@ impl<'a> ActionManager<'a> {
.field(None, Some(name_validator)) .field(None, Some(name_validator))
.build() .build()
{ {
Ok(text) => text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string(), Ok(text) => &text.content()[0].content,
Err(e) => { Err(e) => {
self.report_err(t!("vault.error.internal_error", locales::LANG), Some(e)); self.report_err(t!("vault.error.internal_error", locales::LANG), Some(e));
return; return;
@ -1791,7 +1790,7 @@ impl<'a> ActionManager<'a> {
} }
} }
pub(crate) fn totp_ss_validator(input: TextEntryPayload) -> Option<String> { pub(crate) fn totp_ss_validator(input: &TextEntryPayload) -> Option<String> {
let proposed_ss = input.as_str().to_uppercase(); let proposed_ss = input.as_str().to_uppercase();
if let Some(ss) = base32::decode(base32::Alphabet::RFC4648 { padding: false }, &proposed_ss) { if let Some(ss) = base32::decode(base32::Alphabet::RFC4648 { padding: false }, &proposed_ss) {
if ss.len() > 0 { if ss.len() > 0 {
@ -1816,7 +1815,7 @@ pub(crate) fn totp_ss_validator(input: TextEntryPayload) -> Option<String> {
} }
Some(String::from(t!("vault.illegal_totp", locales::LANG))) Some(String::from(t!("vault.illegal_totp", locales::LANG)))
} }
pub(crate) fn name_validator(input: TextEntryPayload) -> Option<String> { pub(crate) fn name_validator(input: &TextEntryPayload) -> Option<String> {
let proposed_name = input.as_str(); let proposed_name = input.as_str();
if proposed_name.contains(['\n', ':']) { if proposed_name.contains(['\n', ':']) {
// the '\n' is reserved as the delimiter to end the name field, and ':' is the path separator // the '\n' is reserved as the delimiter to end the name field, and ':' is the path separator
@ -1825,7 +1824,7 @@ pub(crate) fn name_validator(input: TextEntryPayload) -> Option<String> {
None None
} }
} }
pub(crate) fn password_validator(input: TextEntryPayload) -> Option<String> { pub(crate) fn password_validator(input: &TextEntryPayload) -> Option<String> {
let proposed_name = input.as_str(); let proposed_name = input.as_str();
if proposed_name.contains(['\n']) { if proposed_name.contains(['\n']) {
// the '\n' is reserved as the delimiter to end the name field // the '\n' is reserved as the delimiter to end the name field
@ -1834,7 +1833,7 @@ pub(crate) fn password_validator(input: TextEntryPayload) -> Option<String> {
None None
} }
} }
fn length_validator(input: TextEntryPayload) -> Option<String> { fn length_validator(input: &TextEntryPayload) -> Option<String> {
let text_str = input.as_str(); let text_str = input.as_str();
match text_str.parse::<u32>() { match text_str.parse::<u32>() {
Ok(input_int) => { Ok(input_int) => {
@ -1847,7 +1846,7 @@ fn length_validator(input: TextEntryPayload) -> Option<String> {
_ => Some(String::from(t!("vault.illegal_number", locales::LANG))), _ => Some(String::from(t!("vault.illegal_number", locales::LANG))),
} }
} }
fn count_validator(input: TextEntryPayload) -> Option<String> { fn count_validator(input: &TextEntryPayload) -> Option<String> {
let text_str = input.as_str(); let text_str = input.as_str();
match text_str.parse::<u64>() { match text_str.parse::<u64>() {
Ok(_input_int) => None, Ok(_input_int) => None,

View file

@ -19,12 +19,12 @@ use actions::ActionOp;
use itemcache::*; use itemcache::*;
use locales::t; use locales::t;
use num_traits::*; use num_traits::*;
use ux::framework::{name_to_style, VaultUx, DEFAULT_FONT, FONT_LIST}; use ux::framework::{DEFAULT_FONT, FONT_LIST, VaultUx, name_to_style};
use vault::ctap::main_hid::HidIterType; use vault::ctap::main_hid::HidIterType;
use vault::env::xous::XousEnv;
use vault::env::Env; use vault::env::Env;
use vault::{Transport, VaultOp, SELF_CONN}; use vault::env::xous::XousEnv;
use xous::{msg_blocking_scalar_unpack, msg_scalar_unpack, send_message, Message}; use vault::{SELF_CONN, Transport, VaultOp};
use xous::{Message, msg_blocking_scalar_unpack, msg_scalar_unpack, send_message};
use xous_ipc::Buffer; use xous_ipc::Buffer;
use xous_usb_hid::device::fido::*; use xous_usb_hid::device::fido::*;
@ -97,7 +97,7 @@ pub enum VaultMode {
Password, Password,
} }
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
pub struct SelectedEntry { pub struct SelectedEntry {
pub key_guid: String, pub key_guid: String,
pub description: String, pub description: String,

View file

@ -67,7 +67,7 @@ pub(crate) fn icontray_server(conn_to_main: xous::CID) {
// every key press, the four slots get queried // every key press, the four slots get queried
prediction.string.clear(); prediction.string.clear();
if prediction.index < ICONS.len() as u32 { if prediction.index < ICONS.len() as u32 {
prediction.string.append(ICONS[prediction.index as usize]).ok(); prediction.string.push_str(ICONS[prediction.index as usize]);
prediction.valid = true; prediction.valid = true;
} else { } else {
prediction.valid = false; prediction.valid = false;