mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
pass unplug events down to the FIDO stack
this is necessary because unplugs actually force some cryptographic state to rekey
This commit is contained in:
parent
52211f078e
commit
a4d0cdba80
3 changed files with 31 additions and 4 deletions
|
|
@ -54,5 +54,6 @@ pub enum U2fCode {
|
||||||
TxAck,
|
TxAck,
|
||||||
RxWait,
|
RxWait,
|
||||||
RxAck,
|
RxAck,
|
||||||
|
Hangup,
|
||||||
Denied,
|
Denied,
|
||||||
}
|
}
|
||||||
|
|
@ -209,10 +209,17 @@ impl UsbHid {
|
||||||
let mut buf = Buffer::into_buf(req).or(Err(xous::Error::InternalError))?;
|
let mut buf = Buffer::into_buf(req).or(Err(xous::Error::InternalError))?;
|
||||||
buf.lend_mut(self.conn, Opcode::U2fRxDeferred.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
buf.lend_mut(self.conn, Opcode::U2fRxDeferred.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||||
let ack = buf.to_original::<U2fMsgIpc, _>().unwrap();
|
let ack = buf.to_original::<U2fMsgIpc, _>().unwrap();
|
||||||
assert_eq!(ack.code, U2fCode::RxAck, "Expected U2fCode::RxAck");
|
match ack.code {
|
||||||
let mut u2fmsg = FidoMsg::default();
|
U2fCode::RxAck => {
|
||||||
u2fmsg.packet.copy_from_slice(&ack.data);
|
let mut u2fmsg = FidoMsg::default();
|
||||||
Ok(u2fmsg)
|
u2fmsg.packet.copy_from_slice(&ack.data);
|
||||||
|
Ok(u2fmsg)
|
||||||
|
},
|
||||||
|
U2fCode::Hangup => {
|
||||||
|
Err(xous::Error::ProcessTerminated)
|
||||||
|
},
|
||||||
|
_ => Err(xous::Error::InternalError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn u2f_send(&self, msg: FidoMsg) -> Result<(), xous::Error> {
|
pub fn u2f_send(&self, msg: FidoMsg) -> Result<(), xous::Error> {
|
||||||
let mut req = U2fMsgIpc {
|
let mut req = U2fMsgIpc {
|
||||||
|
|
|
||||||
|
|
@ -189,6 +189,7 @@ fn main() -> ! {
|
||||||
let mut fido_rx_queue = VecDeque::<[u8; 64]>::new();
|
let mut fido_rx_queue = VecDeque::<[u8; 64]>::new();
|
||||||
|
|
||||||
let mut lockstatus_force_update = true; // some state to track if we've been through a susupend/resume, to help out the status thread with its UX update after a restart-from-cold
|
let mut lockstatus_force_update = true; // some state to track if we've been through a susupend/resume, to help out the status thread with its UX update after a restart-from-cold
|
||||||
|
let mut was_suspend = true;
|
||||||
loop {
|
loop {
|
||||||
let mut msg = xous::receive_message(usbdev_sid).unwrap();
|
let mut msg = xous::receive_message(usbdev_sid).unwrap();
|
||||||
match FromPrimitive::from_usize(msg.body.id()) {
|
match FromPrimitive::from_usize(msg.body.id()) {
|
||||||
|
|
@ -286,6 +287,24 @@ fn main() -> ! {
|
||||||
Err(e) => log::trace!("U2F ERR: {:?}", e),
|
Err(e) => log::trace!("U2F ERR: {:?}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if usb_dev.state() == UsbDeviceState::Suspend {
|
||||||
|
log::info!("suspend detected");
|
||||||
|
if was_suspend == false {
|
||||||
|
// FIDO listener needs to know when USB was unplugged, so that it can reset state per FIDO2 spec
|
||||||
|
if let Some(mut listener) = fido_listener.take() {
|
||||||
|
let mut response = unsafe {
|
||||||
|
Buffer::from_memory_message_mut(listener.body.memory_message_mut().unwrap())
|
||||||
|
};
|
||||||
|
let mut buf = response.to_original::<U2fMsgIpc, _>().unwrap();
|
||||||
|
assert_eq!(buf.code, U2fCode::RxWait, "Expected U2fcode::RxWait in wrapper");
|
||||||
|
buf.code = U2fCode::Hangup;
|
||||||
|
response.replace(buf).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
was_suspend = true;
|
||||||
|
} else {
|
||||||
|
was_suspend = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Some(Opcode::SwitchCores) => msg_blocking_scalar_unpack!(msg, core, _, _, _, {
|
Some(Opcode::SwitchCores) => msg_blocking_scalar_unpack!(msg, core, _, _, _, {
|
||||||
if core == 1 {
|
if core == 1 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue