From ccf9c3e4e1e6cfdfcd37d340df60f99c95a8a753 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:37:41 +0200 Subject: plugin_e2ee: check all encrypted tags in _decrypt and _encrypt 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 | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'poezio/plugin_e2ee.py') diff --git a/poezio/plugin_e2ee.py b/poezio/plugin_e2ee.py index c5c6d802..673ea728 100644 --- a/poezio/plugin_e2ee.py +++ b/poezio/plugin_e2ee.py @@ -383,18 +383,17 @@ class E2EEPlugin(BasePlugin): async def _decrypt(self, message: Message, tab: ChatTabs, passthrough: bool = True) -> None: - has_eme = False + has_eme: bool = False if message.xml.find('{%s}%s' % (EME_NS, EME_TAG)) is not None and \ message['eme']['namespace'] == self.eme_ns: has_eme = True - has_encrypted_tag = False + has_encrypted_tag: bool = False if not has_eme and self.encrypted_tags is not None: + tmp: bool = True 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 - break + tmp = tmp and message.xml.find('{%s}%s' % (namespace, tag)) is not None + has_encrypted_tag = tmp if not has_eme and not has_encrypted_tag: return None @@ -439,14 +438,14 @@ class E2EEPlugin(BasePlugin): # Is this message already encrypted? Do we need to do all these # checks? Such as an OMEMO heartbeat. - has_encrypted_tag = False + has_encrypted_tag: bool = False if self.encrypted_tags is not None: + tmp: bool = True 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 + tmp = tmp and message.xml.find('{%s}%s' % (namespace, tag)) is not None + has_encrypted_tag = tmp + if has_encrypted_tag: + log.debug('Message already contains encrypted tags') # 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 -- cgit v1.2.3