some more login rework
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-04-26 13:18:50 +02:00
parent 772a9e6d2c
commit ae743cde15
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
3 changed files with 10 additions and 14 deletions

View File

@ -1,2 +0,0 @@
#!/usr/bin/env python3

View File

@ -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:

View File

@ -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 != "":