fix circular dependency
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-04-25 18:40:41 +02:00
parent 798b74e5d8
commit 149c206830
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
2 changed files with 13 additions and 7 deletions

View File

@ -8,12 +8,12 @@ from Crypto.PublicKey.RSA import RsaKey
from Crypto.Random import get_random_bytes from Crypto.Random import get_random_bytes
from netsim import network_interface from netsim import network_interface
from server import Server from authentication import Authetication
class NetWrapper: class NetWrapper:
def __init__(self, clientPublicKey: dict, serverPrivateKey: RsaKey, serverInstance: Server): def __init__(self, clientPublicKey: dict, serverPrivateKey: RsaKey, authenticationInstance: Authetication):
self.clientPublicKey = clientPublicKey self.clientPublicKey = clientPublicKey
self.currentClientPublicKey = "".encode('UTF-8') self.currentClientPublicKey = "".encode('UTF-8')
self.serverPrivateKey = serverPrivateKey self.serverPrivateKey = serverPrivateKey
@ -21,7 +21,7 @@ class NetWrapper:
self.network = network_interface('./', 'A') self.network = network_interface('./', 'A')
self.clientAddr = "" self.clientAddr = ""
self.currentUser = "" self.currentUser = ""
self.serverInstance = serverInstance self.authenticationInstance = authenticationInstance
def serverIdentify(self, msg: bytes) -> None: def serverIdentify(self, msg: bytes) -> None:
incommingJson = json.loads(msg.decode('UTF-8')) incommingJson = json.loads(msg.decode('UTF-8'))
@ -77,7 +77,7 @@ class NetWrapper:
retcipher = ChaCha20.new(self.cipherkey, nonce=retnonce) retcipher = ChaCha20.new(self.cipherkey, nonce=retnonce)
plaintext = retcipher.decrypt(retciphertext).decode('UTF-8').split(' ') plaintext = retcipher.decrypt(retciphertext).decode('UTF-8').split(' ')
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.serverInstance.login(plaintext[1], plaintext[2]) 1] != self.currentUser)) and self.authenticationInstance.login(plaintext[1], plaintext[2])
if linsuccess: if linsuccess:
message = "OK".encode('UTF-8') message = "OK".encode('UTF-8')
else: else:
@ -118,7 +118,6 @@ class NetWrapper:
return self.recieveEncryptedMessage(msg) return self.recieveEncryptedMessage(msg)
def logout(self) -> None: def logout(self) -> None:
self.serverInstance.logout()
self.clientAddr = "" self.clientAddr = ""
self.cipherkey = "".encode('UTF-8') self.cipherkey = "".encode('UTF-8')
self.currentClientPublicKey = "".encode('UTF-8') self.currentClientPublicKey = "".encode('UTF-8')

View File

@ -18,7 +18,7 @@ class Server:
passphrase = input() passphrase = input()
self.auth = Authetication() self.auth = Authetication()
self.networkInstance = NetWrapper(self.auth.loadUserPublicKeys(), self.auth.loadServerPrivateKey(passphrase), self.networkInstance = NetWrapper(self.auth.loadUserPublicKeys(), self.auth.loadServerPrivateKey(passphrase),
self) self.auth)
def login(self, username: str, password: str) -> bool: def login(self, username: str, password: str) -> bool:
self.isAuthenticated = True self.isAuthenticated = True
@ -30,6 +30,7 @@ class Server:
return True return True
def logout(self) -> None: def logout(self) -> None:
self.networkInstance.logout()
self.isAuthenticated = False self.isAuthenticated = False
self.availableServer = False self.availableServer = False
self.homeDirectory = "" self.homeDirectory = ""
@ -56,7 +57,13 @@ class Server:
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.homeDirectory == "" or 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 == "MKD": if command == "LOUT":
if secondParam != "" or firstParam != "":
self.networkInstance.sendMessage("ERROR".encode('UTF-8'))
else:
self.logout()
self.networkInstance.sendMessage("OK".encode('UTF-8'))
elif command == "MKD":
if secondParam != "": if secondParam != "":
self.networkInstance.sendMessage("ERROR".encode('UTF-8')) self.networkInstance.sendMessage("ERROR".encode('UTF-8'))
else: else: