summaryrefslogtreecommitdiff
path: root/poezio/plugin_e2ee.py
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2019-07-02 01:10:20 +0200
committerMaxime “pep” Buquet <pep@bouah.net>2019-07-02 01:10:20 +0200
commita166fcb5a3d19653dd445f0e9db68802502f5987 (patch)
tree3ae9b9d6d7185d4f69d114164c7bfe14fab02d08 /poezio/plugin_e2ee.py
parent12e1c0374cd71ef262b3dceb48650ea70fd8b816 (diff)
downloadpoezio-a166fcb5a3d19653dd445f0e9db68802502f5987.tar.gz
poezio-a166fcb5a3d19653dd445f0e9db68802502f5987.tar.bz2
poezio-a166fcb5a3d19653dd445f0e9db68802502f5987.tar.xz
poezio-a166fcb5a3d19653dd445f0e9db68802502f5987.zip
poezio/plugin_e2ee: Implement previous commit, add encrypted_tags attribute
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
Diffstat (limited to 'poezio/plugin_e2ee.py')
-rw-r--r--poezio/plugin_e2ee.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/poezio/plugin_e2ee.py b/poezio/plugin_e2ee.py
index 8b103cb2..91b1a22e 100644
--- a/poezio/plugin_e2ee.py
+++ b/poezio/plugin_e2ee.py
@@ -88,6 +88,11 @@ class E2EEPlugin(BasePlugin):
#: Required. https://xmpp.org/extensions/xep-0380.html.
eme_ns = None # type: Optional[str]
+ #: Used to figure out what messages to attempt decryption for. Also used
+ #: in combination with `tag_whitelist` to avoid removing encrypted tags
+ #: before sending.
+ encrypted_tags = None # type: Optional[List[Tuple[str, str]]]
+
# Static map, to be able to limit to one encryption mechanism per tab at a
# time
_enabled_tabs = {} # type: Dict[JID, Callable]
@@ -180,14 +185,19 @@ class E2EEPlugin(BasePlugin):
def _decrypt(self, message: Message, tab: ChatTabs) -> None:
- # TODO: Not all encrypted messages will contain EME. EME is typically
- # used only when a message contains `<body/>`. Find a way to have the
- # plugin register an element/ns to check for etc.
+ has_eme = False
+ if message.xml.find('{%s}%s' % (EME_NS, EME_TAG)) is not None and \
+ message['eme']['namespace'] == self.eme_ns:
+ has_eme = True
- if message.xml.find('{%s}%s' % (EME_NS, EME_TAG)) is None:
- return None
+ has_encrypted_tag = False
+ if not has_eme and self.encrypted_tags is not None:
+ for (namespace, tag) in self.encrypted_tags:
+ if message.xml.find('{%s}%s' % (namespace, tag)) is not None:
+ has_encrypted_tag = True
+ break
- if message['eme']['namespace'] != self.eme_ns:
+ if not has_eme and not has_encrypted_tag:
return None
log.debug('Received %s message: %r', self.encryption_name, message['body'])