plugin_e2ee: check all encrypted tags in _decrypt and _encrypt

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-07-17 12:37:41 +02:00
parent 2fd3a9ef48
commit ccf9c3e4e1

View file

@ -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