A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
core: fix user keys re-encryption when updating password Signed-off-by: 01zulfi <[email protected]>
01zulfi7190207e5cc1
diff --git a/packages/core/src/api/user-manager.ts b/packages/core/src/api/user-manager.tsindex 8ab3cc5c4..bd6875833 100644--- a/packages/core/src/api/user-manager.ts+++ b/packages/core/src/api/user-manager.ts@@ -666,6 +666,15 @@ class UserManager {usesFallback: await this.usesFallbackPWHash(old_password)});+ // retrieve user keys before deriving a new encryption key+ const oldUserKeys = {+ attachmentsKey: await this.getAttachmentsKey(),+ monographPasswordsKey: await this.getMonographPasswordsKey(),+ inboxKeys: (await this.hasInboxKeys())+ ? await this.getInboxKeys()+ : undefined+ } as const;+await this.db.storage().deriveCryptoKey({password: new_password,salt@@ -678,27 +687,33 @@ class UserManager {const userEncryptionKey = await this.getEncryptionKey();if (userEncryptionKey) {const updateUserPayload: Partial<User> = {};- const attachmentsKey = await this.getAttachmentsKey();- if (attachmentsKey) {+ if (oldUserKeys.attachmentsKey) {user.attachmentsKey = await this.db.storage()- .encrypt(userEncryptionKey, JSON.stringify(attachmentsKey));+ .encrypt(+ userEncryptionKey,+ JSON.stringify(oldUserKeys.attachmentsKey)+ );updateUserPayload.attachmentsKey = user.attachmentsKey;}- const monographPasswordsKey = await this.getMonographPasswordsKey();- if (monographPasswordsKey) {+ if (oldUserKeys.monographPasswordsKey) {user.monographPasswordsKey = await this.db.storage()- .encrypt(userEncryptionKey, JSON.stringify(monographPasswordsKey));+ .encrypt(+ userEncryptionKey,+ JSON.stringify(oldUserKeys.monographPasswordsKey)+ );updateUserPayload.monographPasswordsKey = user.monographPasswordsKey;}- const inboxKeys = await this.getInboxKeys();- if (inboxKeys) {+ if (oldUserKeys.inboxKeys) {user.inboxKeys = {- public: inboxKeys.publicKey,+ public: oldUserKeys.inboxKeys.publicKey,private: await this.db.storage()- .encrypt(userEncryptionKey, JSON.stringify(inboxKeys.privateKey))+ .encrypt(+ userEncryptionKey,+ JSON.stringify(oldUserKeys.inboxKeys.privateKey)+ )};updateUserPayload.inboxKeys = user.inboxKeys;}