From 621c59dce27b315935ce2af2e62a0674f861fae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 18:05:49 +0200 Subject: [PATCH 1/6] fix decode --- server/authentication.py | 2 +- server/netwrapper.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/authentication.py b/server/authentication.py index dbc5e17..ee2e7f4 100644 --- a/server/authentication.py +++ b/server/authentication.py @@ -13,7 +13,7 @@ from Crypto.PublicKey import RSA from Crypto.PublicKey.RSA import RsaKey auth_logger = logging.getLogger('AUTH APPLICATION ') -auth_logger.root.setLevel(logging.INFO) +auth_logger.setLevel(logging.INFO) class Authetication: ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0])) diff --git a/server/netwrapper.py b/server/netwrapper.py index cae72f6..d94b982 100644 --- a/server/netwrapper.py +++ b/server/netwrapper.py @@ -36,8 +36,8 @@ class NetWrapper: cipher = PKCS1_OAEP.new(self.currentClientPublicKey) identMsg = json.dumps( {'type': 'IDY', 'source': self.network.own_addr, - 'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8')))}).decode( - 'ASCII') + 'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8'))).decode('ASCII')}).encode( + 'UTF-8') self.network.send_msg(self.clientAddr, identMsg) def sendMessage(self, message: bytes) -> None: From 42fff36545032792c4223b0e834a5dc23d121845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 18:08:21 +0200 Subject: [PATCH 2/6] unresolved reference --- server/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/authentication.py b/server/authentication.py index ee2e7f4..fd9c159 100644 --- a/server/authentication.py +++ b/server/authentication.py @@ -121,7 +121,7 @@ class Authetication: with open(self.CONFIG_FILE_LOCATION) as json_file: data = json.load(json_file) - dictionary: dict + dictionary = dict() for user in data['user']: key = data['publicKey'] From 5e1e9f3e693aaa257ac08a260b37c64f42c0d9f0 Mon Sep 17 00:00:00 2001 From: "DESKTOP-DPA61F8\\Benedek" Date: Sun, 25 Apr 2021 18:09:43 +0200 Subject: [PATCH 3/6] Duplicate row in auth --- server/authentication.py | 1 - 1 file changed, 1 deletion(-) diff --git a/server/authentication.py b/server/authentication.py index dbc5e17..22897dd 100644 --- a/server/authentication.py +++ b/server/authentication.py @@ -47,7 +47,6 @@ class Authetication: for user in data['user']: if username == user['username']: - b64pwd = b64encode(SHA256.new(password.encode('utf-8')).digest()) try: b64pwd = b64encode(SHA256.new(password.encode('utf-8')).digest()) bcrypt_check(b64pwd, user['password'].encode('utf-8')) From 8957cd6a0490370748752871cfb54b0c1f65f2f1 Mon Sep 17 00:00:00 2001 From: "DESKTOP-DPA61F8\\Benedek" Date: Sun, 25 Apr 2021 18:11:53 +0200 Subject: [PATCH 4/6] Key export doesnt need protection tpye because DER format has default: PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC --- server/config_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/config_init.py b/server/config_init.py index 8d19a03..598d0bb 100644 --- a/server/config_init.py +++ b/server/config_init.py @@ -14,7 +14,7 @@ def generatePrivateKeyForUser(auth: Authetication,username: str, user_passphrase private_key = RSA.generate(2048) public_key = private_key.publickey() - private_key_value = bytes.hex(private_key.exportKey('DER', passphrase=user_passphrase, pkcs=8, protection="scryptAndAES128-CBC")) + private_key_value = bytes.hex(private_key.exportKey('DER', passphrase=user_passphrase, pkcs=8)) public_key_value = bytes.hex(public_key.exportKey('DER', pkcs=8)) ##Save private key in separate file From dc43cc30564d84cf00717bb9408d268195370c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 18:13:14 +0200 Subject: [PATCH 5/6] use bytes --- server/executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/executor.py b/server/executor.py index 9bbf60f..b28379d 100644 --- a/server/executor.py +++ b/server/executor.py @@ -64,7 +64,7 @@ class Executor: strdirectory = strdirectory[:-1] return strdirectory - def putFileInCurrentDirectory(self, filename: str, content) -> str: + def putFileInCurrentDirectory(self, filename: str, content: bytes) -> str: filename = self.sanitizeFile(filename) currenctfile = os.path.join(self.currentDirectory, filename) f = open(currenctfile, "wb") From 5378ec8cdcd9f730f53a07678bd5d0042adf98da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sun, 25 Apr 2021 18:18:37 +0200 Subject: [PATCH 6/6] better recievemessage --- server/netwrapper.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/netwrapper.py b/server/netwrapper.py index d94b982..4eca973 100644 --- a/server/netwrapper.py +++ b/server/netwrapper.py @@ -127,7 +127,12 @@ class NetWrapper: def recieveEncryptedMessage(self, msg: bytes) -> bytes: try: - b64 = json.loads(msg) + b64 = json.loads(msg.decode('UTF-8')) + while not (b64['source'] == self.clientAddr and b64['type'] == 'CMD'): + status, msg = self.network.receive_msg(blocking=True) + if not status: + raise Exception('Network error during connection.') + b64 = json.loads(msg.decode('UTF-8')) retnonce = b64decode(b64['nonce']) retciphertext = b64decode(b64['message']) retcipher = ChaCha20.new(self.cipherkey, nonce=retnonce)