From 5378ec8cdcd9f730f53a07678bd5d0042adf98da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 18:18:37 +0200 Subject: [PATCH] better recievemessage --- server/netwrapper.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/netwrapper.py b/server/netwrapper.py index d94b982..4eca973 100644 --- a/server/netwrapper.py +++ b/server/netwrapper.py @@ -127,7 +127,12 @@ class NetWrapper: def recieveEncryptedMessage(self, msg: bytes) -> bytes: try: - b64 = json.loads(msg) + b64 = json.loads(msg.decode('UTF-8')) + while not (b64['source'] == self.clientAddr and b64['type'] == 'CMD'): + status, msg = self.network.receive_msg(blocking=True) + if not status: + raise Exception('Network error during connection.') + b64 = json.loads(msg.decode('UTF-8')) retnonce = b64decode(b64['nonce']) retciphertext = b64decode(b64['message']) retcipher = ChaCha20.new(self.cipherkey, nonce=retnonce)