Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion libwebauthn/src/proto/ctap1/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,24 @@ impl Ctap1RegisterRequest {

Ctap1RegisterRequest {
version: Ctap1Version::U2fV2,
app_id_hash: app_id_hash,
app_id_hash,
challenge: Vec::from(challenge),
registered_keys,
timeout,
require_user_presence,
}
}

pub fn dummy(timeout: Duration) -> Self {
Ctap1RegisterRequest {
version: Ctap1Version::U2fV2,
app_id_hash: vec![0; 32],
challenge: vec![0; 32],
registered_keys: Vec::new(),
timeout,
require_user_presence: true,
}
}
}

#[derive(Debug)]
Expand Down
20 changes: 9 additions & 11 deletions libwebauthn/src/proto/ctap2/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,15 @@ where
debug!("CTAP2 Authenticator Selection request");
let cbor_request = CborRequest::new(Ctap2CommandCode::AuthenticatorSelection);

loop {
self.cbor_send(&cbor_request, timeout).await?;
let cbor_response = self.cbor_recv(timeout).await?;
match cbor_response.status_code {
CtapError::Ok => {
return Ok(());
}
error => {
warn!(?error, "Selection request failed with status code");
return Err(Error::Ctap(error));
}
self.cbor_send(&cbor_request, timeout).await?;
let cbor_response = self.cbor_recv(timeout).await?;
match cbor_response.status_code {
CtapError::Ok => {
return Ok(());
}
error => {
warn!(?error, "Selection request failed with status code");
return Err(Error::Ctap(error));
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions libwebauthn/src/transport/hid/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use tracing::{debug, instrument, trace, warn, Level};
use tokio::net::UdpSocket;

use crate::proto::ctap1::apdu::{ApduRequest, ApduResponse};
use crate::proto::ctap1::{Ctap1, Ctap1RegisterRequest};
use crate::proto::ctap2::cbor::{CborRequest, CborResponse};
use crate::proto::ctap2::{Ctap2, Ctap2MakeCredentialRequest};
use crate::proto::CtapError;
use crate::transport::channel::{AuthTokenData, Channel, ChannelStatus, Ctap2AuthTokenStore};
use crate::transport::device::SupportedProtocols;
use crate::transport::error::{Error, TransportError};
Expand Down Expand Up @@ -98,6 +101,44 @@ impl<'d> HidChannel<'d> {
Ok(true)
}

#[instrument(skip_all)]
pub async fn blink_and_wait_for_user_presence(
&mut self,
timeout: Duration,
) -> Result<bool, Error> {
let supported = self.supported_protocols().await?;
if supported.fido2 {
let get_info_response = self.ctap2_get_info().await?;
if get_info_response.supports_fido_2_1() {
match self.ctap2_selection(timeout).await {
Ok(_) => Ok(true),
Err(_) => Ok(false),
}
} else {
let ctap2_request = Ctap2MakeCredentialRequest::dummy();
match self.ctap2_make_credential(&ctap2_request, timeout).await {
Ok(_)
| Err(Error::Ctap(CtapError::PINInvalid))
| Err(Error::Ctap(CtapError::PINAuthInvalid))
| Err(Error::Ctap(CtapError::PINNotSet)) => Ok(true),
Err(_) => Ok(false),
}
}
} else if supported.u2f {
let register_request = Ctap1RegisterRequest::dummy(timeout);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Consider adding debug logging to explain we're making a dummy request.

match self.ctap1_register(&register_request).await {
Ok(_)
| Err(Error::Ctap(CtapError::PINInvalid))
| Err(Error::Ctap(CtapError::PINAuthInvalid))
| Err(Error::Ctap(CtapError::PINNotSet)) => Ok(true),
Err(_) => Ok(false),
}
} else {
// Neither fido2 nor u2f supported, so we just mark it as not selected
Ok(false)
}
}

#[instrument(level = Level::DEBUG, skip_all)]
async fn init(&mut self, timeout: Duration) -> Result<InitResponse, Error> {
let nonce: [u8; 8] = thread_rng().gen();
Expand Down
Loading