From 904c01db47effd57d106a9052b8844d416e64c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 17:06:25 +0200 Subject: [PATCH] use ascii --- server/netwrapper.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/netwrapper.py b/server/netwrapper.py index 7148410..a000bc1 100644 --- a/server/netwrapper.py +++ b/server/netwrapper.py @@ -37,14 +37,14 @@ class NetWrapper: identMsg = json.dumps( {'type': 'IDY', 'source': self.network.own_addr, 'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8')))}).encode( - 'UTF-8') + 'ASCII') self.network.send_msg(self.clientAddr, identMsg) def sendMessage(self, message: bytes) -> None: cipher = ChaCha20.new(self.cipherkey, get_random_bytes(12)) ciphertext = cipher.encrypt(message) - nonce = b64encode(cipher.nonce).decode('UTF-8') - ct = b64encode(ciphertext).decode('UTF-8') + nonce = b64encode(cipher.nonce).decode('ASCII') + ct = b64encode(ciphertext).decode('ASCII') sendjson = json.dumps({'type': 'CMD', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode( 'UTF-8') self.network.send_msg(self.clientAddr, sendjson) @@ -52,7 +52,7 @@ class NetWrapper: def keyExchange(self) -> None: dh = pyDH.DiffieHellman() cipher = PKCS1_OAEP.new(self.currentClientPublicKey) - mypubkey = b64encode(cipher.encrypt(str(dh.gen_public_key()).encode('UTF-8'))) + mypubkey = b64encode(cipher.encrypt(str(dh.gen_public_key()).encode('UTF-8'))).decode('ASCII') jsonmsg = json.dumps({'type': 'DH', 'source': self.network.own_addr, 'message': mypubkey}).encode('UTF-8') self.network.send_msg(self.clientAddr, jsonmsg) decodedmsg = {'source': '', 'type': ''} @@ -85,8 +85,8 @@ class NetWrapper: message = "ERROR".encode('UTF-8') cipher = ChaCha20.new(self.cipherkey, get_random_bytes(12)) ciphertext = cipher.encrypt(message) - nonce = b64encode(cipher.nonce).decode('UTF-8') - ct = b64encode(ciphertext).decode('UTF-8') + nonce = b64encode(cipher.nonce).decode('ASCII') + ct = b64encode(ciphertext).decode('ASCII') sendjson = json.dumps( {'type': 'AUT', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode( 'UTF-8')