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
12 changes: 12 additions & 0 deletions libwebauthn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ pub enum Transport {
Hybrid,
}

impl Transport {
/// The WebAuthn authenticator attachment modality this transport implies.
/// libwebauthn only drives roaming authenticators, so all map to `"cross-platform"`.
pub fn authenticator_attachment(self) -> &'static str {
match self {
Transport::Usb | Transport::Ble | Transport::Nfc | Transport::Hybrid => {
"cross-platform"
}
}
}
}

#[derive(Debug, Clone)]
#[cfg_attr(any(test, feature = "virt"), derive(PartialEq))]
pub enum UvUpdate {
Expand Down
35 changes: 34 additions & 1 deletion libwebauthn/src/ops/webauthn/get_assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::{
Ctap2PublicKeyCredentialUserEntity,
},
webauthn::CtapError,
Transport,
};

use super::timeout::DEFAULT_TIMEOUT;
Expand Down Expand Up @@ -478,6 +479,8 @@ pub struct Assertion {
pub credentials_count: Option<u32>,
pub user_selected: Option<bool>,
pub unsigned_extensions_output: Option<GetAssertionResponseUnsignedExtensions>,
/// Transport the assertion was produced over, stamped by the channel.
pub transport: Option<Transport>,
}

impl WebAuthnIDLResponse for Assertion {
Expand Down Expand Up @@ -522,7 +525,9 @@ impl WebAuthnIDLResponse for Assertion {
signature: Base64UrlString::from(self.signature.clone()),
user_handle,
},
authenticator_attachment: None,
authenticator_attachment: self
.transport
.map(|t| t.authenticator_attachment().to_string()),
client_extension_results,
r#type: "public-key".to_string(),
})
Expand Down Expand Up @@ -1422,6 +1427,7 @@ mod tests {
credentials_count: None,
user_selected: None,
unsigned_extensions_output: None,
transport: None,
}
}

Expand Down Expand Up @@ -1480,6 +1486,33 @@ mod tests {
assert_eq!(model.response.signature.0, vec![0xDE, 0xAD, 0xC0, 0xDE]);
}

#[test]
fn test_assertion_to_idl_model_populates_attachment() {
// libwebauthn drives roaming authenticators, so every known transport
// yields authenticatorAttachment "cross-platform" (WebAuthn L3 §5.1).
let mut assertion = create_test_assertion();
let request = create_test_request();

for transport in [
Transport::Usb,
Transport::Ble,
Transport::Nfc,
Transport::Hybrid,
] {
assertion.transport = Some(transport);
let model = assertion.to_idl_model(&request).unwrap();
assert_eq!(
model.authenticator_attachment.as_deref(),
Some("cross-platform")
);
}

// An unknown transport omits the field.
assertion.transport = None;
let model = assertion.to_idl_model(&request).unwrap();
assert_eq!(model.authenticator_attachment, None);
}

#[test]
fn test_assertion_with_user_handle() {
use crate::proto::ctap2::Ctap2PublicKeyCredentialUserEntity;
Expand Down
7 changes: 7 additions & 0 deletions libwebauthn/src/ops/webauthn/large_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,10 @@ mod tests {
.await
.expect("webauthn_get_assertion should succeed");
assert_eq!(response.assertions.len(), 1);
assert_eq!(
response.assertions[0].transport,
Some(crate::Transport::Usb)
);
let large_blob = response.assertions[0]
.unsigned_extensions_output
.as_ref()
Expand Down Expand Up @@ -1184,6 +1188,9 @@ mod tests {
.await
.expect("get_assertion should succeed");
assert_eq!(response.assertions.len(), 2);
for a in &response.assertions {
assert_eq!(a.transport, Some(crate::Transport::Usb));
}
let blob = |i: usize| {
response.assertions[i]
.unsigned_extensions_output
Expand Down
31 changes: 30 additions & 1 deletion libwebauthn/src/ops/webauthn/make_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ impl WebAuthnIDLResponse for MakeCredentialResponse {
public_key_algorithm,
attestation_object: Base64UrlString::from(attestation_object_bytes),
},
authenticator_attachment: None,
authenticator_attachment: self
.transport
.map(|t| t.authenticator_attachment().to_string()),
client_extension_results,
r#type: "public-key".to_string(),
})
Expand Down Expand Up @@ -1814,6 +1816,33 @@ mod tests {
assert!(model.response.transports.is_empty());
}

#[test]
fn test_response_to_idl_model_populates_attachment() {
// libwebauthn drives roaming authenticators, so every known transport
// yields authenticatorAttachment "cross-platform" (WebAuthn L3 §5.1).
let mut response = create_test_response();
let request = create_test_request();

for transport in [
Transport::Usb,
Transport::Ble,
Transport::Nfc,
Transport::Hybrid,
] {
response.transport = Some(transport);
let model = response.to_idl_model(&request).unwrap();
assert_eq!(
model.authenticator_attachment.as_deref(),
Some("cross-platform")
);
}

// An unknown transport omits the field.
response.transport = None;
let model = response.to_idl_model(&request).unwrap();
assert_eq!(model.authenticator_attachment, None);
}

#[test]
fn test_response_to_idl_model_transports_from_get_info() {
// The authenticator's getInfo (0x09) transports are folded with the
Expand Down
1 change: 1 addition & 0 deletions libwebauthn/src/proto/ctap2/model/get_assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ impl Ctap2GetAssertionResponse {
credentials_count: self.credentials_count,
user_selected: self.user_selected,
unsigned_extensions_output,
transport: None,
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions libwebauthn/src/transport/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ pub trait Channel: Send + Sync + Display + Ctap2AuthTokenStore {
async fn status(&self) -> ChannelStatus;
async fn close(&mut self);

/// The transport this channel speaks over, used to populate the registration
/// response `transports` member.
/// The transport this channel speaks over. Drives the registration response
/// `transports` member and the `authenticatorAttachment` of both registration
/// and assertion responses.
fn transport(&self) -> Transport {
Transport::Usb
}
Expand Down
7 changes: 6 additions & 1 deletion libwebauthn/src/webauthn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,15 @@ where
};
trace!(?op, "WebAuthn GetAssertion request");
let protocol = negotiate_protocol(self, op.is_downgradable()).await?;
match protocol {
let mut response = match protocol {
FidoProtocol::FIDO2 => get_assertion_fido2(self, op).await,
FidoProtocol::U2F => get_assertion_u2f(self, op).await,
}?;
let transport = self.transport();
for assertion in &mut response.assertions {
assertion.transport = Some(transport);
}
Ok(response)
}
}

Expand Down
Loading