Skip to content

Commit 4e5cb4a

Browse files
committed
fido: Add user handle to credential search parameters
1 parent 5accd9b commit 4e5cb4a

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bitwarden-fido/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ chrono = { workspace = true }
2727
coset = ">=0.3.7, <0.4"
2828
itertools = ">=0.13.0, <0.15"
2929
p256 = ">=0.13.2, <0.14"
30-
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "eddb5d5599c81a0674f37e5f2935eb7ec4e9e423" }
31-
passkey-client = { git = "https://github.com/bitwarden/passkey-rs", rev = "eddb5d5599c81a0674f37e5f2935eb7ec4e9e423", features = [
30+
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "739d10d34e66a8dfaa16fc8ca15189950a43eb16" }
31+
passkey-client = { git = "https://github.com/bitwarden/passkey-rs", rev = "739d10d34e66a8dfaa16fc8ca15189950a43eb16", features = [
3232
"android-asset-validation",
3333
] }
3434
reqwest = { workspace = true }

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)