This commit is contained in:
parent
bfb7e26d27
commit
a247271021
@ -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)
|
||||
@ -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'):
|
||||
|
Loading…
Reference in New Issue
Block a user