Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xyz-iinuwa-credential-manager-portal-gtk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xyz-iinuwa-credential-manager-portal-gtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde_json = "1.0.140"
tracing = "0.1.41"
tracing-subscriber = "0.3"
zbus = { version = "5.5.0", default-features = false, features = ["blocking-api", "tokio"] }
libwebauthn = { git = "https://github.com/linux-credentials/libwebauthn", rev = "c61492dcc66cc53b33e9d3eb3377017019332964" }
libwebauthn = { git = "https://github.com/linux-credentials/libwebauthn", rev = "21995110e729cb83f3cd5ff3ece4c42315fe8bd3" }
async-trait = "0.1.88"
tokio = { version = "1.45.0", features = ["rt-multi-thread"] }
futures-lite = "2.6.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::time::Duration;
use std::{collections::HashMap, time::Duration};

use async_stream::stream;
use base64::{self, engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use futures_lite::Stream;
use libwebauthn::{
ops::webauthn::GetAssertionResponse,
proto::CtapError,
transport::{hid::HidDevice, Device},
transport::{
hid::{channel::HidChannelHandle, HidDevice},
Device,
},
webauthn::{Error as WebAuthnError, WebAuthn},
UxUpdate,
};
Expand Down Expand Up @@ -71,59 +74,76 @@ impl InProcessUsbHandler {
}
}
UsbStateInternal::SelectingDevice(hid_devices) => {
let expected_answers = hid_devices.len();
let (blinking_tx, mut blinking_rx) =
tokio::sync::mpsc::channel::<Option<HidDevice>>(hid_devices.len());
let mut expected_answers = hid_devices.len();
for mut device in hid_devices {
tokio::sync::mpsc::channel::<Option<usize>>(expected_answers);
let mut channel_map = HashMap::new();
let (setup_tx, mut setup_rx) =
tokio::sync::mpsc::channel::<(usize, HidDevice, HidChannelHandle)>(
expected_answers,
);
for (idx, mut device) in hid_devices.into_iter().enumerate() {
let stx = setup_tx.clone();
let tx = blinking_tx.clone();
tokio::spawn(async move {
let dev = device.clone();

let res = match device.channel().await {
Ok((ref mut channel, _)) => channel
.blink_and_wait_for_user_presence(Duration::from_secs(300))
.await
.map_err(|err| {
format!(
Ok((ref mut channel, _)) => {
let cancel_handle = channel.get_handle();
stx.send((idx, dev, cancel_handle)).await.unwrap();
drop(stx);

let was_selected = channel
.blink_and_wait_for_user_presence(Duration::from_secs(300))
.await;
match was_selected {
Ok(true) => Ok(Some(idx)),
Ok(false) => Ok(None),
Err(err) => Err(format!(
"Failed to send wink request to authenticator: {:?}",
err
)
})
.and_then(|blinking| {
if blinking {
Ok(())
} else {
Err("Authenticator was not able to blink".to_string())
}
}),
)),
}
}
Err(err) => Err(format!(
"Failed to create channel for USB authenticator: {:?}",
err
)),
}
.inspect_err(|err| tracing::warn!(err))
.ok();

if let Err(err) = tx.send(res.map(|_| device)).await {
.unwrap_or_default(); // In case of error, we also send `None`
if let Err(err) = tx.send(res).await {
tracing::error!(
"Failed to send notification of wink response: {:?}",
err,
);
}
});
}
drop(setup_tx);
// Receiving all cancel handles
while let Some((idx, device, handle)) = setup_rx.recv().await {
channel_map.insert(idx, (device, handle));
}

tracing::info!("Waiting for user interaction");
drop(blinking_tx);
let mut state = UsbStateInternal::Idle;
while let Some(msg) = blinking_rx.recv().await {
expected_answers -= 1;
match msg {
Some(device) => {
Some(idx) => {
let (device, _handle) = channel_map.remove(&idx).unwrap();
tracing::info!("User selected device {device:?}.");
for (_key, (device, handle)) in channel_map.into_iter() {
tracing::info!("Cancelling device {device:?}.");
handle.cancel_ongoing_operation().await;
}
state = UsbStateInternal::Connected(device);
break;
}
None => {
if expected_answers == 0 {
break;
} else {
continue;
}
continue;
}
}
}
Expand Down