1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use async_trait::async_trait;
use uuid::Uuid;

use crate::{
    prelude::WebauthnCError, transport::solokey::SoloKeyToken, transport::Token, ui::UiCallback,
};

use super::Ctap20Authenticator;

/// SoloKey (Trussed) vendor-specific commands.
///
/// ## Warning
///
/// These commands currently operate on *any* [`Ctap20Authenticator`][], and do
/// not filter to just SoloKey/Trussed 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 [`crate::transport::solokey`].
#[async_trait]
pub trait SoloKeyAuthenticator {
    /// Gets a SoloKey's lock (secure boot) status.
    async fn get_solokey_lock(&mut self) -> Result<bool, WebauthnCError>;

    /// Gets some random bytes from a SoloKey.
    async fn get_solokey_random(&mut self) -> Result<[u8; 57], WebauthnCError>;

    /// Gets a SoloKey's UUID.
    async fn get_solokey_uuid(&mut self) -> Result<Uuid, WebauthnCError>;

    /// Gets a SoloKey's firmware version.
    async fn get_solokey_version(&mut self) -> Result<u32, WebauthnCError>;
}

#[async_trait]
impl<'a, T: Token + SoloKeyToken, U: UiCallback> SoloKeyAuthenticator
    for Ctap20Authenticator<'a, T, U>
{
    #[inline]
    async fn get_solokey_lock(&mut self) -> Result<bool, WebauthnCError> {
        self.token.get_solokey_lock().await
    }

    #[inline]
    async fn get_solokey_random(&mut self) -> Result<[u8; 57], WebauthnCError> {
        self.token.get_solokey_random().await
    }

    #[inline]
    async fn get_solokey_uuid(&mut self) -> Result<Uuid, WebauthnCError> {
        self.token.get_solokey_uuid().await
    }

    #[inline]
    async fn get_solokey_version(&mut self) -> Result<u32, WebauthnCError> {
        self.token.get_solokey_version().await
    }
}