From 9f8799d729c6b92974cb9f87a35ed8bf67564273 Mon Sep 17 00:00:00 2001 From: Aviad Pineles Date: Tue, 12 Sep 2023 16:06:29 +0300 Subject: [PATCH] fix: don't re-encode public key when changing e2e password (#5174) Co-authored-by: Gleidson Daniel Silva --- app/lib/encryption/encryption.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/lib/encryption/encryption.ts b/app/lib/encryption/encryption.ts index d24df42cd..05071d074 100644 --- a/app/lib/encryption/encryption.ts +++ b/app/lib/encryption/encryption.ts @@ -199,10 +199,16 @@ class Encryption { // Encode the private key const encodedPrivateKey = await this.encodePrivateKey(EJSON.stringify(privateKey), password, this.userId as string); + + // This public key is already encoded using EJSON.stringify in the `persistKeys` method const publicKey = UserPreferences.getString(`${server}-${E2E_PUBLIC_KEY}`); + if (!publicKey) { + throw new Error('Public key not found in local storage, password not changed'); + } + // Send the new keys to the server - await Services.e2eSetUserPublicAndPrivateKeys(EJSON.stringify(publicKey), encodedPrivateKey); + await Services.e2eSetUserPublicAndPrivateKeys(publicKey, encodedPrivateKey); }; // get a encryption room instance