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
9 changes: 5 additions & 4 deletions libwebauthn/examples/authenticator_config_hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use libwebauthn::management::AuthenticatorConfig;
use libwebauthn::pin::PinRequestReason;
use libwebauthn::proto::ctap2::{Ctap2, Ctap2GetInfoResponse};
use libwebauthn::transport::hid::list_devices;
use libwebauthn::transport::Device;
use libwebauthn::transport::{Channel as _, Device};
use libwebauthn::webauthn::Error as WebAuthnError;
use libwebauthn::UvUpdate;
use std::io::{self, Write};
use text_io::read;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tracing_subscriber::{self, EnvFilter};

const TIMEOUT: Duration = Duration::from_secs(10);
Expand All @@ -24,7 +24,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
UvUpdate::UvRetry { attempts_left } => {
Expand Down Expand Up @@ -123,9 +123,10 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

for mut device in devices {
println!("Selected HID authenticator: {}", &device);
let (mut channel, state_recv) = device.channel().await?;
let mut channel = device.channel().await?;
channel.wink(TIMEOUT).await?;

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

let info = channel.ctap2_get_info().await?;
Expand Down
9 changes: 5 additions & 4 deletions libwebauthn/examples/bio_enrollment_hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use std::fmt::Display;
use std::io::{self, Write};
use std::time::Duration;
use text_io::read;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tracing_subscriber::{self, EnvFilter};

use libwebauthn::management::BioEnrollment;
use libwebauthn::pin::PinRequestReason;
use libwebauthn::proto::ctap2::{Ctap2, Ctap2GetInfoResponse, Ctap2LastEnrollmentSampleStatus};
use libwebauthn::transport::hid::list_devices;
use libwebauthn::transport::Device;
use libwebauthn::transport::{Channel as _, Device};
use libwebauthn::webauthn::Error as WebAuthnError;

const TIMEOUT: Duration = Duration::from_secs(10);
Expand All @@ -24,7 +24,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
UvUpdate::UvRetry { attempts_left } => {
Expand Down Expand Up @@ -148,9 +148,10 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

for mut device in devices {
println!("Selected HID authenticator: {}", &device);
let (mut channel, state_recv) = device.channel().await?;
let mut channel = device.channel().await?;
channel.wink(TIMEOUT).await?;

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

let info = channel.ctap2_get_info().await?;
Expand Down
8 changes: 5 additions & 3 deletions libwebauthn/examples/change_pin_hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use std::time::Duration;

use libwebauthn::{
pin::{PinManagement, PinRequestReason},
transport::Channel as _,
UvUpdate,
};
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tracing_subscriber::{self, EnvFilter};

use libwebauthn::transport::hid::list_devices;
Expand All @@ -24,7 +25,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
UvUpdate::UvRetry { attempts_left } => {
Expand Down Expand Up @@ -72,7 +73,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

for mut device in devices {
println!("Selected HID authenticator: {}", &device);
let (mut channel, state_recv) = device.channel().await?;
let mut channel = device.channel().await?;
channel.wink(TIMEOUT).await?;

print!("PIN: Please enter the _new_ PIN: ");
Expand All @@ -84,6 +85,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
return Ok(());
}

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

let response = loop {
Expand Down
9 changes: 5 additions & 4 deletions libwebauthn/examples/cred_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use libwebauthn::proto::ctap2::{
};
use libwebauthn::proto::CtapError;
use libwebauthn::transport::hid::list_devices;
use libwebauthn::transport::Device;
use libwebauthn::transport::{Channel as _, Device};
use libwebauthn::webauthn::Error as WebAuthnError;
use libwebauthn::UvUpdate;
use std::fmt::Display;
use std::io::{self, Write};
use std::time::Duration;
use text_io::read;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tracing_subscriber::{self, EnvFilter};

const TIMEOUT: Duration = Duration::from_secs(10);
Expand All @@ -25,7 +25,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
UvUpdate::UvRetry { attempts_left } => {
Expand Down Expand Up @@ -167,9 +167,10 @@ pub async fn main() -> Result<(), WebAuthnError> {

for mut device in devices {
println!("Selected HID authenticator: {}", &device);
let (mut channel, state_recv) = device.channel().await?;
let mut channel = device.channel().await?;
channel.wink(TIMEOUT).await?;

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

let info = channel.ctap2_get_info().await?;
Expand Down
2 changes: 1 addition & 1 deletion libwebauthn/examples/hid_device_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

tokio::spawn(async move {
let dev = device.clone();
let (mut channel, _state_rx) = device.channel().await.unwrap();
let mut channel = device.channel().await.unwrap();
let handle = channel.get_handle();
stx.send((idx, dev, handle)).await.unwrap();
drop(stx);
Expand Down
9 changes: 5 additions & 4 deletions libwebauthn/examples/prf_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use libwebauthn::UvUpdate;
use rand::{thread_rng, Rng};
use serde_bytes::ByteBuf;
use text_io::read;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tracing_subscriber::{self, EnvFilter};

use libwebauthn::ops::webauthn::{
Expand All @@ -19,7 +19,7 @@ use libwebauthn::ops::webauthn::{
use libwebauthn::pin::PinRequestReason;
use libwebauthn::proto::ctap2::{Ctap2PublicKeyCredentialDescriptor, Ctap2PublicKeyCredentialType};
use libwebauthn::transport::hid::list_devices;
use libwebauthn::transport::Device;
use libwebauthn::transport::{Channel as _, Device};
use libwebauthn::webauthn::{Error as WebAuthnError, WebAuthn};

const TIMEOUT: Duration = Duration::from_secs(10);
Expand All @@ -32,7 +32,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
UvUpdate::UvRetry { attempts_left } => {
Expand Down Expand Up @@ -107,9 +107,10 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

for mut device in devices {
println!("Selected HID authenticator: {}", &device);
let (mut channel, state_recv) = device.channel().await?;
let mut channel = device.channel().await?;
channel.wink(TIMEOUT).await?;

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

let credential = Ctap2PublicKeyCredentialDescriptor {
Expand Down
10 changes: 6 additions & 4 deletions libwebauthn/examples/u2f_ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::error::Error;
use std::time::Duration;

use libwebauthn::UvUpdate;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tracing_subscriber::{self, EnvFilter};

use libwebauthn::ops::u2f::{RegisterRequest, SignRequest};
use libwebauthn::transport::ble::list_devices;
use libwebauthn::transport::Device;
use libwebauthn::transport::{Channel as _, Device};
use libwebauthn::u2f::U2F;

const TIMEOUT: Duration = Duration::from_secs(10);
Expand All @@ -20,7 +20,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
_ => { /* U2F doesn't use other state updates */ }
Expand All @@ -36,7 +36,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
println!("Found {} devices.", devices.len());

for mut device in devices {
let (mut channel, state_recv) = device.channel().await?;
let mut channel = device.channel().await?;

const APP_ID: &str = "https://foo.example.org";
let challenge: &[u8] =
Expand All @@ -46,7 +46,9 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
let register_request =
RegisterRequest::new_u2f_v2(&APP_ID, &challenge, vec![], TIMEOUT, false);

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

let response = channel.u2f_register(&register_request).await?;
println!("Response: {:?}", response);

Expand Down
10 changes: 6 additions & 4 deletions libwebauthn/examples/u2f_hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use std::error::Error;
use std::time::Duration;

use libwebauthn::UvUpdate;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tracing_subscriber::{self, EnvFilter};

use libwebauthn::ops::u2f::{RegisterRequest, SignRequest};
use libwebauthn::transport::hid::list_devices;
use libwebauthn::transport::Device;
use libwebauthn::transport::{Channel as _, Device};
use libwebauthn::u2f::U2F;

const TIMEOUT: Duration = Duration::from_secs(10);
Expand All @@ -21,7 +21,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
_ => { /* U2F doesn't use other state updates */ }
Expand All @@ -38,7 +38,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
println!("Found {} devices.", devices.len());
for mut device in devices {
println!("Winking device: {}", device);
let (mut channel, state_recv) = device.channel().await?;
let mut channel = device.channel().await?;
channel.wink(TIMEOUT).await?;

const APP_ID: &str = "https://foo.example.org";
Expand All @@ -49,7 +49,9 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
let register_request =
RegisterRequest::new_u2f_v2(&APP_ID, &challenge, vec![], TIMEOUT, false);

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

let response = channel.u2f_register(&register_request).await?;
println!("Response: {:?}", response);

Expand Down
12 changes: 7 additions & 5 deletions libwebauthn/examples/webauthn_cable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use qrcode::render::unicode;
use qrcode::QrCode;
use rand::{thread_rng, Rng};
use text_io::read;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tokio::time::sleep;
use tracing_subscriber::{self, EnvFilter};

Expand All @@ -25,7 +25,7 @@ use libwebauthn::proto::ctap2::{
Ctap2CredentialType, Ctap2PublicKeyCredentialDescriptor, Ctap2PublicKeyCredentialRpEntity,
Ctap2PublicKeyCredentialUserEntity,
};
use libwebauthn::transport::Device;
use libwebauthn::transport::{Channel as _, Device};
use libwebauthn::webauthn::{Error as WebAuthnError, WebAuthn};

const TIMEOUT: Duration = Duration::from_secs(120);
Expand All @@ -38,7 +38,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<CableUxUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
CableUxUpdate::UvUpdate(uv_update) => match uv_update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
Expand Down Expand Up @@ -111,9 +111,10 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
println!("{}", image);

// Connect to a known device
let (mut channel, state_recv) = device.channel().await.unwrap();
let mut channel = device.channel().await.unwrap();
println!("Tunnel established {:?}", channel);

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

// Make Credentials ceremony
Expand Down Expand Up @@ -177,9 +178,10 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
.unwrap();

// Connect to a known device
let (mut channel, state_recv) = known_device.channel().await.unwrap();
let mut channel = known_device.channel().await.unwrap();
println!("Tunnel established {:?}", channel);

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

let response = loop {
Expand Down
9 changes: 5 additions & 4 deletions libwebauthn/examples/webauthn_extensions_hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::Duration;
use libwebauthn::UvUpdate;
use rand::{thread_rng, Rng};
use text_io::read;
use tokio::sync::mpsc::Receiver;
use tokio::sync::broadcast::Receiver;
use tracing_subscriber::{self, EnvFilter};

use libwebauthn::ops::webauthn::{
Expand All @@ -21,7 +21,7 @@ use libwebauthn::proto::ctap2::{
Ctap2PublicKeyCredentialUserEntity,
};
use libwebauthn::transport::hid::list_devices;
use libwebauthn::transport::Device;
use libwebauthn::transport::{Channel as _, Device};
use libwebauthn::webauthn::{Error as WebAuthnError, WebAuthn};

const TIMEOUT: Duration = Duration::from_secs(10);
Expand All @@ -34,7 +34,7 @@ fn setup_logging() {
}

async fn handle_updates(mut state_recv: Receiver<UvUpdate>) {
while let Some(update) = state_recv.recv().await {
while let Ok(update) = state_recv.recv().await {
match update {
UvUpdate::PresenceRequired => println!("Please touch your device!"),
UvUpdate::UvRetry { attempts_left } => {
Expand Down Expand Up @@ -97,9 +97,10 @@ pub async fn main() -> Result<(), Box<dyn Error>> {

for mut device in devices {
println!("Selected HID authenticator: {}", &device);
let (mut channel, state_recv) = device.channel().await?;
let mut channel = device.channel().await?;
channel.wink(TIMEOUT).await?;

let state_recv = channel.get_ux_update_receiver();
tokio::spawn(handle_updates(state_recv));

// Make Credentials ceremony
Expand Down
Loading
Loading