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,74 +635,102 @@ 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 entry = &self.filtered_list[self.selection_index].guid;
|
let mode_cache = (*self.mode.lock().unwrap()).clone();
|
||||||
// we re-fetch the entry for autotype, because the PDDB could have unmounted a basis.
|
match mode_cache {
|
||||||
let updated_pw = match self.pddb.borrow().get(
|
VaultMode::Password => {
|
||||||
crate::actions::VAULT_PASSWORD_DICT,
|
let entry = &self.filtered_list[self.selection_index].guid;
|
||||||
entry,
|
// we re-fetch the entry for autotype, because the PDDB could have unmounted a basis.
|
||||||
None,
|
let updated_pw = match self.pddb.borrow().get(
|
||||||
false, false, None,
|
crate::actions::VAULT_PASSWORD_DICT,
|
||||||
Some(crate::basis_change)
|
entry,
|
||||||
) {
|
None,
|
||||||
Ok(mut record) => {
|
false, false, None,
|
||||||
let mut data = Vec::<u8>::new();
|
Some(crate::basis_change)
|
||||||
match record.read_to_end(&mut data) {
|
) {
|
||||||
Ok(_len) => {
|
Ok(mut record) => {
|
||||||
if let Some(mut pw) = crate::actions::deserialize_password(data) {
|
let mut data = Vec::<u8>::new();
|
||||||
match self.usb_dev.send_str(&pw.password) {
|
match record.read_to_end(&mut data) {
|
||||||
Ok(_) => {
|
Ok(_len) => {
|
||||||
pw.count += 1;
|
if let Some(mut pw) = crate::actions::deserialize_password(data) {
|
||||||
pw.atime = utc_now().timestamp() as u64;
|
match self.usb_dev.send_str(&pw.password) {
|
||||||
pw
|
Ok(_) => {
|
||||||
},
|
pw.count += 1;
|
||||||
Err(e) => {
|
pw.atime = utc_now().timestamp() as u64;
|
||||||
log::error!("couldn't autotype password: {:?}", e);
|
pw
|
||||||
return Err(xous::Error::UseBeforeInit);
|
},
|
||||||
|
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 {
|
Err(e) => {
|
||||||
log::error!("couldn't deserialize {}", entry);
|
log::error!("couldn't access key {}: {:?}", entry, e);
|
||||||
return Err(xous::Error::InvalidString);
|
return Err(xous::Error::ProcessNotFound);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("couldn't access key {}: {:?}", entry, e);
|
log::error!("couldn't access key {}: {:?}", entry, e);
|
||||||
return Err(xous::Error::ProcessNotFound);
|
return Err(xous::Error::ProcessNotFound);
|
||||||
},
|
}
|
||||||
}
|
};
|
||||||
}
|
match self.pddb.borrow().delete_key(crate::actions::VAULT_PASSWORD_DICT, entry, None) {
|
||||||
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) {
|
|
||||||
Ok(_) => {}
|
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) => {
|
Err(e) => {
|
||||||
log::error!("couldn't update key {}: {:?}", entry, e);
|
log::error!("couldn't update key {}: {:?}", entry, e);
|
||||||
return Err(xous::Error::OutOfMemory);
|
return Err(xous::Error::OutOfMemory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.pddb.borrow().sync().ok();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
VaultMode::Totp => {
|
||||||
log::error!("couldn't update key {}: {:?}", entry, e);
|
let fields = self.filtered_list[self.selection_index].extra.split(':').collect::<Vec<&str>>();
|
||||||
return Err(xous::Error::OutOfMemory);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub(crate) fn selected_entry(&self) -> Option<SelectedEntry> {
|
pub(crate) fn selected_entry(&self) -> Option<SelectedEntry> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue