Skip to content
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

[PM-6761] Add fido credentials to data model #657

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions crates/bitwarden/src/tool/exporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ mod tests {
uris: None,
totp: None,
autofill_on_page_load: None,
fido2_credentials: None,
}),
id: "fd411a1a-fec8-4070-985d-0e6560860e69".parse().ok(),
organization_id: None,
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden/src/vault/cipher/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ mod tests {
uris: None,
totp: None,
autofill_on_page_load: None,
fido2_credentials: None,
}),
id: "fd411a1a-fec8-4070-985d-0e6560860e69".parse().ok(),
organization_id: None,
Expand Down
56 changes: 56 additions & 0 deletions crates/bitwarden/src/vault/cipher/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@
pub r#match: Option<UriMatchType>,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]

Check warning on line 41 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L41

Added line #L41 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]

Check warning on line 43 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L43

Added line #L43 was not covered by tests
pub struct Fido2Credential {
pub credential_id: EncString,
pub key_type: EncString,
pub key_algorithm: EncString,
pub key_curve: EncString,
pub key_value: EncString,
pub rp_id: EncString,
pub user_handle: Option<EncString>,
pub user_name: Option<EncString>,
pub counter: EncString,
pub rp_name: Option<EncString>,
pub user_display_name: Option<EncString>,
Hinton marked this conversation as resolved.
Show resolved Hide resolved
pub discoverable: EncString,
pub creation_date: DateTime<Utc>,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
Expand All @@ -49,6 +68,8 @@
pub uris: Option<Vec<LoginUri>>,
pub totp: Option<EncString>,
pub autofill_on_page_load: Option<bool>,

pub fido2_credentials: Option<Vec<Fido2Credential>>,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
Expand All @@ -62,6 +83,9 @@
pub uris: Option<Vec<LoginUriView>>,
pub totp: Option<String>,
pub autofill_on_page_load: Option<bool>,

// TODO: Remove this once the SDK supports state
pub fido2_credentials: Option<Vec<Fido2Credential>>,
Comment on lines +87 to +88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ question: I'm curious why? Would it move somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely you wouldn't expose this in the view. Instead you fetch the old entry from state and update values on it. That way you don't have to expose encrypted passkeys in the view.

}

impl KeyEncryptable<SymmetricCryptoKey, LoginUri> for LoginUriView {
Expand All @@ -82,6 +106,7 @@
uris: self.uris.encrypt_with_key(key)?,
totp: self.totp.encrypt_with_key(key)?,
autofill_on_page_load: self.autofill_on_page_load,
fido2_credentials: self.fido2_credentials,
})
}
}
Expand All @@ -104,6 +129,7 @@
uris: self.uris.decrypt_with_key(key).ok().flatten(),
totp: self.totp.decrypt_with_key(key).ok().flatten(),
autofill_on_page_load: self.autofill_on_page_load,
fido2_credentials: self.fido2_credentials.as_ref().map(|v| v.to_vec()),
Hinton marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
Expand All @@ -125,6 +151,10 @@
.transpose()?,
totp: EncString::try_from_optional(login.totp)?,
autofill_on_page_load: login.autofill_on_page_load,
fido2_credentials: login
.fido2_credentials
.map(|v| v.into_iter().map(|c| c.try_into()).collect())
.transpose()?,

Check warning on line 157 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L154-L157

Added lines #L154 - L157 were not covered by tests
})
}
}
Expand Down Expand Up @@ -152,3 +182,29 @@
}
}
}

impl TryFrom<bitwarden_api_api::models::CipherFido2CredentialModel> for Fido2Credential {
type Error = Error;

fn try_from(value: bitwarden_api_api::models::CipherFido2CredentialModel) -> Result<Self> {
Ok(Self {
credential_id: value.credential_id.ok_or(Error::MissingFields)?.parse()?,
key_type: value.key_type.ok_or(Error::MissingFields)?.parse()?,
key_algorithm: value.key_algorithm.ok_or(Error::MissingFields)?.parse()?,
key_curve: value.key_curve.ok_or(Error::MissingFields)?.parse()?,
key_value: value.key_value.ok_or(Error::MissingFields)?.parse()?,
rp_id: value.rp_id.ok_or(Error::MissingFields)?.parse()?,
user_handle: EncString::try_from_optional(value.user_handle)
.ok()
.flatten(),
user_name: EncString::try_from_optional(value.user_name).ok().flatten(),
counter: value.counter.ok_or(Error::MissingFields)?.parse()?,
rp_name: EncString::try_from_optional(value.rp_name).ok().flatten(),
user_display_name: EncString::try_from_optional(value.user_display_name)
.ok()
.flatten(),
discoverable: value.discoverable.ok_or(Error::MissingFields)?.parse()?,
creation_date: value.creation_date.parse().unwrap(),

Check warning on line 207 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L189-L207

Added lines #L189 - L207 were not covered by tests
})
}

Check warning on line 209 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L209

Added line #L209 was not covered by tests
}
Loading