mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
make vendor backup locked out by default; hook to UX enable dialog box
also halts updates of the TOTP timer bar while this is happening to avoid overflowing the server queue with unanswered redraw requests
This commit is contained in:
parent
56172e37a9
commit
8570449b04
4 changed files with 61 additions and 45 deletions
|
|
@ -176,6 +176,7 @@ fn main() -> ! {
|
|||
let mode = Arc::new(Mutex::new(VaultMode::Fido));
|
||||
let item_list = Arc::new(Mutex::new(Vec::<ListItem>::new()));
|
||||
let action_active = Arc::new(AtomicBool::new(false));
|
||||
let allow_host = Arc::new(AtomicBool::new(false));
|
||||
|
||||
// spawn the actions server. This is responsible for grooming the UX elements. It
|
||||
// has to be in its own thread because it uses blocking modal calls that would cause
|
||||
|
|
@ -189,6 +190,7 @@ fn main() -> ! {
|
|||
|
||||
// spawn the FIDO2 USB handler
|
||||
let _ = thread::spawn({
|
||||
let allow_host = allow_host.clone();
|
||||
move || {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
|
|
@ -220,9 +222,12 @@ fn main() -> ! {
|
|||
Some(data) => data,
|
||||
None => {
|
||||
log::debug!("starting processing of vendor data...");
|
||||
let resp = vendor_commands::handle_vendor_command(&mut vendor_session);
|
||||
let resp = vendor_commands::handle_vendor_command(
|
||||
&mut vendor_session,
|
||||
allow_host.load(Ordering::SeqCst)
|
||||
);
|
||||
log::debug!("finished processing of vendor data!");
|
||||
|
||||
|
||||
match vendor_session.is_backup() {
|
||||
true => {
|
||||
if vendor_session.has_backup_data() {
|
||||
|
|
@ -292,7 +297,7 @@ fn main() -> ! {
|
|||
});
|
||||
// spawn the TOTP pumper
|
||||
let pump_sid = xous::create_server().unwrap();
|
||||
crate::totp::pumper(mode.clone(), pump_sid, conn);
|
||||
crate::totp::pumper(mode.clone(), pump_sid, conn, allow_host.clone());
|
||||
let pump_conn = xous::connect(pump_sid).unwrap();
|
||||
|
||||
let menu_sid = xous::create_server().unwrap();
|
||||
|
|
@ -505,13 +510,9 @@ fn main() -> ! {
|
|||
vaultux.readout_mode(true);
|
||||
modals.dynamic_notification_close().ok();
|
||||
|
||||
// TODO: rethink the integration of this menu item. The problem is that if you're in readout
|
||||
// mode and the "vault" mode is active, the "pumper" thread keeps sending messages to redraw
|
||||
// the TOTP timer bar. This will eventually overflow this server's queue and cause a hang.
|
||||
// However, the final integration for this will depend a bit on how the vault upload/download PR
|
||||
// turns out.
|
||||
allow_host.store(true, Ordering::SeqCst);
|
||||
modals.show_notification(t!("vault.readout_active", xous::LANG), None).ok();
|
||||
// TODO: add some variable here to de-activate HID readout once this is done
|
||||
allow_host.store(false, Ordering::SeqCst);
|
||||
|
||||
modals.dynamic_notification(Some(t!("vault.readout_switchover", xous::LANG)), None).ok();
|
||||
vaultux.readout_mode(false);
|
||||
|
|
|
|||
|
|
@ -153,7 +153,12 @@ pub(crate) enum PumpOp {
|
|||
Quit,
|
||||
}
|
||||
|
||||
pub(crate) fn pumper(mode: Arc<Mutex<VaultMode>>, sid: xous::SID, main_conn: xous::CID) {
|
||||
pub(crate) fn pumper(
|
||||
mode: Arc<Mutex<VaultMode>>,
|
||||
sid: xous::SID,
|
||||
main_conn: xous::CID,
|
||||
allow_host: Arc<core::sync::atomic::AtomicBool>
|
||||
) {
|
||||
let _ = thread::spawn({
|
||||
move || {
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
|
|
@ -164,10 +169,12 @@ pub(crate) fn pumper(mode: Arc<Mutex<VaultMode>>, sid: xous::SID, main_conn: xou
|
|||
log::trace!("{:?}", opcode);
|
||||
match opcode {
|
||||
Some(PumpOp::Pump) => {
|
||||
xous::try_send_message(main_conn,
|
||||
Message::new_scalar(crate::VaultOp::Redraw.to_usize().unwrap(),
|
||||
0, 0, 0, 0)
|
||||
).ok(); // don't panic if the queue overflows
|
||||
if !allow_host.load(core::sync::atomic::Ordering::SeqCst) { // don't redraw if we're in host access mode
|
||||
xous::try_send_message(main_conn,
|
||||
Message::new_scalar(crate::VaultOp::Redraw.to_usize().unwrap(),
|
||||
0, 0, 0, 0)
|
||||
).ok(); // don't panic if the queue overflows
|
||||
}
|
||||
let mode_cache = {(*mode.lock().unwrap()).clone()};
|
||||
{ // we really want mode.lock() to be in a different scope so...
|
||||
if mode_cache == VaultMode::Totp {
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ pub fn handle_vendor_data(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn handle_vendor_command(session: &mut VendorSession) -> HidPacketIterator {
|
||||
pub fn handle_vendor_command(session: &mut VendorSession, allow_host: bool) -> HidPacketIterator {
|
||||
let cmd = session.command;
|
||||
let payload = session.data.clone();
|
||||
let channel_id = session.channel_id;
|
||||
|
|
@ -172,41 +172,45 @@ pub fn handle_vendor_command(session: &mut VendorSession) -> HidPacketIterator {
|
|||
log::debug!("got vendor command: {}", cmd);
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
||||
let payload = match session.command {
|
||||
COMMAND_RESTORE_TOTP_CODES => match handle_restore(payload, &xns) {
|
||||
Ok(payload) => Message {
|
||||
cid: channel_id,
|
||||
cmd,
|
||||
payload,
|
||||
},
|
||||
Err(error) => {
|
||||
log::error!("error while restoring codes: {:?}", error);
|
||||
error_message(channel_id, 41)
|
||||
}
|
||||
},
|
||||
COMMAND_BACKUP_TOTP_CODES => match handle_backup(&xns, session) {
|
||||
Ok(payload) => {
|
||||
log::debug!("sending over chunk: {:?}", payload);
|
||||
Message {
|
||||
let payload = if allow_host {
|
||||
match session.command {
|
||||
COMMAND_RESTORE_TOTP_CODES => match handle_restore(payload, &xns) {
|
||||
Ok(payload) => Message {
|
||||
cid: channel_id,
|
||||
cmd,
|
||||
payload,
|
||||
},
|
||||
Err(error) => {
|
||||
log::error!("error while restoring codes: {:?}", error);
|
||||
error_message(channel_id, 41)
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
match error {
|
||||
BackupError::NoMoreChunks => {
|
||||
log::debug!("no more chunks to send via backup!");
|
||||
error_message(channel_id, 88) // TODO(gsora): make this a constant
|
||||
}
|
||||
_ => {
|
||||
log::error!("error while restoring codes: {:?}", error);
|
||||
error_message(channel_id, 42)
|
||||
},
|
||||
COMMAND_BACKUP_TOTP_CODES => match handle_backup(&xns, session) {
|
||||
Ok(payload) => {
|
||||
log::debug!("sending over chunk: {:?}", payload);
|
||||
Message {
|
||||
cid: channel_id,
|
||||
cmd,
|
||||
payload,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => error_message(channel_id, 0x33),
|
||||
Err(error) => {
|
||||
match error {
|
||||
BackupError::NoMoreChunks => {
|
||||
log::debug!("no more chunks to send via backup!");
|
||||
error_message(channel_id, 88) // TODO(gsora): make this a constant
|
||||
}
|
||||
_ => {
|
||||
log::error!("error while restoring codes: {:?}", error);
|
||||
error_message(channel_id, 42)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => error_message(channel_id, 0x33),
|
||||
}
|
||||
} else {
|
||||
error_message(channel_id, 44)
|
||||
};
|
||||
|
||||
HidPacketIterator::new(payload).unwrap()
|
||||
|
|
@ -407,7 +411,7 @@ fn handle_backup(
|
|||
return Ok(new_chunk.into());
|
||||
}
|
||||
|
||||
fn error_message(cid: ChannelID, error_code: u8) -> Message {
|
||||
pub(crate) fn error_message(cid: ChannelID, error_code: u8) -> Message {
|
||||
// This unwrap is safe because the payload length is 1 <= 7609 bytes.
|
||||
Message {
|
||||
cid,
|
||||
|
|
|
|||
|
|
@ -119,6 +119,10 @@ fn main() -> Result<()> {
|
|||
if value == 88 {
|
||||
break;
|
||||
}
|
||||
if value == 44 {
|
||||
log::error!("Device is not in backup mode, operation aborted!");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
return Err(error)?;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue