Skip to content

Commit 0b8bd33

Browse files
committed
Improvements to Passkey uniffi API
1 parent c54a360 commit 0b8bd33

File tree

18 files changed

+1168
-530
lines changed

18 files changed

+1168
-530
lines changed

Cargo.lock

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

crates/bitwarden-crypto/src/uniffi_support.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::{num::NonZeroU32, str::FromStr};
22

33
use crate::{
4-
AsymmetricEncString, CryptoError, EncString, SensitiveString, UniffiCustomTypeConverter,
4+
AsymmetricEncString, CryptoError, EncString, SensitiveString, SensitiveVec,
5+
UniffiCustomTypeConverter,
56
};
67

78
uniffi::custom_type!(NonZeroU32, u32);
@@ -59,3 +60,17 @@ impl UniffiCustomTypeConverter for SensitiveString {
5960
obj.expose().to_owned()
6061
}
6162
}
63+
64+
uniffi::custom_type!(SensitiveVec, Vec<u8>);
65+
66+
impl UniffiCustomTypeConverter for SensitiveVec {
67+
type Builtin = Vec<u8>;
68+
69+
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
70+
Ok(SensitiveVec::new(Box::new(val)))
71+
}
72+
73+
fn from_custom(obj: Self) -> Self::Builtin {
74+
obj.expose().to_owned()
75+
}
76+
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bitwarden::{
88
PublicKeyCredentialAuthenticatorAssertionResponse,
99
PublicKeyCredentialAuthenticatorAttestationResponse,
1010
},
11-
vault::{Cipher, CipherView, Fido2Credential, Fido2CredentialView},
11+
vault::{Cipher, CipherView, Fido2CredentialNewView, Fido2CredentialView},
1212
};
1313

1414
use crate::{error::Result, Client};
@@ -162,12 +162,12 @@ pub trait UserInterface: Send + Sync {
162162
) -> Result<CheckUserResult>;
163163
async fn pick_credential_for_authentication(
164164
&self,
165-
available_credentials: Vec<Cipher>,
165+
available_credentials: Vec<CipherView>,
166166
) -> Result<CipherViewWrapper>;
167167
async fn pick_credential_for_creation(
168168
&self,
169-
available_credentials: Vec<Cipher>,
170-
new_credential: Fido2Credential,
169+
available_credentials: Vec<CipherView>,
170+
new_credential: Fido2CredentialNewView,
171171
) -> Result<CipherViewWrapper>;
172172
}
173173

@@ -178,7 +178,7 @@ pub trait CredentialStore: Send + Sync {
178178
&self,
179179
ids: Option<Vec<Vec<u8>>>,
180180
rip_id: String,
181-
) -> Result<Vec<Cipher>>;
181+
) -> Result<Vec<CipherView>>;
182182

