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

This commit is contained in:
Torma Kristóf 2021-04-26 22:18:53 +02:00
parent 3a20592cff
commit 1e54e17cea
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047

View File

@ -26,9 +26,9 @@ class NetWrapper:
allowed_chars: str = string.ascii_letters + string.punctuation) -> str: allowed_chars: str = string.ascii_letters + string.punctuation) -> str:
return ''.join(random.choice(allowed_chars) for x in range(str_size)) return ''.join(random.choice(allowed_chars) for x in range(str_size))
def ecryptRSAMessage(self, message: str) -> bytes: def ecryptRSAMessage(self, message: bytes) -> bytes:
cipher_rsa = PKCS1_OAEP.new(self.serverPubKey) cipher_rsa = PKCS1_OAEP.new(self.serverPubKey)
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):
@ -58,7 +58,7 @@ class NetWrapper:
return decodedmsg, json.loads(b64decode(decodedmsg['header']).decode('UTF-8')) return decodedmsg, json.loads(b64decode(decodedmsg['header']).decode('UTF-8'))
def identifyServer(self) -> bool: def identifyServer(self) -> bool:
randommsg = self.randomStringGenerator() randommsg = self.randomStringGenerator().encode('UTF-8')
encrypted_msg = self.ecryptRSAMessage(randommsg) encrypted_msg = self.ecryptRSAMessage(randommsg)
header, headersignature = self.signRSAHeader('IDY', {'username': self.username}) header, headersignature = self.signRSAHeader('IDY', {'username': self.username})
identMsg = json.dumps( identMsg = json.dumps(
@ -80,7 +80,7 @@ class NetWrapper:
def createEncryptedChannel(self) -> None: def createEncryptedChannel(self) -> None:
dh = pyDH.DiffieHellman() dh = pyDH.DiffieHellman()
mypubkey = self.ecryptRSAMessage(str(dh.gen_public_key())) mypubkey = self.ecryptRSAMessage(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'),