Echo_bot: prevent loops when decrypting/encrypting
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
79a4f417ed
commit
2dc08c9d2f
1 changed files with 5 additions and 0 deletions
|
@ -88,6 +88,7 @@ class EchoBot(ClientXMPP):
|
||||||
encrypted = msg['omemo_encrypted']
|
encrypted = msg['omemo_encrypted']
|
||||||
body = self['xep_0384'].decrypt_message(encrypted, mfrom, allow_untrusted)
|
body = self['xep_0384'].decrypt_message(encrypted, mfrom, allow_untrusted)
|
||||||
await self.encrypted_reply(msg, 'Thanks for sending\n%s' % body.decode("utf8"))
|
await self.encrypted_reply(msg, 'Thanks for sending\n%s' % body.decode("utf8"))
|
||||||
|
return None
|
||||||
except (MissingOwnKey,):
|
except (MissingOwnKey,):
|
||||||
# The message is missing our own key, it was not encrypted for
|
# The message is missing our own key, it was not encrypted for
|
||||||
# us, and we can't decrypt it.
|
# us, and we can't decrypt it.
|
||||||
|
@ -95,6 +96,7 @@ class EchoBot(ClientXMPP):
|
||||||
msg,
|
msg,
|
||||||
'I can\'t decrypt this message as it is not encrypted for me.',
|
'I can\'t decrypt this message as it is not encrypted for me.',
|
||||||
)
|
)
|
||||||
|
return None
|
||||||
except (NoAvailableSession,) as exn:
|
except (NoAvailableSession,) as exn:
|
||||||
# We received a message from that contained a session that we
|
# We received a message from that contained a session that we
|
||||||
# don't know about (deleted session storage, etc.). We can't
|
# 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 '
|
'I can\'t decrypt this message as it uses an encrypted '
|
||||||
'session I don\'t know about.',
|
'session I don\'t know about.',
|
||||||
)
|
)
|
||||||
|
return None
|
||||||
except (UndecidedException, UntrustedException) as exn:
|
except (UndecidedException, UntrustedException) as exn:
|
||||||
# We received a message from an untrusted device. We can
|
# We received a message from an untrusted device. We can
|
||||||
# choose to decrypt the message nonetheless, with the
|
# choose to decrypt the message nonetheless, with the
|
||||||
|
@ -122,11 +125,13 @@ class EchoBot(ClientXMPP):
|
||||||
)
|
)
|
||||||
# We resend, setting the `allow_untrusted` parameter to True.
|
# We resend, setting the `allow_untrusted` parameter to True.
|
||||||
await self.message(msg, allow_untrusted=True)
|
await self.message(msg, allow_untrusted=True)
|
||||||
|
return None
|
||||||
except (EncryptionPrepareException,):
|
except (EncryptionPrepareException,):
|
||||||
# Slixmpp tried its best, but there were errors it couldn't
|
# Slixmpp tried its best, but there were errors it couldn't
|
||||||
# resolve. At this point you should have seen other exceptions
|
# resolve. At this point you should have seen other exceptions
|
||||||
# and given a chance to resolve them already.
|
# and given a chance to resolve them already.
|
||||||
await self.plain_reply(msg, 'I was not able to decrypt the message.')
|
await self.plain_reply(msg, 'I was not able to decrypt the message.')
|
||||||
|
return None
|
||||||
except (Exception,) as exn:
|
except (Exception,) as exn:
|
||||||
await self.plain_reply(msg, 'An error occured while attempting decryption.\n%r' % exn)
|
await self.plain_reply(msg, 'An error occured while attempting decryption.\n%r' % exn)
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in a new issue