Skip to content

Commit 18041b7

Browse files
authored
[PM-22136] Expose encrypt_fido2_credentials to support cipher encryption in TS clients (#331)
## 🎟️ Tracking [PM-22136](https://bitwarden.atlassian.net/browse/PM-22136) ## 📔 Objective The TS clients use fully decrypted FIDO2 credentials which need to be re-encrypted separately before using the SDK to encrypt the rest of the Cipher. Otherwise, the FIDO2 credential encryption key will be lost. Once the decrypted FIDO2 Credentials are removed from the LoginView in TS, this method can be removed. Related Clients PR: bitwarden/clients#15337 ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes [PM-22136]: https://bitwarden.atlassian.net/browse/PM-22136?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 5211667 commit 18041b7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

crates/bitwarden-vault/src/cipher/cipher_client.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use wasm_bindgen::prelude::*;
66
use super::EncryptionContext;
77
use crate::{
88
cipher::cipher::DecryptCipherListResult, Cipher, CipherError, CipherListView, CipherView,
9-
DecryptError, EncryptError,
9+
DecryptError, EncryptError, Fido2CredentialFullView,
1010
};
1111

1212
#[allow(missing_docs)]
@@ -82,6 +82,24 @@ impl CiphersClient {
8282
Ok(credentials)
8383
}
8484

85+
/// Temporary method used to re-encrypt FIDO2 credentials for a cipher view.
86+
/// Necessary until the TS clients utilize the SDK entirely for FIDO2 credentials management.
87+
/// TS clients create decrypted FIDO2 credentials that need to be encrypted manually when
88+
/// encrypting the rest of the CipherView.
89+
/// TODO: Remove once TS passkey provider implementation uses SDK - PM-8313
90+
#[cfg(feature = "wasm")]
91+
pub fn set_fido2_credentials(
92+
&self,
93+
mut cipher_view: CipherView,
94+
fido2_credentials: Vec<Fido2CredentialFullView>,
95+
) -> Result<CipherView, CipherError> {
96+
let key_store = self.client.internal.get_key_store();
97+
98+
cipher_view.set_new_fido2_credentials(&mut key_store.context(), fido2_credentials)?;
99+
100+
Ok(cipher_view)
101+
}
102+
85103
#[allow(missing_docs)]
86104
pub fn move_to_organization(
87105
&self,

crates/bitwarden-vault/src/cipher/login.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub struct Fido2CredentialView {
144144
#[allow(missing_docs)]
145145
#[derive(Serialize, Deserialize, Debug, Clone)]
146146
#[serde(rename_all = "camelCase", deny_unknown_fields)]
147+
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
147148
pub struct Fido2CredentialFullView {
148149
pub credential_id: String,
149150
pub key_type: String,

0 commit comments

Comments
 (0)