Mercurial > libervia-backend
changeset 3084:ffcdd93b61fa
plugin XEP-0384: specific warning on missing omemo-backend-signal + fixed encoding following Python 3 port
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 07 Dec 2019 11:30:56 +0100 (2019-12-07) |
parents | 3c924cb207d9 |
children | c048fc192739 |
files | sat/plugins/plugin_xep_0384.py setup.py |
diffstat | 2 files changed, 16 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0384.py Fri Dec 06 15:20:00 2019 +0100 +++ b/sat/plugins/plugin_xep_0384.py Sat Dec 07 11:30:56 2019 +0100 @@ -21,7 +21,6 @@ from sat.core.constants import Const as C from sat.core.log import getLogger from sat.core import exceptions -from omemo import exceptions as omemo_excpt from twisted.internet import defer from twisted.words.xish import domish from twisted.words.protocols.jabber import jid @@ -34,14 +33,20 @@ import base64 try: import omemo + from omemo import exceptions as omemo_excpt from omemo.extendedpublicbundle import ExtendedPublicBundle - from omemo_backend_signal import BACKEND as omemo_backend - # from omemo import wireformat -except ImportError as e: +except ImportError: raise exceptions.MissingModule( 'Missing module omemo, please download/install it. You can use ' '"pip install omemo"' ) +try: + from omemo_backend_signal import BACKEND as omemo_backend +except ImportError: + raise exceptions.MissingModule( + 'Missing module omemo-backend-signal, please download/install it. You can use ' + '"pip install omemo-backend-signal"' + ) log = getLogger(__name__) @@ -335,7 +340,7 @@ bundles = {e.userhost(): v for e, v in bundles.items()} encrypt_mess_p = self._session.encryptMessage( bare_jids=bare_jids, - plaintext=message.encode('utf-8'), + plaintext=message.encode(), bundles=bundles, expect_problems=expect_problems) return promise2Deferred(encrypt_mess_p) @@ -425,8 +430,6 @@ expect_problems.setdefault(data.bare_jid, set()).add(data.device) defer.returnValue({}) - - @defer.inlineCallbacks def getTrustUI(self, client, entity_jid=None, trust_data=None, submit_id=None): """Generate a XMLUI to manage trust @@ -512,7 +515,7 @@ xmlui.addLabel(D_("This device ID")) xmlui.addText(str(client._xep_0384_device_id)) xmlui.addLabel(D_("This device fingerprint")) - ik_hex = session.public_bundle.ik.encode('hex').upper() + ik_hex = session.public_bundle.ik.hex().upper() fp_human = ' '.join([ik_hex[i:i+8] for i in range(0, len(ik_hex), 8)]) xmlui.addText(fp_human) xmlui.addEmpty() @@ -525,7 +528,7 @@ xmlui.addLabel(D_("Device ID")) xmlui.addText(str(data['device'])) xmlui.addLabel(D_("Fingerprint")) - ik_hex = data['ik'].encode('hex').upper() + ik_hex = data['ik'].hex().upper() fp_human = ' '.join([ik_hex[i:i+8] for i in range(0, len(ik_hex), 8)]) xmlui.addText(fp_human) xmlui.addLabel(D_("Trust this device?")) @@ -904,7 +907,7 @@ break except Exception as e: msg = _("Can't encrypt message for {entity}: {reason}".format( - entity=entity_bare_jid.full(), reason=str(e).decode('utf-8', 'replace'))) + entity=entity_bare_jid.full(), reason=e)) log.warning(msg) extra = {C.MESS_EXTRA_INFO: C.EXTRA_INFO_ENCR_ERR} client.feedback(entity_bare_jid, msg, extra) @@ -959,7 +962,7 @@ "for our device (device_id: {device_id}, fingerprint: " "{fingerprint}): {xml}").format( device_id=device_id, - fingerprint=omemo_session.public_bundle.ik.encode('hex'), + fingerprint=omemo_session.public_bundle.ik.hex().upper(), xml=encrypted_elt.toXml())) user_msg = (D_("An OMEMO message from {sender} has not been encrypted for " "our device, we can't decrypt it").format( @@ -995,6 +998,7 @@ plaintext = yield omemo_session.decryptMessage(**kwargs) else: post_treat.addCallback(client.encryption.markAsTrusted) + plaintext = plaintext.decode() except Exception as e: log.warning(_("Can't decrypt message: {reason}\n{xml}").format( reason=e, xml=message_elt.toXml()))