forked from kanidm/webauthn-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: implementing SoloKey vendor commands
- Loading branch information
Showing
12 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use async_trait::async_trait; | ||
use uuid::Uuid; | ||
|
||
use crate::{ | ||
prelude::WebauthnCError, transport::solokey::SoloKeyToken, transport::Token, ui::UiCallback, | ||
}; | ||
|
||
use super::Ctap20Authenticator; | ||
|
||
#[async_trait] | ||
pub trait SoloKeyAuthenticator { | ||
async fn get_uuid(&mut self) -> Result<Uuid, WebauthnCError>; | ||
} | ||
|
||
#[async_trait] | ||
impl<'a, T: Token + SoloKeyToken, U: UiCallback> SoloKeyAuthenticator | ||
for Ctap20Authenticator<'a, T, U> | ||
{ | ||
async fn get_uuid(&mut self) -> Result<Uuid, WebauthnCError> { | ||
self.token.get_solokey_uuid().await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use async_trait::async_trait; | ||
use uuid::Uuid; | ||
|
||
use crate::prelude::WebauthnCError; | ||
|
||
use super::AnyToken; | ||
|
||
#[cfg(all(feature = "usb", feature = "vendor-solokey"))] | ||
pub const CMD_UUID: u8 = super::TYPE_INIT | 0x62; | ||
|
||
#[async_trait] | ||
pub trait SoloKeyToken { | ||
async fn get_solokey_uuid(&mut self) -> Result<Uuid, WebauthnCError>; | ||
} | ||
|
||
#[async_trait] | ||
impl SoloKeyToken for AnyToken { | ||
async fn get_solokey_uuid(&mut self) -> Result<Uuid, WebauthnCError> { | ||
match self { | ||
AnyToken::Stub => unimplemented!(), | ||
#[cfg(feature = "bluetooth")] | ||
AnyToken::Bluetooth(_) => Err(WebauthnCError::NotSupported), | ||
#[cfg(feature = "nfc")] | ||
AnyToken::Nfc(_) => Err(WebauthnCError::NotSupported), | ||
#[cfg(feature = "usb")] | ||
AnyToken::Usb(u) => u.get_solokey_uuid().await, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use async_trait::async_trait; | ||
use uuid::Uuid; | ||
|
||
use crate::{ | ||
prelude::WebauthnCError, | ||
transport::{ | ||
solokey::{SoloKeyToken, CMD_UUID}, | ||
types::{U2FError, U2FHID_ERROR}, | ||
}, | ||
usb::framing::U2FHIDFrame, | ||
}; | ||
|
||
use super::{USBToken, USBTransport}; | ||
|
||
#[async_trait] | ||
impl SoloKeyToken for USBToken { | ||
async fn get_solokey_uuid(&mut self) -> Result<Uuid, WebauthnCError> { | ||
let cmd = U2FHIDFrame { | ||
cid: self.cid, | ||
cmd: CMD_UUID, | ||
len: 0, | ||
data: vec![], | ||
}; | ||
self.send_one(&cmd).await?; | ||
|
||
let r = self.recv_one().await?; | ||
match r.cmd { | ||
CMD_UUID => { | ||
if r.len != 16 || r.data.len() != 16 { | ||
return Err(WebauthnCError::InvalidMessageLength); | ||
} | ||
|
||
let u = Uuid::from_bytes( | ||
r.data | ||
.try_into() | ||
.map_err(|_| WebauthnCError::InvalidMessageLength)?, | ||
); | ||
|
||
Ok(u) | ||
} | ||
|
||
U2FHID_ERROR => Err(U2FError::from(r.data.as_slice()).into()), | ||
|
||
_ => Err(WebauthnCError::UnexpectedState), | ||
} | ||
} | ||
} |