Skip to content

Commit 67f36e5

Browse files
authored
Merge pull request #116 from linux-credentials/libwebauthn-json
Use libwebauthn for JSON request parsing
2 parents 2ad09d3 + 27d59c6 commit 67f36e5

10 files changed

Lines changed: 715 additions & 744 deletions

File tree

Cargo.lock

Lines changed: 542 additions & 145 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

credentialsd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async-trait = "0.1.89"
1111
base64 = "0.22.1"
1212
credentialsd-common = { path = "../credentialsd-common" }
1313
futures-lite.workspace = true
14-
libwebauthn = { git = "https://github.com/linux-credentials/libwebauthn.git", rev="80545bff16c4e89a930221e90d3141a76303b84b", features = ["libnfc","pcsc"] }
14+
libwebauthn = { version = "0.3.0", features = ["libnfc","pcsc"] }
1515
# TODO: split nfc and pcsc into separate features
1616
# Also, 0.6.1 fails to build with non-vendored library.
1717
# https://github.com/alexrsagen/rs-nfc1/issues/15

credentialsd/src/credential_service/hybrid.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ impl HybridHandler for InternalHybridHandler {
5151
QrCodeOperationHint::GetAssertionRequest
5252
}
5353
};
54-
let mut device = CableQrCodeDevice::new_transient(hint);
54+
let mut device = match CableQrCodeDevice::new_transient(hint) {
55+
Ok(device) => device,
56+
Err(err) => {
57+
tracing::error!("Failed to create caBLE QR code device: {:?}", err);
58+
return;
59+
}
60+
};
5561
let qr_code = device.qr_code.to_string();
5662
if let Err(err) = tx.send(HybridStateInternal::Init(qr_code)).await {
5763
tracing::error!("Failed to send caBLE update: {:?}", err);

credentialsd/src/credential_service/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ impl From<GetAssertionResponse> for AuthenticatorResponse {
381381
mod test {
382382
use std::{sync::Arc, time::Duration};
383383

384+
use base64::Engine as _;
384385
use libwebauthn::{
385386
ops::webauthn::{
386387
MakeCredentialRequest, ResidentKeyRequirement, UserVerificationRequirement,
@@ -396,9 +397,7 @@ mod test {
396397
credential_service::usb::InProcessUsbHandler,
397398
dbus::test::{DummyFlowServer, DummyUiServer},
398399
model::CredentialRequest,
399-
webauthn::{self, NavigationContext},
400400
};
401-
use credentialsd_common::model::Operation;
402401

403402
use super::{
404403
hybrid::{test::DummyHybridHandler, HybridStateInternal},
@@ -456,13 +455,15 @@ mod test {
456455

457456
fn create_credential_request() -> CredentialRequest {
458457
let challenge = "Ox0AXQz7WUER7BGQFzvVrQbReTkS3sepVGj26qfUhhrWSarkDbGF4T4NuCY1aAwHYzOzKMJJ2YRSatetl0D9bQ";
459-
let origin = NavigationContext::SameOrigin("https://webauthn.io".parse().unwrap());
460-
let client_data_json =
461-
webauthn::format_client_data_json(Operation::Create, challenge, &origin);
462-
let client_data_hash = webauthn::create_client_data_hash(&client_data_json);
458+
let origin = "webauthn.io".to_string();
459+
let is_cross_origin = false;
460+
let challenge_bytes = base64::engine::general_purpose::URL_SAFE_NO_PAD
461+
.decode(challenge)
462+
.expect("valid base64url challenge");
463463
let make_request = MakeCredentialRequest {
464-
hash: client_data_hash,
465-
origin: "https://webauthn.io".to_string(),
464+
challenge: challenge_bytes,
465+
origin: origin.clone(),
466+
cross_origin: Some(is_cross_origin),
466467
relying_party: Ctap2PublicKeyCredentialRpEntity {
467468
id: "webauthn.io".to_string(),
468469
name: Some("webauthn.io".to_string()),

credentialsd/src/credential_service/nfc.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ impl InProcessNfcHandler {
3939
prev_nfc_state: &NfcStateInternal,
4040
) -> Result<NfcStateInternal, Error> {
4141
match libwebauthn::transport::nfc::get_nfc_device().await {
42-
Ok(None) => Ok(NfcStateInternal::Waiting),
43-
Ok(Some(hid_device)) => Ok(NfcStateInternal::Connected(hid_device)),
42+
Ok(Some(nfc_device)) => Ok(NfcStateInternal::Connected(nfc_device)),
43+
Ok(None) => {
44+
let state = NfcStateInternal::Waiting;
45+
Ok(state)
46+
}
4447
Err(err) => {
4548
*failures += 1;
4649
if *failures == 5 {
@@ -527,6 +530,9 @@ async fn handle_nfc_updates(
527530
UvUpdate::PresenceRequired => {
528531
tracing::debug!("Authenticator requested user presence, but that makes no sense for NFC. Skipping");
529532
}
533+
UvUpdate::PinNotSet(_) => {
534+
tracing::error!("Authenticator requested PIN setup, which is not yet supported.");
535+
}
530536
}
531537
}
532538
debug!("NFC update channel closed.");

credentialsd/src/credential_service/usb.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@ async fn handle_usb_updates(
641641
tracing::error!("Authenticator requested user presence, but we cannot relay the message to the credential service: {:?}", err);
642642
}
643643
}
644+
UvUpdate::PinNotSet(_) => {
645+
tracing::error!("Authenticator requested PIN setup, which is not yet supported.");
646+
}
644647
}
645648
}
646649
debug!("USB update channel closed.");

0 commit comments

Comments
 (0)