use ascii
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2021-04-25 17:06:25 +02:00
parent f1220dd49e
commit 904c01db47
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
1 changed files with 6 additions and 6 deletions

View File

@ -37,14 +37,14 @@ class NetWrapper:
identMsg = json.dumps( identMsg = json.dumps(
{'type': 'IDY', 'source': self.network.own_addr, {'type': 'IDY', 'source': self.network.own_addr,
'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8')))}).encode( 'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8')))}).encode(
'UTF-8') 'ASCII')
self.network.send_msg(self.clientAddr, identMsg) self.network.send_msg(self.clientAddr, identMsg)
def sendMessage(self, message: bytes) -> None: def sendMessage(self, message: bytes) -> None:
cipher = ChaCha20.new(self.cipherkey, get_random_bytes(12)) cipher = ChaCha20.new(self.cipherkey, get_random_bytes(12))
ciphertext = cipher.encrypt(message) ciphertext = cipher.encrypt(message)
nonce = b64encode(cipher.nonce).decode('UTF-8') nonce = b64encode(cipher.nonce).decode('ASCII')
ct = b64encode(ciphertext).decode('UTF-8') ct = b64encode(ciphertext).decode('ASCII')
sendjson = json.dumps({'type': 'CMD', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode( sendjson = json.dumps({'type': 'CMD', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode(
'UTF-8') 'UTF-8')
self.network.send_msg(self.clientAddr, sendjson) self.network.send_msg(self.clientAddr, sendjson)
@ -52,7 +52,7 @@ class NetWrapper:
def keyExchange(self) -> None: def keyExchange(self) -> None:
dh = pyDH.DiffieHellman() dh = pyDH.DiffieHellman()
cipher = PKCS1_OAEP.new(self.currentClientPublicKey) cipher = PKCS1_OAEP.new(self.currentClientPublicKey)
mypubkey = b64encode(cipher.encrypt(str(dh.gen_public_key()).encode('UTF-8'))) mypubkey = b64encode(cipher.encrypt(str(dh.gen_public_key()).encode('UTF-8'))).decode('ASCII')
jsonmsg = json.dumps({'type': 'DH', 'source': self.network.own_addr, 'message': mypubkey}).encode('UTF-8') jsonmsg = json.dumps({'type': 'DH', 'source': self.network.own_addr, 'message': mypubkey}).encode('UTF-8')
self.network.send_msg(self.clientAddr, jsonmsg) self.network.send_msg(self.clientAddr, jsonmsg)
decodedmsg = {'source': '', 'type': ''} decodedmsg = {'source': '', 'type': ''}
@ -85,8 +85,8 @@ class NetWrapper:
message = "ERROR".encode('UTF-8') message = "ERROR".encode('UTF-8')
cipher = ChaCha20.new(self.cipherkey, get_random_bytes(12)) cipher = ChaCha20.new(self.cipherkey, get_random_bytes(12))
ciphertext = cipher.encrypt(message) ciphertext = cipher.encrypt(message)
nonce = b64encode(cipher.nonce).decode('UTF-8') nonce = b64encode(cipher.nonce).decode('ASCII')
ct = b64encode(ciphertext).decode('UTF-8') ct = b64encode(ciphertext).decode('ASCII')
sendjson = json.dumps( sendjson = json.dumps(
{'type': 'AUT', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode( {'type': 'AUT', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode(
'UTF-8') 'UTF-8')