| 1 |
use super::{Command, CommandError, CtapResponse, RequestCtap2, StatusCode}; |
| 2 |
use crate::ctap2::attestation::AAGuid; |
| 3 |
use crate::ctap2::server::PublicKeyCredentialParameters; |
| 4 |
use crate::transport::errors::HIDError; |
| 5 |
use crate::transport::{FidoDevice, VirtualFidoDevice}; |
| 6 |
use serde::{ |
| 7 |
de::{Error as SError, IgnoredAny, MapAccess, Visitor}, |
| 8 |
Deserialize, Deserializer, Serialize, |
| 9 |
}; |
| 10 |
use serde_cbor::{de::from_slice, Value}; |
| 11 |
use std::collections::BTreeMap; |
| 12 |
use std::fmt; |
| 13 |
|
| 14 |
#[derive(Debug, Default)] |
| 15 |
pub struct GetInfo {} |
| 16 |
|
| 17 |
impl RequestCtap2 for GetInfo { |
| 18 |
type Output = AuthenticatorInfo; |
| 19 |
|
| 20 |
fn command(&self) -> Command { |
| 21 |
Command::GetInfo |
| 22 |
} |
| 23 |
|
| 24 |
fn wire_format(&self) -> Result<Vec<u8>, HIDError> { |
| 25 |
Ok(Vec::new()) |
| 26 |
} |
| 27 |
|
| 28 |
fn handle_response_ctap2<Dev: FidoDevice>( |
| 29 |
&self, |
| 30 |
_dev: &mut Dev, |
| 31 |
input: &[u8], |
| 32 |
) -> Result<Self::Output, HIDError> { |
| 33 |
if input.is_empty() { |
| 34 |
return Err(CommandError::InputTooSmall.into()); |
| 35 |
} |
| 36 |
|
| 37 |
let status: StatusCode = input[0].into(); |
| 38 |
|
| 39 |
if input.len() > 1 { |
| 40 |
if status.is_ok() { |
| 41 |
trace!("parsing authenticator info data: {:#04X?}", &input); |
| 42 |
let authenticator_info = |
| 43 |
from_slice(&input[1..]).map_err(CommandError::Deserializing)?; |
| 44 |
Ok(authenticator_info) |
| 45 |
} else { |
| 46 |
let data: Value = from_slice(&input[1..]).map_err(CommandError::Deserializing)?; |
| 47 |
Err(CommandError::StatusCode(status, Some(data)).into()) |
| 48 |
} |
| 49 |
} else { |
| 50 |
Err(CommandError::InputTooSmall.into()) |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
fn send_to_virtual_device<Dev: VirtualFidoDevice>( |
| 55 |
&self, |
| 56 |
dev: &mut Dev, |
| 57 |
) -> Result<Self::Output, HIDError> { |
| 58 |
dev.get_info() |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
fn true_val() -> bool { |
| 63 |
true |
| 64 |
} |
| 65 |
|
| 66 |
#[derive(Debug, Deserialize, Clone, Eq, PartialEq, Serialize)] |
| 67 |
pub struct AuthenticatorOptions { |
| 68 |
/// Indicates that the device is attached to the client and therefore can’t |
| 69 |
/// be removed and used on another client. |
| 70 |
#[serde(rename = "plat", default)] |
| 71 |
pub platform_device: bool, |
| 72 |
/// Indicates that the device is capable of storing keys on the device |
| 73 |
/// itself and therefore can satisfy the authenticatorGetAssertion request |
| 74 |
/// with allowList parameter not specified or empty. |
| 75 |
#[serde(rename = "rk", default)] |
| 76 |
pub resident_key: bool, |
| 77 |
|
| 78 |
/// Client PIN: |
| 79 |
/// If present and set to true, it indicates that the device is capable of |
| 80 |
/// accepting a PIN from the client and PIN has been set. |
| 81 |
/// If present and set to false, it indicates that the device is capable of |
| 82 |
/// accepting a PIN from the client and PIN has not been set yet. |
| 83 |
/// If absent, it indicates that the device is not capable of accepting a |
| 84 |
/// PIN from the client. |
| 85 |
/// Client PIN is one of the ways to do user verification. |
| 86 |
#[serde(rename = "clientPin")] |
| 87 |
pub client_pin: Option<bool>, |
| 88 |
|
| 89 |
/// Indicates that the device is capable of testing user presence. |
| 90 |
#[serde(rename = "up", default = "true_val")] |
| 91 |
pub user_presence: bool, |
| 92 |
|
| 93 |
/// Indicates that the device is capable of verifying the user within |
| 94 |
/// itself. For example, devices with UI, biometrics fall into this |
| 95 |
/// category. |
| 96 |
/// If present and set to true, it indicates that the device is capable of |
| 97 |
/// user verification within itself and has been configured. |
| 98 |
/// If present and set to false, it indicates that the device is capable of |
| 99 |
/// user verification within itself and has not been yet configured. For |
| 100 |
/// example, a biometric device that has not yet been configured will |
| 101 |
/// return this parameter set to false. |
| 102 |
/// If absent, it indicates that the device is not capable of user |
| 103 |
/// verification within itself. |
| 104 |
/// A device that can only do Client PIN will not return the "uv" parameter. |
| 105 |
/// If a device is capable of verifying the user within itself as well as |
| 106 |
/// able to do Client PIN, it will return both "uv" and the Client PIN |
| 107 |
/// option. |
| 108 |
// TODO(MS): My Token (key-ID FIDO2) does return Some(false) here, even though |
| 109 |
// it has no built-in verification method. Not to be trusted... |
| 110 |
#[serde(rename = "uv")] |
| 111 |
pub user_verification: Option<bool>, |
| 112 |
|
| 113 |
// ---------------------------------------------------- |
| 114 |
// CTAP 2.1 options |
| 115 |
// ---------------------------------------------------- |
| 116 |
/// If pinUvAuthToken is: |
| 117 |
/// present and set to true |
| 118 |
/// if the clientPin option id is present and set to true, then the |
| 119 |
/// authenticator supports authenticatorClientPIN's getPinUvAuthTokenUsingPinWithPermissions |
| 120 |
/// subcommand. If the uv option id is present and set to true, then |
| 121 |
/// the authenticator supports authenticatorClientPIN's getPinUvAuthTokenUsingUvWithPermissions |
| 122 |
/// subcommand. |
| 123 |
/// present and set to false, or absent. |
| 124 |
/// the authenticator does not support authenticatorClientPIN's |
| 125 |
/// getPinUvAuthTokenUsingPinWithPermissions and getPinUvAuthTokenUsingUvWithPermissions |
| 126 |
/// subcommands. |
| 127 |
#[serde(rename = "pinUvAuthToken")] |
| 128 |
pub pin_uv_auth_token: Option<bool>, |
| 129 |
|
| 130 |
/// If this noMcGaPermissionsWithClientPin is: |
| 131 |
/// present and set to true |
| 132 |
/// A pinUvAuthToken obtained via getPinUvAuthTokenUsingPinWithPermissions |
| 133 |
/// (or getPinToken) cannot be used for authenticatorMakeCredential or |
| 134 |
/// authenticatorGetAssertion commands, because it will lack the necessary |
| 135 |
/// mc and ga permissions. In this situation, platforms SHOULD NOT attempt |
| 136 |
/// to use getPinUvAuthTokenUsingPinWithPermissions if using |
| 137 |
/// getPinUvAuthTokenUsingUvWithPermissions fails. |
| 138 |
/// present and set to false, or absent. |
| 139 |
/// A pinUvAuthToken obtained via getPinUvAuthTokenUsingPinWithPermissions |
| 140 |
/// (or getPinToken) can be used for authenticatorMakeCredential or |
| 141 |
/// authenticatorGetAssertion commands. |
| 142 |
/// Note: noMcGaPermissionsWithClientPin MUST only be present if the |
| 143 |
/// clientPin option ID is present. |
| 144 |
#[serde(rename = "noMcGaPermissionsWithClientPin")] |
| 145 |
pub no_mc_ga_permissions_with_client_pin: Option<bool>, |
| 146 |
|
| 147 |
/// If largeBlobs is: |
| 148 |
/// present and set to true |
| 149 |
/// the authenticator supports the authenticatorLargeBlobs command. |
| 150 |
/// present and set to false, or absent. |
| 151 |
/// The authenticatorLargeBlobs command is NOT supported. |
| 152 |
#[serde(rename = "largeBlobs")] |
| 153 |
pub large_blobs: Option<bool>, |
| 154 |
|
| 155 |
/// Enterprise Attestation feature support: |
| 156 |
/// If ep is: |
| 157 |
/// Present and set to true |
| 158 |
/// The authenticator is enterprise attestation capable, and enterprise |
| 159 |
/// attestation is enabled. |
| 160 |
/// Present and set to false |
| 161 |
/// The authenticator is enterprise attestation capable, and enterprise |
| 162 |
/// attestation is disabled. |
| 163 |
/// Absent |
| 164 |
/// The Enterprise Attestation feature is NOT supported. |
| 165 |
#[serde(rename = "ep")] |
| 166 |
pub ep: Option<bool>, |
| 167 |
|
| 168 |
/// If bioEnroll is: |
| 169 |
/// present and set to true |
| 170 |
/// the authenticator supports the authenticatorBioEnrollment commands, |
| 171 |
/// and has at least one bio enrollment presently provisioned. |
| 172 |
/// present and set to false |
| 173 |
/// the authenticator supports the authenticatorBioEnrollment commands, |
| 174 |
/// and does not yet have any bio enrollments provisioned. |
| 175 |
/// absent |
| 176 |
/// the authenticatorBioEnrollment commands are NOT supported. |
| 177 |
#[serde(rename = "bioEnroll")] |
| 178 |
pub bio_enroll: Option<bool>, |
| 179 |
|
| 180 |
/// "FIDO_2_1_PRE" Prototype Credential management support: |
| 181 |
/// If userVerificationMgmtPreview is: |
| 182 |
/// present and set to true |
| 183 |
/// the authenticator supports the Prototype authenticatorBioEnrollment (0x41) |
| 184 |
/// commands, and has at least one bio enrollment presently provisioned. |
| 185 |
/// present and set to false |
| 186 |
/// the authenticator supports the Prototype authenticatorBioEnrollment (0x41) |
| 187 |
/// commands, and does not yet have any bio enrollments provisioned. |
| 188 |
/// absent |
| 189 |
/// the Prototype authenticatorBioEnrollment (0x41) commands are not supported. |
| 190 |
#[serde(rename = "userVerificationMgmtPreview")] |
| 191 |
pub user_verification_mgmt_preview: Option<bool>, |
| 192 |
|
| 193 |
/// getPinUvAuthTokenUsingUvWithPermissions support for requesting the be permission: |
| 194 |
/// This option ID MUST only be present if bioEnroll is also present. |
| 195 |
/// If uvBioEnroll is: |
| 196 |
/// present and set to true |
| 197 |
/// requesting the be permission when invoking getPinUvAuthTokenUsingUvWithPermissions |
| 198 |
/// is supported. |
| 199 |
/// present and set to false, or absent. |
| 200 |
/// requesting the be permission when invoking getPinUvAuthTokenUsingUvWithPermissions |
| 201 |
/// is NOT supported. |
| 202 |
#[serde(rename = "uvBioEnroll")] |
| 203 |
pub uv_bio_enroll: Option<bool>, |
| 204 |
|
| 205 |
/// authenticatorConfig command support: |
| 206 |
/// If authnrCfg is: |
| 207 |
/// present and set to true |
| 208 |
/// the authenticatorConfig command is supported. |
| 209 |
/// present and set to false, or absent. |
| 210 |
/// the authenticatorConfig command is NOT supported. |
| 211 |
#[serde(rename = "authnrCfg")] |
| 212 |
pub authnr_cfg: Option<bool>, |
| 213 |
|
| 214 |
/// getPinUvAuthTokenUsingUvWithPermissions support for requesting the acfg permission: |
| 215 |
/// This option ID MUST only be present if authnrCfg is also present. |
| 216 |
/// If uvAcfg is: |
| 217 |
/// present and set to true |
| 218 |
/// requesting the acfg permission when invoking getPinUvAuthTokenUsingUvWithPermissions |
| 219 |
/// is supported. |
| 220 |
/// present and set to false, or absent. |
| 221 |
/// requesting the acfg permission when invoking getPinUvAuthTokenUsingUvWithPermissions |
| 222 |
/// is NOT supported. |
| 223 |
#[serde(rename = "uvAcfg")] |
| 224 |
pub uv_acfg: Option<bool>, |
| 225 |
|
| 226 |
/// Credential management support: |
| 227 |
/// If credMgmt is: |
| 228 |
/// present and set to true |
| 229 |
/// the authenticatorCredentialManagement command is supported. |
| 230 |
/// present and set to false, or absent. |
| 231 |
/// the authenticatorCredentialManagement command is NOT supported. |
| 232 |
#[serde(rename = "credMgmt")] |
| 233 |
pub cred_mgmt: Option<bool>, |
| 234 |
|
| 235 |
/// "FIDO_2_1_PRE" Prototype Credential management support: |
| 236 |
/// If credentialMgmtPreview is: |
| 237 |
/// present and set to true |
| 238 |
/// the Prototype authenticatorCredentialManagement (0x41) command is supported. |
| 239 |
/// present and set to false, or absent. |
| 240 |
/// the Prototype authenticatorCredentialManagement (0x41) command is NOT supported. |
| 241 |
#[serde(rename = "credentialMgmtPreview")] |
| 242 |
pub credential_mgmt_preview: Option<bool>, |
| 243 |
|
| 244 |
/// Support for the Set Minimum PIN Length feature. |
| 245 |
/// If setMinPINLength is: |
| 246 |
/// present and set to true |
| 247 |
/// the setMinPINLength subcommand is supported. |
| 248 |
/// present and set to false, or absent. |
| 249 |
/// the setMinPINLength subcommand is NOT supported. |
| 250 |
/// Note: setMinPINLength MUST only be present if the clientPin option ID is present. |
| 251 |
#[serde(rename = "setMinPINLength")] |
| 252 |
pub set_min_pin_length: Option<bool>, |
| 253 |
|
| 254 |
/// Support for making non-discoverable credentials without requiring User Verification. |
| 255 |
/// If makeCredUvNotRqd is: |
| 256 |
/// present and set to true |
| 257 |
/// the authenticator allows creation of non-discoverable credentials without |
| 258 |
/// requiring any form of user verification, if the platform requests this behaviour. |
| 259 |
/// present and set to false, or absent. |
| 260 |
/// the authenticator requires some form of user verification for creating |
| 261 |
/// non-discoverable credentials, regardless of the parameters the platform supplies |
| 262 |
/// for the authenticatorMakeCredential command. |
| 263 |
/// Authenticators SHOULD include this option with the value true. |
| 264 |
#[serde(rename = "makeCredUvNotRqd")] |
| 265 |
pub make_cred_uv_not_rqd: Option<bool>, |
| 266 |
|
| 267 |
/// Support for the Always Require User Verification feature: |
| 268 |
/// If alwaysUv is |
| 269 |
/// present and set to true |
| 270 |
/// the authenticator supports the Always Require User Verification feature and it is enabled. |
| 271 |
/// present and set to false |
| 272 |
/// the authenticator supports the Always Require User Verification feature but it is disabled. |
| 273 |
/// absent |
| 274 |
/// the authenticator does not support the Always Require User Verification feature. |
| 275 |
/// Note: If the alwaysUv option ID is present and true the authenticator MUST set the value |
| 276 |
/// of makeCredUvNotRqd to false. |
| 277 |
#[serde(rename = "alwaysUv")] |
| 278 |
pub always_uv: Option<bool>, |
| 279 |
} |
| 280 |
|
| 281 |
impl Default for AuthenticatorOptions { |
| 282 |
fn default() -> Self { |
| 283 |
AuthenticatorOptions { |
| 284 |
platform_device: false, |
| 285 |
resident_key: false, |
| 286 |
client_pin: None, |
| 287 |
user_presence: true, |
| 288 |
user_verification: None, |
| 289 |
pin_uv_auth_token: None, |
| 290 |
no_mc_ga_permissions_with_client_pin: None, |
| 291 |
large_blobs: None, |
| 292 |
ep: None, |
| 293 |
bio_enroll: None, |
| 294 |
user_verification_mgmt_preview: None, |
| 295 |
uv_bio_enroll: None, |
| 296 |
authnr_cfg: None, |
| 297 |
uv_acfg: None, |
| 298 |
cred_mgmt: None, |
| 299 |
credential_mgmt_preview: None, |
| 300 |
set_min_pin_length: None, |
| 301 |
make_cred_uv_not_rqd: None, |
| 302 |
always_uv: None, |
| 303 |
} |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
#[allow(non_camel_case_types)] |
| 308 |
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] |
| 309 |
pub enum AuthenticatorVersion { |
| 310 |
U2F_V2, |
| 311 |
FIDO_2_0, |
| 312 |
FIDO_2_1_PRE, |
| 313 |
FIDO_2_1, |
| 314 |
} |
| 315 |
|
| 316 |
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)] |
| 317 |
pub struct AuthenticatorInfo { |
| 318 |
pub versions: Vec<AuthenticatorVersion>, |
| 319 |
pub extensions: Vec<String>, |
| 320 |
pub aaguid: AAGuid, |
| 321 |
pub options: AuthenticatorOptions, |
| 322 |
pub max_msg_size: Option<usize>, |
| 323 |
pub pin_protocols: Option<Vec<u64>>, |
| 324 |
// CTAP 2.1 |
| 325 |
pub max_credential_count_in_list: Option<usize>, |
| 326 |
pub max_credential_id_length: Option<usize>, |
| 327 |
pub transports: Option<Vec<String>>, |
| 328 |
pub algorithms: Option<Vec<PublicKeyCredentialParameters>>, |
| 329 |
pub max_ser_large_blob_array: Option<u64>, |
| 330 |
pub force_pin_change: Option<bool>, |
| 331 |
pub min_pin_length: Option<u64>, |
| 332 |
pub firmware_version: Option<u64>, |
| 333 |
pub max_cred_blob_length: Option<u64>, |
| 334 |
pub max_rpids_for_set_min_pin_length: Option<u64>, |
| 335 |
pub preferred_platform_uv_attempts: Option<u64>, |
| 336 |
pub uv_modality: Option<u64>, |
| 337 |
pub certifications: Option<BTreeMap<String, u64>>, |
| 338 |
pub remaining_discoverable_credentials: Option<u64>, |
| 339 |
pub vendor_prototype_config_commands: Option<Vec<u64>>, |
| 340 |
} |
| 341 |
|
| 342 |
impl AuthenticatorInfo { |
| 343 |
pub fn supports_cred_protect(&self) -> bool { |
| 344 |
self.extensions.contains(&"credProtect".to_string()) |
| 345 |
} |
| 346 |
|
| 347 |
pub fn supports_hmac_secret(&self) -> bool { |
| 348 |
self.extensions.contains(&"hmac-secret".to_string()) |
| 349 |
} |
| 350 |
|
| 351 |
pub fn max_supported_version(&self) -> AuthenticatorVersion { |
| 352 |
let versions = vec![ |
| 353 |
AuthenticatorVersion::FIDO_2_1, |
| 354 |
AuthenticatorVersion::FIDO_2_1_PRE, |
| 355 |
AuthenticatorVersion::FIDO_2_0, |
| 356 |
AuthenticatorVersion::U2F_V2, |
| 357 |
]; |
| 358 |
for ver in versions { |
| 359 |
if self.versions.contains(&ver) { |
| 360 |
return ver; |
| 361 |
} |
| 362 |
} |
| 363 |
AuthenticatorVersion::U2F_V2 |
| 364 |
} |
| 365 |
|
| 366 |
pub fn device_is_protected(&self) -> bool { |
| 367 |
self.options.client_pin == Some(true) || self.options.user_verification == Some(true) |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
impl CtapResponse for AuthenticatorInfo {} |
| 372 |
|
| 373 |
macro_rules! parse_next_optional_value { |
| 374 |
($name:expr, $map:expr) => { |
| 375 |
if $name.is_some() { |
| 376 |
return Err(serde::de::Error::duplicate_field("$name")); |
| 377 |
} |
| 378 |
$name = Some($map.next_value()?); |
| 379 |
}; |
| 380 |
} |
| 381 |
|
| 382 |
impl<'de> Deserialize<'de> for AuthenticatorInfo { |
| 383 |
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 384 |
where |
| 385 |
D: Deserializer<'de>, |
| 386 |
{ |
| 387 |
struct AuthenticatorInfoVisitor; |
| 388 |
|
| 389 |
impl<'de> Visitor<'de> for AuthenticatorInfoVisitor { |
| 390 |
type Value = AuthenticatorInfo; |
| 391 |
|
| 392 |
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
| 393 |
formatter.write_str("a byte array") |
| 394 |
} |
| 395 |
|
| 396 |
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error> |
| 397 |
where |
| 398 |
M: MapAccess<'de>, |
| 399 |
{ |
| 400 |
let mut versions = Vec::new(); |
| 401 |
let mut extensions = Vec::new(); |
| 402 |
let mut aaguid = None; |
| 403 |
let mut options = AuthenticatorOptions::default(); |
| 404 |
let mut max_msg_size = None; |
| 405 |
let mut pin_protocols: Option<Vec<_>> = None; |
| 406 |
let mut max_credential_count_in_list = None; |
| 407 |
let mut max_credential_id_length = None; |
| 408 |
let mut transports = None; |
| 409 |
let mut algorithms = None; |
| 410 |
let mut max_ser_large_blob_array = None; |
| 411 |
let mut force_pin_change = None; |
| 412 |
let mut min_pin_length = None; |
| 413 |
let mut firmware_version = None; |
| 414 |
let mut max_cred_blob_length = None; |
| 415 |
let mut max_rpids_for_set_min_pin_length = None; |
| 416 |
let mut preferred_platform_uv_attempts = None; |
| 417 |
let mut uv_modality = None; |
| 418 |
let mut certifications = None; |
| 419 |
let mut remaining_discoverable_credentials = None; |
| 420 |
let mut vendor_prototype_config_commands = None; |
| 421 |
while let Some(key) = map.next_key()? { |
| 422 |
match key { |
| 423 |
0x01 => { |
| 424 |
if !versions.is_empty() { |
| 425 |
return Err(serde::de::Error::duplicate_field("versions")); |
| 426 |
} |
| 427 |
versions = map.next_value()?; |
| 428 |
} |
| 429 |
0x02 => { |
| 430 |
if !extensions.is_empty() { |
| 431 |
return Err(serde::de::Error::duplicate_field("extensions")); |
| 432 |
} |
| 433 |
extensions = map.next_value()?; |
| 434 |
} |
| 435 |
0x03 => { |
| 436 |
parse_next_optional_value!(aaguid, map); |
| 437 |
} |
| 438 |
0x04 => { |
| 439 |
options = map.next_value()?; |
| 440 |
} |
| 441 |
0x05 => { |
| 442 |
parse_next_optional_value!(max_msg_size, map); |
| 443 |
} |
| 444 |
0x06 => { |
| 445 |
parse_next_optional_value!(pin_protocols, map); |
| 446 |
} |
| 447 |
0x07 => { |
| 448 |
parse_next_optional_value!(max_credential_count_in_list, map); |
| 449 |
} |
| 450 |
0x08 => { |
| 451 |
parse_next_optional_value!(max_credential_id_length, map); |
| 452 |
} |
| 453 |
0x09 => { |
| 454 |
parse_next_optional_value!(transports, map); |
| 455 |
} |
| 456 |
0x0a => { |
| 457 |
parse_next_optional_value!(algorithms, map); |
| 458 |
} |
| 459 |
0x0b => { |
| 460 |
parse_next_optional_value!(max_ser_large_blob_array, map); |
| 461 |
} |
| 462 |
0x0c => { |
| 463 |
parse_next_optional_value!(force_pin_change, map); |
| 464 |
} |
| 465 |
0x0d => { |
| 466 |
parse_next_optional_value!(min_pin_length, map); |
| 467 |
} |
| 468 |
0x0e => { |
| 469 |
parse_next_optional_value!(firmware_version, map); |
| 470 |
} |
| 471 |
0x0f => { |
| 472 |
parse_next_optional_value!(max_cred_blob_length, map); |
| 473 |
} |
| 474 |
0x10 => { |
| 475 |
parse_next_optional_value!(max_rpids_for_set_min_pin_length, map); |
| 476 |
} |
| 477 |
0x11 => { |
| 478 |
parse_next_optional_value!(preferred_platform_uv_attempts, map); |
| 479 |
} |
| 480 |
0x12 => { |
| 481 |
parse_next_optional_value!(uv_modality, map); |
| 482 |
} |
| 483 |
0x13 => { |
| 484 |
parse_next_optional_value!(certifications, map); |
| 485 |
} |
| 486 |
0x14 => { |
| 487 |
parse_next_optional_value!(remaining_discoverable_credentials, map); |
| 488 |
} |
| 489 |
0x15 => { |
| 490 |
parse_next_optional_value!(vendor_prototype_config_commands, map); |
| 491 |
} |
| 492 |
k => { |
| 493 |
warn!("GetInfo: unexpected key: {:?}", k); |
| 494 |
let _ = map.next_value::<IgnoredAny>()?; |
| 495 |
continue; |
| 496 |
} |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
if versions.is_empty() { |
| 501 |
return Err(M::Error::custom( |
| 502 |
"expected at least one version, got none".to_string(), |
| 503 |
)); |
| 504 |
} |
| 505 |
|
| 506 |
if let Some(protocols) = &pin_protocols { |
| 507 |
if protocols.is_empty() { |
| 508 |
return Err(M::Error::custom( |
| 509 |
"Token returned empty PIN protocol list, which is not allowed" |
| 510 |
.to_string(), |
| 511 |
)); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
if let Some(aaguid) = aaguid { |
| 516 |
Ok(AuthenticatorInfo { |
| 517 |
versions, |
| 518 |
extensions, |
| 519 |
aaguid, |
| 520 |
options, |
| 521 |
max_msg_size, |
| 522 |
pin_protocols, |
| 523 |
max_credential_count_in_list, |
| 524 |
max_credential_id_length, |
| 525 |
transports, |
| 526 |
algorithms, |
| 527 |
max_ser_large_blob_array, |
| 528 |
force_pin_change, |
| 529 |
min_pin_length, |
| 530 |
firmware_version, |
| 531 |
max_cred_blob_length, |
| 532 |
max_rpids_for_set_min_pin_length, |
| 533 |
preferred_platform_uv_attempts, |
| 534 |
uv_modality, |
| 535 |
certifications, |
| 536 |
remaining_discoverable_credentials, |
| 537 |
vendor_prototype_config_commands, |
| 538 |
}) |
| 539 |
} else { |
| 540 |
Err(M::Error::custom("No AAGuid specified".to_string())) |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
deserializer.deserialize_bytes(AuthenticatorInfoVisitor) |
| 546 |
} |
| 547 |
} |
| 548 |
|
| 549 |
#[cfg(test)] |
| 550 |
pub mod tests { |
| 551 |
use super::*; |
| 552 |
use crate::consts::{Capability, HIDCmd, CID_BROADCAST}; |
| 553 |
use crate::crypto::COSEAlgorithm; |
| 554 |
use crate::transport::device_selector::Device; |
| 555 |
use crate::transport::platform::device::IN_HID_RPT_SIZE; |
| 556 |
use crate::transport::{hid::HIDDevice, FidoDevice, FidoProtocol}; |
| 557 |
use rand::{thread_rng, RngCore}; |
| 558 |
use serde_cbor::de::from_slice; |
| 559 |
|
| 560 |
// Raw data take from https://github.com/Yubico/python-fido2/blob/master/test/test_ctap2.py |
| 561 |
pub const AAGUID_RAW: [u8; 16] = [ |
| 562 |
0xF8, 0xA0, 0x11, 0xF3, 0x8C, 0x0A, 0x4D, 0x15, 0x80, 0x06, 0x17, 0x11, 0x1F, 0x9E, 0xDC, |
| 563 |
0x7D, |
| 564 |
]; |
| 565 |
|
| 566 |
pub const AUTHENTICATOR_INFO_PAYLOAD: [u8; 89] = [ |
| 567 |
0xa6, // map(6) |
| 568 |
0x01, // unsigned(1) |
| 569 |
0x82, // array(2) |
| 570 |
0x66, // text(6) |
| 571 |
0x55, 0x32, 0x46, 0x5f, 0x56, 0x32, // "U2F_V2" |
| 572 |
0x68, // text(8) |
| 573 |
0x46, 0x49, 0x44, 0x4f, 0x5f, 0x32, 0x5f, 0x30, // "FIDO_2_0" |
| 574 |
0x02, // unsigned(2) |
| 575 |
0x82, // array(2) |
| 576 |
0x63, // text(3) |
| 577 |
0x75, 0x76, 0x6d, // "uvm" |
| 578 |
0x6b, // text(11) |
| 579 |
0x68, 0x6d, 0x61, 0x63, 0x2d, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, // "hmac-secret" |
| 580 |
0x03, // unsigned(3) |
| 581 |
0x50, // bytes(16) |
| 582 |
0xf8, 0xa0, 0x11, 0xf3, 0x8c, 0x0a, 0x4d, 0x15, 0x80, 0x06, 0x17, 0x11, 0x1f, 0x9e, 0xdc, |
| 583 |
0x7d, // "\xF8\xA0\u0011\xF3\x8C\nM\u0015\x80\u0006\u0017\u0011\u001F\x9E\xDC}" |
| 584 |
0x04, // unsigned(4) |
| 585 |
0xa4, // map(4) |
| 586 |
0x62, // text(2) |
| 587 |
0x72, 0x6b, // "rk" |
| 588 |
0xf5, // primitive(21) |
| 589 |
0x62, // text(2) |
| 590 |
0x75, 0x70, // "up" |
| 591 |
0xf5, // primitive(21) |
| 592 |
0x64, // text(4) |
| 593 |
0x70, 0x6c, 0x61, 0x74, // "plat" |
| 594 |
0xf4, // primitive(20) |
| 595 |
0x69, // text(9) |
| 596 |
0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x50, 0x69, 0x6e, // "clientPin" |
| 597 |
0xf4, // primitive(20) |
| 598 |
0x05, // unsigned(5) |
| 599 |
0x19, 0x04, 0xb0, // unsigned(1200) |
| 600 |
0x06, // unsigned(6) |
| 601 |
0x81, // array(1) |
| 602 |
0x01, // unsigned(1) |
| 603 |
]; |
| 604 |
|
| 605 |
// Real world example from Yubikey Bio |
| 606 |
pub const AUTHENTICATOR_INFO_PAYLOAD_YK_BIO_5C: [u8; 409] = [ |
| 607 |
0xB3, // map(19) |
| 608 |
0x01, // unsigned(1) |
| 609 |
0x84, // array(4) |
| 610 |
0x66, // text(6) |
| 611 |
0x55, 0x32, 0x46, 0x5F, 0x56, 0x32, // "U2F_V2" |
| 612 |
0x68, // text(8) |
| 613 |
0x46, 0x49, 0x44, 0x4F, 0x5F, 0x32, 0x5F, 0x30, // "FIDO_2_0" |
| 614 |
0x6C, // text(12) |
| 615 |
0x46, 0x49, 0x44, 0x4F, 0x5F, 0x32, 0x5F, 0x31, 0x5F, 0x50, 0x52, |
| 616 |
0x45, // "FIDO_2_1_PRE" |
| 617 |
0x68, // text(8) |
| 618 |
0x46, 0x49, 0x44, 0x4F, 0x5F, 0x32, 0x5F, 0x31, // "FIDO_2_1" |
| 619 |
0x02, // unsigned(2) |
| 620 |
0x85, // array(5) |
| 621 |
0x6B, // text(11) |
| 622 |
0x63, 0x72, 0x65, 0x64, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, // "credProtect" |
| 623 |
0x6B, // text(11) |
| 624 |
0x68, 0x6D, 0x61, 0x63, 0x2D, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, // "hmac-secret" |
| 625 |
0x6C, // text(12) |
| 626 |
0x6C, 0x61, 0x72, 0x67, 0x65, 0x42, 0x6C, 0x6F, 0x62, 0x4B, 0x65, |
| 627 |
0x79, // "largeBlobKey" |
| 628 |
0x68, // text(8) |
| 629 |
0x63, 0x72, 0x65, 0x64, 0x42, 0x6C, 0x6F, 0x62, // "credBlob" |
| 630 |
0x6C, // text(12) |
| 631 |
0x6D, 0x69, 0x6E, 0x50, 0x69, 0x6E, 0x4C, 0x65, 0x6E, 0x67, 0x74, |
| 632 |
0x68, // "minPinLength" |
| 633 |
0x03, // unsigned(3) |
| 634 |
0x50, // bytes(16) |
| 635 |
0xD8, 0x52, 0x2D, 0x9F, 0x57, 0x5B, 0x48, 0x66, 0x88, 0xA9, 0xBA, 0x99, 0xFA, 0x02, 0xF3, |
| 636 |
0x5B, // "\xD8R-\x9FW[Hf\x88\xA9\xBA\x99\xFA\u0002\xF3[" |
| 637 |
0x04, // unsigned(4) |
| 638 |
0xB0, // map(16) |
| 639 |
0x62, // text(2) |
| 640 |
0x72, 0x6B, // "rk" |
| 641 |
0xF5, // primitive(21) |
| 642 |
0x62, // text(2) |
| 643 |
0x75, 0x70, // "up" |
| 644 |
0xF5, // primitive(21) |
| 645 |
0x62, // text(2) |
| 646 |
0x75, 0x76, // "uv" |
| 647 |
0xF5, // primitive(21) |
| 648 |
0x64, // text(4) |
| 649 |
0x70, 0x6C, 0x61, 0x74, // "plat" |
| 650 |
0xF4, // primitive(20) |
| 651 |
0x67, // text(7) |
| 652 |
0x75, 0x76, 0x54, 0x6F, 0x6B, 0x65, 0x6E, // "uvToken" |
| 653 |
0xF5, // primitive(21) |
| 654 |
0x68, // text(8) |
| 655 |
0x61, 0x6C, 0x77, 0x61, 0x79, 0x73, 0x55, 0x76, // "alwaysUv" |
| 656 |
0xF5, // primitive(21) |
| 657 |
0x68, // text(8) |
| 658 |
0x63, 0x72, 0x65, 0x64, 0x4D, 0x67, 0x6D, 0x74, // "credMgmt" |
| 659 |
0xF5, // primitive(21) |
| 660 |
0x69, // text(9) |
| 661 |
0x61, 0x75, 0x74, 0x68, 0x6E, 0x72, 0x43, 0x66, 0x67, // "authnrCfg" |
| 662 |
0xF5, // primitive(21) |
| 663 |
0x69, // text(9) |
| 664 |
0x62, 0x69, 0x6F, 0x45, 0x6E, 0x72, 0x6F, 0x6C, 0x6C, // "bioEnroll" |
| 665 |
0xF5, // primitive(21) |
| 666 |
0x69, // text(9) |
| 667 |
0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x50, 0x69, 0x6E, // "clientPin" |
| 668 |
0xF5, // primitive(21) |
| 669 |
0x6A, // text(10) |
| 670 |
0x6C, 0x61, 0x72, 0x67, 0x65, 0x42, 0x6C, 0x6F, 0x62, 0x73, // "largeBlobs" |
| 671 |
0xF5, // primitive(21) |
| 672 |
0x6E, // text(14) |
| 673 |
0x70, 0x69, 0x6E, 0x55, 0x76, 0x41, 0x75, 0x74, 0x68, 0x54, 0x6F, 0x6B, 0x65, |
| 674 |
0x6E, // "pinUvAuthToken" |
| 675 |
0xF5, // primitive(21) |
| 676 |
0x6F, // text(15) |
| 677 |
0x73, 0x65, 0x74, 0x4D, 0x69, 0x6E, 0x50, 0x49, 0x4E, 0x4C, 0x65, 0x6E, 0x67, 0x74, |
| 678 |
0x68, // "setMinPINLength" |
| 679 |
0xF5, // primitive(21) |
| 680 |
0x70, // text(16) |
| 681 |
0x6D, 0x61, 0x6B, 0x65, 0x43, 0x72, 0x65, 0x64, 0x55, 0x76, 0x4E, 0x6F, 0x74, 0x52, 0x71, |
| 682 |
0x64, // "makeCredUvNotRqd" |
| 683 |
0xF4, // primitive(20) |
| 684 |
0x75, // text(21) |
| 685 |
0x63, 0x72, 0x65, 0x64, 0x65, 0x6E, 0x74, 0x69, 0x61, 0x6C, 0x4D, 0x67, 0x6D, 0x74, 0x50, |
| 686 |
0x72, 0x65, 0x76, 0x69, 0x65, 0x77, // "credentialMgmtPreview" |
| 687 |
0xF5, // primitive(21) |
| 688 |
0x78, 0x1B, // text(27) |
| 689 |
0x75, 0x73, 0x65, 0x72, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, |
| 690 |
0x6E, 0x4D, 0x67, 0x6D, 0x74, 0x50, 0x72, 0x65, 0x76, 0x69, 0x65, |
| 691 |
0x77, // "userVerificationMgmtPreview" |
| 692 |
0xF5, // primitive(21) |
| 693 |
0x05, // unsigned(5) |
| 694 |
0x19, 0x04, 0xB0, // unsigned(1200) |
| 695 |
0x06, // unsigned(6) |
| 696 |
0x82, // array(2) |
| 697 |
0x02, // unsigned(2) |
| 698 |
0x01, // unsigned(1) |
| 699 |
0x07, // unsigned(7) |
| 700 |
0x08, // unsigned(8) |
| 701 |
0x08, // unsigned(8) |
| 702 |
0x18, 0x80, // unsigned(128) |
| 703 |
0x09, // unsigned(9) |
| 704 |
0x81, // array(1) |
| 705 |
0x63, // text(3) |
| 706 |
0x75, 0x73, 0x62, // "usb" |
| 707 |
0x0A, // unsigned(10) |
| 708 |
0x82, // array(2) |
| 709 |
0xA2, // map(2) |
| 710 |
0x63, // text(3) |
| 711 |
0x61, 0x6C, 0x67, // "alg" |
| 712 |
0x26, // negative(6) |
| 713 |
0x64, // text(4) |
| 714 |
0x74, 0x79, 0x70, 0x65, // "type" |
| 715 |
0x6A, // text(10) |
| 716 |
0x70, 0x75, 0x62, 0x6C, 0x69, 0x63, 0x2D, 0x6B, 0x65, 0x79, // "public-key" |
| 717 |
0xA2, // map(2) |
| 718 |
0x63, // text(3) |
| 719 |
0x61, 0x6C, 0x67, // "alg" |
| 720 |
0x27, // negative(7) |
| 721 |
0x64, // text(4) |
| 722 |
0x74, 0x79, 0x70, 0x65, // "type" |
| 723 |
0x6A, // text(10) |
| 724 |
0x70, 0x75, 0x62, 0x6C, 0x69, 0x63, 0x2D, 0x6B, 0x65, 0x79, // "public-key" |
| 725 |
0x0B, // unsigned(11) |
| 726 |
0x19, 0x04, 0x00, // unsigned(1024) |
| 727 |
0x0C, // unsigned(12) |
| 728 |
0xF4, // primitive(20) |
| 729 |
0x0D, // unsigned(13) |
| 730 |
0x04, // unsigned(4) |
| 731 |
0x0E, // unsigned(14) |
| 732 |
0x1A, 0x00, 0x05, 0x05, 0x06, // unsigned(328966) |
| 733 |
0x0F, // unsigned(15) |
| 734 |
0x18, 0x20, // unsigned(32) |
| 735 |
0x10, // unsigned(16) |
| 736 |
0x01, // unsigned(1) |
| 737 |
0x11, // unsigned(17) |
| 738 |
0x03, // unsigned(3) |
| 739 |
0x12, // unsigned(18) |
| 740 |
0x02, // unsigned(2) |
| 741 |
0x14, // unsigned(20) |
| 742 |
0x18, 0x18, // unsigned(24) |
| 743 |
]; |
| 744 |
|
| 745 |
#[test] |
| 746 |
fn parse_authenticator_info() { |
| 747 |
let authenticator_info: AuthenticatorInfo = |
| 748 |
from_slice(&AUTHENTICATOR_INFO_PAYLOAD).unwrap(); |
| 749 |
|
| 750 |
let expected = AuthenticatorInfo { |
| 751 |
versions: vec![AuthenticatorVersion::U2F_V2, AuthenticatorVersion::FIDO_2_0], |
| 752 |
extensions: vec!["uvm".to_string(), "hmac-secret".to_string()], |
| 753 |
aaguid: AAGuid(AAGUID_RAW), |
| 754 |
options: AuthenticatorOptions { |
| 755 |
platform_device: false, |
| 756 |
resident_key: true, |
| 757 |
client_pin: Some(false), |
| 758 |
user_presence: true, |
| 759 |
user_verification: None, |
| 760 |
..Default::default() |
| 761 |
}, |
| 762 |
max_msg_size: Some(1200), |
| 763 |
pin_protocols: Some(vec![1]), |
| 764 |
max_credential_count_in_list: None, |
| 765 |
max_credential_id_length: None, |
| 766 |
transports: None, |
| 767 |
algorithms: None, |
| 768 |
max_ser_large_blob_array: None, |
| 769 |
force_pin_change: None, |
| 770 |
min_pin_length: None, |
| 771 |
firmware_version: None, |
| 772 |
max_cred_blob_length: None, |
| 773 |
max_rpids_for_set_min_pin_length: None, |
| 774 |
preferred_platform_uv_attempts: None, |
| 775 |
uv_modality: None, |
| 776 |
certifications: None, |
| 777 |
remaining_discoverable_credentials: None, |
| 778 |
vendor_prototype_config_commands: None, |
| 779 |
}; |
| 780 |
|
| 781 |
assert_eq!(authenticator_info, expected); |
| 782 |
|
| 783 |
// Test broken auth info |
| 784 |
let mut broken_payload = AUTHENTICATOR_INFO_PAYLOAD.to_vec(); |
| 785 |
// Have one more entry in the map |
| 786 |
broken_payload[0] += 1; |
| 787 |
// Add the additional entry at the back with an invalid key |
| 788 |
broken_payload.extend_from_slice(&[ |
| 789 |
0x17, // unsigned(23) -> invalid key-number. CTAP2.1 goes only to 0x15 |
| 790 |
0x6B, // text(11) |
| 791 |
0x69, 0x6E, 0x76, 0x61, 0x6C, 0x69, 0x64, 0x5F, 0x6B, 0x65, 0x79, // "invalid_key" |
| 792 |
]); |
| 793 |
|
| 794 |
let authenticator_info: AuthenticatorInfo = from_slice(&broken_payload).unwrap(); |
| 795 |
assert_eq!(authenticator_info, expected); |
| 796 |
} |
| 797 |
|
| 798 |
#[test] |
| 799 |
fn parse_authenticator_info_yk_bio_5c() { |
| 800 |
let authenticator_info: AuthenticatorInfo = |
| 801 |
from_slice(&AUTHENTICATOR_INFO_PAYLOAD_YK_BIO_5C).unwrap(); |
| 802 |
|
| 803 |
let expected = AuthenticatorInfo { |
| 804 |
versions: vec![ |
| 805 |
AuthenticatorVersion::U2F_V2, |
| 806 |
AuthenticatorVersion::FIDO_2_0, |
| 807 |
AuthenticatorVersion::FIDO_2_1_PRE, |
| 808 |
AuthenticatorVersion::FIDO_2_1, |
| 809 |
], |
| 810 |
extensions: vec![ |
| 811 |
"credProtect".to_string(), |
| 812 |
"hmac-secret".to_string(), |
| 813 |
"largeBlobKey".to_string(), |
| 814 |
"credBlob".to_string(), |
| 815 |
"minPinLength".to_string(), |
| 816 |
], |
| 817 |
aaguid: AAGuid([ |
| 818 |
0xd8, 0x52, 0x2d, 0x9f, 0x57, 0x5b, 0x48, 0x66, 0x88, 0xa9, 0xba, 0x99, 0xfa, 0x02, |
| 819 |
0xf3, 0x5b, |
| 820 |
]), |
| 821 |
options: AuthenticatorOptions { |
| 822 |
platform_device: false, |
| 823 |
resident_key: true, |
| 824 |
client_pin: Some(true), |
| 825 |
user_presence: true, |
| 826 |
user_verification: Some(true), |
| 827 |
pin_uv_auth_token: Some(true), |
| 828 |
no_mc_ga_permissions_with_client_pin: None, |
| 829 |
large_blobs: Some(true), |
| 830 |
ep: None, |
| 831 |
bio_enroll: Some(true), |
| 832 |
user_verification_mgmt_preview: Some(true), |
| 833 |
uv_bio_enroll: None, |
| 834 |
authnr_cfg: Some(true), |
| 835 |
uv_acfg: None, |
| 836 |
cred_mgmt: Some(true), |
| 837 |
credential_mgmt_preview: Some(true), |
| 838 |
set_min_pin_length: Some(true), |
| 839 |
make_cred_uv_not_rqd: Some(false), |
| 840 |
always_uv: Some(true), |
| 841 |
}, |
| 842 |
max_msg_size: Some(1200), |
| 843 |
pin_protocols: Some(vec![2, 1]), |
| 844 |
max_credential_count_in_list: Some(8), |
| 845 |
max_credential_id_length: Some(128), |
| 846 |
transports: Some(vec!["usb".to_string()]), |
| 847 |
algorithms: Some(vec![ |
| 848 |
PublicKeyCredentialParameters { |
| 849 |
alg: COSEAlgorithm::ES256, |
| 850 |
}, |
| 851 |
PublicKeyCredentialParameters { |
| 852 |
alg: COSEAlgorithm::EDDSA, |
| 853 |
}, |
| 854 |
]), |
| 855 |
max_ser_large_blob_array: Some(1024), |
| 856 |
force_pin_change: Some(false), |
| 857 |
min_pin_length: Some(4), |
| 858 |
firmware_version: Some(328966), |
| 859 |
max_cred_blob_length: Some(32), |
| 860 |
max_rpids_for_set_min_pin_length: Some(1), |
| 861 |
preferred_platform_uv_attempts: Some(3), |
| 862 |
uv_modality: Some(2), |
| 863 |
certifications: None, |
| 864 |
remaining_discoverable_credentials: Some(24), |
| 865 |
vendor_prototype_config_commands: None, |
| 866 |
}; |
| 867 |
|
| 868 |
assert_eq!(authenticator_info, expected); |
| 869 |
} |
| 870 |
|
| 871 |
#[test] |
| 872 |
fn test_get_info_ctap2_only() { |
| 873 |
let mut device = Device::new("commands/get_info").unwrap(); |
| 874 |
assert_eq!(device.get_protocol(), FidoProtocol::CTAP2); |
| 875 |
let nonce = [0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01]; |
| 876 |
|
| 877 |
// channel id |
| 878 |
let mut cid = [0u8; 4]; |
| 879 |
thread_rng().fill_bytes(&mut cid); |
| 880 |
|
| 881 |
// init packet |
| 882 |
let mut msg = CID_BROADCAST.to_vec(); |
| 883 |
msg.extend(vec![HIDCmd::Init.into(), 0x00, 0x08]); // cmd + bcnt |
| 884 |
msg.extend_from_slice(&nonce); |
| 885 |
device.add_write(&msg, 0); |
| 886 |
|
| 887 |
// init_resp packet |
| 888 |
let mut msg = CID_BROADCAST.to_vec(); |
| 889 |
msg.extend(vec![ |
| 890 |
0x06, /* HIDCmd::Init without TYPE_INIT */ |
| 891 |
0x00, 0x11, |
| 892 |
]); // cmd + bcnt |
| 893 |
msg.extend_from_slice(&nonce); |
| 894 |
msg.extend_from_slice(&cid); // new channel id |
| 895 |
|
| 896 |
// We are setting NMSG, to signal that the device does not support CTAP1 |
| 897 |
msg.extend(vec![0x02, 0x04, 0x01, 0x08, 0x01 | 0x04 | 0x08]); // versions + flags (wink+cbor+nmsg) |
| 898 |
device.add_read(&msg, 0); |
| 899 |
|
| 900 |
// ctap2 request |
| 901 |
let mut msg = cid.to_vec(); |
| 902 |
msg.extend(vec![HIDCmd::Cbor.into(), 0x00, 0x1]); // cmd + bcnt |
| 903 |
msg.extend(vec![0x04]); // authenticatorGetInfo |
| 904 |
device.add_write(&msg, 0); |
| 905 |
|
| 906 |
// ctap2 response |
| 907 |
let mut msg = cid.to_vec(); |
| 908 |
msg.extend(vec![HIDCmd::Cbor.into(), 0x00, 0x5A]); // cmd + bcnt |
| 909 |
msg.extend(vec![0]); // Status code: Success |
| 910 |
msg.extend(&AUTHENTICATOR_INFO_PAYLOAD[0..(IN_HID_RPT_SIZE - 8)]); |
| 911 |
device.add_read(&msg, 0); |
| 912 |
// Continuation package |
| 913 |
let mut msg = cid.to_vec(); |
| 914 |
msg.extend(vec![0x00]); // SEQ |
| 915 |
msg.extend(&AUTHENTICATOR_INFO_PAYLOAD[(IN_HID_RPT_SIZE - 8)..]); |
| 916 |
device.add_read(&msg, 0); |
| 917 |
device.init().expect("Failed to init device"); |
| 918 |
|
| 919 |
assert_eq!(device.get_cid(), &cid); |
| 920 |
|
| 921 |
let dev_info = device.get_device_info(); |
| 922 |
assert_eq!( |
| 923 |
dev_info.cap_flags, |
| 924 |
Capability::WINK | Capability::CBOR | Capability::NMSG |
| 925 |
); |
| 926 |
|
| 927 |
let result = device |
| 928 |
.get_authenticator_info() |
| 929 |
.expect("Didn't get any authenticator_info"); |
| 930 |
let expected = AuthenticatorInfo { |
| 931 |
versions: vec![AuthenticatorVersion::U2F_V2, AuthenticatorVersion::FIDO_2_0], |
| 932 |
extensions: vec!["uvm".to_string(), "hmac-secret".to_string()], |
| 933 |
aaguid: AAGuid(AAGUID_RAW), |
| 934 |
options: AuthenticatorOptions { |
| 935 |
platform_device: false, |
| 936 |
resident_key: true, |
| 937 |
client_pin: Some(false), |
| 938 |
user_presence: true, |
| 939 |
user_verification: None, |
| 940 |
..Default::default() |
| 941 |
}, |
| 942 |
max_msg_size: Some(1200), |
| 943 |
pin_protocols: Some(vec![1]), |
| 944 |
max_credential_count_in_list: None, |
| 945 |
max_credential_id_length: None, |
| 946 |
transports: None, |
| 947 |
algorithms: None, |
| 948 |
max_ser_large_blob_array: None, |
| 949 |
force_pin_change: None, |
| 950 |
min_pin_length: None, |
| 951 |
firmware_version: None, |
| 952 |
max_cred_blob_length: None, |
| 953 |
max_rpids_for_set_min_pin_length: None, |
| 954 |
preferred_platform_uv_attempts: None, |
| 955 |
uv_modality: None, |
| 956 |
certifications: None, |
| 957 |
remaining_discoverable_credentials: None, |
| 958 |
vendor_prototype_config_commands: None, |
| 959 |
}; |
| 960 |
|
| 961 |
assert_eq!(result, &expected); |
| 962 |
} |
| 963 |
|
| 964 |
#[test] |
| 965 |
fn test_authenticator_info_max_version() { |
| 966 |
let fido2_0 = AuthenticatorInfo { |
| 967 |
versions: vec![AuthenticatorVersion::U2F_V2, AuthenticatorVersion::FIDO_2_0], |
| 968 |
..Default::default() |
| 969 |
}; |
| 970 |
assert_eq!( |
| 971 |
fido2_0.max_supported_version(), |
| 972 |
AuthenticatorVersion::FIDO_2_0 |
| 973 |
); |
| 974 |
|
| 975 |
let fido2_1_pre = AuthenticatorInfo { |
| 976 |
versions: vec![ |
| 977 |
AuthenticatorVersion::FIDO_2_1_PRE, |
| 978 |
AuthenticatorVersion::U2F_V2, |
| 979 |
], |
| 980 |
..Default::default() |
| 981 |
}; |
| 982 |
assert_eq!( |
| 983 |
fido2_1_pre.max_supported_version(), |
| 984 |
AuthenticatorVersion::FIDO_2_1_PRE |
| 985 |
); |
| 986 |
|
| 987 |
let fido2_1 = AuthenticatorInfo { |
| 988 |
versions: vec![ |
| 989 |
AuthenticatorVersion::FIDO_2_1_PRE, |
| 990 |
AuthenticatorVersion::FIDO_2_1, |
| 991 |
AuthenticatorVersion::U2F_V2, |
| 992 |
AuthenticatorVersion::FIDO_2_0, |
| 993 |
], |
| 994 |
..Default::default() |
| 995 |
}; |
| 996 |
assert_eq!( |
| 997 |
fido2_1.max_supported_version(), |
| 998 |
AuthenticatorVersion::FIDO_2_1 |
| 999 |
); |
| 1000 |
} |
| 1001 |
|
| 1002 |
#[test] |
| 1003 |
fn parse_authenticator_info_protocol_versions() { |
| 1004 |
let mut expected = AuthenticatorInfo { |
| 1005 |
versions: vec![AuthenticatorVersion::U2F_V2, AuthenticatorVersion::FIDO_2_0], |
| 1006 |
extensions: vec!["uvm".to_string(), "hmac-secret".to_string()], |
| 1007 |
aaguid: AAGuid(AAGUID_RAW), |
| 1008 |
options: AuthenticatorOptions { |
| 1009 |
platform_device: false, |
| 1010 |
resident_key: true, |
| 1011 |
client_pin: Some(false), |
| 1012 |
user_presence: true, |
| 1013 |
..Default::default() |
| 1014 |
}, |
| 1015 |
max_msg_size: Some(1200), |
| 1016 |
pin_protocols: None, |
| 1017 |
..Default::default() |
| 1018 |
}; |
| 1019 |
|
| 1020 |
let raw_data = AUTHENTICATOR_INFO_PAYLOAD.to_vec(); |
| 1021 |
// pin protocol entry (last 3 bytes in payload): |
| 1022 |
// 0x06, // unsigned(6) |
| 1023 |
// 0x81, // array(1) |
| 1024 |
// 0x01, // unsigned(1) |
| 1025 |
|
| 1026 |
let mut raw_empty_list = raw_data.clone(); |
| 1027 |
raw_empty_list.pop(); |
| 1028 |
let raw_list_len = raw_empty_list.len(); |
| 1029 |
raw_empty_list[raw_list_len - 1] = 0x80; // array(0) instead of array(1) |
| 1030 |
|
| 1031 |
// Empty protocols-array, that should produce an error |
| 1032 |
from_slice::<AuthenticatorInfo>(&raw_empty_list).unwrap_err(); |
| 1033 |
|
| 1034 |
// No protocols specified |
| 1035 |
let mut raw_no_list = raw_data.clone(); |
| 1036 |
raw_no_list.pop(); |
| 1037 |
raw_no_list.pop(); |
| 1038 |
raw_no_list.pop(); |
| 1039 |
raw_no_list[0] = 0xa5; // map(5) instead of map(6) |
| 1040 |
|
| 1041 |
let authenticator_info: AuthenticatorInfo = from_slice(&raw_no_list).unwrap(); |
| 1042 |
assert_eq!(authenticator_info, expected); |
| 1043 |
|
| 1044 |
// Both 1 and 2 |
| 1045 |
let mut raw_list = raw_data; |
| 1046 |
let raw_list_len = raw_list.len(); |
| 1047 |
raw_list[raw_list_len - 2] = 0x82; // array(2) instead of array(1) |
| 1048 |
raw_list.push(0x02); |
| 1049 |
|
| 1050 |
expected.pin_protocols = Some(vec![1, 2]); |
| 1051 |
let authenticator_info: AuthenticatorInfo = from_slice(&raw_list).unwrap(); |
| 1052 |
assert_eq!(authenticator_info, expected); |
| 1053 |
} |
| 1054 |
} |