183183
async fn save_credential(&self, cred: Cipher) -> Result<()>;
184184
}
@@ -195,7 +195,7 @@ impl bitwarden::platform::fido2::CredentialStore for UniffiTraitBridge<&dyn Cred
195195
&self,
196196
ids: Option<Vec<Vec<u8>>>,
197197
rip_id: String,
198-
) -> BitResult<Vec<Cipher>> {
198+
) -> BitResult<Vec<CipherView>> {
199199
self.0
200200
.find_credentials(ids, rip_id)
201201
.await
@@ -234,7 +234,7 @@ impl bitwarden::platform::fido2::UserInterface for UniffiTraitBridge<&dyn UserIn
234234
}
235235
async fn pick_credential_for_authentication(
236236
&self,
237-
available_credentials: Vec<Cipher>,
237+
available_credentials: Vec<CipherView>,
238238
) -> BitResult<CipherView> {
239239
self.0
240240
.pick_credential_for_authentication(available_credentials)
@@ -244,8 +244,8 @@ impl bitwarden::platform::fido2::UserInterface for UniffiTraitBridge<&dyn UserIn
244244
}
245245
async fn pick_credential_for_creation(
246246
&self,
247-
available_credentials: Vec<Cipher>,
248-
new_credential: Fido2Credential,
247+
available_credentials: Vec<CipherView>,
248+
new_credential: Fido2CredentialNewView,
249249
) -> BitResult<CipherView> {
250250
self.0
251251
.pick_credential_for_creation(available_credentials, new_credential)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bitwarden_crypto::{AsymmetricEncString, EncString, SensitiveString};
1+
use bitwarden_crypto::{AsymmetricEncString, EncString, SensitiveString, SensitiveVec};
22
use uuid::Uuid;
33

44
// Forward the type definitions to the main bitwarden crate
@@ -7,4 +7,5 @@ uniffi::ffi_converter_forward!(DateTime, bitwarden::UniFfiTag, crate::UniFfiTag)
77
uniffi::ffi_converter_forward!(EncString, bitwarden::UniFfiTag, crate::UniFfiTag);
88
uniffi::ffi_converter_forward!(AsymmetricEncString, bitwarden::UniFfiTag, crate::UniFfiTag);
99
uniffi::ffi_converter_forward!(SensitiveString, bitwarden::UniFfiTag, crate::UniFfiTag);
10+
uniffi::ffi_converter_forward!(SensitiveVec, bitwarden::UniFfiTag, crate::UniFfiTag);
1011
uniffi::ffi_converter_forward!(Uuid, bitwarden::UniFfiTag, crate::UniFfiTag);

crates/bitwarden/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ internal = [
2424
mobile = [
2525
"internal",
2626
"dep:uniffi",
27+
"dep:passkey",
28+
"dep:coset",
2729
"bitwarden-crypto/mobile",
2830
"bitwarden-generators/mobile",
2931
] # Mobile-specific features
@@ -43,11 +45,13 @@ chrono = { version = ">=0.4.26, <0.5", features = [
4345
"serde",
4446
"std",
4547
], default-features = false }
48+
coset = { version = "0.3.7", optional = true }
4649
# We don't use this directly (it's used by rand), but we need it here to enable WASM support
4750
getrandom = { version = ">=0.2.9, <0.3", features = ["js"] }
4851
hmac = ">=0.12.1, <0.13"
4952
log = ">=0.4.18, <0.5"
50-
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "12da886102707f87ad97e499c857c0857ece0b85" }
53+
p256 = ">=0.13.2, <0.14"
54+
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "12da886102707f87ad97e499c857c0857ece0b85", optional = true }
5155
rand = ">=0.8.5, <0.9"
5256
reqwest = { version = ">=0.12, <0.13", features = [
5357
"http2",

crates/bitwarden/src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use bitwarden_api_identity::apis::Error as IdentityError;
88
use bitwarden_exporters::ExportError;
99
#[cfg(feature = "internal")]
1010
use bitwarden_generators::{PassphraseError, PasswordError, UsernameError};
11+
#[cfg(feature = "mobile")]
1112
use passkey::client::WebauthnError;
1213
use reqwest::StatusCode;
1314
use thiserror::Error;
@@ -69,8 +70,9 @@ pub enum Error {
6970
#[error(transparent)]
7071
ExportError(#[from] ExportError),
7172

73+
#[cfg(feature = "mobile")]
7274
#[error("Webauthn error: {0:?}")]
73-
WebauthnError(passkey::client::WebauthnError),
75+
WebauthnError(WebauthnError),
7476

7577
#[cfg(feature = "mobile")]
7678
#[error("Uniffi callback error: {0}")]
@@ -80,6 +82,7 @@ pub enum Error {
8082
Internal(Cow<'static, str>),
8183
}
8284

85+
#[cfg(feature = "mobile")]
8386
impl From<WebauthnError> for Error {
8487
fn from(e: WebauthnError) -> Self {
8588
Self::WebauthnError(e)

crates/bitwarden/src/platform/client_platform.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
#[cfg(feature = "mobile")]
2+
use super::ClientFido2;
13
use super::{
24
generate_fingerprint::{generate_fingerprint, generate_user_fingerprint},
3-
ClientFido2, FingerprintRequest, FingerprintResponse,
5+
FingerprintRequest, FingerprintResponse,
46
};
57
use crate::{error::Result, Client};
68

@@ -19,6 +21,7 @@ impl<'a> ClientPlatform<'a> {
1921

2022
/// At the moment this is just a stub implementation that doesn't do anything. It's here to make
2123
/// it possible to check the usability API on the native clients.
24+
#[cfg(feature = "mobile")]
2225
pub fn fido2(&'a mut self) -> ClientFido2<'a> {
2326
ClientFido2 {
2427
client: self.client,

0 commit comments

Comments
 (0)