From c355b14f79a56f465454d65e34a427d77dbb2bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Fri, 30 Nov 2018 18:06:13 +0000 Subject: [PATCH] xep_0384: loop again until encryption errors are fixed or until we're stuck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugin.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugin.py b/plugin.py index 3b876af..2becd44 100644 --- a/plugin.py +++ b/plugin.py @@ -8,7 +8,7 @@ import logging -from typing import Any, Dict, List, Set, Union +from typing import Any, Dict, List, Set, Tuple, Union import os import json @@ -76,6 +76,9 @@ class MissingOwnKey(XEP0384): pass class NoEligibleDevices(XEP0384): pass +class EncryptionPrepareException(XEP0384): pass + + class XEP_0384(BasePlugin): """ @@ -298,7 +301,10 @@ class XEP_0384(BasePlugin): recipients = [jid.bare for jid in recipients] bundles = {} # type: Dict[str, Dict[int, ExtendedPublicBundle]] + old_errors = None # type: Union[None, List[Tuple[Exception, Any, Any]]] while True: + # Try to encrypt and resolve errors until there is no error at all + # or if we hit the same set of errors. errors = [] self._omemo.encryptMessage( @@ -313,9 +319,13 @@ class XEP_0384(BasePlugin): if not errors: break + if errors == old_errors: + raise EncryptionPrepareException + + old_errors = errors + no_eligible_devices = set() # type: Set[str] for (exn, key, val) in errors: - if isinstance(exn, MissingBundleException): bundle = await self._fetch_bundle(key, val) if bundle is not None: @@ -341,8 +351,6 @@ class XEP_0384(BasePlugin): if no_eligible_devices: raise NoEligibleDevices(no_eligible_devices) - break - # Attempt encryption payload = Encrypted() payload['omemo_encrypted'] = self._omemo.encryptMessage(