From eda9b76c36aef006facbfcf8c6da05b3cae72809 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 19 Feb 2024 20:48:46 +0100 Subject: [PATCH] Support invalid CTAPHID commands Previously, we just ignored invalid CTAPHID commands. With this patch, we return a CTAPHID_INVALID_COMMAND error. --- src/pipe.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pipe.rs b/src/pipe.rs index f81dfa1..998e609 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -70,8 +70,12 @@ impl Response { } pub fn error_from_request(request: Request) -> Self { + Self::error_on_channel(request.channel) + } + + pub fn error_on_channel(channel: u32) -> Self { Self { - channel: request.channel, + channel, command: ctaphid_dispatch::command::Command::Error, length: 1, } @@ -292,7 +296,8 @@ impl<'alloc, 'pipe, 'interrupt, Bus: UsbBus> Pipe<'alloc, 'pipe, 'interrupt, Bus Ok(command) => command, // `solo ls` crashes here as it uses command 0x86 Err(_) => { - info!("Ignoring invalid command."); + info!("Received invalid command."); + self.start_sending_error_on_channel(channel, AuthenticatorError::InvalidCommand); return; } }; @@ -616,8 +621,12 @@ impl<'alloc, 'pipe, 'interrupt, Bus: UsbBus> Pipe<'alloc, 'pipe, 'interrupt, Bus } fn start_sending_error(&mut self, request: Request, error: AuthenticatorError) { + self.start_sending_error_on_channel(request.channel, error); + } + + fn start_sending_error_on_channel(&mut self, channel: u32, error: AuthenticatorError) { self.buffer[0] = error as u8; - let response = Response::error_from_request(request); + let response = Response::error_on_channel(channel); self.start_sending(response); }