Skip to content

Commit 9536365

Browse files
committed
fido: Add user handle to credential search parameters
1 parent 00e3fe0 commit 9536365

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

crates/bitwarden-fido/src/authenticator.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,13 @@ impl<'a> Fido2Authenticator<'a> {
255255
pub async fn silently_discover_credentials(
256256
&mut self,
257257
rp_id: String,
258+
user_handle: Option<Vec<u8>>,
258259
) -> Result<Vec<Fido2CredentialAutofillView>, SilentlyDiscoverCredentialsError> {
259260
let key_store = self.client.internal.get_key_store();
260-
let result = self.credential_store.find_credentials(None, rp_id).await?;
261+
let result = self
262+
.credential_store
263+
.find_credentials(None, rp_id, user_handle)
264+
.await?;
261265

262266
let mut ctx = key_store.context();
263267
result
@@ -353,7 +357,7 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> {
353357
&self,
354358
ids: Option<&[passkey::types::webauthn::PublicKeyCredentialDescriptor]>,
355359
rp_id: &str,
356-
_user_handle: Option<&[u8]>,
360+
user_handle: Option<&[u8]>,
357361
) -> Result<Vec<Self::PasskeyItem>, StatusCode> {
358362
#[derive(Debug, Error)]
359363
enum InnerError {
@@ -370,14 +374,15 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> {
370374
this: &CredentialStoreImpl<'_>,
371375
ids: Option<&[passkey::types::webauthn::PublicKeyCredentialDescriptor]>,
372376
rp_id: &str,
377+
user_handle: Option<&[u8]>,
373378
) -> Result<Vec<CipherViewContainer>, InnerError> {
374379
let ids: Option<Vec<Vec<u8>>> =
375380
ids.map(|ids| ids.iter().map(|id| id.id.clone().into()).collect());
376381

377382
let ciphers = this
378383
.authenticator
379384
.credential_store
380-
.find_credentials(ids, rp_id.to_string())
385+
.find_credentials(ids, rp_id.to_string(), user_handle.map(|h| h.to_vec()))
381386
.await?;
382387

383388
// Remove any that don't have Fido2 credentials
@@ -420,7 +425,7 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> {
420425
}
421426
}
422427

423-
inner(self, ids, rp_id).await.map_err(|error| {
428+
inner(self, ids, rp_id, user_handle).await.map_err(|error| {
424429
error!(%error, "Error finding credentials.");
425430
VendorError::try_from(0xF0)
426431
.expect("Valid vendor error code")

crates/bitwarden-fido/src/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait Fido2CredentialStore: Send + Sync {
4242
&self,
4343
ids: Option<Vec<Vec<u8>>>,
4444
rip_id: String,
45-
// TODO: Add user_handle
45+
user_handle: Option<Vec<u8>>,
4646
) -> Result<Vec<CipherView>, Fido2CallbackError>;
4747

4848
async fn all_credentials(&self) -> Result<Vec<CipherListView>, Fido2CallbackError>;

crates/bitwarden-uniffi/src/platform/fido2.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ impl ClientFido2Authenticator {
9292
pub async fn silently_discover_credentials(
9393
&self,
9494
rp_id: String,
95+
user_handle: Option<Vec<u8>>,
9596
) -> Result<Vec<Fido2CredentialAutofillView>> {
9697
let ui = UniffiTraitBridge(self.1.as_ref());
9798
let cs = UniffiTraitBridge(self.2.as_ref());
9899
let mut auth = self.0.create_authenticator(&ui, &cs);
99100

100101
let result = auth
101-
.silently_discover_credentials(rp_id)
102+
.silently_discover_credentials(rp_id, user_handle)
102103
.await
103104
.map_err(Error::SilentlyDiscoverCredentials)?;
104105
Ok(result)
@@ -241,6 +242,7 @@ pub trait Fido2CredentialStore: Send + Sync {
241242
&self,
242243
ids: Option<Vec<Vec<u8>>>,
243244
rip_id: String,
245+
user_handle: Option<Vec<u8>>,
244246
) -> Result<Vec<CipherView>, Fido2CallbackError>;
245247

246248
async fn all_credentials(&self) -> Result<Vec<CipherListView>, Fido2CallbackError>;
@@ -260,9 +262,10 @@ impl bitwarden_fido::Fido2CredentialStore for UniffiTraitBridge<&dyn Fido2Creden
260262
&self,
261263
ids: Option<Vec<Vec<u8>>>,
262264
rip_id: String,
265+
user_handle: Option<Vec<u8>>,
263266
) -> Result<Vec<CipherView>, BitFido2CallbackError> {
264267
self.0
265-
.find_credentials(ids, rip_id)
268+
.find_credentials(ids, rip_id, user_handle)
266269
.await
267270
.map_err(Into::into)
268271
}

0 commit comments

Comments
 (0)