From 66877d52a17433d1d696859c9bfb2d8e0c329b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 26 Apr 2021 22:19:09 +0200 Subject: [PATCH] lets see --- server/netwrapper.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/netwrapper.py b/server/netwrapper.py index 7edd4bb..43bbb98 100644 --- a/server/netwrapper.py +++ b/server/netwrapper.py @@ -25,9 +25,9 @@ class NetWrapper: self.homeDirectory = "" self.authenticationInstance = authenticationInstance - def ecryptRSAMessage(self, message: str) -> bytes: + def encryptRSAMessage(self, message: bytes) -> bytes: cipher_rsa = PKCS1_OAEP.new(self.currentClientPublicKey) - encrypted_msg = cipher_rsa.encrypt(message.encode('UTF-8')) + encrypted_msg = cipher_rsa.encrypt(message) return encrypted_msg def signRSAHeader(self, type: str, extradata: dict) -> (bytes, bytes): @@ -63,7 +63,8 @@ class NetWrapper: except Exception: raise Exception('Bad initial message') retheader, retheadersignature = self.signRSAHeader("IDY", {}) - retmsg = self.ecryptRSAMessage(b64decode(incommingJson['message']).decode('UTF-8')) + dcryptedmsg = self.decryptRSAMessage(b64decode(incommingJson['message'])) + retmsg = self.encryptRSAMessage(dcryptedmsg) identMsg = json.dumps( {'header': retheader, 'headersignature': retheadersignature, 'message': b64encode(retmsg).decode('UTF-8')}).encode( @@ -90,11 +91,11 @@ class NetWrapper: def keyExchange(self) -> None: dh = pyDH.DiffieHellman() - mypubkey = self.ecryptRSAMessage(str(dh.gen_public_key())) + mypubkey = self.encryptRSAMessage(str(dh.gen_public_key()).encode('UTF-8')) header, headersignature = self.signRSAHeader("DH",{}) jsonmsg = json.dumps( {'header': b64encode(header).decode('UTF-8'), 'headersignature': b64encode(headersignature).decode('UTF-8'), - 'message': mypubkey}).encode('UTF-8') + 'message': b64encode(mypubkey).decode('UTF-8')}).encode('UTF-8') self.network.send_msg(self.clientAddr, jsonmsg) status, msg = self.network.receive_msg(blocking=True) if not status: