This commit is contained in:
parent
b4a9ccb334
commit
66877d52a1
@ -25,9 +25,9 @@ class NetWrapper:
|
||||
self.homeDirectory = ""
|
||||
self.authenticationInstance = authenticationInstance
|
||||
|
||||
def ecryptRSAMessage(self, message: str) -> bytes:
|
||||
def encryptRSAMessage(self, message: bytes) -> bytes:
|
||||
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
|
||||
|
||||
def signRSAHeader(self, type: str, extradata: dict) -> (bytes, bytes):
|
||||
@ -63,7 +63,8 @@ class NetWrapper:
|
||||
except Exception:
|
||||
raise Exception('Bad initial message')
|
||||
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(
|
||||
{'header': retheader, 'headersignature': retheadersignature,
|
||||
'message': b64encode(retmsg).decode('UTF-8')}).encode(
|
||||
@ -90,11 +91,11 @@ class NetWrapper:
|
||||
|
||||
def keyExchange(self) -> None:
|
||||
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",{})
|
||||
jsonmsg = json.dumps(
|
||||
{'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)
|
||||
status, msg = self.network.receive_msg(blocking=True)
|
||||
if not status:
|
||||
|
Loading…
Reference in New Issue
Block a user