Skip to content

Commit e59e2ec

Browse files
committed
Make Authenticator store its cryptographic backend
1 parent 0e90306 commit e59e2ec

20 files changed

Lines changed: 309 additions & 103 deletions

File tree

passkey-authenticator/src/authenticator.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use coset::iana;
2-
use passkey_crypto::rng::RngBackend;
2+
use passkey_crypto::{CryptoBackend, rng::RngBackend};
33
use passkey_types::{
44
ctap2::{Aaguid, Ctap2Error, Flags},
55
webauthn,
@@ -68,7 +68,7 @@ impl From<CredentialIdLength> for usize {
6868
}
6969

7070
/// A virtual authenticator with all the necessary state and information.
71-
pub struct Authenticator<S, U> {
71+
pub struct Authenticator<S, U, C> {
7272
/// The authenticator's AAGUID
7373
aaguid: Aaguid,
7474
/// Provides credential storage capabilities
@@ -95,15 +95,19 @@ pub struct Authenticator<S, U> {
9595

9696
/// Supported authenticator extensions
9797
extensions: Extensions,
98+
99+
/// The cryptographic backend of the Authenticator
100+
crypto: C,
98101
}
99102

100-
impl<S, U> Authenticator<S, U>
103+
impl<S, U, C> Authenticator<S, U, C>
101104
where
102105
S: CredentialStore,
103106
U: UserValidationMethod,
107+
C: CryptoBackend,
104108
{
105109
/// Create an authenticator with a known aaguid, a backing storage and a User verification system.
106-
pub fn new(aaguid: Aaguid, store: S, user: U) -> Self {
110+
pub fn new(aaguid: Aaguid, store: S, user: U, crypto: C) -> Self {
107111
Self {
108112
aaguid,
109113
store,
@@ -117,6 +121,7 @@ where
117121
make_credentials_with_signature_counter: false,
118122
credential_id_length: CredentialIdLength::default(),
119123
extensions: Extensions::default(),
124+
crypto,
120125
}
121126
}
122127

passkey-authenticator/src/authenticator/extensions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub(super) struct GetExtensionOutputs {
5454
pub unsigned: Option<get_assertion::UnsignedExtensionOutputs>,
5555
}
5656

57-
impl<S, U> Authenticator<S, U> {
57+
impl<S, U, C> Authenticator<S, U, C> {
5858
pub(super) fn make_extensions(
5959
&self,
6060
request: Option<make_credential::ExtensionInputs>,

passkey-authenticator/src/authenticator/extensions/hmac_secret.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl HmacSecretCredentialSupport {
8181
}
8282
}
8383

84-
impl<S, U> Authenticator<S, U> {
84+
impl<S, U, C> Authenticator<S, U, C> {
8585
pub(super) fn make_hmac_secret(
8686
&self,
8787
hmac_secret_request: Option<bool>,

passkey-authenticator/src/authenticator/extensions/hmac_secret/tests.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ pub(crate) fn prf_eval_request(eval: Option<Vec<u8>>) -> AuthenticatorPrfInputs
2020

2121
#[test]
2222
fn hmac_secret_cycle_works() {
23-
let auth = Authenticator::new(Aaguid::new_empty(), None, MockUserValidationMethod::new())
24-
.hmac_secret(HmacSecretConfig::new_without_uv());
23+
let auth = Authenticator::new(
24+
Aaguid::new_empty(),
25+
None,
26+
MockUserValidationMethod::new(),
27+
RustCryptoBackend,
28+
)
29+
.hmac_secret(HmacSecretConfig::new_without_uv());
2530

2631
let ext = auth
2732
.make_hmac_secret(Some(true))
@@ -99,8 +104,13 @@ fn hmac_secret_cycle_works() {
99104

100105
#[test]
101106
fn hmac_secret_cycle_works_with_one_cred() {
102-
let auth = Authenticator::new(Aaguid::new_empty(), None, MockUserValidationMethod::new())
103-
.hmac_secret(HmacSecretConfig::new_with_uv_only());
107+
let auth = Authenticator::new(
108+
Aaguid::new_empty(),
109+
None,
110+
MockUserValidationMethod::new(),
111+
RustCryptoBackend,
112+
)
113+
.hmac_secret(HmacSecretConfig::new_with_uv_only());
104114

105115
let ext = auth
106116
.make_hmac_secret(Some(true))
@@ -156,8 +166,13 @@ fn hmac_secret_cycle_works_with_one_cred() {
156166

157167
#[test]
158168
fn hmac_secret_cycle_works_with_one_salt() {
159-
let auth = Authenticator::new(Aaguid::new_empty(), None, MockUserValidationMethod::new())
160-
.hmac_secret(HmacSecretConfig::new_with_uv_only());
169+
let auth = Authenticator::new(
170+
Aaguid::new_empty(),
171+
None,
172+
MockUserValidationMethod::new(),
173+
RustCryptoBackend,
174+
)
175+
.hmac_secret(HmacSecretConfig::new_with_uv_only());
161176

162177
let ext = auth
163178
.make_hmac_secret(Some(true))

passkey-authenticator/src/authenticator/get_assertion.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use p256::ecdsa::{SigningKey, signature::SignerMut};
2+
use passkey_crypto::CryptoBackend;
23
use passkey_types::{
34
Bytes,
45
ctap2::{
@@ -15,10 +16,11 @@ use crate::{
1516
user_validation::UiHint,
1617
};
1718

18-
impl<S, U> Authenticator<S, U>
19+
impl<S, U, C> Authenticator<S, U, C>
1920
where
2021
S: CredentialStore + Sync,
2122
U: UserValidationMethod<PasskeyItem = <S as CredentialStore>::PasskeyItem> + Sync,
23+
C: CryptoBackend,
2224
{
2325
/// This method is used by a host to request cryptographic proof of user authentication as well
2426
/// as user consent to a given transaction, using a previously generated credential that is

passkey-authenticator/src/authenticator/get_assertion/tests.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async fn get_assertion_returns_no_credentials_found() {
5353
Aaguid::new_empty(),
5454
store,
5555
MockUserValidationMethod::verified_user_with_hint(1, MockUiHint::InformNoCredentialsFound),
56+
RustCryptoBackend,
5657
);
5758

5859
// Act
@@ -78,6 +79,7 @@ async fn get_assertion_increments_signature_counter_when_counter_is_some() {
7879
1,
7980
MockUiHint::RequestExistingCredential(passkey),
8081
),
82+
RustCryptoBackend,
8183
);
8284

8385
// Act
@@ -100,8 +102,12 @@ async fn unsupported_extension_with_request_gives_no_ext_output() {
100102
let shared_store = Some(create_passkey(None));
101103
let user_mock = MockUserValidationMethod::verified_user(1);
102104

103-
let mut authenticator =
104-
Authenticator::new(Aaguid::new_empty(), shared_store.clone(), user_mock);
105+
let mut authenticator = Authenticator::new(
106+
Aaguid::new_empty(),
107+
shared_store.clone(),
108+
user_mock,
109+
RustCryptoBackend,
110+
);
105111

106112
let request = Request {
107113
extensions: Some(ExtensionInputs {
@@ -125,8 +131,12 @@ async fn unsupported_extension_with_empty_request_gives_no_ext_output() {
125131
let shared_store = Some(create_passkey(None));
126132
let user_mock = MockUserValidationMethod::verified_user(1);
127133

128-
let mut authenticator =
129-
Authenticator::new(Aaguid::new_empty(), shared_store.clone(), user_mock);
134+
let mut authenticator = Authenticator::new(
135+
Aaguid::new_empty(),
136+
shared_store.clone(),
137+
user_mock,
138+
RustCryptoBackend,
139+
);
130140

131141
let request = Request {
132142
extensions: Some(ExtensionInputs::default()),
@@ -147,9 +157,13 @@ async fn supported_extension_with_empty_request_gives_no_ext_output() {
147157
let shared_store = Some(create_passkey(Some(Rng::random_vec(32))));
148158
let user_mock = MockUserValidationMethod::verified_user(1);
149159

150-
let mut authenticator =
151-
Authenticator::new(Aaguid::new_empty(), shared_store.clone(), user_mock)
152-
.hmac_secret(extensions::HmacSecretConfig::new_with_uv_only());
160+
let mut authenticator = Authenticator::new(
161+
Aaguid::new_empty(),
162+
shared_store.clone(),
163+
user_mock,
164+
RustCryptoBackend,
165+
)
166+
.hmac_secret(extensions::HmacSecretConfig::new_with_uv_only());
153167

154168
let request = Request {
155169
extensions: Some(ExtensionInputs::default()),
@@ -170,9 +184,13 @@ async fn supported_extension_without_extension_request_gives_no_ext_output() {
170184
let shared_store = Some(create_passkey(Some(Rng::random_vec(32))));
171185
let user_mock = MockUserValidationMethod::verified_user(1);
172186

173-
let mut authenticator =
174-
Authenticator::new(Aaguid::new_empty(), shared_store.clone(), user_mock)
175-
.hmac_secret(extensions::HmacSecretConfig::new_with_uv_only());
187+
let mut authenticator = Authenticator::new(
188+
Aaguid::new_empty(),
189+
shared_store.clone(),
190+
user_mock,
191+
RustCryptoBackend,
192+
)
193+
.hmac_secret(extensions::HmacSecretConfig::new_with_uv_only());
176194

177195
let request = good_request();
178196

@@ -190,9 +208,13 @@ async fn supported_extension_with_request_gives_output() {
190208
let shared_store = Some(create_passkey(Some(Rng::random_vec(32))));
191209
let user_mock = MockUserValidationMethod::verified_user(1);
192210

193-
let mut authenticator =
194-
Authenticator::new(Aaguid::new_empty(), shared_store.clone(), user_mock)
195-
.hmac_secret(extensions::HmacSecretConfig::new_with_uv_only());
211+
let mut authenticator = Authenticator::new(
212+
Aaguid::new_empty(),
213+
shared_store.clone(),
214+
user_mock,
215+
RustCryptoBackend,
216+
)
217+
.hmac_secret(extensions::HmacSecretConfig::new_with_uv_only());
196218

197219
let request = Request {
198220
extensions: Some(ExtensionInputs {

passkey-authenticator/src/authenticator/get_info.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use passkey_crypto::CryptoBackend;
12
use passkey_types::{
23
ctap2::get_info::{Options, Response, Version},
34
webauthn::PublicKeyCredentialParameters,
@@ -7,7 +8,12 @@ use crate::{
78
Authenticator, CredentialStore, UserValidationMethod, credential_store::DiscoverabilitySupport,
89
};
910

10-
impl<S: CredentialStore, U: UserValidationMethod> Authenticator<S, U> {
11+
impl<S, U, C> Authenticator<S, U, C>
12+
where
13+
S: CredentialStore,
14+
U: UserValidationMethod,
15+
C: CryptoBackend,
16+
{
1117
/// Using this method, the host can request that the authenticator report a list of all
1218
/// supported protocol versions, supported extensions, AAGUID of the device, and its capabilities.
1319
pub async fn get_info(&self) -> Box<Response> {

passkey-authenticator/src/authenticator/make_credential.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use p256::SecretKey;
2-
use passkey_crypto::rng::{Rng, RngBackend};
2+
use passkey_crypto::{
3+
CryptoBackend,
4+
rng::{Rng, RngBackend},
5+
};
36
use passkey_types::{
47
Passkey,
58
ctap2::{
@@ -10,10 +13,11 @@ use passkey_types::{
1013

1114
use crate::{Authenticator, CoseKeyPair, CredentialStore, UiHint, UserValidationMethod};
1215

13-
impl<S, U> Authenticator<S, U>
16+
impl<S, U, C> Authenticator<S, U, C>
1417
where
1518
S: CredentialStore + Sync,
1619
U: UserValidationMethod<PasskeyItem = <S as CredentialStore>::PasskeyItem> + Sync,
20+
C: CryptoBackend,
1721
{
1822
/// This method is invoked by the host to request generation of a new credential in the authenticator.
1923
pub async fn make_credential(&mut self, input: Request) -> Result<Response, StatusCode> {

0 commit comments

Comments
 (0)