mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
first draft of all basis unlock
This has worked in testing, but: - There seems to be a new error unrelated to this with allocating very large blocks of memory, which needs to be traced down. - Because this operation will typically fully block the caller, UX redraws can't happen (unless the caller has a fully multithreaded redraw routine). This needs some thought because: 1. If you have several basis you're trying to unlock, eventually, you'll overflow the application incoming queue with redraw requests, and the system will crash. 2. It's cosmetically disturbing to have the dialog boxes piling up on top of each other during a critical operation like this. I *think* the right thing to do is to refactor the GAM a bit to handle pop-up modals that block a bit more gracefully. But I think it's more urgent to trace down the problem with large blocks of memory being allocated, since it is a functional issue and not a cosmetic one.
This commit is contained in:
parent
0fc13100b1
commit
5008c7afac
4 changed files with 160 additions and 21 deletions
|
|
@ -1,4 +1,46 @@
|
|||
{
|
||||
"pddb.freespace.request": {
|
||||
"en": "⚠ PDDB needs to allocate more free space. ⚠\nIn order to do this safely, you must enumerate all secret Bases now. Any Basis not disclosed could be overwritten.",
|
||||
"ja": "⚠ PDDBは、より多くの空き領域を割り当てる必要があります。⚠\nこれを安全に行うには、今すぐすべてのシークレットベースのロックを解除する必要があります。 ロックされたままのベーシスは上書きされる可能性があります。",
|
||||
"zh": "⚠ PDDB 需要分配更多可用空间。⚠\n为了安全地执行此操作,您现在必须解锁所有秘密基地。 任何被锁定的基础都可以被覆盖。",
|
||||
"en-tts": "⚠ PDDB needs to allocate more free space. ⚠\nIn order to do this safely, you must enumerate all secret Bases now. Any Basis not disclosed could be overwritten."
|
||||
},
|
||||
"pddb.freespace.enumerate": {
|
||||
"en": "Enumerate a Basis?",
|
||||
"ja": "根拠を開示しますか?",
|
||||
"zh": "披露依据?",
|
||||
"en-tts": "Enumerate a Basis?"
|
||||
},
|
||||
"pddb.freespace.enumerate_another": {
|
||||
"en": "Enumerate another Basis?",
|
||||
"ja": "別の根拠を開示しますか?",
|
||||
"zh": "披露另一个依据?",
|
||||
"en-tts": "Enumerate another Basis?"
|
||||
},
|
||||
"pddb.freespace.name": {
|
||||
"en": "Enter name of Basis to enumerate:",
|
||||
"ja": "列挙する基準の名前を入力します。",
|
||||
"zh": "输入要枚举的基础名称:",
|
||||
"en-tts": "Enter name of Basis to enumerate:"
|
||||
},
|
||||
"pddb.freespace.badpass": {
|
||||
"en": "Bad password or Basis does not exist.",
|
||||
"ja": "不正なパスワードまたはベーシスが存在しません。",
|
||||
"zh": "密码错误或基础不存在。",
|
||||
"en-tts": "Bad password, or Basis does not exist."
|
||||
},
|
||||
"pddb.freespace.currentlist": {
|
||||
"en": "The following Bases are enumerated:",
|
||||
"ja": "以下の根拠を列挙します:",
|
||||
"zh": "列举如下依据:",
|
||||
"en-tts": "The following Bases are enumerated:"
|
||||
},
|
||||
"pddb.freespace.finished": {
|
||||
"en": "Enumeration terminated.\n\nShall we proceed to generate the free space cache?",
|
||||
"ja": "空き領域キャッシュの生成に進みましょうか。",
|
||||
"zh": "我们要继续生成可用空间缓存吗?",
|
||||
"en-tts": "Enumeration terminated.\n\nShall we proceed to generate the free space cache?"
|
||||
},
|
||||
"pddb.okay": {
|
||||
"en": "Okay",
|
||||
"ja": "OK",
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ pub(crate) const PDDB_VERSION: u32 = 0x00_00_02_01;
|
|||
#[allow(dead_code)]
|
||||
// PDDB_A_LEN may be shorter than xous::PDDB_LEN, to speed up testing.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) const PDDB_A_LEN: usize = xous::PDDB_LEN as usize;
|
||||
// pub(crate) const PDDB_A_LEN: usize = 4 * 1024 * 1024;
|
||||
// pub(crate) const PDDB_A_LEN: usize = xous::PDDB_LEN as usize;
|
||||
pub(crate) const PDDB_A_LEN: usize = 4 * 1024 * 1024;
|
||||
|
||||
/// range for the starting point of a journal number, picked from a random seed
|
||||
/// the goal is to reduce info leakage about the age of structures relative to each other
|
||||
|
|
|
|||
|
|
@ -130,10 +130,12 @@ pub(crate) struct PddbOs {
|
|||
dna: u64,
|
||||
/// reference to a TrngPool object that's shared among all the hardware functions
|
||||
entropy: Rc<RefCell<TrngPool>>,
|
||||
/// connection to the password request manager
|
||||
pw_cid: xous::CID,
|
||||
}
|
||||
|
||||
impl PddbOs {
|
||||
pub fn new(trngpool: Rc<RefCell<TrngPool>>) -> PddbOs {
|
||||
pub fn new(trngpool: Rc<RefCell<TrngPool>>, pw_cid: xous::CID) -> PddbOs {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
#[cfg(any(target_os = "none", target_os = "xous"))]
|
||||
let pddb = xous::syscall::map_memory(
|
||||
|
|
@ -175,6 +177,7 @@ impl PddbOs {
|
|||
fspace_log_len: 0,
|
||||
dna: llio.soc_dna().unwrap(),
|
||||
entropy: trngpool,
|
||||
pw_cid,
|
||||
};
|
||||
// emulated
|
||||
#[cfg(not(any(target_os = "none", target_os = "xous")))]
|
||||
|
|
@ -197,6 +200,7 @@ impl PddbOs {
|
|||
fspace_log_len: 0,
|
||||
dna: llio.soc_dna().unwrap(),
|
||||
entropy: trngpool,
|
||||
pw_cid,
|
||||
}
|
||||
};
|
||||
ret
|
||||
|
|
@ -1784,6 +1788,14 @@ impl PddbOs {
|
|||
/// a Vec of keys & names, not a BasisCacheEntry -- so it means that the Basis still are "closed"
|
||||
/// at the conclusion of the sweep, but their page use can be accounted for.
|
||||
pub(crate) fn pddb_get_additional_keys(&self, cache: &Vec::<BasisCacheEntry>) -> Option<Vec<([u8; AES_KEYSIZE], String)>> {
|
||||
let mut ret = Vec::<([u8; AES_KEYSIZE], String)>::new();
|
||||
if let Some(sys_key) = &self.system_basis_key {
|
||||
ret.push((sys_key.pt, PDDB_DEFAULT_SYSTEM_BASIS.to_string()));
|
||||
} else {
|
||||
log::error!("No default system basis was set up, this should be an illegal condition when requesting FSCB scan!");
|
||||
panic!("No default system basis was set up, this should be an illegal condition when requesting FSCB scan!");
|
||||
}
|
||||
const SWAP_DELAY_MS: usize = 300;
|
||||
log::info!("{} basis are open, with the following names:", cache.len());
|
||||
for entry in cache {
|
||||
log::info!(" - {}", entry.name);
|
||||
|
|
@ -1791,14 +1803,98 @@ impl PddbOs {
|
|||
|
||||
// 0. allow user to cancel out of the operation -- this will abort everything and cause the current
|
||||
// alloc operation to fail
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let modals = modals::Modals::new(&xns).unwrap();
|
||||
modals.show_notification(t!("pddb.freespace.request", xous::LANG), None).ok();
|
||||
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
|
||||
|
||||
// 1. prompt user to enter any name/password combos for other basis we want to keep
|
||||
// 2. validate the name/password combo
|
||||
// 3. add to the Aes256 return vec
|
||||
// 4. repeat summary print-out
|
||||
let mut request_str = t!("pddb.freespace.enumerate", xous::LANG);
|
||||
while self.yes_no_approval(&modals, request_str) {
|
||||
request_str = t!("pddb.freespace.enumerate_another", xous::LANG); // use a plural for the next request to clarify UX flow
|
||||
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
|
||||
|
||||
// for now, do nothing -- just indicate success with a returned empty set
|
||||
Some(Vec::<([u8; AES_KEYSIZE], String)>::new())
|
||||
match modals
|
||||
.alert_builder(t!("pddb.freespace.name", xous::LANG))
|
||||
.field(None, None)
|
||||
.build()
|
||||
{
|
||||
Ok(bname) => {
|
||||
let name = bname.first().as_str().to_string();
|
||||
let request = BasisRequestPassword {
|
||||
db_name: xous_ipc::String::from_str(name.to_string()),
|
||||
plaintext_pw: None,
|
||||
};
|
||||
let mut buf = Buffer::into_buf(request).unwrap();
|
||||
buf.lend_mut(self.pw_cid, PwManagerOpcode::RequestPassword.to_u32().unwrap()).unwrap();
|
||||
let retpass = buf.to_original::<BasisRequestPassword, _>().unwrap();
|
||||
// 2. validate the name/password combo
|
||||
let basis_key = self.basis_derive_key(
|
||||
&name,
|
||||
retpass.plaintext_pw.unwrap().as_str().unwrap()
|
||||
);
|
||||
let maybe_entry = if let Some(basis_map) =
|
||||
self.pt_scan_key(&basis_key.pt, &name) {
|
||||
let aad = self.data_aad(&name);
|
||||
if let Some(root_page) = basis_map.get(&VirtAddr::new(VPAGE_SIZE as u64).unwrap()) {
|
||||
match self.data_decrypt_page_with_commit(&basis_key.data, &aad, root_page) {
|
||||
Some(_data) => {
|
||||
// if the root page decrypts, we accept the password; no further checking is done.
|
||||
Some((basis_key.pt, name.to_string()))
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// 3. add to the Aes256 return vec
|
||||
if let Some((key, name)) = maybe_entry {
|
||||
ret.push((key, name));
|
||||
} else {
|
||||
modals.show_notification(t!("pddb.freespace.badpass", xous::LANG), None).ok();
|
||||
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
|
||||
}
|
||||
},
|
||||
_ => return None,
|
||||
};
|
||||
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
|
||||
// 4. repeat summary print-out
|
||||
let mut blist = String::from(t!("pddb.freespace.currentlist", xous::LANG));
|
||||
for (_key, name) in ret.iter() {
|
||||
blist.push_str("\n");
|
||||
blist.push_str(name);
|
||||
}
|
||||
modals.show_notification(&blist, None).ok();
|
||||
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
|
||||
}
|
||||
// done!
|
||||
if self.yes_no_approval(&modals, t!("pddb.freespace.finished", xous::LANG)) {
|
||||
Some(ret)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn yes_no_approval(&self, modals: &modals::Modals, request: &str) -> bool {
|
||||
modals.add_list(
|
||||
vec![t!("pddb.yes", xous::LANG), t!("pddb.no", xous::LANG)]
|
||||
).expect("couldn't build confirmation dialog");
|
||||
match modals.get_radiobutton(request) {
|
||||
Ok(response) => {
|
||||
if &response == t!("pddb.yes", xous::LANG) {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
log::error!("get approval failed");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Derives a 256-bit AES encryption key for a basis given a basis name and its password.
|
||||
|
|
|
|||
|
|
@ -437,8 +437,21 @@ fn wrapped_main() -> ! {
|
|||
// for less-secured user prompts (everything but password entry)
|
||||
let modals = modals::Modals::new(&xns).expect("can't connect to Modals server");
|
||||
|
||||
// our very own password modal. Password modals are precious and privately owned, to avoid
|
||||
// other processes from crafting them.
|
||||
let pw_sid = xous::create_server().expect("couldn't create a server for the password UX handler");
|
||||
let pw_cid = xous::connect(pw_sid).expect("couldn't connect to the password UX handler");
|
||||
let pw_handle = thread::spawn({
|
||||
move || {
|
||||
password_ux_manager(
|
||||
xous::connect(pddb_sid).unwrap(),
|
||||
pw_sid
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
// OS-specific PDDB driver
|
||||
let mut pddb_os = PddbOs::new(Rc::clone(&entropy));
|
||||
let mut pddb_os = PddbOs::new(Rc::clone(&entropy), pw_cid);
|
||||
// storage for the basis cache
|
||||
let mut basis_cache = BasisCache::new();
|
||||
// storage for the token lookup: given an ApiToken, return a dict/key/basis set. Basis can be None or specified.
|
||||
|
|
@ -483,18 +496,6 @@ fn wrapped_main() -> ! {
|
|||
hw_testcase(&mut pddb_os);
|
||||
}
|
||||
|
||||
// our very own password modal. Password modals are precious and privately owned, to avoid
|
||||
// other processes from crafting them.
|
||||
let pw_sid = xous::create_server().expect("couldn't create a server for the password UX handler");
|
||||
let pw_cid = xous::connect(pw_sid).expect("couldn't connect to the password UX handler");
|
||||
let pw_handle = thread::spawn({
|
||||
move || {
|
||||
password_ux_manager(
|
||||
xous::connect(pddb_sid).unwrap(),
|
||||
pw_sid
|
||||
)
|
||||
}
|
||||
});
|
||||
// our menu handler
|
||||
let my_cid = xous::connect(pddb_sid).unwrap();
|
||||
let _ = thread::spawn({
|
||||
|
|
|
|||
Loading…
Reference in a new issue