Skip to content

Commit 6c8b739

Browse files
committed
chore(vault): unconditionally enable cipher-keys
1 parent 39f49d0 commit 6c8b739

11 files changed

Lines changed: 57 additions & 126 deletions

File tree

crates/bitwarden-core/src/client/flags.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
1010
#[serde(default, rename_all = "kebab-case")]
1111
pub struct Flags {
12-
/// Enable cipher key encryption.
13-
#[serde(alias = "enableCipherKeyEncryption", alias = "cipher-key-encryption")]
14-
pub enable_cipher_key_encryption: bool,
15-
1612
/// Enable strict cipher field decryption (propagates errors instead of nulling fields).
1713
#[serde(alias = "pm-34500-strict-cipher-decryption")]
1814
pub strict_cipher_decryption: bool,
@@ -41,30 +37,30 @@ mod tests {
4137
fn test_load_empty_map() {
4238
let map = std::collections::HashMap::new();
4339
let flags = Flags::load_from_map(map);
44-
assert!(!flags.enable_cipher_key_encryption);
40+
assert!(!flags.strict_cipher_decryption);
4541
}
4642

4743
#[test]
4844
fn test_load_valid_map() {
4945
let mut map = std::collections::HashMap::new();
50-
map.insert("enableCipherKeyEncryption".into(), true);
46+
map.insert("strict-cipher-decryption".into(), true);
5147
let flags = Flags::load_from_map(map);
52-
assert!(flags.enable_cipher_key_encryption);
48+
assert!(flags.strict_cipher_decryption);
5349
}
5450

5551
#[test]
5652
fn test_load_valid_map_alias() {
5753
let mut map = std::collections::HashMap::new();
58-
map.insert("cipher-key-encryption".into(), true);
54+
map.insert("pm-34500-strict-cipher-decryption".into(), true);
5955
let flags = Flags::load_from_map(map);
60-
assert!(flags.enable_cipher_key_encryption);
56+
assert!(flags.strict_cipher_decryption);
6157
}
6258

6359
#[test]
6460
fn test_load_invalid_map() {
6561
let mut map = std::collections::HashMap::new();
6662
map.insert("thisIsNotAFlag".into(), true);
6763
let flags = Flags::load_from_map(map);
68-
assert!(!flags.enable_cipher_key_encryption);
64+
assert!(!flags.strict_cipher_decryption);
6965
}
7066
}

crates/bitwarden-core/src/client/flags_client.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,15 @@ mod tests {
158158

159159
// With no flags loaded yet, get should return defaults.
160160
let initial = client.flags().get().await;
161-
assert!(!initial.enable_cipher_key_encryption);
162161
assert!(!initial.strict_cipher_decryption);
163162

164163
// Loading flags should persist them via the FLAGS setting.
165164
let mut map = HashMap::new();
166-
map.insert("enableCipherKeyEncryption".to_string(), true);
167165
map.insert("pm-34500-strict-cipher-decryption".to_string(), true);
168166
client.flags().load(map).await;
169167

170168
// get should now return the loaded values.
171169
let loaded = client.flags().get().await;
172-
assert!(loaded.enable_cipher_key_encryption);
173170
assert!(loaded.strict_cipher_decryption);
174171

175172
// The values should be readable directly from the setting too.
@@ -182,7 +179,6 @@ mod tests {
182179
.await
183180
.unwrap()
184181
.expect("flags should be persisted after load");
185-
assert!(persisted.enable_cipher_key_encryption);
186182
assert!(persisted.strict_cipher_decryption);
187183
}
188184

@@ -192,7 +188,7 @@ mod tests {
192188
Mock::given(method("GET"))
193189
.and(path("/config"))
194190
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
195-
"featureStates": { "enableCipherKeyEncryption": true }
191+
"featureStates": { "pm-34500-strict-cipher-decryption": true }
196192
})))
197193
.expect(1)
198194
.mount(&server)
@@ -202,7 +198,7 @@ mod tests {
202198
let before = Utc::now();
203199
client.flags().fetch(true).await.unwrap();
204200

205-
assert!(client.flags().get().await.enable_cipher_key_encryption);
201+
assert!(client.flags().get().await.strict_cipher_decryption);
206202
let fetched_at = read_fetched_at(&client)
207203
.await
208204
.expect("fetched_at must be set after a successful fetch");
@@ -247,7 +243,7 @@ mod tests {
247243
Mock::given(method("GET"))
248244
.and(path("/config"))
249245
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
250-
"featureStates": { "enableCipherKeyEncryption": true }
246+
"featureStates": { "pm-34500-strict-cipher-decryption": true }
251247
})))
252248
.expect(1)
253249
.mount(&server)
@@ -259,7 +255,7 @@ mod tests {
259255

260256
client.flags().fetch(false).await.unwrap();
261257

262-
assert!(client.flags().get().await.enable_cipher_key_encryption);
258+
assert!(client.flags().get().await.strict_cipher_decryption);
263259
let fetched_at = read_fetched_at(&client).await.unwrap();
264260
assert!(fetched_at > stale);
265261
}
@@ -277,14 +273,14 @@ mod tests {
277273
client
278274
.flags()
279275
.load(HashMap::from([(
280-
"enableCipherKeyEncryption".to_string(),
276+
"pm-34500-strict-cipher-decryption".to_string(),
281277
true,
282278
)]))
283279
.await;
284280

285281
assert!(client.flags().fetch(true).await.is_err());
286282
assert!(
287-
client.flags().get().await.enable_cipher_key_encryption,
283+
client.flags().get().await.strict_cipher_decryption,
288284
"previously persisted flags must survive a failed fetch"
289285
);
290286
}

