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

This commit is contained in:
Torma Kristóf 2021-04-26 17:20:14 +02:00
parent e8ab5d0ddd
commit 12dd07c749
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047

View File

@ -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')