From 98102d075c7163f2ca11f1758e14c895fe6643d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 1 Jul 2019 01:16:40 +0200 Subject: e2ee-api: Add only if is present MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As per discussion in jdev@ Signed-off-by: Maxime “pep” Buquet --- poezio/plugin_e2ee.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'poezio') diff --git a/poezio/plugin_e2ee.py b/poezio/plugin_e2ee.py index ef58a051..1580bd6d 100644 --- a/poezio/plugin_e2ee.py +++ b/poezio/plugin_e2ee.py @@ -169,23 +169,31 @@ class E2EEPlugin(BasePlugin): log.debug('Sending %s message: %r', self.encryption_name, message['body']) - message['eme']['namespace'] = self.eme_ns - message['eme']['name'] = self.encryption_name + has_body = message.xml.find('{%s}%s' % (JCLIENT_NS, 'body')) is not None # Call the enabled encrypt method self._enabled_tabs[jid](message, tab) + if has_body: + # Only add EME tag if the message has a body. + # Per discussion in jdev@: + # The receiving client needs to know the message contains + # meaningful information or not to display notifications to the + # user, and not display anything when it's e.g., a chatstate. + # This does leak the fact that the encrypted payload contains a + # message. + message['eme']['namespace'] = self.eme_ns + message['eme']['name'] = self.encryption_name + + if self.replace_body_with_eme: + self.core.xmpp['xep_0380'].replace_body_with_eme(message) + # Filter stanza with the whitelist if we don't do stanza encryption if not self.stanza_encryption: for elem in message.xml[:]: if elem.tag not in self.tag_whitelist: message.xml.remove(elem) - if self.replace_body_with_eme: - body = message.xml.find('{%s}%s' % (JCLIENT_NS, 'body')) - if body is not None: - self.core.xmpp['xep_0380'].replace_body_with_eme(message) - log.debug('Encrypted %s message: %r', self.encryption_name, message['body']) return None -- cgit v1.2.3