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.
- Loading branch information
Showing
10 changed files
with
159 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
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,34 @@ | ||
use async_trait::async_trait; | ||
|
||
use crate::{ | ||
prelude::WebauthnCError, | ||
transport::{yubikey::YubiKeyToken, Token}, | ||
ui::UiCallback, | ||
}; | ||
|
||
use super::Ctap20Authenticator; | ||
|
||
/// YubiKey vendor-specific commands. | ||
/// | ||
/// ## Warning | ||
/// | ||
/// These commands currently operate on *any* [`Ctap20Authenticator`][], and do | ||
/// not filter to just YubiKey devices. Due to the nature of CTAP | ||
/// vendor-specific commands, this may cause unexpected or undesirable behaviour | ||
/// on other vendors' keys. | ||
/// | ||
/// Protocol notes are in TODO | ||
#[async_trait] | ||
pub trait YubiKeyAuthenticator { | ||
async fn get_yubikey_config(&mut self) -> Result<bool, WebauthnCError>; | ||
} | ||
|
||
#[async_trait] | ||
impl<'a, T: Token + YubiKeyToken, U: UiCallback> YubiKeyAuthenticator | ||
for Ctap20Authenticator<'a, T, U> | ||
{ | ||
#[inline] | ||
async fn get_yubikey_config(&mut self) -> Result<bool, WebauthnCError> { | ||
self.token.get_yubikey_config().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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! YubiKey vendor-specific commands. | ||
//! | ||
//! ## USB HID | ||
//! | ||
//! Commands are sent on a `U2FHIDFrame` level, and values are bitwise-OR'd | ||
//! with `transport::TYPE_INIT` (0x80). | ||
//! | ||
//! Command | Description | Request | Response | ||
//! ------- | ----------- | ------- | -------- | ||
//! | ||
//! ## NFC | ||
//! | ||
//! ## References | ||
//! | ||
use async_trait::async_trait; | ||
|
||
use crate::prelude::WebauthnCError; | ||
|
||
use super::AnyToken; | ||
|
||
#[cfg(all(feature = "usb", feature = "vendor-yubikey"))] | ||
pub(crate) const CMD_GET_CONFIG: u8 = super::TYPE_INIT | 0x42; | ||
|
||
/// See [`YubiKeyAuthenticator`](crate::ctap2::YubiKeyAuthenticator). | ||
#[async_trait] | ||
pub trait YubiKeyToken { | ||
/// See [`SoloKeyAuthenticator::get_solokey_lock()`](crate::ctap2::SoloKeyAuthenticator::get_solokey_lock). | ||
async fn get_yubikey_config(&mut self) -> Result<bool, WebauthnCError>; | ||
} | ||
|
||
#[async_trait] | ||
#[allow(clippy::unimplemented)] | ||
impl YubiKeyToken for AnyToken { | ||
async fn get_yubikey_config(&mut self) -> Result<bool, 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_yubikey_config().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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use async_trait::async_trait; | ||
use uuid::Uuid; | ||
|
||
#[cfg(all(feature = "usb", feature = "vendor-yubikey"))] | ||
use crate::transport::yubikey::CMD_GET_CONFIG; | ||
|
||
use crate::{ | ||
prelude::WebauthnCError, | ||
transport::{ | ||
types::{U2FError, U2FHID_ERROR}, | ||
yubikey::YubiKeyToken, | ||
}, | ||
usb::{framing::U2FHIDFrame, USBToken}, | ||
}; | ||
|
||
#[async_trait] | ||
impl YubiKeyToken for USBToken { | ||
async fn get_yubikey_config(&mut self) -> Result<bool, WebauthnCError> { | ||
let cmd = U2FHIDFrame { | ||
cid: self.cid, | ||
cmd: CMD_GET_CONFIG, | ||
len: 0, | ||
data: vec![], | ||
}; | ||
self.send_one(&cmd).await?; | ||
|
||
let r = self.recv_one().await?; | ||
debug!("config: {}", hex::encode(r.data)); | ||
todo!() | ||
// match r.cmd { | ||
// CMD_LOCK => { | ||
// if r.len != 1 || r.data.len() != 1 { | ||
// return Err(WebauthnCError::InvalidMessageLength); | ||
// } | ||
|
||
// Ok(r.data[0] != 0) | ||
// } | ||
|
||
// U2FHID_ERROR => Err(U2FError::from(r.data.as_slice()).into()), | ||
|
||
// _ => Err(WebauthnCError::UnexpectedState), | ||
// } | ||
} | ||
} |