From 781056152a4b8e5b6bc70031aafd65bf9d59fd1c Mon Sep 17 00:00:00 2001 From: Kumar Ankur Date: Tue, 28 Aug 2018 02:38:58 +0530 Subject: [PATCH 1/3] Support password history #155 (#156) * Password History Support (#155) * down.sql logic not required as per review comments --- migrations/2018-08-27-172114_update_ciphers/down.sql | 0 migrations/2018-08-27-172114_update_ciphers/up.sql | 3 +++ src/api/core/ciphers.rs | 4 ++++ src/db/models/cipher.rs | 8 ++++++++ src/db/schema.rs | 1 + 5 files changed, 16 insertions(+) create mode 100644 migrations/2018-08-27-172114_update_ciphers/down.sql create mode 100644 migrations/2018-08-27-172114_update_ciphers/up.sql diff --git a/migrations/2018-08-27-172114_update_ciphers/down.sql b/migrations/2018-08-27-172114_update_ciphers/down.sql new file mode 100644 index 0000000..e69de29 diff --git a/migrations/2018-08-27-172114_update_ciphers/up.sql b/migrations/2018-08-27-172114_update_ciphers/up.sql new file mode 100644 index 0000000..624efd6 --- /dev/null +++ b/migrations/2018-08-27-172114_update_ciphers/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE ciphers + ADD COLUMN + password_history TEXT; \ No newline at end of file diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index beb68e0..eefd167 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -112,6 +112,8 @@ struct CipherData { Identity: Option, Favorite: Option, + + PasswordHistory: Option, } #[post("/ciphers/admin", data = "")] @@ -177,6 +179,7 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head type_data["Name"] = Value::String(data.Name.clone()); type_data["Notes"] = data.Notes.clone().map(Value::String).unwrap_or(Value::Null); type_data["Fields"] = data.Fields.clone().unwrap_or(Value::Null); + type_data["PasswordHistory"] = data.PasswordHistory.clone().unwrap_or(Value::Null); // TODO: ******* Backwards compat end ********** cipher.favorite = data.Favorite.unwrap_or(false); @@ -184,6 +187,7 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head cipher.notes = data.Notes; cipher.fields = data.Fields.map(|f| f.to_string()); cipher.data = type_data.to_string(); + cipher.password_history = data.PasswordHistory.map(|f| f.to_string()); cipher.save(&conn); diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 3faf1ae..917a76e 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -32,6 +32,7 @@ pub struct Cipher { pub data: String, pub favorite: bool, + pub password_history: Option, } /// Local methods @@ -55,6 +56,7 @@ impl Cipher { fields: None, data: String::new(), + password_history: None, } } } @@ -77,6 +79,10 @@ impl Cipher { let fields_json: JsonValue = if let Some(ref fields) = self.fields { serde_json::from_str(fields).unwrap() } else { JsonValue::Null }; + + let password_history_json: JsonValue = if let Some(ref password_history) = self.password_history { + serde_json::from_str(password_history).unwrap() + } else { JsonValue::Null }; let mut data_json: JsonValue = serde_json::from_str(&self.data).unwrap(); @@ -108,6 +114,8 @@ impl Cipher { "Object": "cipher", "Edit": true, + + "PasswordHistory": password_history_json, }); let key = match self.type_ { diff --git a/src/db/schema.rs b/src/db/schema.rs index f39701b..5382e69 100644 --- a/src/db/schema.rs +++ b/src/db/schema.rs @@ -21,6 +21,7 @@ table! { fields -> Nullable, data -> Text, favorite -> Bool, + password_history -> Nullable, } } From 6660b0aef391f6bc20ce1991ff843a85d63b3afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Tue, 28 Aug 2018 03:21:22 +0200 Subject: [PATCH 2/3] Updated web vault to version 2.2 --- Dockerfile | 6 +++--- docker/set-vault-baseurl.patch | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 860e76c..9ec3355 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ####################### VAULT BUILD IMAGE ####################### FROM node:8-alpine as vault -ENV VAULT_VERSION "v2.1.1" +ENV VAULT_VERSION "v2.2.0" ENV URL "https://github.com/bitwarden/web.git" @@ -47,7 +47,7 @@ COPY ./rust-toolchain ./rust-toolchain # Builds your dependencies and removes the # dummy project, except the target folder # This folder contains the compiled dependencies -RUN cargo build --release +RUN cargo build --release --features vendored_openssl RUN find . -not -path "./target*" -delete # Copies the complete project @@ -56,7 +56,7 @@ COPY . . # Builds again, this time it'll just be # your actual source files being built -RUN cargo build --release +RUN cargo build --release --features vendored_openssl ######################## RUNTIME IMAGE ######################## # Create a new stage with a minimal image diff --git a/docker/set-vault-baseurl.patch b/docker/set-vault-baseurl.patch index 492f6b6..5e87202 100644 --- a/docker/set-vault-baseurl.patch +++ b/docker/set-vault-baseurl.patch @@ -1,7 +1,7 @@ --- a/src/app/services/services.module.ts +++ b/src/app/services/services.module.ts -@@ -116,17 +116,15 @@ const exportService = new ExportService(folderService, cipherService, apiService - const importService = new ImportService(cipherService, folderService, apiService, i18nService, collectionService); +@@ -120,20 +120,17 @@ const notificationsService = new NotificationsService(userService, syncService, + const environmentService = new EnvironmentService(apiService, storageService, notificationsService); const auditService = new AuditService(cryptoFunctionService, apiService); -const analytics = new Analytics(window, () => platformUtilsService.isDev() || platformUtilsService.isSelfHost(), @@ -15,9 +15,14 @@ - const isDev = platformUtilsService.isDev(); - if (!isDev && platformUtilsService.isSelfHost()) { - environmentService.baseUrl = window.location.origin; +- } else { +- environmentService.notificationsUrl = isDev ? 'http://localhost:61840' : +- 'https://notifications.bitwarden.com'; // window.location.origin + '/notifications'; - } + const isDev = false; + environmentService.baseUrl = window.location.origin; ++ environmentService.notificationsUrl = window.location.origin + '/notifications'; ++ await apiService.setUrls({ base: isDev ? null : window.location.origin, api: isDev ? 'http://localhost:4000' : null, From 761a0a3393f2ea296762b119531974505e6c8bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Tue, 28 Aug 2018 12:54:57 +0200 Subject: [PATCH 3/3] Removed accidental change to Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9ec3355..c2b9f7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,7 +47,7 @@ COPY ./rust-toolchain ./rust-toolchain # Builds your dependencies and removes the # dummy project, except the target folder # This folder contains the compiled dependencies -RUN cargo build --release --features vendored_openssl +RUN cargo build --release RUN find . -not -path "./target*" -delete # Copies the complete project @@ -56,7 +56,7 @@ COPY . . # Builds again, this time it'll just be # your actual source files being built -RUN cargo build --release --features vendored_openssl +RUN cargo build --release ######################## RUNTIME IMAGE ######################## # Create a new stage with a minimal image