mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
add autotype to TOTP. why not?
This commit is contained in:
parent
6aadbf3cae
commit
819b84954a
1 changed files with 82 additions and 66 deletions
|
|
@ -190,7 +190,7 @@ impl VaultUx {
|
||||||
/*
|
/*
|
||||||
Entry Users
|
Entry Users
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
- autotype pw
|
- autotype pw totp
|
||||||
- add new pw totp
|
- add new pw totp
|
||||||
- edit pw totp fido
|
- edit pw totp fido
|
||||||
- delete pw totp fido
|
- delete pw totp fido
|
||||||
|
|
@ -203,19 +203,7 @@ impl VaultUx {
|
||||||
self.menu_mgr.delete_item(t!("vault.menu_addnew", xous::LANG));
|
self.menu_mgr.delete_item(t!("vault.menu_addnew", xous::LANG));
|
||||||
match *self.mode.lock().unwrap() {
|
match *self.mode.lock().unwrap() {
|
||||||
VaultMode::Fido => (),
|
VaultMode::Fido => (),
|
||||||
VaultMode::Totp => {
|
VaultMode::Password | 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 => {
|
|
||||||
self.menu_mgr.insert_item(
|
self.menu_mgr.insert_item(
|
||||||
MenuItem {
|
MenuItem {
|
||||||
name: xous_ipc::String::from_str(t!("vault.menu_addnew", xous::LANG)),
|
name: xous_ipc::String::from_str(t!("vault.menu_addnew", xous::LANG)),
|
||||||
|
|
@ -647,6 +635,9 @@ impl VaultUx {
|
||||||
if self.selection_index >= self.filtered_list.len() {
|
if self.selection_index >= self.filtered_list.len() {
|
||||||
return Err(xous::Error::InvalidPID);
|
return Err(xous::Error::InvalidPID);
|
||||||
}
|
}
|
||||||
|
let mode_cache = (*self.mode.lock().unwrap()).clone();
|
||||||
|
match mode_cache {
|
||||||
|
VaultMode::Password => {
|
||||||
let entry = &self.filtered_list[self.selection_index].guid;
|
let entry = &self.filtered_list[self.selection_index].guid;
|
||||||
// we re-fetch the entry for autotype, because the PDDB could have unmounted a basis.
|
// we re-fetch the entry for autotype, because the PDDB could have unmounted a basis.
|
||||||
let updated_pw = match self.pddb.borrow().get(
|
let updated_pw = match self.pddb.borrow().get(
|
||||||
|
|
@ -715,6 +706,31 @@ impl VaultUx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.pddb.borrow().sync().ok();
|
self.pddb.borrow().sync().ok();
|
||||||
|
}
|
||||||
|
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),
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub(crate) fn selected_entry(&self) -> Option<SelectedEntry> {
|
pub(crate) fn selected_entry(&self) -> Option<SelectedEntry> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue