diff --git a/client/netwrapper.py b/client/netwrapper.py index 56c7438..77dd3d2 100644 --- a/client/netwrapper.py +++ b/client/netwrapper.py @@ -23,12 +23,10 @@ class NetWrapper: self.serverPubKey = serverPubKey self.cipherkey = "".encode('UTF-8') - def randomStringGenerator(self, str_size: int = 128, allowed_chars: str = string.ascii_letters + string.punctuation) -> str: return ''.join(random.choice(allowed_chars) for x in range(str_size)) - def identifyServer(self) -> bool: randommsg = self.randomStringGenerator() cipher_rsa = PKCS1_OAEP.new(self.serverPubKey) @@ -47,7 +45,6 @@ class NetWrapper: retmsg = cipher_rsa.decrypt(b64decode(returnJson['message'])).decode('UTF-8') return retmsg == randommsg - def createEncryptedChannel(self): dh = pyDH.DiffieHellman() cipher_rsa = PKCS1_OAEP.new(self.serverPubKey) @@ -55,7 +52,7 @@ class NetWrapper: jsonmsg = json.dumps({'type': 'DH', 'source': self.network.own_addr, 'message': mypubkey}).encode('UTF-8') self.network.send_msg(self.serverAddr, jsonmsg) decodedmsg = {'source': '', 'type': ''} - while not (decodedmsg['source'] == self.serverAddr and decodedmsg['type'] == 'DH'): + while not (decodedmsg['source'] == self.serverAddr and decodedmsg['type'] == 'DH'): status, msg = self.network.receive_msg(blocking=True) if not status: raise Exception('Network error during connection.') @@ -77,7 +74,7 @@ class NetWrapper: 'UTF-8') self.network.send_msg(self.serverAddr, sendjson) b64 = {'source': '', 'type': ''} - while not (b64['source'] == self.serverAddr and b64['type'] == 'AUT'): + while not (b64['source'] == self.serverAddr and b64['type'] == 'AUT'): status, msg = self.network.receive_msg(blocking=True) if not status: raise Exception('Network error during connection.') @@ -92,7 +89,6 @@ class NetWrapper: except Exception: print("Incorrect decryption") - def connectToServer(self): identStatus = self.identifyServer() if not identStatus: @@ -102,7 +98,6 @@ class NetWrapper: pw = input() self.authenticate(pw) - def sendMessage(self, message: bytes): cipher = ChaCha20.new(key=self.cipherkey, nonce=get_random_bytes(12)) ciphertext = cipher.encrypt(message) @@ -112,7 +107,6 @@ class NetWrapper: 'UTF-8') self.network.send_msg(self.serverAddr, sendjson) - def recieveMessage(self) -> bytes: b64 = {'source': '', 'type': ''} while not (b64['source'] == self.serverAddr and b64['type'] == 'AUT'):