From 957b555d930b14f99f1dedd4d52ea1f1d0a92ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 28 Mar 2020 12:28:52 +0100 Subject: [PATCH] Raise an exception when the payload is not of the form we expect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp_omemo/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/slixmpp_omemo/__init__.py b/slixmpp_omemo/__init__.py index bb786b7..80de0a9 100644 --- a/slixmpp_omemo/__init__.py +++ b/slixmpp_omemo/__init__.py @@ -170,6 +170,10 @@ class UndecidedException(XEP0384): self.ik = ik +class ErroneousPayload(XEP0384): + """To be raised when the payload is not of the form we expect""" + + class XEP_0384(BasePlugin): """ @@ -512,6 +516,8 @@ class XEP_0384(BasePlugin): allow_untrusted: bool = False, ) -> Optional[str]: header = encrypted['header'] + if encrypted['payload']['value'] is None: + raise ErroneousPayload('The payload element was empty') payload = b64dec(encrypted['payload']['value']) jid = sender.bare @@ -524,7 +530,11 @@ class XEP_0384(BasePlugin): key = Key(key) isPrekeyMessage = key['prekey'] in TRUE_VALUES + if key['value'] is None: + raise ErroneousPayload('The key element was empty') message = b64dec(key['value']) + if header['iv']['value'] is None: + raise ErroneousPayload('The iv element was empty') iv = b64dec(header['iv']['value']) # XXX: 'cipher' is part of KeyTransportMessages and is used when no payload