xep_0384: Change behaviour for NoElibibleDevices, add comments

Thanks to Syndace for the explanation.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2018-12-31 21:51:56 +01:00
parent 2880aef846
commit 77dccdb332

View file

@ -100,13 +100,6 @@ def _generate_encrypted_payload(encrypted) -> Encrypted:
return tag return tag
def _exn_matching_jid(jid: str, exn: Exception) -> bool:
if not hasattr(exn, 'bare_jid'):
return False
return isinstance(exn, omemo.exceptions.OMEMOException) and exn.bare_jid == jid
# XXX: This should probably be moved in plugins/base.py? # XXX: This should probably be moved in plugins/base.py?
class PluginCouldNotLoad(Exception): pass class PluginCouldNotLoad(Exception): pass
@ -121,9 +114,6 @@ class MissingOwnKey(XEP0384): pass
class NoAvailableSession(XEP0384): pass class NoAvailableSession(XEP0384): pass
class NoEligibleDevices(XEP0384): pass
class EncryptionPrepareException(XEP0384): pass class EncryptionPrepareException(XEP0384): pass
@ -387,26 +377,18 @@ 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.NoEligibleDevicesException):
# This error is apparently returned every time the omemo
# lib couldn't find a device to encrypt to for a
# particular JID.
# In case there is also an MissingBundleException in the
# returned errors, ignore this and retry later, assuming
# the fetching of the bundle succeeded. TODO: Ensure that it
# did.
# This exception is mostly useful when a contact does not
# do OMEMO, or hasn't published any device list for any
# other reason.
if any(_exn_matching_jid(exn.bare_jid, err) for err in errors):
continue
no_eligible_devices.add(exn.bare_jid)
elif isinstance(exn, omemo.exceptions.UntrustedException): elif isinstance(exn, omemo.exceptions.UntrustedException):
# TODO: Pass the exception down to the lib user # TODO: Pass the exception down to the lib user
# raise UntrustedException(exn.bare_jid, exn.device, exn.ik) # raise UntrustedException(exn.bare_jid, exn.device, exn.ik)
self._omemo.trust(exn.bare_jid, exn.device, exn.ik) self._omemo.trust(exn.bare_jid, exn.device, exn.ik)
elif isinstance(exn, omemo.exceptions.NoEligibleDevicesException):
if no_eligible_devices: # This error is returned by the library to specify that
raise NoEligibleDevices(no_eligible_devices) # encryption is not possible to any device of a user.
# This always comes with a more specific exception, (empty
# device list, missing bundles, trust issues, etc.).
# This does the heavy lifting of state management, and
# seeing if it's possible to encrypt at all, or not.
# This exception is only passed to the user, that should
# decide what to do with it, as there isn't much we can if
# other issues can't be resolved.
continue