Encode error -> too long plaintext for random message
All checks were successful
continuous-integration/drone/push Build is passing

Json error -> binary cannot be serialized
This commit is contained in:
DESKTOP-DPA61F8\Benedek 2021-04-25 16:56:02 +02:00
parent 10c481bc72
commit c63c516ab9
2 changed files with 7 additions and 3 deletions

View File

@ -99,12 +99,15 @@ while True:
if separatedCommand[0] == 'LIN' and len(separatedCommand) == 3: if separatedCommand[0] == 'LIN' and len(separatedCommand) == 3:
network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, separatedCommand[1], SERVER_PUBLIC_KEY) network = NetWrapper(CLIENT_PRIVATE_KEY, CLIENT_ADDRESS, separatedCommand[1], SERVER_PUBLIC_KEY)
print('Start')
if not network.identifyServer(): if not network.identifyServer():
print('Server identification failed!') print('Server identification failed!')
continue continue
print('Identified')
network.createEncryptedChannel() network.createEncryptedChannel()
print('Channel created')
network.authenticate(password=separatedCommand[2]) network.authenticate(password=separatedCommand[2])
print('Authenticated')
LOGGED_IN = True LOGGED_IN = True
continue continue

View File

@ -23,7 +23,7 @@ class NetWrapper:
self.cipherkey = "".encode('UTF-8') self.cipherkey = "".encode('UTF-8')
def randomStringGenerator(self, str_size: int = 512, def randomStringGenerator(self, str_size: int = 128,
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))
@ -33,7 +33,8 @@ class NetWrapper:
cipher_rsa = PKCS1_OAEP.new(self.serverPubKey) cipher_rsa = PKCS1_OAEP.new(self.serverPubKey)
identMsg = json.dumps( identMsg = json.dumps(
{'type': 'IDY', 'source': self.network.own_addr, 'username': self.username, {'type': 'IDY', 'source': self.network.own_addr, 'username': self.username,
'message': b64encode(cipher_rsa.encrypt(randommsg.encode('UTF-8')))}).encode( ##b64encode has to str
'message': str(b64encode(cipher_rsa.encrypt(randommsg.encode('UTF-8'))))}).encode(
'UTF-8') 'UTF-8')
self.network.send_msg(self.serverAddr, identMsg) self.network.send_msg(self.serverAddr, identMsg)
returnJson = {'source': '', 'type': ''} returnJson = {'source': '', 'type': ''}