Skip to content

Commit 6dab92f

Browse files
Use provided timeout parameter for CBOR requests, instead of hardcoded 250ms
1 parent ed261ca commit 6dab92f

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

libwebauthn/examples/webauthn_cable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use libwebauthn::proto::ctap2::{
2525
use libwebauthn::transport::Device;
2626
use libwebauthn::webauthn::{Error as WebAuthnError, WebAuthn};
2727

28-
const TIMEOUT: Duration = Duration::from_secs(10);
28+
const TIMEOUT: Duration = Duration::from_secs(120);
2929

3030
fn setup_logging() {
3131
tracing_subscriber::fmt()

libwebauthn/src/proto/ctap2/protocol.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ where
101101
async fn ctap2_make_credential(
102102
&mut self,
103103
request: &Ctap2MakeCredentialRequest,
104-
_timeout: Duration,
104+
timeout: Duration,
105105
) -> Result<Ctap2MakeCredentialResponse, Error> {
106106
trace!(?request);
107-
self.cbor_send(&request.into(), TIMEOUT_GET_INFO).await?;
108-
let cbor_response = self.cbor_recv(TIMEOUT_GET_INFO).await?;
107+
self.cbor_send(&request.into(), timeout).await?;
108+
let cbor_response = self.cbor_recv(timeout).await?;
109109
match cbor_response.status_code {
110110
CtapError::Ok => (),
111111
error => return Err(Error::Ctap(error)),
@@ -121,11 +121,11 @@ where
121121
async fn ctap2_get_assertion(
122122
&mut self,
123123
request: &Ctap2GetAssertionRequest,
124-
_timeout: Duration,
124+
timeout: Duration,
125125
) -> Result<Ctap2GetAssertionResponse, Error> {
126126
trace!(?request);
127-
self.cbor_send(&request.into(), TIMEOUT_GET_INFO).await?;
128-
let cbor_response = self.cbor_recv(TIMEOUT_GET_INFO).await?;
127+
self.cbor_send(&request.into(), timeout).await?;
128+
let cbor_response = self.cbor_recv(timeout).await?;
129129
match cbor_response.status_code {
130130
CtapError::Ok => (),
131131
error => return Err(Error::Ctap(error)),
@@ -140,12 +140,12 @@ where
140140
#[instrument(skip_all)]
141141
async fn ctap2_get_next_assertion(
142142
&mut self,
143-
_timeout: Duration,
143+
timeout: Duration,
144144
) -> Result<Ctap2GetAssertionResponse, Error> {
145145
debug!("CTAP2 GetNextAssertion request");
146146
let cbor_request = CborRequest::new(Ctap2CommandCode::AuthenticatorGetNextAssertion);
147-
self.cbor_send(&cbor_request, TIMEOUT_GET_INFO).await?;
148-
let cbor_response = self.cbor_recv(TIMEOUT_GET_INFO).await?;
147+
self.cbor_send(&cbor_request, timeout).await?;
148+
let cbor_response = self.cbor_recv(timeout).await?;
149149
let data = unwrap_field!(cbor_response.data);
150150
let ctap_response = parse_cbor!(Ctap2GetAssertionResponse, &data);
151151
debug!("CTAP2 GetNextAssertion successful");
@@ -154,13 +154,13 @@ where
154154
}
155155

156156
#[instrument(skip_all)]
157-
async fn ctap2_selection(&mut self, _timeout: Duration) -> Result<(), Error> {
157+
async fn ctap2_selection(&mut self, timeout: Duration) -> Result<(), Error> {
158158
debug!("CTAP2 Authenticator Selection request");
159159
let cbor_request = CborRequest::new(Ctap2CommandCode::AuthenticatorSelection);
160160

161161
loop {
162-
self.cbor_send(&cbor_request, TIMEOUT_GET_INFO).await?;
163-
let cbor_response = self.cbor_recv(TIMEOUT_GET_INFO).await?;
162+
self.cbor_send(&cbor_request, timeout).await?;
163+
let cbor_response = self.cbor_recv(timeout).await?;
164164
match cbor_response.status_code {
165165
CtapError::Ok => {
166166
return Ok(());
@@ -177,11 +177,11 @@ where
177177
async fn ctap2_client_pin(
178178
&mut self,
179179
request: &Ctap2ClientPinRequest,
180-
_timeou: Duration,
180+
timeout: Duration,
181181
) -> Result<Ctap2ClientPinResponse, Error> {
182182
trace!(?request);
183-
self.cbor_send(&request.into(), TIMEOUT_GET_INFO).await?;
184-
let cbor_response = self.cbor_recv(TIMEOUT_GET_INFO).await?;
183+
self.cbor_send(&request.into(), timeout).await?;
184+
let cbor_response = self.cbor_recv(timeout).await?;
185185
match cbor_response.status_code {
186186
CtapError::Ok => (),
187187
error => return Err(Error::Ctap(error)),
@@ -203,11 +203,11 @@ where
203203
async fn ctap2_authenticator_config(
204204
&mut self,
205205
request: &Ctap2AuthenticatorConfigRequest,
206-
_timeout: Duration,
206+
timeout: Duration,
207207
) -> Result<(), Error> {
208208
trace!(?request);
209-
self.cbor_send(&request.into(), TIMEOUT_GET_INFO).await?;
210-
let cbor_response = self.cbor_recv(TIMEOUT_GET_INFO).await?;
209+
self.cbor_send(&request.into(), timeout).await?;
210+
let cbor_response = self.cbor_recv(timeout).await?;
211211
match cbor_response.status_code {
212212
CtapError::Ok => {
213213
return Ok(());
@@ -226,11 +226,11 @@ where
226226
async fn ctap2_bio_enrollment(
227227
&mut self,
228228
request: &Ctap2BioEnrollmentRequest,
229-
_timeout: Duration,
229+
timeout: Duration,
230230
) -> Result<Ctap2BioEnrollmentResponse, Error> {
231231
trace!(?request);
232-
self.cbor_send(&request.into(), TIMEOUT_GET_INFO).await?;
233-
let cbor_response = self.cbor_recv(TIMEOUT_GET_INFO).await?;
232+
self.cbor_send(&request.into(), timeout).await?;
233+
let cbor_response = self.cbor_recv(timeout).await?;
234234
match cbor_response.status_code {
235235
CtapError::Ok => (),
236236
error => return Err(Error::Ctap(error)),
@@ -252,11 +252,11 @@ where
252252
async fn ctap2_credential_management(
253253
&mut self,
254254
request: &Ctap2CredentialManagementRequest,
255-
_timeout: Duration,
255+
timeout: Duration,
256256
) -> Result<Ctap2CredentialManagementResponse, Error> {
257257
trace!(?request);
258-
self.cbor_send(&request.into(), TIMEOUT_GET_INFO).await?;
259-
let cbor_response = self.cbor_recv(TIMEOUT_GET_INFO).await?;
258+
self.cbor_send(&request.into(), timeout).await?;
259+
let cbor_response = self.cbor_recv(timeout).await?;
260260
match cbor_response.status_code {
261261
CtapError::Ok => (),
262262
error => return Err(Error::Ctap(error)),

libwebauthn/src/transport/cable/channel.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,21 @@ impl<'d> Channel for CableChannel<'d> {
8383
error!(%error, "CBOR request send failure");
8484
Err(Error::Transport(TransportError::TransportUnavailable))
8585
}
86-
Err(_) => Err(Error::Transport(TransportError::Timeout)),
86+
Err(elapsed) => {
87+
error!({ %elapsed, ?timeout }, "CBOR request send timeout");
88+
Err(Error::Transport(TransportError::Timeout))
89+
}
8790
}
8891
}
8992

9093
async fn cbor_recv(&mut self, timeout: Duration) -> Result<CborResponse, Error> {
9194
match time::timeout(timeout, self.cbor_receiver.recv()).await {
9295
Ok(Some(response)) => Ok(response),
9396
Ok(None) => Err(Error::Transport(TransportError::TransportUnavailable)),
94-
Err(_) => Err(Error::Transport(TransportError::Timeout)),
97+
Err(elapsed) => {
98+
error!({ %elapsed, ?timeout }, "CBOR response recv timeout");
99+
Err(Error::Transport(TransportError::Timeout))
100+
}
95101
}
96102
}
97103

0 commit comments

Comments
 (0)