Skip to content

[PM-7840] Implement the stubbed out Passkey uniffi API #779

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

Merged
merged 41 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
419101d
Improvements to Passkey uniffi API
dani-garcia May 3, 2024
d2041a3
Here we go again with the uniffi workaround
dani-garcia May 13, 2024
07642dc
Remove stub credential
dani-garcia May 13, 2024
9e704a4
Add a warning about silent discover
dani-garcia May 13, 2024
c21f94a
Changes based on review
dani-garcia May 14, 2024
26a3c63
Fmt
dani-garcia May 14, 2024
16b8b03
Change API based on latest spec
dani-garcia May 14, 2024
27ca115
Update passkey-rs and respect the UV value provided in get_assertion …
dani-garcia May 14, 2024
c63d806
Update passkey-rs for async is_verification_enabled
dani-garcia May 14, 2024
82dac1b
Merge branch 'main' into ps/uniffi-passkey-improvements
dani-garcia May 14, 2024
3a82eec
Handle URL parse error
dani-garcia May 14, 2024
77f07a0
Return valid authenticator data
dani-garcia May 14, 2024
499ebb9
Use valid error codes
dani-garcia May 14, 2024
5478d3c
Merge branch 'main' into ps/uniffi-passkey-improvements
dani-garcia May 14, 2024
3a03ba5
Remove unneeded require_resident_key field
dani-garcia May 15, 2024
2832bcf
Change where we transform UV (#786)
coroiu May 15, 2024
ad3e4de
Actually call pick_credential_for_authentication
dani-garcia May 15, 2024
1e8c37f
Remove crypto copied from passkey-rs
dani-garcia May 17, 2024
55938d6
Fix some review comments
dani-garcia May 17, 2024
aa48fce
Implement UIHint
dani-garcia May 20, 2024
ea7ca9e
Formatting
dani-garcia May 20, 2024
e537b6f
Merge branch 'main' into ps/uniffi-passkey-improvements
dani-garcia May 23, 2024
1d90784
Improve error handling, don't panic when an exception is thrown
dani-garcia May 23, 2024
54f511a
Make p256 optional
dani-garcia May 23, 2024
01b12f1
Improve ClientData comment
dani-garcia May 23, 2024
5c5c386
Update swift example
dani-garcia May 23, 2024
10fa9f7
Merge branch 'main' into ps/uniffi-passkey-improvements
dani-garcia May 24, 2024
2a448bd
Remove some todos
dani-garcia May 24, 2024
a7b21d3
Remove some more todos
dani-garcia May 24, 2024
8caaeed
requested_uv and uv conversion
dani-garcia May 24, 2024
5143d1d
Remove comments
dani-garcia May 27, 2024
c9fa74b
Merge branch 'main' into ps/uniffi-passkey-improvements
dani-garcia May 29, 2024
432e06a
Remove some unnecessary locks and takes
dani-garcia May 29, 2024
99b7f56
Simplify ClientData
dani-garcia May 29, 2024
7a4b8b1
Update pick_credential_for_creation, move functions to check_user, in…
dani-garcia May 30, 2024
2d297b7
Support b64 credential IDs
dani-garcia May 30, 2024
acafb94
Merge branch 'main' into ps/uniffi-passkey-improvements
dani-garcia Jun 3, 2024
7a2680f
Update iOS example
dani-garcia Jun 3, 2024
e111192
Merge branch 'main' into ps/uniffi-passkey-improvements
dani-garcia Jun 3, 2024
75dc8d3
Update passkey-rs
dani-garcia Jun 3, 2024
f852dbf
Validate that the provided credential ID matches what is stored
dani-garcia Jun 4, 2024
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion crates/bitwarden-crypto/src/uniffi_support.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{num::NonZeroU32, str::FromStr};

use crate::{
AsymmetricEncString, CryptoError, EncString, SensitiveString, UniffiCustomTypeConverter,
AsymmetricEncString, CryptoError, EncString, SensitiveString, SensitiveVec,
UniffiCustomTypeConverter,
};

uniffi::custom_type!(NonZeroU32, u32);
Expand Down Expand Up @@ -59,3 +60,24 @@
obj.expose().to_owned()
}
}

uniffi::custom_type!(SensitiveVec, Vec<u8>);

impl UniffiCustomTypeConverter for SensitiveVec {
type Builtin = Vec<u8>;

fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
Ok(SensitiveVec::new(Box::new(val)))
}

Check warning on line 71 in crates/bitwarden-crypto/src/uniffi_support.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-crypto/src/uniffi_support.rs#L69-L71

Added lines #L69 - L71 were not covered by tests

fn from_custom(obj: Self) -> Self::Builtin {
obj.expose().to_owned()
}

Check warning on line 75 in crates/bitwarden-crypto/src/uniffi_support.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-crypto/src/uniffi_support.rs#L73-L75

Added lines #L73 - L75 were not covered by tests
}

/// Uniffi doesn't seem to be generating the SensitiveVec unless it's being used by
/// a record somewhere. This is a workaround to make sure the type is generated.
#[derive(uniffi::Record)]
struct SupportSensitiveVec {
sensitive_string: SensitiveVec,
}
18 changes: 9 additions & 9 deletions crates/bitwarden-uniffi/src/platform/fido2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PublicKeyCredentialAuthenticatorAssertionResponse,
PublicKeyCredentialAuthenticatorAttestationResponse,
},
vault::{Cipher, CipherView, Fido2Credential, Fido2CredentialView},
vault::{Cipher, CipherView, Fido2CredentialNewView, Fido2CredentialView},
};

