webauthn_authenticator_rs/ctap2/
solokey.rs

1use async_trait::async_trait;
2use uuid::Uuid;
3
4use crate::{
5    prelude::WebauthnCError, transport::solokey::SoloKeyToken, transport::Token, ui::UiCallback,
6};
7
8use super::Ctap20Authenticator;
9
10/// SoloKey (Trussed) vendor-specific commands.
11///
12/// ## Warning
13///
14/// These commands currently operate on *any* [`Ctap20Authenticator`][], and do
15/// not filter to just SoloKey/Trussed devices. Due to the nature of CTAP
16/// vendor-specific commands, this may cause unexpected or undesirable behaviour
17/// on other vendors' keys.
18///
19/// Protocol notes are in [`crate::transport::solokey`].
20#[async_trait]
21pub trait SoloKeyAuthenticator {
22    /// Gets a SoloKey's lock (secure boot) status.
23    async fn get_solokey_lock(&mut self) -> Result<bool, WebauthnCError>;
24
25    /// Gets some random bytes from a SoloKey.
26    async fn get_solokey_random(&mut self) -> Result<[u8; 57], WebauthnCError>;
27
28    /// Gets a SoloKey's UUID.
29    async fn get_solokey_uuid(&mut self) -> Result<Uuid, WebauthnCError>;
30
31    /// Gets a SoloKey's firmware version.
32    async fn get_solokey_version(&mut self) -> Result<u32, WebauthnCError>;
33}
34
35#[async_trait]
36impl<'a, T: Token + SoloKeyToken, U: UiCallback> SoloKeyAuthenticator
37    for Ctap20Authenticator<'a, T, U>
38{
39    #[inline]
40    async fn get_solokey_lock(&mut self) -> Result<bool, WebauthnCError> {
41        self.token.get_solokey_lock().await
42    }
43
44    #[inline]
45    async fn get_solokey_random(&mut self) -> Result<[u8; 57], WebauthnCError> {
46        self.token.get_solokey_random().await
47    }
48
49    #[inline]
50    async fn get_solokey_uuid(&mut self) -> Result<Uuid, WebauthnCError> {
51        self.token.get_solokey_uuid().await
52    }
53
54    #[inline]
55    async fn get_solokey_version(&mut self) -> Result<u32, WebauthnCError> {
56        self.token.get_solokey_version().await
57    }
58}