From 4b51f117bb2b1aa8a65baae2e7a5b94f01a5617a 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:12:25 +0000 Subject: [PATCH] xep_0384: Generate XML from encrypted payload received from the lib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugin.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index 2becd44..3682927 100644 --- a/plugin.py +++ b/plugin.py @@ -161,6 +161,23 @@ class XEP_0384(BasePlugin): return iq + def _generate_encrypted_payload(self, encrypted) -> Encrypted: + tag = Encrypted() + + tag['header']['sid'] = str(encrypted['sid']) + tag['header']['iv']['value'] = b64enc(encrypted['iv']) + tag['payload']['value'] = b64enc(encrypted['payload']) + + for message in encrypted['messages']: + key = Key() + key['value'] = b64enc(message['message']) + key['rid'] = str(message['rid']) + if message['pre_key']: + key['prekey'] = '1' + tag['header'].append(key) + + return tag + async def _publish_bundle(self) -> None: if self._omemo.republish_bundle: iq = self._generate_bundle_iq() @@ -352,14 +369,12 @@ class XEP_0384(BasePlugin): raise NoEligibleDevices(no_eligible_devices) # Attempt encryption - payload = Encrypted() - payload['omemo_encrypted'] = self._omemo.encryptMessage( + encrypted = self._omemo.encryptMessage( recipients, plaintext.encode('utf-8'), bundles, always_trust=True, ) - - return payload + return self._generate_encrypted_payload(encrypted) register_plugin(XEP_0384)