Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the user-handle to be dependent on the store info discoverability #42

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion passkey-authenticator/src/authenticator/make_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ where
// credential.
let CoseKeyPair { public, private } = CoseKeyPair::from_secret_key(&private_key, algorithm);

let store_info = self.store.get_info().await;

let is_passkey_rk = store_info
.discoverability
.is_passkey_discoverable(input.options.rk);

let passkey = Passkey {
key: private,
rp_id: input.rp.id.clone(),
credential_id: credential_id.into(),
user_handle: input.options.rk.then_some(input.user.id.clone()),
user_handle: is_passkey_rk.then(|| input.user.id.clone()),
counter: self.make_credentials_with_signature_counter.then_some(0),
extensions: extensions.credential,
};
Expand Down
11 changes: 11 additions & 0 deletions passkey-authenticator/src/credential_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ pub enum DiscoverabilitySupport {
ForcedDiscoverable,
}

impl DiscoverabilitySupport {
/// Helper method to determine if the store created a discoverable credential or not.
pub fn is_passkey_discoverable(&self, rk_input: bool) -> bool {
match self {
DiscoverabilitySupport::Full => rk_input,
DiscoverabilitySupport::OnlyNonDiscoverable => false,
DiscoverabilitySupport::ForcedDiscoverable => true,
}
}
}

/// Use this on a type that enables storage and fetching of credentials
#[async_trait::async_trait]
pub trait CredentialStore {
Expand Down
10 changes: 2 additions & 8 deletions passkey-client/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
//! [credprops]: https://w3c.github.io/webauthn/#sctn-authenticator-credential-properties-extension
//! [prf]: https://w3c.github.io/webauthn/#prf-extension

use passkey_authenticator::{
CredentialStore, DiscoverabilitySupport, StoreInfo, UserValidationMethod,
};
use passkey_authenticator::{CredentialStore, StoreInfo, UserValidationMethod};
use passkey_types::{
ctap2::{get_assertion, get_info, make_credential},
webauthn::{
Expand Down Expand Up @@ -53,11 +51,7 @@ where
) -> AuthenticationExtensionsClientOutputs {
let cred_props_requested = request.and_then(|ext| ext.cred_props) == Some(true);
let cred_props = if cred_props_requested {
let discoverable = match store_info.discoverability {
DiscoverabilitySupport::Full => rk,
DiscoverabilitySupport::OnlyNonDiscoverable => false,
DiscoverabilitySupport::ForcedDiscoverable => true,
};
let discoverable = store_info.discoverability.is_passkey_discoverable(rk);

Some(CredentialPropertiesOutput {
discoverable: Some(discoverable),
Expand Down
Loading