Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion crates/bitwarden-core/src/key_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub(crate) use non_generic_wrappers::*;
mod security_state;
#[cfg(feature = "internal")]
pub use security_state::{
MINIMUM_ENFORCE_ICON_URI_HASH_VERSION, SecurityState, SignedSecurityState,
MINIMUM_ENFORCE_CIPHER_KEY_ENCRYPTION_VERSION, MINIMUM_ENFORCE_ICON_URI_HASH_VERSION,
SecurityState, SignedSecurityState,
};
#[cfg(feature = "internal")]
mod user_decryption;
Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden-core/src/key_management/security_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use crate::UserId;

/// Icon URI hashes are enforced starting with this security state version.
pub const MINIMUM_ENFORCE_ICON_URI_HASH_VERSION: u64 = 2;
/// Cipher keys are part of the upgrade to v2 encryption. This version enforces their presence.
pub const MINIMUM_ENFORCE_CIPHER_KEY_ENCRYPTION_VERSION: u64 = 2;

#[cfg(feature = "wasm")]
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
Expand Down
13 changes: 10 additions & 3 deletions crates/bitwarden-vault/src/cipher/cipher_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bitwarden_core::{Client, OrganizationId, key_management::SymmetricKeyId};
use bitwarden_core::{
Client, OrganizationId,
key_management::{MINIMUM_ENFORCE_CIPHER_KEY_ENCRYPTION_VERSION, SymmetricKeyId},
};
use bitwarden_crypto::{CompositeEncryptable, IdentifyKey, SymmetricCryptoKey};
#[cfg(feature = "wasm")]
use bitwarden_encoding::B64;
Expand Down Expand Up @@ -31,11 +34,13 @@ impl CiphersClient {
// TODO: Once this flag is removed, the key generation logic should
// be moved directly into the KeyEncryptable implementation
if cipher_view.key.is_none()
&& self
&& (self
.client
.internal
.get_flags()
.enable_cipher_key_encryption
|| self.client.internal.get_security_version()
>= MINIMUM_ENFORCE_CIPHER_KEY_ENCRYPTION_VERSION)
{
let key = cipher_view.key_identifier();
cipher_view.generate_cipher_key(&mut key_store.context(), key)?;
Expand Down Expand Up @@ -80,11 +85,13 @@ impl CiphersClient {
ctx.set_symmetric_key(NEW_KEY_ID, new_key)?;

if cipher_view.key.is_none()
&& self
&& (self
.client
.internal
.get_flags()
.enable_cipher_key_encryption
|| self.client.internal.get_security_version()
>= MINIMUM_ENFORCE_CIPHER_KEY_ENCRYPTION_VERSION)
{
cipher_view.generate_cipher_key(&mut ctx, NEW_KEY_ID)?;
} else {
Expand Down
Loading