Skip to content

Commit 9ac2bb0

Browse files
Set fido.cable subprotocol on WebSocket connection
1 parent db56a46 commit 9ac2bb0

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

libwebauthn/src/transport/cable/tunnel.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use tokio_tungstenite::tungstenite::http::StatusCode;
1313
use tokio_tungstenite::tungstenite::Message;
1414
use tokio_tungstenite::{connect_async, MaybeTlsStream, WebSocketStream};
1515
use tracing::{debug, error, trace, warn};
16+
use tungstenite::client::IntoClientRequest;
1617

1718
use super::channel::{CableChannel, CableChannelDevice};
1819
use super::qr_code_device::CableQrCodeDevice;
@@ -140,9 +141,13 @@ pub async fn connect<'d>(
140141
tunnel_domain, routing_id, tunnel_id
141142
);
142143
debug!(?connect_url, "Connecting to tunnel server");
143-
// TODO: set protocol: fido.cable
144+
let mut request = connect_url.into_client_request().or(Err(Error::Transport(TransportError::InvalidEndpoint)))?;
145+
request.headers_mut().insert(
146+
"Sec-WebSocket-Protocol",
147+
"fido.cable".parse().or(Err(Error::Transport(TransportError::InvalidEndpoint)))?,
148+
);
144149

145-
let (mut ws_stream, response) = match connect_async(&connect_url).await {
150+
let (mut ws_stream, response) = match connect_async(request).await {
146151
Ok((ws_stream, response)) => (ws_stream, response),
147152
Err(e) => {
148153
error!(?e, "Failed to connect to tunnel server");

0 commit comments

Comments
 (0)