From f3d9143bf6df75892e76bbe1eb2dae5426305e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 19 Feb 2019 00:09:16 +0000 Subject: [PATCH] xep_0384: update to using TrustException from the omemo lib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index e210a8c..c42820f 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -130,10 +130,18 @@ class NoAvailableSession(XEP0384): pass class EncryptionPrepareException(XEP0384): pass -class UntrustedException(XEP0384): pass +class UntrustedException(XEP0384): + def __init__(self, bare_jid, device, ik): + self.bare_jid = JID(bare_jid) + self.device = device + self.ik = ik -class UndecidedException(XEP0384): pass +class UndecidedException(XEP0384): + def __init__(self, bare_jid, device, ik): + self.bare_jid = JID(bare_jid) + self.device = device + self.ik = ik class XEP_0384(BasePlugin): @@ -359,8 +367,12 @@ class XEP_0384(BasePlugin): # this case we can't decrypt the message and it's going to be lost # in any case, but we want to tell the user, always. raise NoAvailableSession(jid, sid) - except (omemo.exceptions.UntrustedException,) as e: - raise UntrustedException(e) + except (omemo.exceptions.TrustException,) as exn: + if exn.problem == 'undecided': + raise UndecidedException(exn.bare_jid, exn.device, exn.ik) + elif exn.problem == 'untrusted': + raise UntrustedException(exn.bare_jid, exn.device, exn.ik) + raise finally: asyncio.ensure_future(self._publish_bundle()) @@ -415,14 +427,14 @@ class XEP_0384(BasePlugin): if bundle is not None: devices = bundles.setdefault(exn.bare_jid, {}) devices[exn.device] = bundle - elif isinstance(exn, omemo.exceptions.UntrustedException): - # On UntrustedException, there are two possibilities. + elif isinstance(exn, omemo.exceptions.TrustException): + # On TrustException, there are two possibilities. # Either trust has not been explicitely set yet, and is # 'undecided', or the device is explicitely not # trusted. When undecided, we need to ask our user to make # a choice. If untrusted, then we can safely tell the # OMEMO lib to not encrypt to this device - if self._omemo.getTrustForDevice(exn.bare_jid, exn.device) is None: + if exn.problem == 'undecided': raise UndecidedException(exn.bare_jid, exn.device, exn.ik) expect_problems.setdefault(exn.bare_jid, []).append(exn.device) elif isinstance(exn, omemo.exceptions.NoEligibleDevicesException):