diff --git a/server/authentication.py b/server/authentication.py index dbc5e17..7505ae2 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])) @@ -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')) @@ -121,7 +120,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'] 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 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") diff --git a/server/netwrapper.py b/server/netwrapper.py index cae72f6..4eca973 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: @@ -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)