Skip to content

Commit

Permalink
Changes based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia committed May 14, 2024
1 parent 9e704a4 commit c21f94a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ getrandom = { version = ">=0.2.9, <0.3", features = ["js"] }
hmac = ">=0.12.1, <0.13"
log = ">=0.4.18, <0.5"
p256 = ">=0.13.2, <0.14"
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "12da886102707f87ad97e499c857c0857ece0b85", optional = true }
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "2df7838b8832322d309c399a4c0f6ca2979af12d", optional = true }
rand = ">=0.8.5, <0.9"
reqwest = { version = ">=0.12, <0.13", features = [
"http2",
Expand Down
36 changes: 18 additions & 18 deletions crates/bitwarden/src/platform/fido2/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'a> Fido2Authenticator<'a> {
&mut self,
request: MakeCredentialRequest,
) -> Result<MakeCredentialResult> {
let mut authenticator = self.get_passkey_authenticator();
let mut authenticator = self.get_authenticator();

Check warning on line 36 in crates/bitwarden/src/platform/fido2/authenticator.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/authenticator.rs#L36

Added line #L36 was not covered by tests

let response = authenticator
.make_credential(ctap2::make_credential::Request {

Check warning on line 39 in crates/bitwarden/src/platform/fido2/authenticator.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/authenticator.rs#L38-L39

Added lines #L38 - L39 were not covered by tests
Expand All @@ -51,22 +51,18 @@ impl<'a> Fido2Authenticator<'a> {
.pub_key_cred_params
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?,
.collect::<Result<_, _>>()?,

Check warning on line 54 in crates/bitwarden/src/platform/fido2/authenticator.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/authenticator.rs#L53-L54

Added lines #L53 - L54 were not covered by tests
exclude_list: request
.exclude_list
.map(|x| {
x.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()
})
.map(|x| x.into_iter().map(TryInto::try_into).collect())
.transpose()?,
extensions: request
.extensions
.map(|e| serde_json::from_str(&e))
.transpose()?,

Check warning on line 62 in crates/bitwarden/src/platform/fido2/authenticator.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/authenticator.rs#L57-L62

Added lines #L57 - L62 were not covered by tests
// TODO(Fido2): Where do we get these from?
options: passkey::types::ctap2::make_credential::Options {
rk: true,
rk: request.require_resident_key,

Check warning on line 65 in crates/bitwarden/src/platform/fido2/authenticator.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/authenticator.rs#L65

Added line #L65 was not covered by tests
up: true,
uv: true,
},
Expand Down Expand Up @@ -97,7 +93,7 @@ impl<'a> Fido2Authenticator<'a> {
&mut self,
request: GetAssertionRequest,
) -> Result<GetAssertionResult> {
let mut authenticator = self.get_passkey_authenticator();
let mut authenticator = self.get_authenticator();

Check warning on line 96 in crates/bitwarden/src/platform/fido2/authenticator.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/authenticator.rs#L96

Added line #L96 was not covered by tests

let response = authenticator
.get_assertion(ctap2::get_assertion::Request {
Expand All @@ -116,7 +112,6 @@ impl<'a> Fido2Authenticator<'a> {
.map(|e| serde_json::from_str(&e))
.transpose()?,
options: passkey::types::ctap2::make_credential::Options {
// TODO(Fido2): Are these right?
rk: request.options.rk,
up: true,
uv: request.options.uv != UV::Discouraged,
Expand Down Expand Up @@ -159,7 +154,7 @@ impl<'a> Fido2Authenticator<'a> {
.collect())

Check warning on line 154 in crates/bitwarden/src/platform/fido2/authenticator.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/authenticator.rs#L149-L154

Added lines #L149 - L154 were not covered by tests
}

pub(super) fn get_passkey_authenticator(
pub(super) fn get_authenticator(
&self,
) -> Authenticator<CredentialStoreImpl, UserValidationMethodImpl> {
Authenticator::new(
Expand Down Expand Up @@ -200,7 +195,6 @@ pub(super) struct UserValidationMethodImpl<'a> {
#[async_trait::async_trait]
impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> {
type PasskeyItem = CipherViewContainer;

async fn find_credentials(
&self,
ids: Option<&[passkey::types::webauthn::PublicKeyCredentialDescriptor]>,
Expand Down Expand Up @@ -258,22 +252,23 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> {
cred: Passkey,
user: passkey::types::ctap2::make_credential::PublicKeyCredentialUserEntity,
rp: passkey::types::ctap2::make_credential::PublicKeyCredentialRpEntity,
// TODO(Fido2): Use this
_options: passkey::types::ctap2::get_assertion::Options,
) -> Result<(), StatusCode> {
// This is just a wrapper around the actual implementation to allow for ? error handling
// TODO(Fido2): User is unused, do we need it?
async fn inner(
this: &mut CredentialStoreImpl<'_>,
cred: Passkey,
_user: passkey::types::ctap2::make_credential::PublicKeyCredentialUserEntity,
user: passkey::types::ctap2::make_credential::PublicKeyCredentialUserEntity,
rp: passkey::types::ctap2::make_credential::PublicKeyCredentialRpEntity,
) -> Result<()> {
let creds = this
.authenticator
.credential_store
.find_credentials(None, rp.id)
.find_credentials(None, rp.id.clone())
.await?;

let cred: Fido2CredentialFullView = cred.clone().try_into()?;
let cred = Fido2CredentialFullView::try_from_credential(cred, user, rp)?;

let mut picked = this
.authenticator
Expand Down Expand Up @@ -322,9 +317,14 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> {
.await?;

// Get the credential with the same id as the one we're updating
// TODO(Fido2): Is this the right id to check?
creds.retain(|c| {
c.id.map(|i| i.as_bytes().as_slice() == cred.credential_id.deref())
c.login
.as_ref()
.and_then(|l| l.fido2_credentials.as_ref())
.and_then(|f| f.first())
.map(|cipher_cred| {
cipher_cred.credential_id.expose().as_bytes() == cred.credential_id.deref()
})
.unwrap_or(false)
});
let cred = match creds.len() {
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden/src/platform/fido2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'a> Fido2Client<'a> {
client_data: ClientData,
) -> Result<PublicKeyCredentialAuthenticatorAttestationResponse> {
let mut client =
passkey::client::Client::new(self.authenticator.get_passkey_authenticator());
passkey::client::Client::new(self.authenticator.get_authenticator());

Check warning on line 26 in crates/bitwarden/src/platform/fido2/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/client.rs#L25-L26

Added lines #L25 - L26 were not covered by tests

// TODO(Fido2): Handle this error

Check warning on line 28 in crates/bitwarden/src/platform/fido2/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/client.rs#L28

Added line #L28 was not covered by tests
let origin = Url::parse(&origin).expect("Invalid URL");
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<'a> Fido2Client<'a> {
client_data: ClientData,
) -> Result<PublicKeyCredentialAuthenticatorAssertionResponse> {
let mut client =
passkey::client::Client::new(self.authenticator.get_passkey_authenticator());
passkey::client::Client::new(self.authenticator.get_authenticator());

Check warning on line 72 in crates/bitwarden/src/platform/fido2/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/client.rs#L71-L72

Added lines #L71 - L72 were not covered by tests

// TODO(Fido2): Handle this error

Check warning on line 74 in crates/bitwarden/src/platform/fido2/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/client.rs#L74

Added line #L74 was not covered by tests
let origin = Url::parse(&origin).expect("Invalid URL");
Expand Down
16 changes: 9 additions & 7 deletions crates/bitwarden/src/platform/fido2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ impl TryFrom<Fido2CredentialFullView> for Passkey {
}

Check warning on line 120 in crates/bitwarden/src/platform/fido2/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/mod.rs#L120

Added line #L120 was not covered by tests
}

impl TryFrom<Passkey> for Fido2CredentialFullView {
type Error = crate::error::Error;

fn try_from(value: Passkey) -> Result<Self, Self::Error> {
impl Fido2CredentialFullView {
pub(crate) fn try_from_credential(
value: Passkey,
user: passkey::types::ctap2::make_credential::PublicKeyCredentialUserEntity,
rp: passkey::types::ctap2::make_credential::PublicKeyCredentialRpEntity,
) -> Result<Self> {
let cred_id: Vec<u8> = value.credential_id.into();

Ok(Fido2CredentialFullView {
Expand All @@ -133,14 +135,14 @@ impl TryFrom<Passkey> for Fido2CredentialFullView {
key_curve: SensitiveString::new(Box::new("P-256".to_owned())),
key_value: SensitiveVec::new(Box::new(cose_key_to_pkcs8(&value.key)?)),
rp_id: SensitiveString::new(Box::new(value.rp_id)),
rp_name: None,
rp_name: rp.name.map(|n| SensitiveString::new(Box::new(n))),
user_handle: Some(SensitiveVec::new(Box::new(cred_id))),

// TODO(Fido2): Storing the counter as a string seems like a bad idea, but we don't have
// support for EncString -> number decryption
counter: SensitiveString::new(Box::new(value.counter.unwrap_or(0).to_string())),
user_name: None,
user_display_name: None,
user_name: user.name.map(|n| SensitiveString::new(Box::new(n))),
user_display_name: user.display_name.map(|n| SensitiveString::new(Box::new(n))),
// TODO(Fido2): Same as the counter, but with booleans this time
discoverable: SensitiveString::new(Box::new("true".to_owned())),
creation_date: chrono::offset::Utc::now(),

Check warning on line 148 in crates/bitwarden/src/platform/fido2/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/mod.rs#L124-L148

Added lines #L124 - L148 were not covered by tests
Expand Down

0 comments on commit c21f94a

Please sign in to comment.