This commit is contained in:
parent
281af0fb2e
commit
9dc4cab674
@ -23,7 +23,7 @@ class NetWrapper:
|
|||||||
self.username = username
|
self.username = username
|
||||||
self.privateKey = privateKey
|
self.privateKey = privateKey
|
||||||
self.serverPubKey = serverPubKey
|
self.serverPubKey = serverPubKey
|
||||||
self.cipherkey="".encode('UTF-8')
|
self.cipherkey = "".encode('UTF-8')
|
||||||
|
|
||||||
def randomStringGenerator(self, str_size: int = 512,
|
def randomStringGenerator(self, str_size: int = 512,
|
||||||
allowed_chars: str = string.ascii_letters + string.punctuation) -> str:
|
allowed_chars: str = string.ascii_letters + string.punctuation) -> str:
|
||||||
@ -53,7 +53,7 @@ class NetWrapper:
|
|||||||
cipher = PKCS1_OAEP.new(rsakey)
|
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.serverAddr,jsonmsg)
|
self.network.send_msg(self.serverAddr, jsonmsg)
|
||||||
status, msg = self.network.receive_msg(blocking=True)
|
status, msg = self.network.receive_msg(blocking=True)
|
||||||
if not status:
|
if not status:
|
||||||
raise Exception('Network error during connection.')
|
raise Exception('Network error during connection.')
|
||||||
@ -69,7 +69,8 @@ class NetWrapper:
|
|||||||
ciphertext = cipher.encrypt(message)
|
ciphertext = cipher.encrypt(message)
|
||||||
nonce = b64encode(cipher.nonce).decode('UTF-8')
|
nonce = b64encode(cipher.nonce).decode('UTF-8')
|
||||||
ct = b64encode(ciphertext).decode('UTF-8')
|
ct = b64encode(ciphertext).decode('UTF-8')
|
||||||
sendjson = json.dumps({'type': 'AUT', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode('UTF-8')
|
sendjson = json.dumps({'type': 'AUT', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode(
|
||||||
|
'UTF-8')
|
||||||
self.network.send_msg(self.serverAddr, sendjson)
|
self.network.send_msg(self.serverAddr, sendjson)
|
||||||
status, msg = self.network.receive_msg(blocking=True)
|
status, msg = self.network.receive_msg(blocking=True)
|
||||||
if not status:
|
if not status:
|
||||||
@ -99,8 +100,9 @@ class NetWrapper:
|
|||||||
ciphertext = cipher.encrypt(message)
|
ciphertext = cipher.encrypt(message)
|
||||||
nonce = b64encode(cipher.nonce).decode('UTF-8')
|
nonce = b64encode(cipher.nonce).decode('UTF-8')
|
||||||
ct = b64encode(ciphertext).decode('UTF-8')
|
ct = b64encode(ciphertext).decode('UTF-8')
|
||||||
sendjson = json.dumps({'type': 'CMD', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode('UTF-8')
|
sendjson = json.dumps({'type': 'CMD', 'source': self.network.own_addr, 'nonce': nonce, 'message': ct}).encode(
|
||||||
self.network.send_msg(self.serverAddr,sendjson)
|
'UTF-8')
|
||||||
|
self.network.send_msg(self.serverAddr, sendjson)
|
||||||
|
|
||||||
def recieveMessage(self) -> bytes:
|
def recieveMessage(self) -> bytes:
|
||||||
status, msg = self.network.receive_msg(blocking=True)
|
status, msg = self.network.receive_msg(blocking=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user