diff options
author | Maxime “pep” Buquet <pep@bouah.net> | 2019-06-06 13:21:29 +0200 |
---|---|---|
committer | Maxime “pep” Buquet <pep@bouah.net> | 2019-07-01 19:42:45 +0200 |
commit | d56d44225316652f8a818771c661c6f2463eb23f (patch) | |
tree | 73a2d3aa1a4d76d2aba97a60b3280649cc97a98b /plugins | |
parent | b9deb7e16485c5bf2f1152a11ecb9b1ccdab0042 (diff) | |
download | poezio-d56d44225316652f8a818771c661c6f2463eb23f.tar.gz poezio-d56d44225316652f8a818771c661c6f2463eb23f.tar.bz2 poezio-d56d44225316652f8a818771c661c6f2463eb23f.tar.xz poezio-d56d44225316652f8a818771c661c6f2463eb23f.zip |
First shot of an E2EE plugin interface
Features:
- Decryption by default once the plugin is loaded if messages contains
the right EME magic
- Encryption of messages only if encryption is enabled for the current
tab
Missing pieces:
- No special treatment done on the order of the treatment for messages
yet
- No special handling of non-Partial(/Full) Stanza Encryption yet (i.e.,
removing stuff other than <body/>)
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/b64.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/plugins/b64.py b/plugins/b64.py new file mode 100644 index 00000000..57b2664f --- /dev/null +++ b/plugins/b64.py @@ -0,0 +1,50 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# +# Copyright © 2019 Maxime “pep” Buquet <pep@bouah.net> +# +# Distributed under terms of the zlib license. + +""" +Usage +----- + +Base64 encryption plugin. + +This plugin also respects security guidelines listed in XEP-0419. + +.. glossary:: + /b64 + **Usage:** ``/b64`` + + This command enables encryption of outgoing messages for the current + tab. +""" + +from base64 import b64decode, b64encode +from poezio.plugin_e2ee import E2EEPlugin +from slixmpp import Message + + +class Plugin(E2EEPlugin): + """Base64 Plugin""" + + encryption_name = 'base64' + encryption_short_name = 'b64' + eme_ns = 'urn:xmpps:base64:0' + + def decrypt(self, message: Message, _tab) -> None: + """ + Decrypt base64 + """ + body = message['body'] + message['body'] = b64decode(body.encode()).decode() + + def encrypt(self, message: Message, _tab) -> None: + """ + Encrypt to base64 + """ + # TODO: Stop using <body/> for this. Put the encoded payload in another element. + body = message['body'] + message['body'] = b64encode(body.encode()).decode() |