This commit is contained in:
parent
3dbde8fbb8
commit
f1220dd49e
@ -12,7 +12,7 @@ def generatePrivateKeyForUser(auth: Authetication,username: str, user_passphrase
|
|||||||
|
|
||||||
private_key = RSA.generate(2048)
|
private_key = RSA.generate(2048)
|
||||||
public_key = private_key.publickey()
|
public_key = private_key.publickey()
|
||||||
private_key_value = bytes.hex(private_key.exportKey('DER', passphrase=user_passphrase, pkcs=8))
|
private_key_value = bytes.hex(private_key.exportKey('DER', passphrase=user_passphrase, pkcs=8, protection="scryptAndAES128-CBC"))
|
||||||
public_key_value = bytes.hex(public_key.exportKey('DER', pkcs=8))
|
public_key_value = bytes.hex(public_key.exportKey('DER', pkcs=8))
|
||||||
|
|
||||||
##Save private key in separate file
|
##Save private key in separate file
|
||||||
@ -44,7 +44,7 @@ def generatePrivateKeyForServer(auth: Authetication,passphrase: str) -> str:
|
|||||||
|
|
||||||
private_key = RSA.generate(2048)
|
private_key = RSA.generate(2048)
|
||||||
public_key = private_key.publickey()
|
public_key = private_key.publickey()
|
||||||
private_key_value = bytes.hex(private_key.exportKey('DER', passphrase=passphrase, pkcs=8))
|
private_key_value = bytes.hex(private_key.exportKey('DER', passphrase=passphrase, pkcs=8, protection="scryptAndAES128-CBC"))
|
||||||
public_key_value = bytes.hex(public_key.exportKey('DER', pkcs=8))
|
public_key_value = bytes.hex(public_key.exportKey('DER', pkcs=8))
|
||||||
|
|
||||||
data['serverPrivateKey'] = private_key_value
|
data['serverPrivateKey'] = private_key_value
|
||||||
|
@ -31,9 +31,9 @@ class NetWrapper:
|
|||||||
self.clientAddr = incommingJson['source']
|
self.clientAddr = incommingJson['source']
|
||||||
self.currentUser = incommingJson['username']
|
self.currentUser = incommingJson['username']
|
||||||
self.currentClientPublicKey = self.clientPublicKey[self.currentUser]
|
self.currentClientPublicKey = self.clientPublicKey[self.currentUser]
|
||||||
retmsg = self.serverPrivateKey.decrypt(b64decode(incommingJson['message'])).decode('UTF-8')
|
cipher_rsa = PKCS1_OAEP.new(self.serverPrivateKey)
|
||||||
rsakey = RSA.import_key(self.currentClientPublicKey)
|
retmsg = cipher_rsa.decrypt(b64decode(incommingJson['message'])).decode('UTF-8')
|
||||||
cipher = PKCS1_OAEP.new(rsakey)
|
cipher = PKCS1_OAEP.new(self.currentClientPublicKey)
|
||||||
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(
|
||||||
@ -51,8 +51,7 @@ class NetWrapper:
|
|||||||
|
|
||||||
def keyExchange(self) -> None:
|
def keyExchange(self) -> None:
|
||||||
dh = pyDH.DiffieHellman()
|
dh = pyDH.DiffieHellman()
|
||||||
rsakey = RSA.import_key(self.currentClientPublicKey)
|
cipher = PKCS1_OAEP.new(self.currentClientPublicKey)
|
||||||
cipher = PKCS1_OAEP.new(rsakey)
|
|
||||||
mypubkey = b64encode(cipher.encrypt(str(dh.gen_public_key()).encode('UTF-8')))
|
mypubkey = b64encode(cipher.encrypt(str(dh.gen_public_key()).encode('UTF-8')))
|
||||||
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)
|
||||||
@ -62,7 +61,8 @@ class NetWrapper:
|
|||||||
if not status:
|
if not status:
|
||||||
raise Exception('Network error during connection.')
|
raise Exception('Network error during connection.')
|
||||||
decodedmsg = json.loads(msg.decode('UTF-8'))
|
decodedmsg = json.loads(msg.decode('UTF-8'))
|
||||||
serverpubkey = int(self.serverPrivateKey.decrypt(b64decode(decodedmsg['message'])).decode('UTF-8'))
|
cipher_rsa = PKCS1_OAEP.new(self.serverPrivateKey)
|
||||||
|
serverpubkey = int(cipher_rsa.decrypt(b64decode(decodedmsg['message'])).decode('UTF-8'))
|
||||||
self.cipherkey = dh.gen_shared_key(serverpubkey).encode('UTF-8')
|
self.cipherkey = dh.gen_shared_key(serverpubkey).encode('UTF-8')
|
||||||
|
|
||||||
def login(self) -> bool:
|
def login(self) -> bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user