This commit is contained in:
parent
e8ab5d0ddd
commit
12dd07c749
@ -73,7 +73,8 @@ class NetWrapper:
|
||||
nonce = b64encode(cipher.nonce).decode('UTF-8')
|
||||
ct = b64encode(ciphertext).decode('UTF-8')
|
||||
b64tag = b64encode(tag).decode('UTF-8')
|
||||
sendjson = json.dumps({'header': b64encode(header).decode('UTF-8'), 'nonce': nonce, 'message': ct, 'tag': b64tag}).encode(
|
||||
sendjson = json.dumps(
|
||||
{'header': b64encode(header).decode('UTF-8'), 'nonce': nonce, 'message': ct, 'tag': b64tag}).encode(
|
||||
'UTF-8')
|
||||
self.network.send_msg(self.serverAddr, sendjson)
|
||||
try:
|
||||
@ -86,7 +87,7 @@ class NetWrapper:
|
||||
retcipher = ChaCha20_Poly1305.new(key=self.cipherkey, nonce=retnonce)
|
||||
retcipher.update(b64decode(b64['header']))
|
||||
retheader = json.loads(b64decode(b64['header']).decode('UTF-8'))
|
||||
plaintext = retcipher.decrypt_and_verify(retciphertext,b64decode(b64['tag'])).decode('UTF-8')
|
||||
plaintext = retcipher.decrypt_and_verify(retciphertext, b64decode(b64['tag'])).decode('UTF-8')
|
||||
if plaintext != "OK" or not (retheader['source'] == self.serverAddr and retheader['type'] == 'AUT'):
|
||||
raise Exception('Authentication error')
|
||||
except Exception as e:
|
||||
@ -108,7 +109,8 @@ class NetWrapper:
|
||||
ciphertext, tag = cipher.encrypt_and_digest(message)
|
||||
nonce = b64encode(cipher.nonce).decode('UTF-8')
|
||||
ct = b64encode(ciphertext).decode('UTF-8')
|
||||
sendjson = json.dumps({'header': b64encode(header).decode('UTF-8'), 'nonce': nonce, 'message': ct, 'tag': b64encode(tag).decode('UTF-8')}).encode(
|
||||
sendjson = json.dumps({'header': b64encode(header).decode('UTF-8'), 'nonce': nonce, 'message': ct,
|
||||
'tag': b64encode(tag).decode('UTF-8')}).encode(
|
||||
'UTF-8')
|
||||
self.network.send_msg(self.serverAddr, sendjson)
|
||||
|
||||
@ -121,7 +123,7 @@ class NetWrapper:
|
||||
retnonce = b64decode(b64['nonce'])
|
||||
retciphertext = b64decode(b64['message'])
|
||||
retcipher = ChaCha20_Poly1305.new(key=self.cipherkey, nonce=retnonce)
|
||||
plaintext = retcipher.decrypt_and_verify(retciphertext,b64decode(b64['tag']))
|
||||
plaintext = retcipher.decrypt_and_verify(retciphertext, b64decode(b64['tag']))
|
||||
retheader = json.loads(b64decode(b64['header']).decode('UTF-8'))
|
||||
if not (retheader['source'] == self.serverAddr and retheader['type'] == 'CMD'):
|
||||
return "ERROR".encode('UTF-8')
|
||||
|
Loading…
Reference in New Issue
Block a user