2019-06-06 11:21:29 +00:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim:fenc=utf-8
|
|
|
|
#
|
|
|
|
# Copyright © 2019 Maxime “pep” Buquet <pep@bouah.net>
|
|
|
|
#
|
2020-06-06 19:54:12 +00:00
|
|
|
# Distributed under terms of the GPL-3.0+ license.
|
2019-06-06 11:21:29 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
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
|
2022-03-16 22:33:16 +00:00
|
|
|
from typing import List, Optional
|
|
|
|
from slixmpp import Message, JID
|
|
|
|
|
2019-06-06 11:21:29 +00:00
|
|
|
from poezio.plugin_e2ee import E2EEPlugin
|
2022-03-16 23:13:44 +00:00
|
|
|
from poezio.tabs import (
|
|
|
|
ChatTab,
|
|
|
|
MucTab,
|
|
|
|
PrivateTab,
|
|
|
|
DynamicConversationTab,
|
|
|
|
StaticConversationTab,
|
|
|
|
)
|
2019-06-06 11:21:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Plugin(E2EEPlugin):
|
|
|
|
"""Base64 Plugin"""
|
|
|
|
|
|
|
|
encryption_name = 'base64'
|
|
|
|
encryption_short_name = 'b64'
|
|
|
|
eme_ns = 'urn:xmpps:base64:0'
|
|
|
|
|
2019-06-27 22:21:21 +00:00
|
|
|
# This encryption mechanism is using <body/> as a container
|
|
|
|
replace_body_with_eme = False
|
|
|
|
|
2022-03-16 23:13:44 +00:00
|
|
|
# In what tab is it ok to use this plugin. Here we want all of them
|
|
|
|
supported_tab_types = (
|
|
|
|
MucTab,
|
|
|
|
PrivateTab,
|
|
|
|
DynamicConversationTab,
|
|
|
|
StaticConversationTab,
|
|
|
|
)
|
|
|
|
|
2022-03-11 23:54:24 +00:00
|
|
|
async def decrypt(self, message: Message, jid: Optional[JID], _tab: Optional[ChatTab]) -> None:
|
2019-06-06 11:21:29 +00:00
|
|
|
"""
|
|
|
|
Decrypt base64
|
|
|
|
"""
|
|
|
|
body = message['body']
|
|
|
|
message['body'] = b64decode(body.encode()).decode()
|
|
|
|
|
2022-03-16 22:33:16 +00:00
|
|
|
async def encrypt(self, message: Message, _jid: Optional[List[JID]], _tab: ChatTab) -> None:
|
2019-06-06 11:21:29 +00:00
|
|
|
"""
|
|
|
|
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()
|