From 2fd3a9ef4865097d9d86ecb7d0101ecc4d1bde8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 17 Jul 2021 12:35:39 +0200 Subject: plugin_e2ee: drop message if tab is None and doesn't contain encrypted tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/plugin_e2ee.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/poezio/plugin_e2ee.py b/poezio/plugin_e2ee.py index 178a3b51..c5c6d802 100644 --- a/poezio/plugin_e2ee.py +++ b/poezio/plugin_e2ee.py @@ -436,6 +436,18 @@ class E2EEPlugin(BasePlugin): raise NothingToEncrypt() message = stanza + + # Is this message already encrypted? Do we need to do all these + # checks? Such as an OMEMO heartbeat. + has_encrypted_tag = False + if self.encrypted_tags is not None: + for (namespace, tag) in self.encrypted_tags: + if message.xml.find('{%s}%s' % (namespace, tag)) is not None: + # TODO: count all encrypted tags. + has_encrypted_tag = True + log.debug('Message already contains an encrypted tag') + break + # Find who to encrypt to. If in a groupchat this can be multiple JIDs. # It is possible that we are not able to find a jid (e.g., semi-anon # MUCs). Let the plugin decide what to do with this information. @@ -448,19 +460,13 @@ class E2EEPlugin(BasePlugin): if tab is None: # Possible message sent directly by the e2ee lib? log.debug( 'A message we do not have a tab for ' - 'is being sent to \'%s\'. \n%r.', message['to'], message, + 'is being sent to \'%s\'. %s. \n%r.', + message['to'], + 'Dropping' if not has_encrypted_tag else '', + message, ) - - # Is this message already encrypted? Do we need to do all these - # checks? Possibly an OMEMO heartbeat. - has_encrypted_tag = False - if self.encrypted_tags is not None: - for (namespace, tag) in self.encrypted_tags: - if message.xml.find('{%s}%s' % (namespace, tag)) is not None: - # TODO: count all encrypted tags. - has_encrypted_tag = True - log.debug('Message already contains an encrypted tag') - break + if not has_encrypted_tag: + return None parent = None if isinstance(tab, PrivateTab): -- cgit v1.2.3