From e647775608f9ca23f46ffd8c6838854552d206f8 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 31 May 2023 20:31:44 +0100 Subject: [PATCH] All: When resetting the master password, also create a new master key with that password --- packages/lib/services/e2ee/utils.test.ts | 5 +++++ packages/lib/services/e2ee/utils.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/packages/lib/services/e2ee/utils.test.ts b/packages/lib/services/e2ee/utils.test.ts index 0972371ca4..f629e8f36e 100644 --- a/packages/lib/services/e2ee/utils.test.ts +++ b/packages/lib/services/e2ee/utils.test.ts @@ -145,6 +145,11 @@ describe('e2ee/utils', () => { expect(localSyncInfo().ppk.id).not.toBe(previousPpk.id); expect(localSyncInfo().ppk.privateKey.ciphertext).not.toBe(previousPpk.privateKey.ciphertext); expect(localSyncInfo().ppk.publicKey).not.toBe(previousPpk.publicKey); + + // Also check that a new master key has been created, that it is active and enabled + expect(localSyncInfo().masterKeys.length).toBe(3); + expect(localSyncInfo().activeMasterKeyId).toBe(localSyncInfo().masterKeys[2].id); + expect(masterKeyEnabled(localSyncInfo().masterKeys[2])).toBe(true); }); it('should fix active key selection issues - 1', async () => { diff --git a/packages/lib/services/e2ee/utils.ts b/packages/lib/services/e2ee/utils.ts index 52d513dc86..5df4835cd5 100644 --- a/packages/lib/services/e2ee/utils.ts +++ b/packages/lib/services/e2ee/utils.ts @@ -311,6 +311,10 @@ export async function resetMasterPassword(encryptionService: EncryptionService, } Setting.setValue('encryption.masterPassword', newPassword); + + const masterKey = await encryptionService.generateMasterKey(newPassword); + await MasterKey.save(masterKey); + await loadMasterKeysFromSettings(encryptionService); } export enum MasterPasswordStatus {