Skip to content

Commit acca773

Browse files
feat(transport): thread persistent token store through ChannelSettings
1 parent 92299c0 commit acca773

36 files changed

Lines changed: 153 additions & 87 deletions

libwebauthn-tests/tests/basic_ctap1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::time::Duration;
22

33
use libwebauthn::ops::u2f::{RegisterRequest, SignRequest};
4-
use libwebauthn::transport::{Channel, Device};
4+
use libwebauthn::transport::{Channel, ChannelSettings, Device};
55
use libwebauthn::u2f::U2F;
66
use libwebauthn::UvUpdate;
77
use libwebauthn_tests::virt::get_virtual_device;
@@ -21,7 +21,7 @@ async fn test_webauthn_basic_ctap1() {
2121
let mut device = get_virtual_device();
2222

2323
println!("Selected HID authenticator: {}", &device);
24-
let mut channel = device.channel().await.unwrap();
24+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
2525
channel.wink(TIMEOUT).await.unwrap();
2626

2727
const APP_ID: &str = "https://foo.example.org";

libwebauthn-tests/tests/basic_ctap2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::Duration;
22

33
use libwebauthn::ops::webauthn::{GetAssertionRequest, GetAssertionRequestExtensions};
44
use libwebauthn::proto::ctap2::Ctap2PublicKeyCredentialDescriptor;
5-
use libwebauthn::transport::{Channel, Device};
5+
use libwebauthn::transport::{Channel, ChannelSettings, Device};
66
use libwebauthn::webauthn::WebAuthn;
77
use libwebauthn::UvUpdate;
88
use libwebauthn::{
@@ -33,7 +33,7 @@ async fn test_webauthn_basic_ctap2() {
3333
let challenge: [u8; 32] = thread_rng().gen();
3434

3535
println!("Selected HID authenticator: {}", &device);
36-
let mut channel = device.channel().await.unwrap();
36+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
3737
channel.wink(TIMEOUT).await.unwrap();
3838

3939
// Make Credentials ceremony

libwebauthn-tests/tests/pin_protocols.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::Duration;
22

33
use libwebauthn::pin::PinManagement;
44
use libwebauthn::proto::ctap2::Ctap2PinUvAuthProtocol;
5-
use libwebauthn::transport::{Channel, Device};
5+
use libwebauthn::transport::{Channel, ChannelSettings, Device};
66
use libwebauthn::UvUpdate;
77
use libwebauthn_tests::virt::get_virtual_device;
88
use test_log::test;
@@ -23,7 +23,7 @@ async fn test_webauthn_change_pin_once() {
2323
let protos = [Ctap2PinUvAuthProtocol::One, Ctap2PinUvAuthProtocol::Two];
2424
for proto in protos {
2525
let mut device = get_virtual_device();
26-
let mut channel = device.channel().await.unwrap();
26+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
2727

2828
let mut state_recv = channel.get_ux_update_receiver();
2929

@@ -43,7 +43,7 @@ async fn test_webauthn_change_pin_twice() {
4343
let protos = [Ctap2PinUvAuthProtocol::One, Ctap2PinUvAuthProtocol::Two];
4444
for proto in protos {
4545
let mut device = get_virtual_device();
46-
let mut channel = device.channel().await.unwrap();
46+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
4747

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

libwebauthn-tests/tests/preflight.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use libwebauthn::proto::ctap2::{
1111
};
1212
use libwebauthn::proto::CtapError;
1313
use libwebauthn::transport::hid::channel::HidChannel;
14-
use libwebauthn::transport::{Channel, Device};
14+
use libwebauthn::transport::{Channel, ChannelSettings, Device};
1515
use libwebauthn::webauthn::{Error, WebAuthn};
1616
use libwebauthn::UvUpdate;
1717
use libwebauthn_tests::virt::get_virtual_device;
@@ -98,7 +98,7 @@ fn create_credential(id: &[u8]) -> Ctap2PublicKeyCredentialDescriptor {
9898
async fn preflight_no_exclude_list() {
9999
// Make credential with exclude_list: None. Should do nothing in preflight and return a credential
100100
let mut device = get_virtual_device();
101-
let mut channel = device.channel().await.unwrap();
101+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
102102

103103
let user_id: [u8; 32] = thread_rng().gen();
104104

@@ -119,7 +119,7 @@ async fn preflight_nonsense_exclude_list() {
119119
// Make credential with nonsense exclude_list. Should remove everything in preflight and return a credential
120120

121121
let mut device = get_virtual_device();
122-
let mut channel = device.channel().await.unwrap();
122+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
123123

124124
let user_id: [u8; 32] = thread_rng().gen();
125125

@@ -147,7 +147,7 @@ async fn preflight_mixed_exclude_list() {
147147
// Make credential with a mixed exclude_list that contains 2 real ones. Should remove the two fake ones in preflight and return an error
148148

149149
let mut device = get_virtual_device();
150-
let mut channel = device.channel().await.unwrap();
150+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
151151

152152
let user_id: [u8; 32] = thread_rng().gen();
153153

@@ -194,7 +194,7 @@ async fn preflight_no_allow_list() {
194194
// Get assertion with allow_list: None. Should do nothing in preflight and return an error OR credentials, if a discoverable credential for example.org is present on the device
195195

196196
let mut device = get_virtual_device();
197-
let mut channel = device.channel().await.unwrap();
197+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
198198

199199
let user_id: [u8; 32] = thread_rng().gen();
200200

@@ -221,7 +221,7 @@ async fn preflight_nonsense_allow_list() {
221221
// Get assertion with nonsense allow_list. Should remove everything in preflight and return an error, AND run a dummy request to provoke a touch
222222

223223
let mut device = get_virtual_device();
224-
let mut channel = device.channel().await.unwrap();
224+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
225225

226226
let user_id: [u8; 32] = thread_rng().gen();
227227

@@ -255,7 +255,7 @@ async fn preflight_with_appid_exclude_finds_legacy_credential() {
255255
// while passing the legacy rpId as `appid_exclude`. The credential
256256
// should be detected, matching WebAuthn L3 §10.1.2 semantics.
257257
let mut device = get_virtual_device();
258-
let mut channel = device.channel().await.unwrap();
258+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
259259

260260
let user_id: [u8; 32] = thread_rng().gen();
261261
let _state_recv = channel.get_ux_update_receiver();
@@ -305,7 +305,7 @@ async fn preflight_mixed_allow_list() {
305305
// Get assertion with a mixed allow_list that contains 2 real ones. Should remove the two fake ones in preflight
306306

307307
let mut device = get_virtual_device();
308-
let mut channel = device.channel().await.unwrap();
308+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
309309

310310
let user_id: [u8; 32] = thread_rng().gen();
311311

libwebauthn-tests/tests/prf.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use libwebauthn::ops::webauthn::{
88
use libwebauthn::pin::PinManagement;
99
use libwebauthn::proto::ctap2::{Ctap2PinUvAuthProtocol, Ctap2PublicKeyCredentialDescriptor};
1010
use libwebauthn::transport::hid::channel::HidChannel;
11-
use libwebauthn::transport::{Channel, Ctap2AuthTokenStore, Device};
11+
use libwebauthn::transport::{Channel, ChannelSettings, Ctap2AuthTokenStore, Device};
1212
use libwebauthn::webauthn::{Error as WebAuthnError, PlatformError, WebAuthn};
1313
use libwebauthn::UvUpdate;
1414
use libwebauthn::{
@@ -28,14 +28,14 @@ const TIMEOUT: Duration = Duration::from_secs(10);
2828
#[test(tokio::test)]
2929
async fn test_webauthn_prf_no_pin_set() {
3030
let mut device = get_virtual_device();
31-
let mut channel = device.channel().await.unwrap();
31+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
3232
run_test_battery(&mut channel, false).await;
3333
}
3434

3535
#[test(tokio::test)]
3636
async fn test_webauthn_prf_with_pin_set() {
3737
let mut device = get_virtual_device();
38-
let mut channel = device.channel().await.unwrap();
38+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
3939
channel
4040
.change_pin(String::from("1234"), TIMEOUT)
4141
.await
@@ -46,7 +46,7 @@ async fn test_webauthn_prf_with_pin_set() {
4646
#[test(tokio::test)]
4747
async fn test_webauthn_prf_with_pin_set_forced_pin_protocol_one() {
4848
let mut device = get_virtual_device();
49-
let mut channel = device.channel().await.unwrap();
49+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
5050
channel.set_forced_pin_protocol(Ctap2PinUvAuthProtocol::One);
5151
channel
5252
.change_pin(String::from("1234"), TIMEOUT)
@@ -58,7 +58,7 @@ async fn test_webauthn_prf_with_pin_set_forced_pin_protocol_one() {
5858
#[test(tokio::test)]
5959
async fn test_webauthn_prf_with_pin_set_forced_pin_protocol_two() {
6060
let mut device = get_virtual_device();
61-
let mut channel = device.channel().await.unwrap();
61+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
6262
channel.set_forced_pin_protocol(Ctap2PinUvAuthProtocol::Two);
6363
channel
6464
.change_pin(String::from("1234"), TIMEOUT)
@@ -74,7 +74,7 @@ async fn test_webauthn_prf_with_pin_set_forced_pin_protocol_two() {
7474
#[test(tokio::test)]
7575
async fn test_webauthn_prf_eval_at_create_degrades_when_unsupported() {
7676
let mut device = get_virtual_device();
77-
let mut channel = device.channel().await.unwrap();
77+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
7878
let state_recv = channel.get_ux_update_receiver();
7979
// PRF forces UV=required (webauthn#2337); no-PIN device drives PIN setup.
8080
tokio::spawn(handle_updates(
@@ -659,7 +659,7 @@ async fn run_failed_test(
659659
#[test(tokio::test)]
660660
async fn test_webauthn_prf_variable_length_input() {
661661
let mut device = get_virtual_device();
662-
let mut channel = device.channel().await.unwrap();
662+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
663663

664664
let user_id: [u8; 32] = thread_rng().gen();
665665
let challenge: [u8; 32] = thread_rng().gen();
@@ -810,7 +810,7 @@ fn basic_make_credential_request(
810810
#[test(tokio::test)]
811811
async fn test_webauthn_prf_upgrades_uv_at_registration() {
812812
let mut device = get_virtual_device();
813-
let mut channel = device.channel().await.unwrap();
813+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
814814
channel.change_pin("1234".into(), TIMEOUT).await.unwrap();
815815

816816
let state_recv = channel.get_ux_update_receiver();
@@ -852,7 +852,7 @@ async fn test_webauthn_prf_upgrades_uv_at_registration() {
852852
#[test(tokio::test)]
853853
async fn test_webauthn_no_prf_no_upgrade() {
854854
let mut device = get_virtual_device();
855-
let mut channel = device.channel().await.unwrap();
855+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
856856
channel.change_pin("1234".into(), TIMEOUT).await.unwrap();
857857

858858
let state_recv = channel.get_ux_update_receiver();
@@ -886,7 +886,7 @@ async fn test_webauthn_no_prf_no_upgrade() {
886886
#[test(tokio::test)]
887887
async fn test_webauthn_prf_upgrades_uv_at_assertion() {
888888
let mut device = get_virtual_device();
889-
let mut channel = device.channel().await.unwrap();
889+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
890890
channel.change_pin("1234".into(), TIMEOUT).await.unwrap();
891891

892892
let user_id: [u8; 32] = thread_rng().gen();

libwebauthn/examples/ceremony/u2f_ble.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33

44
use libwebauthn::ops::u2f::{RegisterRequest, SignRequest};
55
use libwebauthn::transport::ble::list_devices;
6-
use libwebauthn::transport::{Channel as _, Device};
6+
use libwebauthn::transport::{Channel as _, ChannelSettings, Device};
77
use libwebauthn::u2f::U2F;
88

99
#[path = "../common/mod.rs"]
@@ -19,7 +19,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
1919
println!("Found {} devices.", devices.len());
2020

2121
for mut device in devices {
22-
let mut channel = device.channel().await?;
22+
let mut channel = device.channel(ChannelSettings::default()).await?;
2323

2424
const APP_ID: &str = "https://foo.example.org";
2525
let challenge: &[u8] =

libwebauthn/examples/ceremony/u2f_hid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33

44
use libwebauthn::ops::u2f::{RegisterRequest, SignRequest};
55
use libwebauthn::transport::hid::list_devices;
6-
use libwebauthn::transport::{Channel as _, Device};
6+
use libwebauthn::transport::{Channel as _, ChannelSettings, Device};
77
use libwebauthn::u2f::U2F;
88

99
#[path = "../common/mod.rs"]
@@ -20,7 +20,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
2020

2121
for mut device in devices {
2222
println!("Winking device: {}", device);
23-
let mut channel = device.channel().await?;
23+
let mut channel = device.channel(ChannelSettings::default()).await?;
2424
channel.wink(TIMEOUT).await?;
2525

2626
const APP_ID: &str = "https://foo.example.org";

libwebauthn/examples/ceremony/u2f_nfc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33

44
use libwebauthn::ops::u2f::{RegisterRequest, SignRequest};
55
use libwebauthn::transport::nfc::{get_nfc_device, is_nfc_available};
6-
use libwebauthn::transport::{Channel as _, Device};
6+
use libwebauthn::transport::{Channel as _, ChannelSettings, Device};
77
use libwebauthn::u2f::U2F;
88

99
#[path = "../common/mod.rs"]
@@ -24,7 +24,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
2424

2525
if let Some(mut device) = device {
2626
println!("Selected NFC authenticator: {}", &device);
27-
let mut channel = device.channel().await?;
27+
let mut channel = device.channel(ChannelSettings::default()).await?;
2828

2929
const APP_ID: &str = "https://foo.example.org";
3030
let challenge: &[u8] =

libwebauthn/examples/ceremony/webauthn_ble.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use libwebauthn::ops::webauthn::{
66
};
77
use libwebauthn::proto::ctap2::Ctap2PublicKeyCredentialDescriptor;
88
use libwebauthn::transport::ble::list_devices;
9-
use libwebauthn::transport::{Channel as _, Device};
9+
use libwebauthn::transport::{Channel as _, ChannelSettings, Device};
1010
use libwebauthn::webauthn::WebAuthn;
1111

1212
#[path = "../common/mod.rs"]
@@ -21,7 +21,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
2121

2222
for mut device in devices {
2323
println!("Selected BLE authenticator: {}", &device);
24-
let mut channel = device.channel().await?;
24+
let mut channel = device.channel(ChannelSettings::default()).await?;
2525

2626
let request_origin: RequestOrigin =
2727
"https://example.org".try_into().expect("Invalid origin");

libwebauthn/examples/ceremony/webauthn_cable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use libwebauthn::ops::webauthn::{
1414
DatFilePublicSuffixList, JsonFormat, MakeCredentialRequest, OriginValidation, RelatedOrigins,
1515
RequestOrigin, RequestSettings, WebAuthnIDLResponse as _,
1616
};
17-
use libwebauthn::transport::{Channel as _, Device};
17+
use libwebauthn::transport::{Channel as _, ChannelSettings, Device};
1818
use libwebauthn::webauthn::WebAuthn;
1919

2020
#[path = "../common/mod.rs"]
@@ -79,7 +79,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
7979
.build();
8080
println!("{}", image);
8181

82-
let mut channel = device.channel().await.unwrap();
82+
let mut channel = device.channel(ChannelSettings::default()).await.unwrap();
8383
println!("Channel established {:?}", channel);
8484

8585
let state_recv = channel.get_ux_update_receiver();

0 commit comments

Comments
 (0)