summaryrefslogtreecommitdiff
path: root/doc/source/dev/e2ee.rst
blob: 08cae7154cf82b05b818f213d82fb9bb493f8550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
End-to-end Encryption API documentation
=======================================

E2EEPlugin
----------

.. module:: poezio.plugin_e2ee


.. autoclass:: E2EEPlugin
  :members:

Builds on top of :py:class:`~BasePlugin` and requires the developer to
implement two methods, `decrypt` and `encrypt`, as well as the
`encryption_name` and `eme_ns` attribute.

Please refer to :py:class:`~BasePlugin` for more information on how to
write plugins.

Example plugins
---------------

**Example 1:** Base64 plugin

.. code-block:: python

    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'

        # This encryption mechanism is using <body/> as a container
        replace_body_with_eme = False

        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()