From f16fc58d707b9ed55355e62440fb95185f972090 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 15 Aug 2018 11:43:52 -0400 Subject: [PATCH] allow original cipher to be passed during encrypt --- src/abstractions/cipher.service.ts | 2 +- src/services/cipher.service.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/abstractions/cipher.service.ts b/src/abstractions/cipher.service.ts index 1046077659..71fa641228 100644 --- a/src/abstractions/cipher.service.ts +++ b/src/abstractions/cipher.service.ts @@ -14,7 +14,7 @@ export abstract class CipherService { decryptedCipherCache: CipherView[]; clearCache: () => void; - encrypt: (model: CipherView, key?: SymmetricCryptoKey) => Promise; + encrypt: (model: CipherView, key?: SymmetricCryptoKey, originalCipher?: Cipher) => Promise; encryptFields: (fieldsModel: FieldView[], key: SymmetricCryptoKey) => Promise; encryptField: (fieldModel: FieldView, key: SymmetricCryptoKey) => Promise; get: (id: string) => Promise; diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index 3903495af8..5222ca0688 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -80,11 +80,14 @@ export class CipherService implements CipherServiceAbstraction { this.decryptedCipherCache = null; } - async encrypt(model: CipherView, key?: SymmetricCryptoKey): Promise { + async encrypt(model: CipherView, key?: SymmetricCryptoKey, originalCipher: Cipher = null): Promise { // Adjust password history if (model.id != null) { - const existingCipher = await (await this.get(model.id)).decrypt(); - if (existingCipher != null) { + if (originalCipher == null) { + originalCipher = await this.get(model.id); + } + if (originalCipher != null) { + const existingCipher = await originalCipher.decrypt(); model.passwordHistory = existingCipher.passwordHistory || []; if (model.type === CipherType.Login && existingCipher.type === CipherType.Login) { if (existingCipher.login.password != null && existingCipher.login.password !== '' &&