mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
Merge remote-tracking branch 'origin/vault' into libstd-fs
This commit is contained in:
commit
1388da7680
10 changed files with 456 additions and 238 deletions
|
|
@ -1,4 +1,34 @@
|
|||
{
|
||||
"vault.basis.name": {
|
||||
"en": "Enter name of Basis to unlock:",
|
||||
"ja": "ロックを解除する基準の名前を入力してください:",
|
||||
"zh": "输入要解锁的基础名称:",
|
||||
"en-tts": "Enter name of Basis to unlock:"
|
||||
},
|
||||
"vault.basis.create": {
|
||||
"en": "Enter name of Basis to create:",
|
||||
"ja": "作成する基準の名前を入力します:",
|
||||
"zh": "输入要创建的基础名称:",
|
||||
"en-tts": "Enter name of Basis to create:"
|
||||
},
|
||||
"vault.basis.created_mount": {
|
||||
"en": "Basis created. Mount it now?",
|
||||
"ja": "ベーシスが作成されました。 今それをマウントしますか?",
|
||||
"zh": "创建的基础。 现在装吗?",
|
||||
"en-tts": "Basis created. Mount it now?"
|
||||
},
|
||||
"vault.basis.none": {
|
||||
"en": "No active secret Bases. Would you like to create one?",
|
||||
"ja": "アクティブな秘密の根拠はありません。 作成しますか?",
|
||||
"zh": "没有有效的秘密基础。 你想创建一个吗?",
|
||||
"en-tts": "No active secret Bases. Would you like to create one?"
|
||||
},
|
||||
"vault.basis.unmount": {
|
||||
"en": "Select the Bases to unmount:",
|
||||
"ja": "アンマウントするベースを選択します:",
|
||||
"zh": "选择要卸载的基础:",
|
||||
"en-tts": "Select the Bases to unmount:"
|
||||
},
|
||||
"vault.edit_dialog": {
|
||||
"en": "Make your changes and press enter.\nUse the d-pad to navigate entries.",
|
||||
"ja": "変更を加えてEnterキーを押します。 D-PADを使用してエントリをナビゲートします。",
|
||||
|
|
@ -17,6 +47,12 @@
|
|||
"zh": "现在自动输入...",
|
||||
"en-tts": "Autotyping..."
|
||||
},
|
||||
"vault.error.basis_unlock_error": {
|
||||
"en": "Basis does not exist. Or maybe wrong password?",
|
||||
"ja": "根拠は存在しません。 または多分間違ったパスワード?",
|
||||
"zh": "基础不存在。 或者密码错误?",
|
||||
"en-tts": "Basis does not exist. Or maybe wrong password?"
|
||||
},
|
||||
"vault.error.mount_pddb": {
|
||||
"en": "PDDB not mounted. Please init root keys and then init PDDB.",
|
||||
"ja": "PDDBがマウントされていません。 ルートキーを初期化してから、PDDBを初期化してください。",
|
||||
|
|
@ -359,6 +395,18 @@
|
|||
"zh": "更改字体",
|
||||
"en-tts": "🔇"
|
||||
},
|
||||
"vault.menu_unlock_basis": {
|
||||
"en": "Unlock secret Basis",
|
||||
"ja": "シークレットベースのロックを解除",
|
||||
"zh": "解锁秘密基础",
|
||||
"en-tts": "Unlock secret basis"
|
||||
},
|
||||
"vault.menu_manage_basis": {
|
||||
"en": "Manage Bases",
|
||||
"ja": "管理基盤",
|
||||
"zh": "管理基础",
|
||||
"en-tts": "Manage Bases"
|
||||
},
|
||||
"vault.menu_close": {
|
||||
"en": "Close submenu",
|
||||
"ja": "メニューを閉じる",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use core::convert::TryFrom;
|
||||
use std::thread;
|
||||
use std::{thread, io::ErrorKind};
|
||||
use gam::TextEntryPayload;
|
||||
use pddb::BasisRetentionPolicy;
|
||||
use std::sync::{Arc, Mutex, atomic::{AtomicBool, Ordering}};
|
||||
use num_traits::*;
|
||||
use xous::{SID, msg_blocking_scalar_unpack, Message, send_message};
|
||||
|
|
@ -58,6 +59,8 @@ pub(crate) enum ActionOp {
|
|||
MenuEditStage2,
|
||||
MenuDeleteStage2,
|
||||
MenuClose,
|
||||
MenuUnlockBasis,
|
||||
MenuManageBasis,
|
||||
/// Internal ops
|
||||
UpdateMode,
|
||||
Quit,
|
||||
|
|
@ -103,6 +106,18 @@ pub(crate) fn start_actions_thread(
|
|||
manager.retrieve_db();
|
||||
manager.deactivate();
|
||||
},
|
||||
Some(ActionOp::MenuUnlockBasis) => {
|
||||
manager.activate();
|
||||
manager.unlock_basis();
|
||||
manager.retrieve_db();
|
||||
manager.deactivate();
|
||||
},
|
||||
Some(ActionOp::MenuManageBasis) => {
|
||||
manager.activate();
|
||||
manager.manage_basis();
|
||||
manager.retrieve_db();
|
||||
manager.deactivate();
|
||||
}
|
||||
Some(ActionOp::MenuClose) => {
|
||||
// dummy activate/de-activate cycle because we have to trigger a redraw of the underlying UX
|
||||
manager.activate();
|
||||
|
|
@ -333,10 +348,12 @@ impl ActionManager {
|
|||
Ok(mut data) => {
|
||||
match data.write(&ser) {
|
||||
Ok(len) => log::debug!("wrote {} bytes", len),
|
||||
Err(e) => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
Err(e) => {log::error!("internal error");
|
||||
self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e))},
|
||||
}
|
||||
}
|
||||
Err(e) => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
Err(e) => { log::error!("internal error");
|
||||
self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e))},
|
||||
}
|
||||
log::debug!("syncing...");
|
||||
self.pddb.borrow().sync().ok();
|
||||
|
|
@ -485,23 +502,31 @@ impl ActionManager {
|
|||
pw.notes = edit_data.content()[3].content.as_str().unwrap().to_string();
|
||||
pw.atime = utc_now().timestamp() as u64;
|
||||
Some(pw)
|
||||
} else { self.report_err(t!("vault.error.record_error", xous::LANG), None::<std::io::Error>); None }
|
||||
} else { log::error!("record error");
|
||||
self.report_err(t!("vault.error.record_error", xous::LANG), None::<std::io::Error>); None }
|
||||
}
|
||||
Err(e) => { self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)); None }
|
||||
Err(e) => { log::error!("internal error"); self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)); None }
|
||||
};
|
||||
maybe_update
|
||||
}
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::NotFound => self.report_err(t!("vault.error.not_found", xous::LANG), None::<std::io::Error>),
|
||||
_ => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
std::io::ErrorKind::NotFound => {
|
||||
log::error!("not found");
|
||||
self.report_err(t!("vault.error.not_found", xous::LANG), None::<std::io::Error>)
|
||||
},
|
||||
_ => {
|
||||
log::error!("internal error");
|
||||
self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e))
|
||||
},
|
||||
}
|
||||
None
|
||||
}
|
||||
};
|
||||
if let Some(update) = maybe_update {
|
||||
self.pddb.borrow().delete_key(dict, entry.key_name.as_str().unwrap(), None)
|
||||
.unwrap_or_else(|e| self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)));
|
||||
.unwrap_or_else(|e| {log::error!("internal error");
|
||||
self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e))});
|
||||
match self.pddb.borrow().get(
|
||||
dict, entry.key_name.as_str().unwrap(), None,
|
||||
false, true, Some(VAULT_ALLOC_HINT),
|
||||
|
|
@ -511,9 +536,13 @@ impl ActionManager {
|
|||
let ser = serialize_password(&update);
|
||||
record.write(&ser)
|
||||
.unwrap_or_else(|e| {
|
||||
log::error!("internal error");
|
||||
self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)); 0});
|
||||
}
|
||||
Err(e) => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
Err(e) => {
|
||||
log::error!("internal error");
|
||||
self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e))
|
||||
},
|
||||
}
|
||||
}
|
||||
self.pddb.borrow().sync().ok();
|
||||
|
|
@ -548,7 +577,7 @@ impl ActionManager {
|
|||
}
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::NotFound => self.report_err(t!("vault.error.not_found", xous::LANG), None::<std::io::Error>),
|
||||
std::io::ErrorKind::NotFound => self.report_err(t!("vault.error.fido2", xous::LANG), None::<std::io::Error>),
|
||||
_ => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
}
|
||||
None
|
||||
|
|
@ -682,7 +711,10 @@ impl ActionManager {
|
|||
std::io::ErrorKind::NotFound => {
|
||||
log::debug!("Password dictionary not yet created");
|
||||
}
|
||||
_ => self.report_err("Dictionary error accessing password database", Some(e)),
|
||||
_ => {
|
||||
log::error!("Dictionary error accessing password database");
|
||||
self.report_err("Dictionary error accessing password database", Some(e))
|
||||
},
|
||||
}
|
||||
Vec::new()
|
||||
}
|
||||
|
|
@ -714,13 +746,20 @@ impl ActionManager {
|
|||
};
|
||||
il.push(li);
|
||||
} else {
|
||||
log::error!("Couldn't deserialize password");
|
||||
self.report_err("Couldn't deserialize password:", Some(key));
|
||||
}
|
||||
}
|
||||
Err(e) => self.report_err("Couldn't access password key", Some(e)),
|
||||
Err(e) => {
|
||||
log::error!("Couldn't access password key");
|
||||
self.report_err("Couldn't access password key", Some(e))
|
||||
},
|
||||
}
|
||||
}
|
||||
Err(e) => self.report_err("Couldn't access password key", Some(e)),
|
||||
Err(e) => {
|
||||
log::error!("Couldn't access password key");
|
||||
self.report_err("Couldn't access password key", Some(e))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -876,6 +915,87 @@ impl ActionManager {
|
|||
}
|
||||
il.sort();
|
||||
}
|
||||
|
||||
pub(crate) fn unlock_basis(&mut self) {
|
||||
let name = match self.modals
|
||||
.alert_builder(t!("vault.basis.name", xous::LANG))
|
||||
.field(None, Some(name_validator))
|
||||
.build()
|
||||
{
|
||||
Ok(text) => {
|
||||
text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string()
|
||||
},
|
||||
_ => {log::error!("Name entry failed"); self.action_active.store(false, Ordering::SeqCst); return}
|
||||
};
|
||||
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
|
||||
match self.pddb.borrow().unlock_basis(&name, Some(BasisRetentionPolicy::Persist)) {
|
||||
Ok(_) => log::debug!("Basis {} unlocked", name),
|
||||
Err(e) => match e.kind() {
|
||||
ErrorKind::PermissionDenied => {
|
||||
self.report_err(t!("vault.error.basis_unlock_error", xous::LANG), None::<std::io::Error>)
|
||||
},
|
||||
_ => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn manage_basis(&mut self) {
|
||||
let mut bases = self.pddb.borrow().list_basis();
|
||||
bases.retain(|name| name != pddb::PDDB_DEFAULT_SYSTEM_BASIS);
|
||||
let b: Vec<&str> = bases.iter().map(AsRef::as_ref).collect();
|
||||
if bases.len() > 0 {
|
||||
self.modals
|
||||
.add_list(
|
||||
b
|
||||
).expect("couldn't create unmount modal");
|
||||
match self.modals.get_checkbox(t!("vault.basis.unmount", xous::LANG)) {
|
||||
Ok(unmount) => {
|
||||
for b in unmount {
|
||||
match self.pddb.borrow().lock_basis(&b) {
|
||||
Ok(_) => log::debug!("basis {} locked", b),
|
||||
Err(e) => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
}
|
||||
} else {
|
||||
if self.yes_no_approval(t!("vault.basis.none", xous::LANG)) {
|
||||
let name = match self.modals
|
||||
.alert_builder(t!("vault.basis.create", xous::LANG))
|
||||
.field(None, Some(name_validator))
|
||||
.build()
|
||||
{
|
||||
Ok(text) => {
|
||||
text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string()
|
||||
},
|
||||
Err(e) => {self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)); return}
|
||||
};
|
||||
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
|
||||
match self.pddb.borrow().create_basis(&name) {
|
||||
Ok(_) => {
|
||||
if self.yes_no_approval(t!("vault.basis.created_mount", xous::LANG)) {
|
||||
match self.pddb.borrow().unlock_basis(&name, Some(BasisRetentionPolicy::Persist)) {
|
||||
Ok(_) => log::debug!("Basis {} unlocked", name),
|
||||
Err(e) => match e.kind() {
|
||||
ErrorKind::PermissionDenied => {
|
||||
self.report_err(t!("vault.error.basis_unlock_error", xous::LANG), None::<std::io::Error>)
|
||||
},
|
||||
_ => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
Err(e) => self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)),
|
||||
}
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="testing")]
|
||||
pub(crate) fn populate_tests(&mut self) {
|
||||
use crate::ux::serialize_app_info;
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ impl PersistentStore {
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::MASTER_KEYS,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(64), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut master_keys) => {
|
||||
|
|
@ -152,7 +152,7 @@ impl PersistentStore {
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::CRED_RANDOM_SECRET,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(64), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut cred_random) => {
|
||||
|
|
@ -174,7 +174,7 @@ impl PersistentStore {
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::AAGUID,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(16), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut aaguid) => {
|
||||
|
|
@ -220,7 +220,7 @@ impl PersistentStore {
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::ATTESTATION_PRIVATE_KEY,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(32), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut aapriv) => {
|
||||
|
|
@ -244,7 +244,7 @@ impl PersistentStore {
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::ATTESTATION_CERTIFICATE,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(512), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut cert) => {
|
||||
|
|
@ -516,7 +516,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::GLOBAL_SIGNATURE_COUNTER,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(4), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut gsc) => {
|
||||
|
|
@ -546,7 +546,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::GLOBAL_SIGNATURE_COUNTER,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(4), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut gsc) => {
|
||||
|
|
@ -565,7 +565,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::MASTER_KEYS,
|
||||
None, false, false, None, Some(crate::basis_change)
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false, None, Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut mk) => {
|
||||
let mut master_keys = [0u8; 64];
|
||||
|
|
@ -588,7 +588,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::CRED_RANDOM_SECRET,
|
||||
None, false, false, None, Some(crate::basis_change)
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false, None, Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut crs) => {
|
||||
let mut cred_random_secret = [0u8; 64];
|
||||
|
|
@ -609,7 +609,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::PIN_HASH,
|
||||
None, false, false, None, Some(crate::basis_change)
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false, None, Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut ph) => {
|
||||
let mut pin_hash = [0u8; PIN_AUTH_LENGTH];
|
||||
|
|
@ -648,7 +648,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::PIN_HASH,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(PIN_AUTH_LENGTH), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut ph) => {
|
||||
|
|
@ -677,7 +677,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::PIN_RETRIES,
|
||||
None, false, false, None, Some(crate::basis_change)
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false, None, Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut pr) => {
|
||||
let mut value = [0u8; 1];
|
||||
|
|
@ -701,7 +701,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::PIN_RETRIES,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(1), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut pr) => {
|
||||
|
|
@ -721,7 +721,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().delete_key(
|
||||
FIDO_DICT,
|
||||
PIN_RETRIES,
|
||||
None
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS)
|
||||
) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => match e.kind() {
|
||||
|
|
@ -737,7 +737,8 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::MIN_PIN_LENGTH,
|
||||
None, false, false, None, Some(crate::basis_change)
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS),
|
||||
false, false, None, Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut pr) => {
|
||||
let mut value = [0u8; 1];
|
||||
|
|
@ -759,7 +760,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::MIN_PIN_LENGTH,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(1), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut pl) => {
|
||||
|
|
@ -779,7 +780,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
if let Some(mut mplri) = self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::_MIN_PIN_LENGTH_RP_IDS,
|
||||
None, false, false,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false,
|
||||
None, Some(crate::basis_change)
|
||||
).ok() {
|
||||
let mut data = Vec::<u8>::new();
|
||||
|
|
@ -812,7 +813,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_DICT,
|
||||
key::_MIN_PIN_LENGTH_RP_IDS,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(_MAX_RP_IDS_LENGTH), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut mrpli) => {
|
||||
|
|
@ -831,7 +832,8 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::ATTESTATION_PRIVATE_KEY,
|
||||
None, false, false, None, Some(crate::basis_change)
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false,
|
||||
None, Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut apk) => {
|
||||
let mut key = [0u8; key_material::ATTESTATION_PRIVATE_KEY_LENGTH];
|
||||
|
|
@ -863,7 +865,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::ATTESTATION_PRIVATE_KEY,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(key_material::ATTESTATION_PRIVATE_KEY_LENGTH), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut apk) => {
|
||||
|
|
@ -882,7 +884,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
if let Some(mut acert) = self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::ATTESTATION_CERTIFICATE,
|
||||
None, false, false,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false,
|
||||
None, Some(crate::basis_change)
|
||||
).ok() {
|
||||
let mut data = Vec::<u8>::new();
|
||||
|
|
@ -907,7 +909,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::ATTESTATION_CERTIFICATE,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(1024), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut acert) => {
|
||||
|
|
@ -926,7 +928,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
if let Some(mut guid) = self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::AAGUID,
|
||||
None, false, false,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false,
|
||||
None, Some(crate::basis_change)
|
||||
).ok() {
|
||||
let mut data = [0u8; key_material::AAGUID_LENGTH];
|
||||
|
|
@ -952,7 +954,7 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
match self.pddb.borrow().get(
|
||||
FIDO_PERSISTENT_DICT,
|
||||
key::AAGUID,
|
||||
None, false, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, true,
|
||||
Some(key_material::AAGUID_LENGTH), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut guid) => {
|
||||
|
|
@ -970,27 +972,29 @@ openssl asn1parse -in opensk_cert.pem -inform pem
|
|||
///
|
||||
/// In particular persistent entries are not reset.
|
||||
pub fn reset(&mut self, _rng: &mut impl Rng256) -> Result<(), Ctap2StatusCode> {
|
||||
match self.pddb.borrow().delete_dict(FIDO_DICT, None) {
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => Ok(()),
|
||||
_ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), // PDDB internal error
|
||||
}
|
||||
Ok(_) => Ok(()),
|
||||
}?;
|
||||
match self.pddb.borrow().delete_dict(FIDO_CRED_DICT, None) {
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => Ok(()),
|
||||
_ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), // PDDB internal error
|
||||
}
|
||||
Ok(_) => Ok(()),
|
||||
}?;
|
||||
match self.pddb.borrow().delete_dict(crate::fido::U2F_APP_DICT, None) {
|
||||
match self.pddb.borrow().delete_dict(FIDO_DICT, Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS)) {
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => Ok(()),
|
||||
_ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), // PDDB internal error
|
||||
}
|
||||
Ok(_) => Ok(()),
|
||||
}?;
|
||||
for basis in self.pddb.borrow().list_basis().iter () {
|
||||
match self.pddb.borrow().delete_dict(FIDO_CRED_DICT, Some(basis)) {
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => Ok(()),
|
||||
_ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), // PDDB internal error
|
||||
}
|
||||
Ok(_) => Ok(()),
|
||||
}?;
|
||||
match self.pddb.borrow().delete_dict(crate::fido::U2F_APP_DICT, Some(basis)) {
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => Ok(()),
|
||||
_ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), // PDDB internal error
|
||||
}
|
||||
Ok(_) => Ok(()),
|
||||
}?;
|
||||
}
|
||||
// don't delete the persistent dictionary...
|
||||
self.init()?;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -107,6 +107,10 @@ To clear test entries:
|
|||
pddb dictdelete vault.totp
|
||||
pddb dictdelete fido.cred
|
||||
pddb dictdelete fido.u2fapps
|
||||
|
||||
Issue: editing an entry in a non-secret basis while a secret basis is open won't work because
|
||||
the delete key function doesn't work in that case. Need to modify the `get` routine to return
|
||||
the basis so we can specify which basis to edit...
|
||||
*/
|
||||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
|
|
@ -471,6 +475,7 @@ fn check_user_presence(_cid: ChannelID) -> Result<(), Ctap2StatusCode> {
|
|||
}
|
||||
|
||||
pub(crate) fn basis_change() {
|
||||
log::info!("got basis change");
|
||||
xous::send_message(SELF_CONN.load(Ordering::SeqCst),
|
||||
Message::new_scalar(VaultOp::BasisChange.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).unwrap();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,20 @@ pub fn create_submenu(vault_conn: xous::CID, actions_conn: xous::CID, menu_mgr:
|
|||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
menu_items.push(MenuItem {
|
||||
name: xous_ipc::String::from_str(t!("vault.menu_unlock_basis", xous::LANG)),
|
||||
action_conn: Some(actions_conn),
|
||||
action_opcode: ActionOp::MenuUnlockBasis.to_u32().unwrap(),
|
||||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
menu_items.push(MenuItem {
|
||||
name: xous_ipc::String::from_str(t!("vault.menu_manage_basis", xous::LANG)),
|
||||
action_conn: Some(actions_conn),
|
||||
action_opcode: ActionOp::MenuManageBasis.to_u32().unwrap(),
|
||||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
menu_items.push(MenuItem {
|
||||
name: xous_ipc::String::from_str(t!("vault.menu_change_font", xous::LANG)),
|
||||
action_conn: Some(vault_conn),
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ pub(crate) struct VaultUx {
|
|||
filtered_list: Vec::<ListItem>,
|
||||
/// the index into the item_list that is selected
|
||||
selection_index: usize,
|
||||
/// last filter query, so we can re-use it when mode is changed
|
||||
last_query: String,
|
||||
|
||||
/// pddb handle
|
||||
pddb: RefCell::<Pddb>,
|
||||
|
|
@ -176,6 +178,7 @@ impl VaultUx {
|
|||
usb_dev: usb_device_xous::UsbHid::new(),
|
||||
last_epoch: current_time / 30,
|
||||
current_time,
|
||||
last_query: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -183,18 +186,21 @@ impl VaultUx {
|
|||
self.title_dirty = true;
|
||||
self.filtered_list.clear();
|
||||
self.selection_index = 0;
|
||||
self.filter("");
|
||||
let query = self.last_query.to_string();
|
||||
self.filter(&query);
|
||||
self.swap_submenu();
|
||||
}
|
||||
|
||||
/*
|
||||
Entry Users
|
||||
-------------------------------------
|
||||
- autotype pw
|
||||
- autotype pw totp
|
||||
- add new pw totp
|
||||
- edit pw totp fido
|
||||
- delete pw totp fido
|
||||
- change font pw totp fido
|
||||
- unlock basis pw totp fido
|
||||
- list/lock basis pw totp fido
|
||||
- close pw totp fido
|
||||
*/
|
||||
pub fn swap_submenu(&mut self) {
|
||||
|
|
@ -203,19 +209,7 @@ impl VaultUx {
|
|||
self.menu_mgr.delete_item(t!("vault.menu_addnew", xous::LANG));
|
||||
match *self.mode.lock().unwrap() {
|
||||
VaultMode::Fido => (),
|
||||
VaultMode::Totp => {
|
||||
self.menu_mgr.insert_item(
|
||||
MenuItem {
|
||||
name: xous_ipc::String::from_str(t!("vault.menu_addnew", xous::LANG)),
|
||||
action_conn: Some(self.actions_conn),
|
||||
action_opcode: ActionOp::MenuAddnew.to_u32().unwrap(),
|
||||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
},
|
||||
0
|
||||
);
|
||||
},
|
||||
VaultMode::Password => {
|
||||
VaultMode::Password | VaultMode::Totp => {
|
||||
self.menu_mgr.insert_item(
|
||||
MenuItem {
|
||||
name: xous_ipc::String::from_str(t!("vault.menu_addnew", xous::LANG)),
|
||||
|
|
@ -244,7 +238,7 @@ impl VaultUx {
|
|||
let style = match self.pddb.borrow().get(
|
||||
VAULT_CONFIG_DICT,
|
||||
VAULT_CONFIG_KEY_FONT,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(32), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut style_key) => {
|
||||
|
|
@ -275,13 +269,13 @@ impl VaultUx {
|
|||
self.items_per_screen = available_height / self.item_height;
|
||||
}
|
||||
pub(crate) fn set_glyph_style(&mut self, style: GlyphStyle) {
|
||||
self.pddb.borrow().delete_key(VAULT_CONFIG_DICT, VAULT_CONFIG_KEY_FONT, None)
|
||||
self.pddb.borrow().delete_key(VAULT_CONFIG_DICT, VAULT_CONFIG_KEY_FONT, Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS))
|
||||
.expect("couldn't delete previous setting");
|
||||
|
||||
match self.pddb.borrow().get(
|
||||
VAULT_CONFIG_DICT,
|
||||
VAULT_CONFIG_KEY_FONT,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(32), Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut style_key) => {
|
||||
|
|
@ -358,6 +352,7 @@ impl VaultUx {
|
|||
pub(crate) fn input(&mut self, line: &str) -> Result<(), xous::Error> {
|
||||
self.title_dirty = true;
|
||||
self.filter(line);
|
||||
self.last_query = line.to_string();
|
||||
Ok(())
|
||||
}
|
||||
fn get_page(&self) -> i16 {
|
||||
|
|
@ -647,74 +642,102 @@ impl VaultUx {
|
|||
if self.selection_index >= self.filtered_list.len() {
|
||||
return Err(xous::Error::InvalidPID);
|
||||
}
|
||||
let entry = &self.filtered_list[self.selection_index].guid;
|
||||
// we re-fetch the entry for autotype, because the PDDB could have unmounted a basis.
|
||||
let updated_pw = match self.pddb.borrow().get(
|
||||
crate::actions::VAULT_PASSWORD_DICT,
|
||||
entry,
|
||||
None,
|
||||
false, false, None,
|
||||
Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut record) => {
|
||||
let mut data = Vec::<u8>::new();
|
||||
match record.read_to_end(&mut data) {
|
||||
Ok(_len) => {
|
||||
if let Some(mut pw) = crate::actions::deserialize_password(data) {
|
||||
match self.usb_dev.send_str(&pw.password) {
|
||||
Ok(_) => {
|
||||
pw.count += 1;
|
||||
pw.atime = utc_now().timestamp() as u64;
|
||||
pw
|
||||
},
|
||||
Err(e) => {
|
||||
log::error!("couldn't autotype password: {:?}", e);
|
||||
return Err(xous::Error::UseBeforeInit);
|
||||
let mode_cache = (*self.mode.lock().unwrap()).clone();
|
||||
match mode_cache {
|
||||
VaultMode::Password => {
|
||||
let entry = &self.filtered_list[self.selection_index].guid;
|
||||
// we re-fetch the entry for autotype, because the PDDB could have unmounted a basis.
|
||||
let updated_pw = match self.pddb.borrow().get(
|
||||
crate::actions::VAULT_PASSWORD_DICT,
|
||||
entry,
|
||||
None,
|
||||
false, false, None,
|
||||
Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut record) => {
|
||||
let mut data = Vec::<u8>::new();
|
||||
match record.read_to_end(&mut data) {
|
||||
Ok(_len) => {
|
||||
if let Some(mut pw) = crate::actions::deserialize_password(data) {
|
||||
match self.usb_dev.send_str(&pw.password) {
|
||||
Ok(_) => {
|
||||
pw.count += 1;
|
||||
pw.atime = utc_now().timestamp() as u64;
|
||||
pw
|
||||
},
|
||||
Err(e) => {
|
||||
log::error!("couldn't autotype password: {:?}", e);
|
||||
return Err(xous::Error::UseBeforeInit);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log::error!("couldn't deserialize {}", entry);
|
||||
return Err(xous::Error::InvalidString);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log::error!("couldn't deserialize {}", entry);
|
||||
return Err(xous::Error::InvalidString);
|
||||
Err(e) => {
|
||||
log::error!("couldn't access key {}: {:?}", entry, e);
|
||||
return Err(xous::Error::ProcessNotFound);
|
||||
},
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("couldn't access key {}: {:?}", entry, e);
|
||||
return Err(xous::Error::ProcessNotFound);
|
||||
},
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("couldn't access key {}: {:?}", entry, e);
|
||||
return Err(xous::Error::ProcessNotFound);
|
||||
}
|
||||
};
|
||||
match self.pddb.borrow().delete_key(crate::actions::VAULT_PASSWORD_DICT, entry, None) {
|
||||
Ok(_) => {}
|
||||
Err(_e) => {
|
||||
return Err(xous::Error::InternalError);
|
||||
}
|
||||
}
|
||||
match self.pddb.borrow().get(
|
||||
crate::actions::VAULT_PASSWORD_DICT, entry, None,
|
||||
false, true, Some(crate::actions::VAULT_ALLOC_HINT),
|
||||
Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut record) => {
|
||||
let ser = crate::actions::serialize_password(&updated_pw);
|
||||
match record.write(&ser) {
|
||||
}
|
||||
};
|
||||
match self.pddb.borrow().delete_key(crate::actions::VAULT_PASSWORD_DICT, entry, None) {
|
||||
Ok(_) => {}
|
||||
Err(_e) => {
|
||||
return Err(xous::Error::InternalError);
|
||||
}
|
||||
}
|
||||
match self.pddb.borrow().get(
|
||||
crate::actions::VAULT_PASSWORD_DICT, entry, None,
|
||||
false, true, Some(crate::actions::VAULT_ALLOC_HINT),
|
||||
Some(crate::basis_change)
|
||||
) {
|
||||
Ok(mut record) => {
|
||||
let ser = crate::actions::serialize_password(&updated_pw);
|
||||
match record.write(&ser) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
log::error!("couldn't update key {}: {:?}", entry, e);
|
||||
return Err(xous::Error::OutOfMemory);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("couldn't update key {}: {:?}", entry, e);
|
||||
return Err(xous::Error::OutOfMemory);
|
||||
}
|
||||
}
|
||||
self.pddb.borrow().sync().ok();
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("couldn't update key {}: {:?}", entry, e);
|
||||
return Err(xous::Error::OutOfMemory);
|
||||
VaultMode::Totp => {
|
||||
let fields = self.filtered_list[self.selection_index].extra.split(':').collect::<Vec<&str>>();
|
||||
if fields.len() == 4 {
|
||||
let shared_secret = base32::decode(
|
||||
base32::Alphabet::RFC4648 { padding: false }, fields[0])
|
||||
.unwrap_or(vec![]);
|
||||
let digit_count = u8::from_str_radix(fields[1], 10).unwrap_or(6);
|
||||
let step_seconds = u16::from_str_radix(fields[2], 10).unwrap_or(30);
|
||||
let algorithm = TotpAlgorithm::try_from(fields[2]).unwrap_or(TotpAlgorithm::HmacSha1);
|
||||
let totp = totp::TotpEntry {
|
||||
step_seconds,
|
||||
shared_secret,
|
||||
digit_count,
|
||||
algorithm
|
||||
};
|
||||
let code = generate_totp_code(
|
||||
totp::get_current_unix_time().unwrap_or(0),
|
||||
&totp
|
||||
).unwrap_or(t!("vault.error.record_error", xous::LANG).to_string());
|
||||
self.usb_dev.send_str(&code).ok();
|
||||
}
|
||||
}
|
||||
_ => log::error!("Illegal state! we shouldn't be having an autotype on {:?}", mode_cache),
|
||||
}
|
||||
self.pddb.borrow().sync().ok();
|
||||
Ok(())
|
||||
}
|
||||
pub(crate) fn selected_entry(&self) -> Option<SelectedEntry> {
|
||||
|
|
|
|||
|
|
@ -326,12 +326,6 @@ impl InputTracker {
|
|||
self.insert_prediction(0);
|
||||
do_redraw = true;
|
||||
} else {
|
||||
self.pred_phrase.clear();
|
||||
self.line.clear();
|
||||
self.can_unpick = false;
|
||||
self.last_trigger_char = Some(0);
|
||||
self.characters = 0;
|
||||
self.insertion = 0;
|
||||
retstring = Some(xous_ipc::String::<4000>::from_str("\u{0011}"));
|
||||
do_redraw = true;
|
||||
}
|
||||
|
|
@ -341,12 +335,6 @@ impl InputTracker {
|
|||
self.insert_prediction(1);
|
||||
do_redraw = true;
|
||||
} else {
|
||||
self.pred_phrase.clear();
|
||||
self.line.clear();
|
||||
self.can_unpick = false;
|
||||
self.last_trigger_char = Some(0);
|
||||
self.characters = 0;
|
||||
self.insertion = 0;
|
||||
retstring = Some(xous_ipc::String::<4000>::from_str("\u{0012}"));
|
||||
do_redraw = true;
|
||||
}
|
||||
|
|
@ -356,12 +344,6 @@ impl InputTracker {
|
|||
self.insert_prediction(2);
|
||||
do_redraw = true;
|
||||
} else {
|
||||
self.pred_phrase.clear();
|
||||
self.line.clear();
|
||||
self.can_unpick = false;
|
||||
self.last_trigger_char = Some(0);
|
||||
self.characters = 0;
|
||||
self.insertion = 0;
|
||||
retstring = Some(xous_ipc::String::<4000>::from_str("\u{0013}"));
|
||||
do_redraw = true;
|
||||
}
|
||||
|
|
@ -371,12 +353,6 @@ impl InputTracker {
|
|||
self.insert_prediction(3);
|
||||
do_redraw = true;
|
||||
} else {
|
||||
self.pred_phrase.clear();
|
||||
self.line.clear();
|
||||
self.can_unpick = false;
|
||||
self.last_trigger_char = Some(0);
|
||||
self.characters = 0;
|
||||
self.insertion = 0;
|
||||
retstring = Some(xous_ipc::String::<4000>::from_str("\u{0014}"));
|
||||
do_redraw = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -256,6 +256,14 @@ impl BasisCache {
|
|||
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||
}
|
||||
}
|
||||
/// Returns a Vec which is a list of Bases to visit, in order of visitation, to create the union view.
|
||||
pub(crate) fn access_list(&self) -> Vec::<String> {
|
||||
let mut al = Vec::<String>::new();
|
||||
for entry in self.cache.iter().rev() {
|
||||
al.push(entry.name.to_string());
|
||||
}
|
||||
al
|
||||
}
|
||||
fn select_basis(&mut self, basis_name: Option<&str>) -> Option<usize> {
|
||||
if self.cache.len() == 0 {
|
||||
log::error!("Can't select basis: PDDB is not mounted");
|
||||
|
|
@ -941,6 +949,7 @@ impl BasisCache {
|
|||
}
|
||||
} else {
|
||||
for basis in self.cache.iter_mut() {
|
||||
log::info!("syncing {}", basis.name);
|
||||
basis.sync(hw)?;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -779,74 +779,78 @@ fn main() -> ! {
|
|||
buffer.replace(mgmt).unwrap();
|
||||
}
|
||||
Some(Opcode::KeyRequest) => {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req: PddbKeyRequest = buffer.to_original::<PddbKeyRequest, _>().unwrap();
|
||||
let bname = if req.basis_specified {
|
||||
Some(req.basis.as_str().unwrap())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let dict = req.dict.as_str().expect("dict utf-8 decode error");
|
||||
let key = req.key.as_str().expect("key utf-8 decode error");
|
||||
if basis_cache.dict_attributes(&mut pddb_os, dict, bname).is_err() {
|
||||
if req.create_dict {
|
||||
match basis_cache.dict_add(&mut pddb_os, dict, bname) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::OutOfMemory => {req.result = PddbRequestCode::NoFreeSpace; buffer.replace(req).unwrap(); continue}
|
||||
std::io::ErrorKind::NotFound => {req.result = PddbRequestCode::NotMounted; buffer.replace(req).unwrap(); continue}
|
||||
_ => {req.result = PddbRequestCode::InternalError; buffer.replace(req).unwrap(); continue}
|
||||
for basis in basis_cache.access_list().iter() {
|
||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||
let mut req: PddbKeyRequest = buffer.to_original::<PddbKeyRequest, _>().unwrap();
|
||||
let bname = if req.basis_specified {
|
||||
Some(req.basis.as_str().unwrap())
|
||||
} else {
|
||||
Some(basis.as_str())
|
||||
};
|
||||
let dict = req.dict.as_str().expect("dict utf-8 decode error");
|
||||
let key = req.key.as_str().expect("key utf-8 decode error");
|
||||
log::debug!("get: {:?} {}", bname, key);
|
||||
if basis_cache.dict_attributes(&mut pddb_os, dict, bname).is_err() {
|
||||
if req.create_dict {
|
||||
match basis_cache.dict_add(&mut pddb_os, dict, bname) {
|
||||
Ok(_) => (),
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::OutOfMemory => {req.result = PddbRequestCode::NoFreeSpace; buffer.replace(req).unwrap(); continue}
|
||||
std::io::ErrorKind::NotFound => {req.result = PddbRequestCode::NotMounted; buffer.replace(req).unwrap(); continue}
|
||||
_ => {req.result = PddbRequestCode::InternalError; buffer.replace(req).unwrap(); continue}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
req.result = PddbRequestCode::NotFound;
|
||||
buffer.replace(req).unwrap(); continue
|
||||
}
|
||||
}
|
||||
let alloc_hint = if let Some(hint) = req.alloc_hint {Some(hint as usize)} else {None};
|
||||
if basis_cache.key_attributes(&mut pddb_os, dict, key, bname).is_err() {
|
||||
if !req.create_key {
|
||||
req.result = PddbRequestCode::NotFound;
|
||||
buffer.replace(req).unwrap(); continue
|
||||
} else {
|
||||
// create an empty key placeholder
|
||||
let empty: [u8; 0] = [];
|
||||
match basis_cache.key_update(&mut pddb_os,
|
||||
dict, key, &empty, None, alloc_hint, bname, true
|
||||
) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {
|
||||
log::error!("Couldn't allocate key: {:?}", e);
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::NotFound => req.result = PddbRequestCode::NotMounted,
|
||||
std::io::ErrorKind::OutOfMemory => req.result = PddbRequestCode::NoFreeSpace,
|
||||
_ => req.result = PddbRequestCode::InternalError,
|
||||
}
|
||||
buffer.replace(req).unwrap(); continue
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
req.result = PddbRequestCode::NotFound;
|
||||
buffer.replace(req).unwrap(); continue
|
||||
}
|
||||
}
|
||||
let alloc_hint = if let Some(hint) = req.alloc_hint {Some(hint as usize)} else {None};
|
||||
if basis_cache.key_attributes(&mut pddb_os, dict, key, bname).is_err() {
|
||||
if !req.create_key {
|
||||
req.result = PddbRequestCode::NotFound;
|
||||
buffer.replace(req).unwrap(); continue
|
||||
// at this point, we have established a basis/dict/key tuple.
|
||||
let token: ApiToken = [pddb_os.trng_u32(), pddb_os.trng_u32(), pddb_os.trng_u32()];
|
||||
let cid = if let Some(cb_sid) = req.cb_sid {
|
||||
Some(xous::connect(xous::SID::from_array(cb_sid)).expect("couldn't connect for callback"))
|
||||
} else {
|
||||
// create an empty key placeholder
|
||||
let empty: [u8; 0] = [];
|
||||
match basis_cache.key_update(&mut pddb_os,
|
||||
dict, key, &empty, None, alloc_hint, bname, true
|
||||
) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {
|
||||
log::error!("Couldn't allocate key: {:?}", e);
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::NotFound => req.result = PddbRequestCode::NotMounted,
|
||||
std::io::ErrorKind::OutOfMemory => req.result = PddbRequestCode::NoFreeSpace,
|
||||
_ => req.result = PddbRequestCode::InternalError,
|
||||
}
|
||||
buffer.replace(req).unwrap(); continue
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
};
|
||||
let token_record = TokenRecord {
|
||||
dict: String::from(dict),
|
||||
key: String::from(key),
|
||||
basis: if let Some(name) = bname {Some(String::from(name))} else {None},
|
||||
conn: cid,
|
||||
alloc_hint,
|
||||
};
|
||||
token_dict.insert(token, token_record);
|
||||
req.token = Some(token);
|
||||
req.result = PddbRequestCode::NoErr;
|
||||
buffer.replace(req).unwrap();
|
||||
break; // if we got here, entry was found, stop searching
|
||||
}
|
||||
// at this point, we have established a basis/dict/key tuple.
|
||||
let token: ApiToken = [pddb_os.trng_u32(), pddb_os.trng_u32(), pddb_os.trng_u32()];
|
||||
let cid = if let Some(cb_sid) = req.cb_sid {
|
||||
Some(xous::connect(xous::SID::from_array(cb_sid)).expect("couldn't connect for callback"))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let token_record = TokenRecord {
|
||||
dict: String::from(dict),
|
||||
key: String::from(key),
|
||||
basis: if let Some(name) = bname {Some(String::from(name))} else {None},
|
||||
conn: cid,
|
||||
alloc_hint,
|
||||
};
|
||||
token_dict.insert(token, token_record);
|
||||
req.token = Some(token);
|
||||
req.result = PddbRequestCode::NoErr;
|
||||
buffer.replace(req).unwrap();
|
||||
}
|
||||
Some(Opcode::KeyDrop) => msg_blocking_scalar_unpack!(msg, t0, t1, t2, _, {
|
||||
let token: ApiToken = [t0 as u32, t1 as u32, t2 as u32];
|
||||
|
|
@ -1124,19 +1128,28 @@ fn main() -> ! {
|
|||
let pbuf = PddbBuf::from_slice_mut(buffer.as_mut()); // direct translation, no serialization necessary for performance
|
||||
let token = pbuf.token;
|
||||
if let Some(rec) = token_dict.get(&token) {
|
||||
match basis_cache.key_read(&mut pddb_os,
|
||||
&rec.dict, &rec.key,
|
||||
&mut pbuf.data[..pbuf.len as usize], Some(pbuf.position as usize),
|
||||
if let Some (name) = &rec.basis {Some(&name)} else {None}) {
|
||||
Ok(readlen) => {
|
||||
pbuf.len = readlen as u16;
|
||||
pbuf.retcode = PddbRetcode::Ok;
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => pbuf.retcode = PddbRetcode::BasisLost,
|
||||
std::io::ErrorKind::UnexpectedEof => pbuf.retcode = PddbRetcode::UnexpectedEof,
|
||||
std::io::ErrorKind::OutOfMemory => pbuf.retcode = PddbRetcode::DiskFull,
|
||||
_ => pbuf.retcode = PddbRetcode::InternalError,
|
||||
for basis in basis_cache.access_list().iter() {
|
||||
let temp = if let Some (name) = &rec.basis {Some(name)} else {Some(basis)};
|
||||
log::debug!("read (spec: {:?}){:?} {}", rec.basis, temp, rec.key);
|
||||
match basis_cache.key_read(&mut pddb_os,
|
||||
&rec.dict, &rec.key,
|
||||
&mut pbuf.data[..pbuf.len as usize], Some(pbuf.position as usize),
|
||||
// this is a bit inefficient because if a specific basis is specified *and* the key does not exist,
|
||||
// it'll retry the same basis for a number of times equal to the number of bases open.
|
||||
// However, usually, there's only 1-2 bases open, and usually, if you specify a basis,
|
||||
// the key will be a hit, so, we let it stand.
|
||||
if let Some (name) = &rec.basis {Some(&name)} else {Some(basis)}) {
|
||||
Ok(readlen) => {
|
||||
pbuf.len = readlen as u16;
|
||||
pbuf.retcode = PddbRetcode::Ok;
|
||||
break;
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => pbuf.retcode = PddbRetcode::BasisLost,
|
||||
std::io::ErrorKind::UnexpectedEof => pbuf.retcode = PddbRetcode::UnexpectedEof,
|
||||
std::io::ErrorKind::OutOfMemory => pbuf.retcode = PddbRetcode::DiskFull,
|
||||
_ => pbuf.retcode = PddbRetcode::InternalError,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1149,20 +1162,25 @@ fn main() -> ! {
|
|||
let pbuf = PddbBuf::from_slice_mut(buffer.as_mut()); // direct translation, no serialization necessary for performance
|
||||
let token = pbuf.token;
|
||||
if let Some(rec) = token_dict.get(&token) {
|
||||
match basis_cache.key_update(&mut pddb_os,
|
||||
&rec.dict, &rec.key,
|
||||
&pbuf.data[..pbuf.len as usize], Some(pbuf.position as usize),
|
||||
rec.alloc_hint, if let Some (name) = &rec.basis {Some(&name)} else {None},
|
||||
false
|
||||
) {
|
||||
Ok(_) => {
|
||||
pbuf.retcode = PddbRetcode::Ok;
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => pbuf.retcode = PddbRetcode::BasisLost,
|
||||
std::io::ErrorKind::UnexpectedEof => pbuf.retcode = PddbRetcode::UnexpectedEof,
|
||||
std::io::ErrorKind::OutOfMemory => pbuf.retcode = PddbRetcode::DiskFull,
|
||||
_ => pbuf.retcode = PddbRetcode::InternalError,
|
||||
for basis in basis_cache.access_list().iter() {
|
||||
let temp = if let Some (name) = &rec.basis {Some(name)} else {Some(basis)};
|
||||
log::debug!("write (spec: {:?}){:?} {}", rec.basis, temp, rec.key);
|
||||
match basis_cache.key_update(&mut pddb_os,
|
||||
&rec.dict, &rec.key,
|
||||
&pbuf.data[..pbuf.len as usize], Some(pbuf.position as usize),
|
||||
rec.alloc_hint, if let Some (name) = &rec.basis {Some(&name)} else {Some(basis)},
|
||||
false
|
||||
) {
|
||||
Ok(_) => {
|
||||
pbuf.retcode = PddbRetcode::Ok;
|
||||
break;
|
||||
}
|
||||
Err(e) => match e.kind() {
|
||||
std::io::ErrorKind::NotFound => pbuf.retcode = PddbRetcode::BasisLost,
|
||||
std::io::ErrorKind::UnexpectedEof => pbuf.retcode = PddbRetcode::UnexpectedEof,
|
||||
std::io::ErrorKind::OutOfMemory => pbuf.retcode = PddbRetcode::DiskFull,
|
||||
_ => pbuf.retcode = PddbRetcode::InternalError,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1188,6 +1206,7 @@ fn main() -> ! {
|
|||
let mut note = String::from(t!("pddb.menu.listbasis_response", xous::LANG));
|
||||
for basis in bases.iter() {
|
||||
note.push_str(basis);
|
||||
note.push_str("\n");
|
||||
}
|
||||
modals.show_notification(¬e, None).expect("couldn't show basis list");
|
||||
},
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ pub fn start_time_server() {
|
|||
let mut offset_key = offset_handle.get(
|
||||
TIME_SERVER_DICT,
|
||||
TIME_SERVER_UTC_OFFSET,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(8),
|
||||
None::<fn()>
|
||||
).expect("couldn't open UTC offset key");
|
||||
|
|
@ -253,7 +253,7 @@ pub fn start_time_server() {
|
|||
let mut tz_key = tz_handle.get(
|
||||
TIME_SERVER_DICT,
|
||||
TIME_SERVER_TZ_OFFSET,
|
||||
None, true, true,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), true, true,
|
||||
Some(8),
|
||||
None::<fn()>
|
||||
).expect("couldn't open TZ offset key");
|
||||
|
|
@ -532,7 +532,7 @@ pub fn start_time_ux(sid: xous::SID) {
|
|||
let maybe_tz_set_key = tz_set_handle.get(
|
||||
TIME_SERVER_DICT,
|
||||
TIME_SERVER_TZ_OFFSET,
|
||||
None, false, false,
|
||||
Some(pddb::PDDB_DEFAULT_SYSTEM_BASIS), false, false,
|
||||
None,
|
||||
None::<fn()>
|
||||
).ok();
|
||||
|
|
|
|||
Loading…
Reference in a new issue