Quellcode durchsuchen

Don't show unnecessary errors for undecryptable OMEMO messages

As mentioned in the XEP, don't show error messages for OMEMO messages
that can't be decrypted because they were already decrypted before or
because they weren't encrypted for this device.
JC Brand vor 3 Jahren
Ursprung
Commit
07b2425ff9
2 geänderte Dateien mit 36 neuen und 18 gelöschten Zeilen
  1. 11 1
      src/headless/plugins/muc/muc.js
  2. 25 17
      src/plugins/omemo/utils.js

+ 11 - 1
src/headless/plugins/muc/muc.js

@@ -1928,7 +1928,14 @@ const ChatRoomMixin = {
      * @returns {Promise<boolean>}
      */
     async shouldShowErrorMessage (attrs) {
-        if (attrs['error_condition'] === 'not-acceptable' && (await this.rejoinIfNecessary())) {
+        if (attrs.error_type === 'Decryption') {
+            if (attrs.error_message === "Message key not found. The counter was repeated or the key was not filled.") {
+                // OMEMO message which we already decrypted before
+                return false;
+            } else if ( attrs.error_condition === 'not-encrypted-for-this-device') {
+                return false;
+            }
+        } else if (attrs.error_condition === 'not-acceptable' && (await this.rejoinIfNecessary())) {
             return false;
         }
         return _converse.ChatBox.prototype.shouldShowErrorMessage.call(this, attrs);
@@ -2198,7 +2205,10 @@ const ChatRoomMixin = {
         if (u.isErrorObject(attrs)) {
             attrs.stanza && log.error(attrs.stanza);
             return log.error(attrs.message);
+        } else if (attrs.type === 'error' && !(await this.shouldShowErrorMessage(attrs))) {
+            return;
         }
+
         const message = this.getDuplicateMessage(attrs);
         if (message) {
             (message.get('type') === 'groupchat') && this.updateMessage(message, attrs);

+ 25 - 17
src/plugins/omemo/utils.js

@@ -204,12 +204,22 @@ export function handleEncryptedFiles (richtext) {
 }
 
 export function parseEncryptedMessage (stanza, attrs) {
-    if (attrs.is_encrypted && attrs.encrypted.key) {
-        // https://xmpp.org/extensions/xep-0384.html#usecases-receiving
-        if (attrs.encrypted.prekey === true) {
-            return decryptPrekeyWhisperMessage(attrs);
+    if (attrs.is_encrypted) {
+        if (!attrs.encrypted.key) {
+            return Object.assign(attrs, {
+                'error_condition': 'not-encrypted-for-this-device',
+                'error_type': 'Decryption',
+                'is_ephemeral': true,
+                'is_error': true,
+                'type': 'error'
+            });
         } else {
-            return decryptWhisperMessage(attrs);
+            // https://xmpp.org/extensions/xep-0384.html#usecases-receiving
+            if (attrs.encrypted.prekey === true) {
+                return decryptPrekeyWhisperMessage(attrs);
+            } else {
+                return decryptWhisperMessage(attrs);
+            }
         }
     } else {
         return attrs;
@@ -287,18 +297,16 @@ async function handleDecryptedWhisperMessage (attrs, key_and_tag) {
 }
 
 function getDecryptionErrorAttributes (e) {
-    if (api.settings.get('loglevel') === 'debug') {
-        return {
-            'error_text':
-                __('Sorry, could not decrypt a received OMEMO message due to an error.') + ` ${e.name} ${e.message}`,
-            'error_type': 'Decryption',
-            'is_ephemeral': true,
-            'is_error': true,
-            'type': 'error'
-        };
-    } else {
-        return {};
-    }
+    return {
+        'error_text':
+            __('Sorry, could not decrypt a received OMEMO message due to an error.') + ` ${e.name} ${e.message}`,
+        'error_condition': e.name,
+        'error_message': e.message,
+        'error_type': 'Decryption',
+        'is_ephemeral': true,
+        'is_error': true,
+        'type': 'error'
+    };
 }
 
 async function decryptPrekeyWhisperMessage (attrs) {