From 2dc08c9d2f344d143b18cd2c1692e79a720cd9d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 2 Sep 2019 02:21:00 +0200 Subject: [PATCH] Echo_bot: prevent loops when decrypting/encrypting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- examples/echo_client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/echo_client.py b/examples/echo_client.py index f5fc2ee..954280a 100644 --- a/examples/echo_client.py +++ b/examples/echo_client.py @@ -88,6 +88,7 @@ class EchoBot(ClientXMPP): encrypted = msg['omemo_encrypted'] body = self['xep_0384'].decrypt_message(encrypted, mfrom, allow_untrusted) await self.encrypted_reply(msg, 'Thanks for sending\n%s' % body.decode("utf8")) + return None except (MissingOwnKey,): # The message is missing our own key, it was not encrypted for # us, and we can't decrypt it. @@ -95,6 +96,7 @@ class EchoBot(ClientXMPP): msg, 'I can\'t decrypt this message as it is not encrypted for me.', ) + return None except (NoAvailableSession,) as exn: # We received a message from that contained a session that we # don't know about (deleted session storage, etc.). We can't @@ -107,6 +109,7 @@ class EchoBot(ClientXMPP): 'I can\'t decrypt this message as it uses an encrypted ' 'session I don\'t know about.', ) + return None except (UndecidedException, UntrustedException) as exn: # We received a message from an untrusted device. We can # choose to decrypt the message nonetheless, with the @@ -122,11 +125,13 @@ class EchoBot(ClientXMPP): ) # We resend, setting the `allow_untrusted` parameter to True. await self.message(msg, allow_untrusted=True) + return None except (EncryptionPrepareException,): # Slixmpp tried its best, but there were errors it couldn't # resolve. At this point you should have seen other exceptions # and given a chance to resolve them already. await self.plain_reply(msg, 'I was not able to decrypt the message.') + return None except (Exception,) as exn: await self.plain_reply(msg, 'An error occured while attempting decryption.\n%r' % exn) raise