crates/bitwarden-core/src/client/test_accounts.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ impl Client {
4242
pub async fn init_test_account(account: TestAccount) -> Self {
4343
let client = Client::new_test(None);
4444

45-
client
46-
.flags()
47-
.load(HashMap::from([(
48-
"enableCipherKeyEncryption".to_owned(),
49-
true,
50-
)]))
51-
.await;
52-
5345
client
5446
.crypto()
5547
.initialize_user_crypto(account.user)

crates/bitwarden-fido/src/authenticator.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,7 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> {
497497
.client
498498
.vault()
499499
.ciphers()
500-
.encrypt(selected)
501-
.await?;
500+
.encrypt(selected)?;
502501

503502
this.authenticator
504503
.credential_store
@@ -572,8 +571,7 @@ impl passkey::authenticator::CredentialStore for CredentialStoreImpl<'_> {
572571
.client
573572
.vault()
574573
.ciphers()
575-
.encrypt(selected)
576-
.await?;
574+
.encrypt(selected)?;
577575

578576
this.authenticator
579577
.credential_store

crates/bitwarden-uniffi/src/vault/ciphers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub struct CiphersClient(pub(crate) bitwarden_vault::CiphersClient);
1414
#[uniffi::export(async_runtime = "tokio")]
1515
impl CiphersClient {
1616
/// Encrypt cipher
17-
pub async fn encrypt(&self, cipher_view: CipherView) -> Result<EncryptionContext> {
18-
Ok(self.0.encrypt(cipher_view).await?)
17+
pub fn encrypt(&self, cipher_view: CipherView) -> Result<EncryptionContext> {
18+
Ok(self.0.encrypt(cipher_view)?)
1919
}
2020

2121
/// Decrypt cipher

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,10 @@ impl CipherAdminClient {
112112

113113
let mut view: CipherView = convert_request_to_cipher_view(request);
114114

115-
// TODO: Once this flag is removed, the key generation logic should
116-
// be moved directly into the CompositeEncryptable implementation.
117-
if self.client.flags().get().await.enable_cipher_key_encryption {
118-
let key = view.key_identifier();
119-
view.generate_cipher_key(&mut key_store.context(), key)?;
120-
}
115+
// TODO: The key generation logic should be moved directly into the
116+
// CompositeEncryptable implementation.
117+
let key = view.key_identifier();
118+
view.generate_cipher_key(&mut key_store.context(), key)?;
121119

122120
let use_blob = should_use_blob_encryption(&key_store.context(), view.organization_id);
123121

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ impl<T> From<bitwarden_api_api::apis::Error<T>> for EditCipherAdminError {
5353
}
5454
}
5555

56-
// `use_strict_decryption`, `enable_cipher_key_encryption`, and `use_blob` are
57-
// short-lived feature-rollout flags that will be removed once their migrations
58-
// complete, at which point the argument count drops back under the limit.
56+
// `use_strict_decryption` and `use_blob` are short-lived feature-rollout flags
57+
// that will be removed once their migrations complete, at which point the
58+
// argument count drops back under the limit.
5959
#[allow(clippy::too_many_arguments)]
6060
async fn edit_cipher(
6161
key_store: &KeyStore<KeySlotIds>,
@@ -64,7 +64,6 @@ async fn edit_cipher(
6464
original_cipher_view: CipherView,
6565
request: CipherEditRequest,
6666
use_strict_decryption: bool,
67-
enable_cipher_key_encryption: bool,
6867
use_blob: bool,
6968
) -> Result<CipherView, EditCipherAdminError> {
7069
let cipher_id = request.id;
@@ -76,9 +75,9 @@ async fn edit_cipher(
7675
let mut view: CipherView = convert_request_to_cipher_view(request);
7776
view.update_password_history(&original_cipher_view);
7877

79-
// TODO: Once this flag is removed, the key generation logic should be
80-
// moved directly into the CompositeEncryptable implementation.
81-
if view.key.is_none() && enable_cipher_key_encryption {
78+
// TODO: The key generation logic should be moved directly into the
79+
// CompositeEncryptable implementation.
80+
if view.key.is_none() {
8281
let key = view.key_identifier();
8382
view.generate_cipher_key(&mut key_store.context(), key)?;
8483
}
@@ -167,9 +166,6 @@ impl CipherAdminClient {
167166
.get_user_id()
168167
.ok_or(NotAuthenticatedError)?;
169168

170-
let enable_cipher_key_encryption =
171-
self.client.flags().get().await.enable_cipher_key_encryption;
172-
173169
let use_blob = should_use_blob_encryption(&key_store.context(), request.organization_id);
174170

175171
edit_cipher(
@@ -179,7 +175,6 @@ impl CipherAdminClient {
179175
original_cipher_view,
180176
request,
181177
self.is_strict_decrypt().await,
182-
enable_cipher_key_encryption,
183178
use_blob,
184179
)
185180
.await
@@ -327,7 +322,6 @@ mod tests {
327322
request,
328323
false,
329324
false,
330-
false,
331325
)
332326
.await
333327
.unwrap();
@@ -383,7 +377,6 @@ mod tests {
383377
original_cipher_view,
384378
request,
385379
false,
386-
false,
387380
true, // use_blob
388381
)
389382
.await
@@ -419,7 +412,6 @@ mod tests {
419412
request,
420413
false,
421414
false,
422-
false,
423415
)
424416
.await;
425417

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,10 @@ impl CiphersClient {
179179

180180
let mut view: CipherView = convert_request_to_cipher_view(request);
181181

182-
// TODO: Once this flag is removed, the key generation logic should
183-
// be moved directly into the CompositeEncryptable implementation.
184-
if self.client.flags().get().await.enable_cipher_key_encryption {
185-
let key = view.key_identifier();
186-
view.generate_cipher_key(&mut key_store.context(), key)?;
187-
}
182+
// TODO: The key generation logic should be moved directly into the
183+
// CompositeEncryptable implementation.
184+
let key = view.key_identifier();
185+
view.generate_cipher_key(&mut key_store.context(), key)?;
188186

189187
let use_blob = self.should_use_blob_encryption(view.organization_id);
190188

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ pub(crate) fn convert_request_to_cipher_view(r: CipherEditRequest) -> CipherView
165165
}
166166
}
167167

168-
// `use_strict_decryption`, `enable_cipher_key_encryption`, and `use_blob` are
169-
// short-lived feature-rollout flags that will be removed once their migrations
170-
// complete, at which point the argument count drops back under the limit.
168+
// `use_strict_decryption` and `use_blob` are short-lived feature-rollout flags
169+
// that will be removed once their migrations complete, at which point the
170+
// argument count drops back under the limit.
171171
#[allow(clippy::too_many_arguments)]
172172
async fn edit_cipher<R: Repository<Cipher> + ?Sized>(
173173
key_store: &KeyStore<KeySlotIds>,
@@ -176,7 +176,6 @@ async fn edit_cipher<R: Repository<Cipher> + ?Sized>(
176176
encrypted_for: UserId,
177177
request: CipherEditRequest,
178178
use_strict_decryption: bool,
179-
enable_cipher_key_encryption: bool,
180179
use_blob: bool,
181180
) -> Result<CipherView, EditCipherError> {
182181
let cipher_id = request.id;
@@ -191,9 +190,9 @@ async fn edit_cipher<R: Repository<Cipher> + ?Sized>(
191190
let mut view: CipherView = convert_request_to_cipher_view(request);
192191
view.update_password_history(&original_cipher_view);
193192

194-
// TODO: Once this flag is removed, the key generation logic should be
195-
// moved directly into the CompositeEncryptable implementation.
196-
if view.key.is_none() && enable_cipher_key_encryption {
193+
// TODO: The key generation logic should be moved directly into the
194+
// CompositeEncryptable implementation.
195+
if view.key.is_none() {
197196
let key = view.key_identifier();
198197
view.generate_cipher_key(&mut key_store.context(), key)?;
199198
}
@@ -273,9 +272,6 @@ impl CiphersClient {
273272
.get_user_id()
274273
.ok_or(NotAuthenticatedError)?;
275274

276-
let enable_cipher_key_encryption =
277-
self.client.flags().get().await.enable_cipher_key_encryption;
278-
279275
let use_blob = self.should_use_blob_encryption(request.organization_id);
280276

281277
edit_cipher(
@@ -285,7 +281,6 @@ impl CiphersClient {
285281
user_id,
286282
request,
287283
self.is_strict_decrypt().await,
288-
enable_cipher_key_encryption,
289284
use_blob,
290285
)
291286
.await
@@ -564,7 +559,6 @@ mod tests {
564559
request,
565560
false,
566561
false,
567-
false,
568562
)
569563
.await
570564
.unwrap();
@@ -704,7 +698,6 @@ mod tests {
704698
request,
705699
false,
706700
false,
707-
false,
708701
)
709702
.await;
710703

@@ -747,7 +740,6 @@ mod tests {
747740
request,
748741
false,
749742
false,
750-
false,
751743
)
752744
.await;
753745

0 commit comments

Comments
 (0)