some more login rework
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
772a9e6d2c
commit
ae743cde15
@ -1,2 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
@ -22,6 +22,7 @@ class NetWrapper:
|
|||||||
self.network = network_interface('./../../netsim/network/', 'A')
|
self.network = network_interface('./../../netsim/network/', 'A')
|
||||||
self.clientAddr = ""
|
self.clientAddr = ""
|
||||||
self.currentUser = ""
|
self.currentUser = ""
|
||||||
|
self.homeDirectory = ""
|
||||||
self.authenticationInstance = authenticationInstance
|
self.authenticationInstance = authenticationInstance
|
||||||
|
|
||||||
def serverIdentify(self, msg: bytes) -> None:
|
def serverIdentify(self, msg: bytes) -> None:
|
||||||
@ -80,8 +81,9 @@ class NetWrapper:
|
|||||||
retciphertext = b64decode(b64['message'])
|
retciphertext = b64decode(b64['message'])
|
||||||
retcipher = ChaCha20.new(key=self.cipherkey, nonce=retnonce)
|
retcipher = ChaCha20.new(key=self.cipherkey, nonce=retnonce)
|
||||||
plaintext = retcipher.decrypt(retciphertext).decode('UTF-8').split(' ')
|
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[
|
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:
|
if linsuccess:
|
||||||
message = "OK".encode('UTF-8')
|
message = "OK".encode('UTF-8')
|
||||||
else:
|
else:
|
||||||
@ -132,6 +134,7 @@ class NetWrapper:
|
|||||||
self.cipherkey = "".encode('UTF-8')
|
self.cipherkey = "".encode('UTF-8')
|
||||||
self.currentClientPublicKey = "".encode('UTF-8')
|
self.currentClientPublicKey = "".encode('UTF-8')
|
||||||
self.currentUser = ""
|
self.currentUser = ""
|
||||||
|
self.homeDirectory = ""
|
||||||
|
|
||||||
def recieveEncryptedMessage(self, msg: bytes) -> bytes:
|
def recieveEncryptedMessage(self, msg: bytes) -> bytes:
|
||||||
try:
|
try:
|
||||||
|
@ -6,12 +6,11 @@ from netwrapper import NetWrapper
|
|||||||
|
|
||||||
class Server:
|
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.isAuthenticated = False
|
||||||
self.homeDirectory = homeDirectory
|
|
||||||
self.sessionTimeout = sessionTimeout
|
self.sessionTimeout = sessionTimeout
|
||||||
self.availableServer = availableServer
|
self.availableServer = availableServer
|
||||||
self.executor = Executor(homeDirectory)
|
self.executor = Executor("")
|
||||||
|
|
||||||
def initServer(self):
|
def initServer(self):
|
||||||
print("Please enter your private key passphrase")
|
print("Please enter your private key passphrase")
|
||||||
@ -20,14 +19,9 @@ class Server:
|
|||||||
self.networkInstance = NetWrapper(self.auth.loadUserPublicKeys(), self.auth.loadServerPrivateKey(passphrase),
|
self.networkInstance = NetWrapper(self.auth.loadUserPublicKeys(), self.auth.loadServerPrivateKey(passphrase),
|
||||||
self.auth)
|
self.auth)
|
||||||
|
|
||||||
def login(self, username: str, password: str) -> bool:
|
def login(self, homeDir: str) -> None:
|
||||||
self.isAuthenticated = True
|
self.isAuthenticated = True
|
||||||
home_directory = self.auth.login(username, password)
|
self.executor.baseDir = Executor(homeDir)
|
||||||
self.executor.baseDir = Executor(home_directory)
|
|
||||||
if not home_directory:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
def logout(self) -> None:
|
def logout(self) -> None:
|
||||||
self.networkInstance.logout()
|
self.networkInstance.logout()
|
||||||
@ -38,6 +32,7 @@ class Server:
|
|||||||
|
|
||||||
def parseCommand(self, command: str) -> None:
|
def parseCommand(self, command: str) -> None:
|
||||||
if command == "LINOK":
|
if command == "LINOK":
|
||||||
|
self.login(self.networkInstance.homeDirectory)
|
||||||
self.networkInstance.sendMessage("LINOK".encode('UTF-8'))
|
self.networkInstance.sendMessage("LINOK".encode('UTF-8'))
|
||||||
elif command == "LINERROR":
|
elif command == "LINERROR":
|
||||||
self.networkInstance.sendMessage("LINERROR".encode('UTF-8'))
|
self.networkInstance.sendMessage("LINERROR".encode('UTF-8'))
|
||||||
@ -55,7 +50,7 @@ class Server:
|
|||||||
return self.execute(parsedCommand[0], parsedCommand[1], parsedCommand[2])
|
return self.execute(parsedCommand[0], parsedCommand[1], parsedCommand[2])
|
||||||
|
|
||||||
def execute(self, command: str, firstParam: str = "", secondParam: str = "") -> None:
|
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?")
|
raise Exception("Directories must not be empty string. Did the user log in?")
|
||||||
if command == "LOUT":
|
if command == "LOUT":
|
||||||
if secondParam != "" or firstParam != "":
|
if secondParam != "" or firstParam != "":
|
||||||
|
Loading…
Reference in New Issue
Block a user