Skip to content

Commit d37f5ad

Browse files
committed
Remove unnecessary RelyingPartyWrapper type
1 parent 915bcbc commit d37f5ad

File tree

5 files changed

+49
-123
lines changed

5 files changed

+49
-123
lines changed

src/ctap2/commands/get_assertion.rs

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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, RelyingPartyWrapper, RpIdHash,
16+
PublicKeyCredentialDescriptor, PublicKeyCredentialUserEntity, RelyingParty, RpIdHash,
1717
UserVerificationRequirement,
1818
};
1919
use crate::ctap2::utils::{read_be_u32, read_byte};
@@ -159,7 +159,7 @@ impl GetAssertionExtensions {
159159
#[derive(Debug, Clone)]
160160
pub struct GetAssertion {
161161
pub client_data_hash: ClientDataHash,
162-
pub rp: RelyingPartyWrapper,
162+
pub rp: RelyingParty,
163163
pub allow_list: Vec<PublicKeyCredentialDescriptor>,
164164

165165
// https://www.w3.org/TR/webauthn/#client-extension-input
@@ -176,7 +176,7 @@ pub struct GetAssertion {
176176
impl GetAssertion {
177177
pub fn new(
178178
client_data_hash: ClientDataHash,
179-
rp: RelyingPartyWrapper,
179+
rp: RelyingParty,
180180
allow_list: Vec<PublicKeyCredentialDescriptor>,
181181
options: GetAssertionOptions,
182182
extensions: GetAssertionExtensions,
@@ -195,10 +195,8 @@ impl GetAssertion {
195195
// Handle extensions whose outputs are not encoded in the authenticator data.
196196
// 1. appId
197197
if let Some(app_id) = &self.extensions.app_id {
198-
result.extensions.app_id = Some(
199-
result.assertion.auth_data.rp_id_hash
200-
== RelyingPartyWrapper::from(app_id.as_str()).hash(),
201-
);
198+
result.extensions.app_id =
199+
Some(result.assertion.auth_data.rp_id_hash == RelyingParty::from(app_id).hash());
202200
}
203201
}
204202
}
@@ -225,11 +223,7 @@ impl PinUvAuthCommand for GetAssertion {
225223
}
226224

227225
fn get_rp_id(&self) -> Option<&String> {
228-
match &self.rp {
229-
// CTAP1 case: We only have the hash, not the entire RpID
230-
RelyingPartyWrapper::Hash(..) => None,
231-
RelyingPartyWrapper::Data(r) => Some(&r.id),
232-
}
226+
Some(&self.rp.id)
233227
}
234228

235229
fn can_skip_user_verification(
@@ -273,17 +267,7 @@ impl Serialize for GetAssertion {
273267
}
274268

275269
let mut map = serializer.serialize_map(Some(map_len))?;
276-
match self.rp {
277-
RelyingPartyWrapper::Data(ref d) => {
278-
map.serialize_entry(&1, &d.id)?;
279-
}
280-
_ => {
281-
return Err(S::Error::custom(
282-
"Can't serialize a RelyingParty::Hash for CTAP2",
283-
));
284-
}
285-
}
286-
270+
map.serialize_entry(&1, &self.rp.id)?;
287271
map.serialize_entry(&2, &self.client_data_hash)?;
288272
if !self.allow_list.is_empty() {
289273
map.serialize_entry(&3, &self.allow_list)?;
@@ -621,8 +605,8 @@ pub mod test {
621605
do_credential_list_filtering_ctap1, do_credential_list_filtering_ctap2,
622606
};
623607
use crate::ctap2::server::{
624-
PublicKeyCredentialDescriptor, PublicKeyCredentialUserEntity, RelyingParty,
625-
RelyingPartyWrapper, RpIdHash, Transport,
608+
PublicKeyCredentialDescriptor, PublicKeyCredentialUserEntity, RelyingParty, RpIdHash,
609+
Transport,
626610
};
627611
use crate::transport::device_selector::Device;
628612
use crate::transport::hid::HIDDevice;
@@ -641,10 +625,7 @@ pub mod test {
641625
};
642626
let assertion = GetAssertion::new(
643627
client_data.hash().expect("failed to serialize client data"),
644-
RelyingPartyWrapper::Data(RelyingParty {
645-
id: String::from("example.com"),
646-
name: Some(String::from("Acme")),
647-
}),
628+
RelyingParty::from("example.com"),
648629
vec![PublicKeyCredentialDescriptor {
649630
id: vec![
650631
0x3E, 0xBD, 0x89, 0xBF, 0x77, 0xEC, 0x50, 0x97, 0x55, 0xEE, 0x9C, 0x26, 0x35,
@@ -851,10 +832,7 @@ pub mod test {
851832
};
852833
let mut assertion = GetAssertion::new(
853834
client_data.hash().expect("failed to serialize client data"),
854-
RelyingPartyWrapper::Data(RelyingParty {
855-
id: String::from("example.com"),
856-
name: Some(String::from("Acme")),
857-
}),
835+
RelyingParty::from("example.com"),
858836
vec![allowed_key.clone()],
859837
GetAssertionOptions {
860838
user_presence: Some(true),
@@ -942,10 +920,7 @@ pub mod test {
942920
};
943921
let mut assertion = GetAssertion::new(
944922
client_data.hash().expect("failed to serialize client data"),
945-
RelyingPartyWrapper::Data(RelyingParty {
946-
id: String::from("example.com"),
947-
name: Some(String::from("Acme")),
948-
}),
923+
RelyingParty::from("example.com"),
949924
vec![too_long_key_handle.clone()],
950925
GetAssertionOptions {
951926
user_presence: Some(true),
@@ -1081,10 +1056,7 @@ pub mod test {
10811056
};
10821057
let assertion = GetAssertion::new(
10831058
client_data.hash().expect("failed to serialize client data"),
1084-
RelyingPartyWrapper::Data(RelyingParty {
1085-
id: String::from("example.com"),
1086-
name: Some(String::from("Acme")),
1087-
}),
1059+
RelyingParty::from("example.com"),
10881060
vec![
10891061
// This should never be tested, because it gets pre-filtered, since it is too long
10901062
// (see max_credential_id_length)

src/ctap2/commands/make_credentials.rs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use crate::ctap2::client_data::ClientDataHash;
1515
use crate::ctap2::server::{
1616
AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs,
1717
CredentialProtectionPolicy, PublicKeyCredentialDescriptor, PublicKeyCredentialParameters,
18-
PublicKeyCredentialUserEntity, RelyingParty, RelyingPartyWrapper, RpIdHash,
19-
UserVerificationRequirement,
18+
PublicKeyCredentialUserEntity, RelyingParty, RpIdHash, UserVerificationRequirement,
2019
};
2120
use crate::ctap2::utils::{read_byte, serde_parse_err};
2221
use crate::errors::AuthenticatorError;
@@ -25,7 +24,7 @@ use crate::transport::{FidoDevice, VirtualFidoDevice};
2524
use crate::u2ftypes::CTAP1RequestAPDU;
2625
use serde::{
2726
de::{Error as DesError, MapAccess, Unexpected, Visitor},
28-
ser::{Error as SerError, SerializeMap},
27+
ser::SerializeMap,
2928
Deserialize, Deserializer, Serialize, Serializer,
3029
};
3130
use serde_cbor::{self, de::from_slice, ser, Value};
@@ -259,7 +258,7 @@ impl From<AuthenticationExtensionsClientInputs> for MakeCredentialsExtensions {
259258
#[derive(Debug, Clone)]
260259
pub struct MakeCredentials {
261260
pub client_data_hash: ClientDataHash,
262-
pub rp: RelyingPartyWrapper,
261+
pub rp: RelyingParty,
263262
// Note(baloo): If none -> ctap1
264263
pub user: Option<PublicKeyCredentialUserEntity>,
265264
pub pub_cred_params: Vec<PublicKeyCredentialParameters>,
@@ -281,7 +280,7 @@ impl MakeCredentials {
281280
#[allow(clippy::too_many_arguments)]
282281
pub fn new(
283282
client_data_hash: ClientDataHash,
284-
rp: RelyingPartyWrapper,
283+
rp: RelyingParty,
285284
user: Option<PublicKeyCredentialUserEntity>,
286285
pub_cred_params: Vec<PublicKeyCredentialParameters>,
287286
exclude_list: Vec<PublicKeyCredentialDescriptor>,
@@ -350,11 +349,7 @@ impl PinUvAuthCommand for MakeCredentials {
350349
}
351350

352351
fn get_rp_id(&self) -> Option<&String> {
353-
match &self.rp {
354-
// CTAP1 case: We only have the hash, not the entire RpID
355-
RelyingPartyWrapper::Hash(..) => None,
356-
RelyingPartyWrapper::Data(r) => Some(&r.id),
357-
}
352+
Some(&self.rp.id)
358353
}
359354

360355
fn can_skip_user_verification(
@@ -417,16 +412,7 @@ impl Serialize for MakeCredentials {
417412

418413
let mut map = serializer.serialize_map(Some(map_len))?;
419414
map.serialize_entry(&0x01, &self.client_data_hash)?;
420-
match self.rp {
421-
RelyingPartyWrapper::Data(ref d) => {
422-
map.serialize_entry(&0x02, &d)?;
423-
}
424-
_ => {
425-
return Err(S::Error::custom(
426-
"Can't serialize a RelyingParty::Hash for CTAP2",
427-
));
428-
}
429-
}
415+
map.serialize_entry(&0x02, &self.rp)?;
430416
map.serialize_entry(&0x03, &self.user)?;
431417
map.serialize_entry(&0x04, &self.pub_cred_params)?;
432418
if !self.exclude_list.is_empty() {
@@ -561,10 +547,7 @@ pub(crate) fn dummy_make_credentials_cmd() -> MakeCredentials {
561547
208, 206, 230, 252, 125, 191, 89, 154, 145, 157, 184, 251, 149, 19, 17, 38, 159, 14,
562548
183, 129, 247, 132, 28, 108, 192, 84, 74, 217, 218, 52, 21, 75,
563549
]),
564-
RelyingPartyWrapper::Data(RelyingParty {
565-
id: String::from("make.me.blink"),
566-
..Default::default()
567-
}),
550+
RelyingParty::from("make.me.blink"),
568551
Some(PublicKeyCredentialUserEntity {
569552
id: vec![0],
570553
name: Some(String::from("make.me.blink")),
@@ -599,7 +582,6 @@ pub mod test {
599582
use crate::ctap2::server::RpIdHash;
600583
use crate::ctap2::server::{
601584
PublicKeyCredentialParameters, PublicKeyCredentialUserEntity, RelyingParty,
602-
RelyingPartyWrapper,
603585
};
604586
use crate::transport::device_selector::Device;
605587
use crate::transport::hid::HIDDevice;
@@ -618,10 +600,10 @@ pub mod test {
618600
}
619601
.hash()
620602
.expect("failed to serialize client data"),
621-
RelyingPartyWrapper::Data(RelyingParty {
603+
RelyingParty {
622604
id: String::from("example.com"),
623605
name: Some(String::from("Acme")),
624-
}),
606+
},
625607
Some(PublicKeyCredentialUserEntity {
626608
id: base64::engine::general_purpose::URL_SAFE
627609
.decode("MIIBkzCCATigAwIBAjCCAZMwggE4oAMCAQIwggGTMII=")
@@ -675,10 +657,7 @@ pub mod test {
675657
}
676658
.hash()
677659
.expect("failed to serialize client data"),
678-
RelyingPartyWrapper::Data(RelyingParty {
679-
id: String::from("example.com"),
680-
name: Some(String::from("Acme")),
681-
}),
660+
RelyingParty::from("example.com"),
682661
Some(PublicKeyCredentialUserEntity {
683662
id: base64::engine::general_purpose::URL_SAFE
684663
.decode("MIIBkzCCATigAwIBAjCCAZMwggE4oAMCAQIwggGTMII=")

src/ctap2/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ use crate::ctap2::preflight::{
3535
silently_discover_credentials,
3636
};
3737
use crate::ctap2::server::{
38-
CredentialProtectionPolicy, RelyingPartyWrapper, ResidentKeyRequirement,
39-
UserVerificationRequirement,
38+
CredentialProtectionPolicy, RelyingParty, ResidentKeyRequirement, UserVerificationRequirement,
4039
};
4140
use crate::errors::{AuthenticatorError, UnsupportedOption};
4241
use crate::statecallback::StateCallback;
@@ -470,7 +469,7 @@ pub fn register<Dev: FidoDevice>(
470469

471470
let mut makecred = MakeCredentials::new(
472471
ClientDataHash(args.client_data_hash),
473-
RelyingPartyWrapper::Data(args.relying_party),
472+
args.relying_party,
474473
Some(args.user),
475474
args.pub_cred_params,
476475
args.exclude_list,
@@ -574,28 +573,25 @@ pub fn sign<Dev: FidoDevice>(
574573
}
575574

576575
let mut allow_list = args.allow_list;
577-
let mut rp_id = args.relying_party_id;
576+
let mut rp_id = RelyingParty::from(args.relying_party_id);
578577
let client_data_hash = ClientDataHash(args.client_data_hash);
579578
if let Some(ref app_id) = args.extensions.app_id {
580579
if !allow_list.is_empty() {
581580
// Try to silently discover U2F credentials that require the FIDO App ID extension. If
582581
// any are found, we should use the alternate RP ID instead of the provided RP ID.
583-
let silent_creds = silently_discover_credentials(
584-
dev,
585-
&allow_list,
586-
&RelyingPartyWrapper::from(app_id.as_str()),
587-
&client_data_hash,
588-
);
582+
let alt_rp_id = RelyingParty::from(app_id);
583+
let silent_creds =
584+
silently_discover_credentials(dev, &allow_list, &alt_rp_id, &client_data_hash);
589585
if !silent_creds.is_empty() {
590586
allow_list = silent_creds;
591-
rp_id = app_id.to_string();
587+
rp_id = alt_rp_id;
592588
}
593589
}
594590
}
595591

596592
let mut get_assertion = GetAssertion::new(
597593
client_data_hash,
598-
RelyingPartyWrapper::from(rp_id.as_str()),
594+
rp_id,
599595
allow_list,
600596
GetAssertionOptions {
601597
user_presence: Some(args.user_presence_req),

src/ctap2/preflight.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::commands::get_assertion::{GetAssertion, GetAssertionExtensions, GetAs
33
use super::commands::{PinUvAuthCommand, RequestCtap1, Retryable};
44
use crate::consts::{PARAMETER_SIZE, U2F_AUTHENTICATE, U2F_CHECK_IS_REGISTERED};
55
use crate::crypto::PinUvAuthToken;
6-
use crate::ctap2::server::{PublicKeyCredentialDescriptor, RelyingPartyWrapper};
6+
use crate::ctap2::server::{PublicKeyCredentialDescriptor, RelyingParty};
77
use crate::errors::AuthenticatorError;
88
use crate::transport::errors::{ApduErrorStatus, HIDError};
99
use crate::transport::{FidoDevice, FidoProtocol, VirtualFidoDevice};
@@ -19,7 +19,7 @@ use sha2::{Digest, Sha256};
1919
pub struct CheckKeyHandle<'assertion> {
2020
pub key_handle: &'assertion [u8],
2121
pub client_data_hash: &'assertion [u8],
22-
pub rp: &'assertion RelyingPartyWrapper,
22+
pub rp: &'assertion RelyingParty,
2323
}
2424

2525
impl<'assertion> RequestCtap1 for CheckKeyHandle<'assertion> {
@@ -81,7 +81,7 @@ impl<'assertion> RequestCtap1 for CheckKeyHandle<'assertion> {
8181
pub(crate) fn do_credential_list_filtering_ctap1<Dev: FidoDevice>(
8282
dev: &mut Dev,
8383
cred_list: &[PublicKeyCredentialDescriptor],
84-
rp: &RelyingPartyWrapper,
84+
rp: &RelyingParty,
8585
client_data_hash: &ClientDataHash,
8686
) -> Option<PublicKeyCredentialDescriptor> {
8787
let key_handle = cred_list
@@ -112,7 +112,7 @@ pub(crate) fn do_credential_list_filtering_ctap1<Dev: FidoDevice>(
112112
pub(crate) fn do_credential_list_filtering_ctap2<Dev: FidoDevice>(
113113
dev: &mut Dev,
114114
cred_list: &[PublicKeyCredentialDescriptor],
115-
rp: &RelyingPartyWrapper,
115+
rp: &RelyingParty,
116116
pin_uv_auth_token: Option<PinUvAuthToken>,
117117
) -> Result<Vec<PublicKeyCredentialDescriptor>, AuthenticatorError> {
118118
let info = dev
@@ -190,7 +190,7 @@ pub(crate) fn do_credential_list_filtering_ctap2<Dev: FidoDevice>(
190190
pub(crate) fn silently_discover_credentials<Dev: FidoDevice>(
191191
dev: &mut Dev,
192192
cred_list: &[PublicKeyCredentialDescriptor],
193-
rp: &RelyingPartyWrapper,
193+
rp: &RelyingParty,
194194
client_data_hash: &ClientDataHash,
195195
) -> Vec<PublicKeyCredentialDescriptor> {
196196
if dev.get_protocol() == FidoProtocol::CTAP2 {

0 commit comments

Comments
 (0)