From e8450bcf518040dbc69fc0e55b3bfc5e8612aaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 1 Dec 2018 02:15:35 +0000 Subject: omemo: Add dummy sending command for testing purposes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/omemo_plugin.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/plugins/omemo_plugin.py b/plugins/omemo_plugin.py index efd64722..c25e5fea 100644 --- a/plugins/omemo_plugin.py +++ b/plugins/omemo_plugin.py @@ -15,8 +15,11 @@ import textwrap from poezio.plugin import BasePlugin from poezio.tabs import ConversationTab from poezio.xdg import CACHE_HOME +from slixmpp import JID from slixmpp.plugins.xep_0384.plugin import MissingOwnKey +from typing import List, Optional + import logging log = logging.getLogger(__name__) @@ -66,6 +69,12 @@ class Plugin(BasePlugin): help='Clear all other OMEMO devices', ) + self.api.add_command( + 'encrypted_message', + self.send_message, + help='Send OMEMO encrypted message', + ) + self.api.add_event_handler( 'conversation_say_after', self.on_conversation_say_after, @@ -101,6 +110,31 @@ class Plugin(BasePlugin): """ self.info(textwrap.dedent(info).strip()) + def send_message(self, _args): + asyncio.ensure_future( + self._send_message( + "Hello Encrypted World!", + [JID('some@jid')], + mto=JID('some@jid'), + mtype='chat', + ), + ) + + async def _send_message( + self, + payload: str, + recipients: List[JID], + mto: Optional[JID] = None, + mtype: Optional[str] = 'chat', + ) -> None: + encrypted = await self.xmpp['xep_0384'].encrypt_message(payload, recipients) + msg = self.core.xmpp.make_message(mto, mtype=mtype) + msg['body'] = 'This message is encrypted with Legacy OMEMO (eu.siacs.conversations.axolotl)' + msg['eme']['namespace'] = 'eu.siacs.conversations.axolotl' + msg.append(encrypted) + log.debug('BAR: message: %r', msg) + msg.send() + def on_conversation_say_after(self, message, tab): """ Outbound messages -- cgit v1.2.3