Skip to content

Commit cb8a2c1

Browse files
committed
Return authenticator attachment with results
1 parent 925b9b8 commit cb8a2c1

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

src/ctap2/commands/get_assertion.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::ctap2::commands::get_next_assertion::GetNextAssertion;
1313
use crate::ctap2::commands::make_credentials::UserVerification;
1414
use crate::ctap2::server::{
1515
AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs,
16-
PublicKeyCredentialDescriptor, PublicKeyCredentialUserEntity, RelyingParty, RpIdHash,
17-
UserVerificationRequirement,
16+
AuthenticatorAttachment, PublicKeyCredentialDescriptor, PublicKeyCredentialUserEntity,
17+
RelyingParty, RpIdHash, UserVerificationRequirement,
1818
};
1919
use crate::ctap2::utils::{read_be_u32, read_byte};
2020
use crate::errors::AuthenticatorError;
@@ -191,7 +191,13 @@ impl GetAssertion {
191191
}
192192
}
193193

194-
pub fn finalize_result<Dev: FidoDevice>(&self, _dev: &Dev, result: &mut GetAssertionResult) {
194+
pub fn finalize_result<Dev: FidoDevice>(&self, dev: &Dev, result: &mut GetAssertionResult) {
195+
result.attachment = match dev.get_authenticator_info() {
196+
Some(info) if info.options.platform_device => AuthenticatorAttachment::Platform,
197+
Some(_) => AuthenticatorAttachment::CrossPlatform,
198+
None => AuthenticatorAttachment::Unknown,
199+
};
200+
195201
// Handle extensions whose outputs are not encoded in the authenticator data.
196202
// 1. appId
197203
if let Some(app_id) = &self.extensions.app_id {
@@ -399,6 +405,7 @@ impl RequestCtap2 for GetAssertion {
399405
let mut results = Vec::with_capacity(number_of_credentials);
400406
results.push(GetAssertionResult {
401407
assertion: assertion.into(),
408+
attachment: AuthenticatorAttachment::Unknown,
402409
extensions: Default::default(),
403410
});
404411

@@ -408,6 +415,7 @@ impl RequestCtap2 for GetAssertion {
408415
let assertion = dev.send_cbor(&msg)?;
409416
results.push(GetAssertionResult {
410417
assertion: assertion.into(),
418+
attachment: AuthenticatorAttachment::Unknown,
411419
extensions: Default::default(),
412420
});
413421
}
@@ -457,6 +465,7 @@ impl From<GetAssertionResponse> for Assertion {
457465
#[derive(Debug, PartialEq, Eq)]
458466
pub struct GetAssertionResult {
459467
pub assertion: Assertion,
468+
pub attachment: AuthenticatorAttachment,
460469
pub extensions: AuthenticationExtensionsClientOutputs,
461470
}
462471

@@ -493,6 +502,7 @@ impl GetAssertionResult {
493502

494503
Ok(GetAssertionResult {
495504
assertion,
505+
attachment: AuthenticatorAttachment::Unknown,
496506
extensions: Default::default(),
497507
})
498508
}
@@ -606,8 +616,8 @@ pub mod test {
606616
do_credential_list_filtering_ctap1, do_credential_list_filtering_ctap2,
607617
};
608618
use crate::ctap2::server::{
609-
PublicKeyCredentialDescriptor, PublicKeyCredentialUserEntity, RelyingParty, RpIdHash,
610-
Transport,
619+
AuthenticatorAttachment, PublicKeyCredentialDescriptor, PublicKeyCredentialUserEntity,
620+
RelyingParty, RpIdHash, Transport,
611621
};
612622
use crate::transport::device_selector::Device;
613623
use crate::transport::hid::HIDDevice;
@@ -768,6 +778,7 @@ pub mod test {
768778

769779
let expected = vec![GetAssertionResult {
770780
assertion: expected_assertion,
781+
attachment: AuthenticatorAttachment::Unknown,
771782
extensions: Default::default(),
772783
}];
773784
let response = device.send_cbor(&assertion).unwrap();
@@ -900,6 +911,7 @@ pub mod test {
900911

901912
let expected = vec![GetAssertionResult {
902913
assertion: expected_assertion,
914+
attachment: AuthenticatorAttachment::Unknown,
903915
extensions: Default::default(),
904916
}];
905917
assert_eq!(response, expected);
@@ -1041,6 +1053,7 @@ pub mod test {
10411053

10421054
let expected = vec![GetAssertionResult {
10431055
assertion: expected_assertion,
1056+
attachment: AuthenticatorAttachment::Unknown,
10441057
extensions: Default::default(),
10451058
}];
10461059
assert_eq!(response, expected);

src/ctap2/commands/make_credentials.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use crate::ctap2::attestation::{
1414
use crate::ctap2::client_data::ClientDataHash;
1515
use crate::ctap2::server::{
1616
AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs,
17-
CredentialProtectionPolicy, PublicKeyCredentialDescriptor, PublicKeyCredentialParameters,
18-
PublicKeyCredentialUserEntity, RelyingParty, RpIdHash, UserVerificationRequirement,
17+
AuthenticatorAttachment, CredentialProtectionPolicy, PublicKeyCredentialDescriptor,
18+
PublicKeyCredentialParameters, PublicKeyCredentialUserEntity, RelyingParty, RpIdHash,
19+
UserVerificationRequirement,
1920
};
2021
use crate::ctap2::utils::{read_byte, serde_parse_err};
2122
use crate::errors::AuthenticatorError;
@@ -34,6 +35,7 @@ use std::io::{Cursor, Read};
3435
#[derive(Debug, PartialEq, Eq)]
3536
pub struct MakeCredentialsResult {
3637
pub att_obj: AttestationObject,
38+
pub attachment: AuthenticatorAttachment,
3739
pub extensions: AuthenticationExtensionsClientOutputs,
3840
}
3941

@@ -102,6 +104,7 @@ impl MakeCredentialsResult {
102104

103105
Ok(Self {
104106
att_obj,
107+
attachment: AuthenticatorAttachment::Unknown,
105108
extensions: Default::default(),
106109
})
107110
}
@@ -186,6 +189,7 @@ impl<'de> Deserialize<'de> for MakeCredentialsResult {
186189
auth_data,
187190
att_stmt,
188191
},
192+
attachment: AuthenticatorAttachment::Unknown,
189193
extensions: Default::default(),
190194
})
191195
}
@@ -303,6 +307,12 @@ impl MakeCredentials {
303307
pub fn finalize_result<Dev: FidoDevice>(&self, dev: &Dev, result: &mut MakeCredentialsResult) {
304308
let maybe_info = dev.get_authenticator_info();
305309

310+
result.attachment = match maybe_info {
311+
Some(info) if info.options.platform_device => AuthenticatorAttachment::Platform,
312+
Some(_) => AuthenticatorAttachment::CrossPlatform,
313+
None => AuthenticatorAttachment::Unknown,
314+
};
315+
306316
// Handle extensions whose outputs are not encoded in the authenticator data.
307317
// 1. credProps
308318
// "set clientExtensionResults["credProps"]["rk"] to the value of the
@@ -595,7 +605,8 @@ pub mod test {
595605
use crate::ctap2::commands::{RequestCtap1, RequestCtap2};
596606
use crate::ctap2::server::RpIdHash;
597607
use crate::ctap2::server::{
598-
PublicKeyCredentialParameters, PublicKeyCredentialUserEntity, RelyingParty,
608+
AuthenticatorAttachment, PublicKeyCredentialParameters, PublicKeyCredentialUserEntity,
609+
RelyingParty,
599610
};
600611
use crate::transport::device_selector::Device;
601612
use crate::transport::hid::HIDDevice;
@@ -653,6 +664,7 @@ pub mod test {
653664

654665
let expected = MakeCredentialsResult {
655666
att_obj: create_attestation_obj(),
667+
attachment: AuthenticatorAttachment::Unknown,
656668
extensions: Default::default(),
657669
};
658670

@@ -813,6 +825,7 @@ pub mod test {
813825

814826
let expected = MakeCredentialsResult {
815827
att_obj,
828+
attachment: AuthenticatorAttachment::Unknown,
816829
extensions: Default::default(),
817830
};
818831

src/ctap2/server.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ pub struct AuthenticationExtensionsClientOutputs {
379379
pub hmac_create_secret: Option<bool>,
380380
}
381381

382+
#[derive(Clone, Debug, PartialEq, Eq)]
383+
pub enum AuthenticatorAttachment {
384+
CrossPlatform,
385+
Platform,
386+
Unknown,
387+
}
388+
382389
#[cfg(test)]
383390
mod test {
384391
use super::{

0 commit comments

Comments
 (0)