From ae743cde15afa7c9a8f148475dcd1a2fe651170d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Mon, 26 Apr 2021 13:18:50 +0200 Subject: [PATCH] some more login rework --- server/authenticator.py | 2 -- server/netwrapper.py | 5 ++++- server/server.py | 17 ++++++----------- 3 files changed, 10 insertions(+), 14 deletions(-) delete mode 100644 server/authenticator.py diff --git a/server/authenticator.py b/server/authenticator.py deleted file mode 100644 index 63f77b6..0000000 --- a/server/authenticator.py +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env python3 - diff --git a/server/netwrapper.py b/server/netwrapper.py index 732d03b..909fa95 100644 --- a/server/netwrapper.py +++ b/server/netwrapper.py @@ -22,6 +22,7 @@ class NetWrapper: self.network = network_interface('./../../netsim/network/', 'A') self.clientAddr = "" self.currentUser = "" + self.homeDirectory = "" self.authenticationInstance = authenticationInstance def serverIdentify(self, msg: bytes) -> None: @@ -80,8 +81,9 @@ class NetWrapper: retciphertext = b64decode(b64['message']) retcipher = ChaCha20.new(key=self.cipherkey, nonce=retnonce) plaintext = retcipher.decrypt(retciphertext).decode('UTF-8').split(' ') + self.homeDirectory = self.authenticationInstance.login(plaintext[1], plaintext[2]) linsuccess = (not (len(plaintext) != 3 or plaintext[0] != "LIN" or plaintext[ - 1] != self.currentUser)) and self.authenticationInstance.login(plaintext[1], plaintext[2]) + 1] != self.currentUser)) and self.homeDirectory if linsuccess: message = "OK".encode('UTF-8') else: @@ -132,6 +134,7 @@ class NetWrapper: self.cipherkey = "".encode('UTF-8') self.currentClientPublicKey = "".encode('UTF-8') self.currentUser = "" + self.homeDirectory = "" def recieveEncryptedMessage(self, msg: bytes) -> bytes: try: diff --git a/server/server.py b/server/server.py index 16c5c1c..ac400ff 100644 --- a/server/server.py +++ b/server/server.py @@ -6,12 +6,11 @@ from netwrapper import NetWrapper class Server: - def __init__(self, homeDirectory: str = "", sessionTimeout: int = 120, availableServer: bool = True): + def __init__(self, sessionTimeout: int = 120, availableServer: bool = True): self.isAuthenticated = False - self.homeDirectory = homeDirectory self.sessionTimeout = sessionTimeout self.availableServer = availableServer - self.executor = Executor(homeDirectory) + self.executor = Executor("") def initServer(self): print("Please enter your private key passphrase") @@ -20,14 +19,9 @@ class Server: self.networkInstance = NetWrapper(self.auth.loadUserPublicKeys(), self.auth.loadServerPrivateKey(passphrase), self.auth) - def login(self, username: str, password: str) -> bool: + def login(self, homeDir: str) -> None: self.isAuthenticated = True - home_directory = self.auth.login(username, password) - self.executor.baseDir = Executor(home_directory) - if not home_directory: - return False - else: - return True + self.executor.baseDir = Executor(homeDir) def logout(self) -> None: self.networkInstance.logout() @@ -38,6 +32,7 @@ class Server: def parseCommand(self, command: str) -> None: if command == "LINOK": + self.login(self.networkInstance.homeDirectory) self.networkInstance.sendMessage("LINOK".encode('UTF-8')) elif command == "LINERROR": self.networkInstance.sendMessage("LINERROR".encode('UTF-8')) @@ -55,7 +50,7 @@ class Server: return self.execute(parsedCommand[0], parsedCommand[1], parsedCommand[2]) def execute(self, command: str, firstParam: str = "", secondParam: str = "") -> None: - if self.homeDirectory == "" or self.executor.currentDirectory == "" or self.executor.baseDir == "": + if self.executor.currentDirectory == "" or self.executor.baseDir == "": raise Exception("Directories must not be empty string. Did the user log in?") if command == "LOUT": if secondParam != "" or firstParam != "":