lets see
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-04-26 22:19:09 +02:00
parent b4a9ccb334
commit 66877d52a1
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047

View File

@ -25,9 +25,9 @@ class NetWrapper:
self.homeDirectory = "" self.homeDirectory = ""
self.authenticationInstance = authenticationInstance self.authenticationInstance = authenticationInstance
def ecryptRSAMessage(self, message: str) -> bytes: def encryptRSAMessage(self, message: bytes) -> bytes:
cipher_rsa = PKCS1_OAEP.new(self.currentClientPublicKey) cipher_rsa = PKCS1_OAEP.new(self.currentClientPublicKey)
encrypted_msg = cipher_rsa.encrypt(message.encode('UTF-8')) encrypted_msg = cipher_rsa.encrypt(message)
return encrypted_msg return encrypted_msg
def signRSAHeader(self, type: str, extradata: dict) -> (bytes, bytes): def signRSAHeader(self, type: str, extradata: dict) -> (bytes, bytes):
@ -63,7 +63,8 @@ class NetWrapper:
except Exception: except Exception:
raise Exception('Bad initial message') raise Exception('Bad initial message')
retheader, retheadersignature = self.signRSAHeader("IDY", {}) retheader, retheadersignature = self.signRSAHeader("IDY", {})
retmsg = self.ecryptRSAMessage(b64decode(incommingJson['message']).decode('UTF-8')) dcryptedmsg = self.decryptRSAMessage(b64decode(incommingJson['message']))
retmsg = self.encryptRSAMessage(dcryptedmsg)
identMsg = json.dumps( identMsg = json.dumps(
{'header': retheader, 'headersignature': retheadersignature, {'header': retheader, 'headersignature': retheadersignature,
'message': b64encode(retmsg).decode('UTF-8')}).encode( 'message': b64encode(retmsg).decode('UTF-8')}).encode(
@ -90,11 +91,11 @@ class NetWrapper:
def keyExchange(self) -> None: def keyExchange(self) -> None:
dh = pyDH.DiffieHellman() dh = pyDH.DiffieHellman()
mypubkey = self.ecryptRSAMessage(str(dh.gen_public_key())) mypubkey = self.encryptRSAMessage(str(dh.gen_public_key()).encode('UTF-8'))
header, headersignature = self.signRSAHeader("DH",{}) header, headersignature = self.signRSAHeader("DH",{})
jsonmsg = json.dumps( jsonmsg = json.dumps(
{'header': b64encode(header).decode('UTF-8'), 'headersignature': b64encode(headersignature).decode('UTF-8'), {'header': b64encode(header).decode('UTF-8'), 'headersignature': b64encode(headersignature).decode('UTF-8'),
'message': mypubkey}).encode('UTF-8') 'message': b64encode(mypubkey).decode('UTF-8')}).encode('UTF-8')
self.network.send_msg(self.clientAddr, jsonmsg) self.network.send_msg(self.clientAddr, jsonmsg)
status, msg = self.network.receive_msg(blocking=True) status, msg = self.network.receive_msg(blocking=True)
if not status: if not status: