xep_0384: update to using TrustException from the omemo lib
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
de1ecb730a
commit
f3d9143bf6
1 changed files with 19 additions and 7 deletions
|
@ -130,10 +130,18 @@ class NoAvailableSession(XEP0384): pass
|
||||||
class EncryptionPrepareException(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):
|
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
|
# 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.
|
# in any case, but we want to tell the user, always.
|
||||||
raise NoAvailableSession(jid, sid)
|
raise NoAvailableSession(jid, sid)
|
||||||
except (omemo.exceptions.UntrustedException,) as e:
|
except (omemo.exceptions.TrustException,) as exn:
|
||||||
raise UntrustedException(e)
|
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:
|
finally:
|
||||||
asyncio.ensure_future(self._publish_bundle())
|
asyncio.ensure_future(self._publish_bundle())
|
||||||
|
|
||||||
|
@ -415,14 +427,14 @@ class XEP_0384(BasePlugin):
|
||||||
if bundle is not None:
|
if bundle is not None:
|
||||||
devices = bundles.setdefault(exn.bare_jid, {})
|
devices = bundles.setdefault(exn.bare_jid, {})
|
||||||
devices[exn.device] = bundle
|
devices[exn.device] = bundle
|
||||||
elif isinstance(exn, omemo.exceptions.UntrustedException):
|
elif isinstance(exn, omemo.exceptions.TrustException):
|
||||||
# On UntrustedException, there are two possibilities.
|
# On TrustException, there are two possibilities.
|
||||||
# Either trust has not been explicitely set yet, and is
|
# Either trust has not been explicitely set yet, and is
|
||||||
# 'undecided', or the device is explicitely not
|
# 'undecided', or the device is explicitely not
|
||||||
# trusted. When undecided, we need to ask our user to make
|
# trusted. When undecided, we need to ask our user to make
|
||||||
# a choice. If untrusted, then we can safely tell the
|
# a choice. If untrusted, then we can safely tell the
|
||||||
# OMEMO lib to not encrypt to this device
|
# 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)
|
raise UndecidedException(exn.bare_jid, exn.device, exn.ik)
|
||||||
expect_problems.setdefault(exn.bare_jid, []).append(exn.device)
|
expect_problems.setdefault(exn.bare_jid, []).append(exn.device)
|
||||||
elif isinstance(exn, omemo.exceptions.NoEligibleDevicesException):
|
elif isinstance(exn, omemo.exceptions.NoEligibleDevicesException):
|
||||||
|
|
Loading…
Reference in a new issue