This commit is contained in:
parent
4854a71b32
commit
8eea92a714
@ -37,12 +37,14 @@ class NetWrapper:
|
||||
'message': b64encode(cipher.encrypt(randommsg.encode('UTF-8')))}).encode(
|
||||
'UTF-8')
|
||||
self.network.send_msg(self.serverAddr, identMsg)
|
||||
returnJson = {'source': '', 'type': ''}
|
||||
while not (returnJson['source'] == self.serverAddr and returnJson['type'] == 'IDY'):
|
||||
status, msg = self.network.receive_msg(blocking=True)
|
||||
if not status:
|
||||
raise Exception('Network error during connection.')
|
||||
returnJson = json.loads(msg.decode('UTF-8'))
|
||||
myrsakey = RSA.import_key(self.privateKey)
|
||||
mycipher = PKCS1_OAEP.new(myrsakey)
|
||||
returnJson = json.loads(msg.decode('UTF-8'))
|
||||
retmsg = mycipher.decrypt(b64decode(returnJson['message'])).decode('UTF-8')
|
||||
return retmsg == randommsg
|
||||
|
||||
@ -53,6 +55,8 @@ class NetWrapper:
|
||||
mypubkey = b64encode(cipher.encrypt(str(dh.gen_public_key()).encode('UTF-8')))
|
||||
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'):
|
||||
status, msg = self.network.receive_msg(blocking=True)
|
||||
if not status:
|
||||
raise Exception('Network error during connection.')
|
||||
@ -70,12 +74,13 @@ class NetWrapper:
|
||||
ct = b64encode(ciphertext).decode('UTF-8')
|
||||
sendjson = json.dumps({'type': 'AUT', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode(
|
||||
'UTF-8')
|
||||
self.network.send_msg(self.serverAddr, sendjson)
|
||||
b64 = {'source': '', 'type': ''}
|
||||
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.')
|
||||
b64 = json.loads(msg.decode('UTF-8'))
|
||||
try:
|
||||
b64 = json.loads(msg)
|
||||
retnonce = b64decode(b64['nonce'])
|
||||
retciphertext = b64decode(b64['message'])
|
||||
retcipher = ChaCha20.new(self.cipherkey, nonce=retnonce)
|
||||
@ -104,11 +109,13 @@ class NetWrapper:
|
||||
self.network.send_msg(self.serverAddr, sendjson)
|
||||
|
||||
def recieveMessage(self) -> bytes:
|
||||
b64 = {'source': '', 'type': ''}
|
||||
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.')
|
||||
b64 = json.loads(msg.decode('UTF-8'))
|
||||
try:
|
||||
b64 = json.loads(msg)
|
||||
retnonce = b64decode(b64['nonce'])
|
||||
retciphertext = b64decode(b64['message'])
|
||||
retcipher = ChaCha20.new(self.cipherkey, nonce=retnonce)
|
||||
|
Loading…
Reference in New Issue
Block a user