Skip to content

Commit cb4b683

Browse files
authored
Implement cipher key encryption (dani-garcia#3990)
1 parent 6eaf131 commit cb4b683

File tree

12 files changed

+29
-1
lines changed

12 files changed

+29
-1
lines changed

migrations/mysql/2023-10-21-221242_add_cipher_key/down.sql

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE ciphers
2+
ADD COLUMN "key" TEXT;

migrations/postgresql/2023-10-21-221242_add_cipher_key/down.sql

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE ciphers
2+
ADD COLUMN "key" TEXT;

migrations/sqlite/2023-10-21-221242_add_cipher_key/down.sql

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE ciphers
2+
ADD COLUMN "key" TEXT;

src/api/core/ciphers.rs

+3
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ pub struct CipherData {
206206
// TODO: Some of these might appear all the time, no need for Option
207207
OrganizationId: Option<String>,
208208

209+
Key: Option<String>,
210+
209211
/*
210212
Login = 1,
211213
SecureNote = 2,
@@ -483,6 +485,7 @@ pub async fn update_cipher_from_data(
483485
None => err!("Data missing"),
484486
};
485487

488+
cipher.key = data.Key;
486489
cipher.name = data.Name;
487490
cipher.notes = data.Notes;
488491
cipher.fields = data.Fields.map(|f| _clean_cipher_data(f).to_string());

src/api/core/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ fn version() -> Json<&'static str> {
194194
fn config() -> Json<Value> {
195195
let domain = crate::CONFIG.domain();
196196
Json(json!({
197-
"version": crate::VERSION,
197+
// Note: The clients use this version to handle backwards compatibility concerns
198+
// This means they expect a version that closely matches the Bitwarden server version
199+
// We should make sure that we keep this updated when we support the new server features
200+
// Version history:
201+
// - Individual cipher key encryption: 2023.9.1
202+
"version": "2023.9.1",
198203
"gitHash": option_env!("GIT_REV"),
199204
"server": {
200205
"name": "Vaultwarden",
@@ -207,6 +212,12 @@ fn config() -> Json<Value> {
207212
"notifications": format!("{domain}/notifications"),
208213
"sso": "",
209214
},
215+
"featureStates": {
216+
// Any feature flags that we want the clients to use
217+
// Can check the enabled ones at:
218+
// https://vault.bitwarden.com/api/config
219+
"autofill-v2": true
220+
},
210221
"object": "config",
211222
}))
212223
}

src/db/models/cipher.rs

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ db_object! {
2323
pub user_uuid: Option<String>,
2424
pub organization_uuid: Option<String>,
2525

26+
pub key: Option<String>,
27+
2628
/*
2729
Login = 1,
2830
SecureNote = 2,
@@ -62,6 +64,8 @@ impl Cipher {
6264
user_uuid: None,
6365
organization_uuid: None,
6466

67+
key: None,
68+
6569
atype,
6670
name,
6771

@@ -203,6 +207,7 @@ impl Cipher {
203207
"DeletedDate": self.deleted_at.map_or(Value::Null, |d| Value::String(format_date(&d))),
204208
"Reprompt": self.reprompt.unwrap_or(RepromptType::None as i32),
205209
"OrganizationId": self.organization_uuid,
210+
"Key": self.key,
206211
"Attachments": attachments_json,
207212
// We have UseTotp set to true by default within the Organization model.
208213
// This variable together with UsersGetPremium is used to show or hide the TOTP counter.

src/db/schemas/mysql/schema.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ table! {
1515
updated_at -> Datetime,
1616
user_uuid -> Nullable<Text>,
1717
organization_uuid -> Nullable<Text>,
18+
key -> Nullable<Text>,
1819
atype -> Integer,
1920
name -> Text,
2021
notes -> Nullable<Text>,

src/db/schemas/postgresql/schema.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ table! {
1515
updated_at -> Timestamp,
1616
user_uuid -> Nullable<Text>,
1717
organization_uuid -> Nullable<Text>,
18+
key -> Nullable<Text>,
1819
atype -> Integer,
1920
name -> Text,
2021
notes -> Nullable<Text>,

src/db/schemas/sqlite/schema.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ table! {
1515
updated_at -> Timestamp,
1616
user_uuid -> Nullable<Text>,
1717
organization_uuid -> Nullable<Text>,
18+
key -> Nullable<Text>,
1819
atype -> Integer,
1920
name -> Text,
2021
notes -> Nullable<Text>,

0 commit comments

Comments
 (0)