Browse Source

omemo: Remove all sessions when generating new keys

After generating new keys, when one sends out an encrypted message, it
must be a PreKeyWhisperMessage which contains a preKey to be used to
initiate a new session, otherwise the message can't be decrypted.

So we remove all existing sessions in order to force new sessions to be
created and thereby new PreKeyWhisperMessages to be sent out.

Updates #3769
JC Brand 1 tháng trước cách đây
mục cha
commit
b6b4a90779

+ 6 - 0
src/headless/plugins/omemo/api.js

@@ -90,6 +90,12 @@ export default {
                 const fp = generateFingerprint(device);
                 await omemo_store.publishBundle();
                 await devicelist.publishDevices();
+
+                // Remove all existing sessions.
+                // We'll need to create new sessions (i.e. send out a new PreKeyWhisperMessage)
+                // when sending messages.
+                await omemo_store.removeAllSessions();
+
                 return fp;
             },
         },

+ 1 - 1
src/headless/plugins/omemo/parsers.js

@@ -94,7 +94,7 @@ async function decryptWhisperMessage(attrs) {
     try {
         const key_and_tag = await session_cipher.decryptWhisperMessage(key, 'binary');
         const plaintext = await handleDecryptedWhisperMessage(attrs, key_and_tag);
-        return Object.assign(attrs, { 'plaintext': plaintext });
+        return Object.assign(attrs, { plaintext });
     } catch (e) {
         log.error(`${e.name} ${e.message}`);
         return Object.assign(attrs, getDecryptionErrorAttributes(e));

+ 2 - 2
src/headless/plugins/omemo/store.js

@@ -199,9 +199,9 @@ class OMEMOStore extends Model {
     }
 
     /**
-     * @param {string} identifier
+     * @param {string} [identifier='']
      */
-    removeAllSessions(identifier) {
+    removeAllSessions(identifier='') {
         const keys = Object.keys(this.attributes).filter((key) =>
             key.startsWith('session' + identifier) ? key : false
         );

+ 2 - 2
src/headless/types/plugins/omemo/store.d.ts

@@ -72,9 +72,9 @@ declare class OMEMOStore extends Model {
      */
     removeSession(identifier: string): Promise<false | Awaited<this>>;
     /**
-     * @param {string} identifier
+     * @param {string} [identifier='']
      */
-    removeAllSessions(identifier: string): Promise<void>;
+    removeAllSessions(identifier?: string): Promise<void>;
     publishBundle(): any;
     generateMissingPreKeys(): Promise<void>;
     /**