From 4b565c0f7b17e7b647476f5fd8a750bf842e9979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 1 Dec 2018 18:38:02 +0000 Subject: [PATCH] xep_0384: document & raise NoAvailableSession MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugin.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/plugin.py b/plugin.py index 16223c6..bfde067 100644 --- a/plugin.py +++ b/plugin.py @@ -73,6 +73,9 @@ class XEP0384(Exception): pass class MissingOwnKey(XEP0384): pass +class NoAvailableSession(XEP0384): pass + + class NoEligibleDevices(XEP0384): pass @@ -293,15 +296,24 @@ class XEP_0384(BasePlugin): # XXX: 'cipher' is part of KeyTransportMessages and is used when no payload # is passed. We do not implement this yet. - _cipher, body = self._omemo.decryptMessage( - jid, - sid, - iv, - message, - isPrekeyMessage, - payload, - ) - return body + try: + _cipher, body = self._omemo.decryptMessage( + jid, + sid, + iv, + message, + isPrekeyMessage, + payload, + ) + return body + except (omemo.exceptions.NoSessionException,) as e: + # This might happen when the sender is sending using a session + # that we don't know about (deleted session storage, etc.). In + # 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. + # TODO: get ahold of bare_jid and device_id to pass in the + # exception. + raise NoAvailableSession def _fetching_bundle(self, jid: str, exn: Exception, key: str, _val: Any) -> bool: return isinstance(exn, omemo.exceptions.MissingBundleException) and key == jid