use crate::{error::Result, Client};
Expand Down Expand Up @@ -162,12 +162,12 @@
) -> Result<CheckUserResult>;
async fn pick_credential_for_authentication(
&self,
available_credentials: Vec<Cipher>,
available_credentials: Vec<CipherView>,
) -> Result<CipherViewWrapper>;
async fn pick_credential_for_creation(
&self,
available_credentials: Vec<Cipher>,
new_credential: Fido2Credential,
available_credentials: Vec<CipherView>,
new_credential: Fido2CredentialNewView,
) -> Result<CipherViewWrapper>;
}

Expand All @@ -178,7 +178,7 @@
&self,
ids: Option<Vec<Vec<u8>>>,
rip_id: String,
) -> Result<Vec<Cipher>>;
) -> Result<Vec<CipherView>>;

async fn save_credential(&self, cred: Cipher) -> Result<()>;
}
Expand All @@ -195,7 +195,7 @@
&self,
ids: Option<Vec<Vec<u8>>>,
rip_id: String,
) -> BitResult<Vec<Cipher>> {
) -> BitResult<Vec<CipherView>> {

Check warning on line 198 in crates/bitwarden-uniffi/src/platform/fido2.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L198 was not covered by tests
self.0
.find_credentials(ids, rip_id)
.await
Expand Down Expand Up @@ -234,7 +234,7 @@
}
async fn pick_credential_for_authentication(
&self,
available_credentials: Vec<Cipher>,
available_credentials: Vec<CipherView>,
) -> BitResult<CipherView> {
self.0
.pick_credential_for_authentication(available_credentials)
Expand All @@ -244,8 +244,8 @@
}
async fn pick_credential_for_creation(
&self,
available_credentials: Vec<Cipher>,
new_credential: Fido2Credential,
available_credentials: Vec<CipherView>,
new_credential: Fido2CredentialNewView,
) -> BitResult<CipherView> {
self.0
.pick_credential_for_creation(available_credentials, new_credential)
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden-uniffi/src/uniffi_support.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bitwarden_crypto::{AsymmetricEncString, EncString, SensitiveString};
use bitwarden_crypto::{AsymmetricEncString, EncString, SensitiveString, SensitiveVec};
use uuid::Uuid;

// Forward the type definitions to the main bitwarden crate
Expand All @@ -7,4 +7,5 @@ uniffi::ffi_converter_forward!(DateTime, bitwarden::UniFfiTag, crate::UniFfiTag)
uniffi::ffi_converter_forward!(EncString, bitwarden::UniFfiTag, crate::UniFfiTag);
uniffi::ffi_converter_forward!(AsymmetricEncString, bitwarden::UniFfiTag, crate::UniFfiTag);
uniffi::ffi_converter_forward!(SensitiveString, bitwarden::UniFfiTag, crate::UniFfiTag);
uniffi::ffi_converter_forward!(SensitiveVec, bitwarden::UniFfiTag, crate::UniFfiTag);
uniffi::ffi_converter_forward!(Uuid, bitwarden::UniFfiTag, crate::UniFfiTag);
6 changes: 5 additions & 1 deletion crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal = [
mobile = [
"internal",
"dep:uniffi",
"dep:passkey",
"dep:coset",
"bitwarden-crypto/mobile",
"bitwarden-generators/mobile",
] # Mobile-specific features
Expand All @@ -43,11 +45,13 @@ chrono = { version = ">=0.4.26, <0.5", features = [
"serde",
"std",
], default-features = false }
coset = { version = "0.3.7", optional = true }
# We don't use this directly (it's used by rand), but we need it here to enable WASM support
getrandom = { version = ">=0.2.9, <0.3", features = ["js"] }
hmac = ">=0.12.1, <0.13"
log = ">=0.4.18, <0.5"
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "12da886102707f87ad97e499c857c0857ece0b85" }
p256 = ">=0.13.2, <0.14"
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "12da886102707f87ad97e499c857c0857ece0b85", optional = true }
rand = ">=0.8.5, <0.9"
reqwest = { version = ">=0.12, <0.13", features = [
"http2",
Expand Down
5 changes: 4 additions & 1 deletion crates/bitwarden/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use bitwarden_api_identity::apis::Error as IdentityError;
use bitwarden_exporters::ExportError;
#[cfg(feature = "internal")]
use bitwarden_generators::{PassphraseError, PasswordError, UsernameError};
#[cfg(feature = "mobile")]
use passkey::client::WebauthnError;
use reqwest::StatusCode;
use thiserror::Error;
Expand Down Expand Up @@ -69,8 +70,9 @@ pub enum Error {
#[error(transparent)]
ExportError(#[from] ExportError),

#[cfg(feature = "mobile")]
#[error("Webauthn error: {0:?}")]
WebauthnError(passkey::client::WebauthnError),
WebauthnError(WebauthnError),

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

#[cfg(feature = "mobile")]
impl From<WebauthnError> for Error {
fn from(e: WebauthnError) -> Self {
Self::WebauthnError(e)
Expand Down
5 changes: 4 additions & 1 deletion crates/bitwarden/src/platform/client_platform.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(feature = "mobile")]
use super::ClientFido2;
use super::{
generate_fingerprint::{generate_fingerprint, generate_user_fingerprint},
ClientFido2, FingerprintRequest, FingerprintResponse,
FingerprintRequest, FingerprintResponse,
};
use crate::{error::Result, Client};

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

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