diff options
author | Maxime “pep” Buquet <pep@bouah.net> | 2021-07-17 12:35:39 +0200 |
---|---|---|
committer | Maxime “pep” Buquet <pep@bouah.net> | 2022-03-16 08:09:11 +0100 |
commit | 2fd3a9ef4865097d9d86ecb7d0101ecc4d1bde8d (patch) | |
tree | 7449fc128d87d5baef0b96c5d3ece8654b69d743 | |
parent | c75573ddf8e206004b986eb40e86a05962e30dce (diff) | |
download | poezio-2fd3a9ef4865097d9d86ecb7d0101ecc4d1bde8d.tar.gz poezio-2fd3a9ef4865097d9d86ecb7d0101ecc4d1bde8d.tar.bz2 poezio-2fd3a9ef4865097d9d86ecb7d0101ecc4d1bde8d.tar.xz poezio-2fd3a9ef4865097d9d86ecb7d0101ecc4d1bde8d.zip |
plugin_e2ee: drop message if tab is None and doesn't contain encrypted tag
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r-- | poezio/plugin_e2ee.py | 30 |
1 files 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): |