diff --git a/client/netwrapper.py b/client/netwrapper.py index 8671fd1..369bc9a 100644 --- a/client/netwrapper.py +++ b/client/netwrapper.py @@ -26,9 +26,9 @@ class NetWrapper: allowed_chars: str = string.ascii_letters + string.punctuation) -> str: return ''.join(random.choice(allowed_chars) for x in range(str_size)) - def ecryptRSAMessage(self, message: str) -> bytes: + def ecryptRSAMessage(self, message: bytes) -> bytes: cipher_rsa = PKCS1_OAEP.new(self.serverPubKey) - 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): @@ -58,7 +58,7 @@ class NetWrapper: return decodedmsg, json.loads(b64decode(decodedmsg['header']).decode('UTF-8')) def identifyServer(self) -> bool: - randommsg = self.randomStringGenerator() + randommsg = self.randomStringGenerator().encode('UTF-8') encrypted_msg = self.ecryptRSAMessage(randommsg) header, headersignature = self.signRSAHeader('IDY', {'username': self.username}) identMsg = json.dumps( @@ -80,7 +80,7 @@ class NetWrapper: def createEncryptedChannel(self) -> None: dh = pyDH.DiffieHellman() - mypubkey = self.ecryptRSAMessage(str(dh.gen_public_key())) + mypubkey = self.ecryptRSAMessage(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'),