mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
port apps/vault to use xous-ipc 0.10
This commit is contained in:
parent
cdc841124d
commit
e5bd1cffb9
3 changed files with 42 additions and 43 deletions
|
|
@ -3,8 +3,8 @@ use std::cell::RefCell;
|
|||
use std::io::ErrorKind;
|
||||
use std::io::{Read, Write};
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
};
|
||||
|
||||
use gam::TextEntryPayload;
|
||||
|
|
@ -17,15 +17,15 @@ use perflib::*;
|
|||
use persistent_store::store::OPENSK2_DICT;
|
||||
use vault::env::xous::U2F_APP_DICT;
|
||||
use vault::{
|
||||
atime_to_str, basis_change, ctap::data_formats::PublicKeyCredentialSource, deserialize_app_info,
|
||||
serialize_app_info, utc_now, AppInfo, VAULT_ALLOC_HINT, VAULT_PASSWORD_DICT, VAULT_TOTP_DICT,
|
||||
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,
|
||||
};
|
||||
use xous::{send_message, Message};
|
||||
use xous::{Message, send_message};
|
||||
|
||||
use crate::storage::{self, PasswordRecord, StorageContent};
|
||||
use crate::totp::TotpAlgorithm;
|
||||
use crate::{storage::TotpRecord, ListItem, ListKey};
|
||||
use crate::{ItemLists, SelectedEntry, VaultMode};
|
||||
use crate::{ListItem, ListKey, storage::TotpRecord};
|
||||
#[cfg(feature = "vaultperf")]
|
||||
const FILE_ID_APPS_VAULT_SRC_ACTIONS: u32 = 1;
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ impl<'a> ActionManager<'a> {
|
|||
.field(None, Some(password_validator))
|
||||
.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");
|
||||
self.action_active.store(false, Ordering::SeqCst);
|
||||
|
|
@ -179,7 +179,7 @@ impl<'a> ActionManager<'a> {
|
|||
.field(None, Some(password_validator))
|
||||
.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");
|
||||
self.action_active.store(false, Ordering::SeqCst);
|
||||
|
|
@ -246,7 +246,7 @@ impl<'a> ActionManager<'a> {
|
|||
.field(Some(password), Some(password_validator))
|
||||
.build()
|
||||
{
|
||||
Ok(text) => text.content()[0].content,
|
||||
Ok(text) => &text.content()[0].content,
|
||||
_ => {
|
||||
log::error!("Name entry failed");
|
||||
self.action_active.store(false, Ordering::SeqCst);
|
||||
|
|
@ -322,7 +322,7 @@ impl<'a> ActionManager<'a> {
|
|||
#[cfg(feature = "ux-swap-delay")]
|
||||
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
|
||||
let pg2 = PasswordGenerator {
|
||||
length: length as usize,
|
||||
length: *length as usize,
|
||||
numbers: number,
|
||||
lowercase_letters: lower,
|
||||
uppercase_letters: upper,
|
||||
|
|
@ -342,13 +342,13 @@ impl<'a> ActionManager<'a> {
|
|||
}
|
||||
} else {
|
||||
approved = true;
|
||||
maybe_password
|
||||
maybe_password.to_string()
|
||||
};
|
||||
}
|
||||
let mut record = storage::PasswordRecord {
|
||||
version: VAULT_PASSWORD_REC_VERSION,
|
||||
description,
|
||||
username,
|
||||
description: description.to_string(),
|
||||
username: username.to_string(),
|
||||
password,
|
||||
notes: if bip39 {
|
||||
"bip39".to_string()
|
||||
|
|
@ -382,7 +382,7 @@ impl<'a> ActionManager<'a> {
|
|||
.field(None, Some(password_validator))
|
||||
.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");
|
||||
self.action_active.store(false, Ordering::SeqCst);
|
||||
|
|
@ -422,7 +422,7 @@ impl<'a> ActionManager<'a> {
|
|||
.field(None, Some(totp_ss_validator))
|
||||
.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");
|
||||
self.action_active.store(false, Ordering::SeqCst);
|
||||
|
|
@ -460,7 +460,7 @@ impl<'a> ActionManager<'a> {
|
|||
.field(Some("0".to_string()), Some(count_validator))
|
||||
.build()
|
||||
{
|
||||
Ok(entry) => &(entry.content()[0].content).parse::<u64>().unwrap(),
|
||||
Ok(entry) => (entry.content()[0].content).parse::<u64>().unwrap(),
|
||||
_ => {
|
||||
log::error!("Count entry failed");
|
||||
self.action_active.store(false, Ordering::SeqCst);
|
||||
|
|
@ -475,7 +475,7 @@ impl<'a> ActionManager<'a> {
|
|||
// record after entering it.
|
||||
let mut totp = storage::TotpRecord {
|
||||
version: VAULT_TOTP_REC_VERSION,
|
||||
name: description,
|
||||
name: description.to_string(),
|
||||
secret: validated_secret,
|
||||
algorithm: TotpAlgorithm::HmacSha1,
|
||||
digits: 6,
|
||||
|
|
@ -512,20 +512,19 @@ impl<'a> ActionManager<'a> {
|
|||
|
||||
if choice.is_none() {
|
||||
// we're dealing with FIDO stuff, use the custom code path
|
||||
let dictionary =
|
||||
match usize::from_str_radix(entry.key_guid.as_str().unwrap_or("UTF8-error"), 10) {
|
||||
Ok(fido_key) => {
|
||||
if vault::ctap::storage::key::CREDENTIALS.contains(&fido_key) {
|
||||
persistent_store::store::OPENSK2_DICT // heuristic: all fido2 keys are simple integers
|
||||
} else {
|
||||
U2F_APP_DICT
|
||||
}
|
||||
let dictionary = match usize::from_str_radix(entry.key_guid.as_str(), 10) {
|
||||
Ok(fido_key) => {
|
||||
if vault::ctap::storage::key::CREDENTIALS.contains(&fido_key) {
|
||||
persistent_store::store::OPENSK2_DICT // heuristic: all fido2 keys are simple integers
|
||||
} else {
|
||||
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(
|
||||
dictionary,
|
||||
entry.key_guid.as_str().unwrap_or("UTF8-error"),
|
||||
entry.key_guid.as_str(),
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
|
|
@ -536,7 +535,7 @@ impl<'a> ActionManager<'a> {
|
|||
let attr = candidate.attributes().expect("couldn't get key attributes");
|
||||
match self.pddb.borrow().delete_key(
|
||||
dictionary,
|
||||
entry.key_guid.as_str().unwrap_or("UTF8-error"),
|
||||
entry.key_guid.as_str(),
|
||||
Some(&attr.basis),
|
||||
) {
|
||||
Ok(_) => {
|
||||
|
|
@ -556,7 +555,7 @@ impl<'a> ActionManager<'a> {
|
|||
} else {
|
||||
// we're deleting either a password, or a totp
|
||||
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 {
|
||||
// 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
|
||||
|
|
@ -604,7 +603,7 @@ impl<'a> ActionManager<'a> {
|
|||
match entry.mode {
|
||||
VaultMode::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 pw: storage::PasswordRecord = match storage.get_record(&choice, guid) {
|
||||
Ok(record) => record,
|
||||
|
|
@ -1438,7 +1437,7 @@ impl<'a> ActionManager<'a> {
|
|||
.field(None, Some(name_validator))
|
||||
.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");
|
||||
self.action_active.store(false, Ordering::SeqCst);
|
||||
|
|
@ -1492,7 +1491,7 @@ impl<'a> ActionManager<'a> {
|
|||
.field(None, Some(name_validator))
|
||||
.build()
|
||||
{
|
||||
Ok(text) => text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string(),
|
||||
Ok(text) => &text.content()[0].content,
|
||||
Err(e) => {
|
||||
self.report_err(t!("vault.error.internal_error", locales::LANG), Some(e));
|
||||
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();
|
||||
if let Some(ss) = base32::decode(base32::Alphabet::RFC4648 { padding: false }, &proposed_ss) {
|
||||
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)))
|
||||
}
|
||||
pub(crate) fn name_validator(input: TextEntryPayload) -> Option<String> {
|
||||
pub(crate) fn name_validator(input: &TextEntryPayload) -> Option<String> {
|
||||
let proposed_name = input.as_str();
|
||||
if proposed_name.contains(['\n', ':']) {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
pub(crate) fn password_validator(input: TextEntryPayload) -> Option<String> {
|
||||
pub(crate) fn password_validator(input: &TextEntryPayload) -> Option<String> {
|
||||
let proposed_name = input.as_str();
|
||||
if proposed_name.contains(['\n']) {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
fn length_validator(input: TextEntryPayload) -> Option<String> {
|
||||
fn length_validator(input: &TextEntryPayload) -> Option<String> {
|
||||
let text_str = input.as_str();
|
||||
match text_str.parse::<u32>() {
|
||||
Ok(input_int) => {
|
||||
|
|
@ -1847,7 +1846,7 @@ fn length_validator(input: TextEntryPayload) -> Option<String> {
|
|||
_ => 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();
|
||||
match text_str.parse::<u64>() {
|
||||
Ok(_input_int) => None,
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ use actions::ActionOp;
|
|||
use itemcache::*;
|
||||
use locales::t;
|
||||
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::env::xous::XousEnv;
|
||||
use vault::env::Env;
|
||||
use vault::{Transport, VaultOp, SELF_CONN};
|
||||
use xous::{msg_blocking_scalar_unpack, msg_scalar_unpack, send_message, Message};
|
||||
use vault::env::xous::XousEnv;
|
||||
use vault::{SELF_CONN, Transport, VaultOp};
|
||||
use xous::{Message, msg_blocking_scalar_unpack, msg_scalar_unpack, send_message};
|
||||
use xous_ipc::Buffer;
|
||||
use xous_usb_hid::device::fido::*;
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ pub enum VaultMode {
|
|||
Password,
|
||||
}
|
||||
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
|
||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
|
||||
pub struct SelectedEntry {
|
||||
pub key_guid: String,
|
||||
pub description: String,
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ pub(crate) fn icontray_server(conn_to_main: xous::CID) {
|
|||
// every key press, the four slots get queried
|
||||
prediction.string.clear();
|
||||
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;
|
||||
} else {
|
||||
prediction.valid = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue