pep8
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-04-26 00:23:57 +02:00
parent bfb7e26d27
commit a247271021
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047

View File

@ -23,12 +23,10 @@ class NetWrapper:
self.serverPubKey = serverPubKey self.serverPubKey = serverPubKey
self.cipherkey = "".encode('UTF-8') self.cipherkey = "".encode('UTF-8')
def randomStringGenerator(self, str_size: int = 128, def randomStringGenerator(self, str_size: int = 128,
allowed_chars: str = string.ascii_letters + string.punctuation) -> str: allowed_chars: str = string.ascii_letters + string.punctuation) -> str:
return ''.join(random.choice(allowed_chars) for x in range(str_size)) return ''.join(random.choice(allowed_chars) for x in range(str_size))
def identifyServer(self) -> bool: def identifyServer(self) -> bool:
randommsg = self.randomStringGenerator() randommsg = self.randomStringGenerator()
cipher_rsa = PKCS1_OAEP.new(self.serverPubKey) cipher_rsa = PKCS1_OAEP.new(self.serverPubKey)
@ -47,7 +45,6 @@ class NetWrapper:
retmsg = cipher_rsa.decrypt(b64decode(returnJson['message'])).decode('UTF-8') retmsg = cipher_rsa.decrypt(b64decode(returnJson['message'])).decode('UTF-8')
return retmsg == randommsg return retmsg == randommsg
def createEncryptedChannel(self): def createEncryptedChannel(self):
dh = pyDH.DiffieHellman() dh = pyDH.DiffieHellman()
cipher_rsa = PKCS1_OAEP.new(self.serverPubKey) cipher_rsa = PKCS1_OAEP.new(self.serverPubKey)
@ -92,7 +89,6 @@ class NetWrapper:
except Exception: except Exception:
print("Incorrect decryption") print("Incorrect decryption")
def connectToServer(self): def connectToServer(self):
identStatus = self.identifyServer() identStatus = self.identifyServer()
if not identStatus: if not identStatus:
@ -102,7 +98,6 @@ class NetWrapper:
pw = input() pw = input()
self.authenticate(pw) self.authenticate(pw)
def sendMessage(self, message: bytes): def sendMessage(self, message: bytes):
cipher = ChaCha20.new(key=self.cipherkey, nonce=get_random_bytes(12)) cipher = ChaCha20.new(key=self.cipherkey, nonce=get_random_bytes(12))
ciphertext = cipher.encrypt(message) ciphertext = cipher.encrypt(message)
@ -112,7 +107,6 @@ class NetWrapper:
'UTF-8') 'UTF-8')
self.network.send_msg(self.serverAddr, sendjson) self.network.send_msg(self.serverAddr, sendjson)
def recieveMessage(self) -> bytes: def recieveMessage(self) -> bytes:
b64 = {'source': '', 'type': ''} b64 = {'source': '', 'type': ''}
while not (b64['source'] == self.serverAddr and b64['type'] == 'AUT'): while not (b64['source'] == self.serverAddr and b64['type'] == 'AUT'):