Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
poezio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
205
Issues
205
List
Boards
Labels
Service Desk
Milestones
Merge Requests
10
Merge Requests
10
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poezio
poezio
Commits
a8bf37eb
Verified
Commit
a8bf37eb
authored
Jul 01, 2019
by
Maxime Buquet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
e2ee-api: Add documentation
Signed-off-by:
Maxime “pep” Buquet
<
pep@bouah.net
>
parent
dd6efb14
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
8 deletions
+111
-8
doc/source/dev/e2ee.rst
doc/source/dev/e2ee.rst
+55
-0
doc/source/dev/index.rst
doc/source/dev/index.rst
+1
-0
poezio/plugin_e2ee.py
poezio/plugin_e2ee.py
+55
-8
No files found.
doc/source/dev/e2ee.rst
0 → 100644
View file @
a8bf37eb
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()
doc/source/dev/index.rst
View file @
a8bf37eb
...
...
@@ -14,6 +14,7 @@ About plugins
:maxdepth: 2
plugin
e2ee
events
slix
xep
...
...
poezio/plugin_e2ee.py
View file @
a8bf37eb
...
...
@@ -35,13 +35,31 @@ HINTS_NS = 'urn:xmpp:hints'
class
E2EEPlugin
(
BasePlugin
):
"""Interface for E2EE plugins
"""
"""Interface for E2EE plugins
.
# Specifies that the encryption mechanism does more than encrypting
# <body/>.
This is a wrapper built on top of BasePlugin. It provides a base for
End-to-end Encryption mechanisms in poezio.
Plugin developers are excepted to implement the `decrypt` and
`encrypt` function, provide an encryption name (and/or short name),
and an eme namespace.
Once loaded, the plugin will attempt to decrypt any message that
contains an EME message that matches the one set.
The plugin will also register a command (using the short name) to
enable encryption per tab. It is only possible to have one encryption
mechanism per tab, even if multiple e2ee plugins are loaded.
The encryption status will be displayed in the status bar, using the
plugin short name, alongside the JID, nickname etc.
"""
#: Specifies that the encryption mechanism does more than encrypting
#: <body/>.
stanza_encryption
=
False
# Whitelist applied to messages when `stanza_encryption` is False.
#
:
Whitelist applied to messages when `stanza_encryption` is False.
tag_whitelist
=
list
(
map
(
lambda
x
:
'{%s}%s'
%
(
x
[
0
],
x
[
1
]),
[
(
JCLIENT_NS
,
'body'
),
(
EME_NS
,
EME_TAG
),
...
...
@@ -52,13 +70,22 @@ class E2EEPlugin(BasePlugin):
# TODO: Add other encryption mechanisms tags here
]))
#: Replaces body with `eme <https://xmpp.org/extensions/xep-0380.html>`_
#: if set. Should be suitable for most plugins except those using <body/>
#: directly as their encryption container, like OTR, or the example base64
#: plugin in poezio.
replace_body_with_eme
=
True
# At least one of encryption_name and encryption_short_name must be set
#: Encryption name, used in command descriptions, and logs. At least one
#: of `encryption_name` and `encryption_short_name` must be set.
encryption_name
=
None
# type: Optional[str]
#: Encryption short name, used as command name, and also to display
#: encryption status in a tab. At least one of `encryption_name` and
#: `encryption_short_name` must be set.
encryption_short_name
=
None
# type: Optional[str]
# Required.
#
:
Required.
eme_ns
=
None
# type: Optional[str]
# Static map, to be able to limit to one encryption mechanism per tab at a
...
...
@@ -217,9 +244,29 @@ class E2EEPlugin(BasePlugin):
return
message
def
decrypt
(
self
,
_message
:
Message
,
tab
:
ChatTabs
):
"""Decryption method"""
"""Decryption method
This is a method the plugin must implement. It is expected that this
method will edit the received message and return nothing.
:param message: Message to be decrypted.
:param tab: Tab the message is coming from.
:returns: None
"""
raise
NotImplementedError
def
encrypt
(
self
,
_message
:
Message
,
tab
:
ChatTabs
):
"""Encryption method"""
"""Encryption method
This is a method the plugin must implement. It is expected that this
method will edit the received message and return nothing.
:param message: Message to be encrypted.
:param tab: Tab the message is going to.
:returns: None
"""
raise
NotImplementedError
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment