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):