Compare commits

...

3 Commits

Author SHA1 Message Date
4bd161de54
create init function
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-25 17:55:05 +02:00
0874645719
Merge branch 'master' of https://git.kmlabz.com/BiztProtoBois/server into master 2021-04-25 17:51:08 +02:00
8d7754edc2
oops 2021-04-25 17:50:43 +02:00
3 changed files with 12 additions and 16 deletions

View File

@ -3,4 +3,5 @@ from server import Server
if __name__ == '__main__': if __name__ == '__main__':
server = Server() server = Server()
server.initServer()
server.startServer() server.startServer()

View File

@ -36,7 +36,7 @@ class NetWrapper:
cipher = PKCS1_OAEP.new(self.currentClientPublicKey) cipher = PKCS1_OAEP.new(self.currentClientPublicKey)
identMsg = json.dumps( identMsg = json.dumps(
{'type': 'IDY', 'source': self.network.own_addr, {'type': 'IDY', 'source': self.network.own_addr,
'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8')))}).encode( 'message': b64encode(cipher.encrypt(retmsg.encode('UTF-8')))}).decode(
'ASCII') 'ASCII')
self.network.send_msg(self.clientAddr, identMsg) self.network.send_msg(self.clientAddr, identMsg)

View File

@ -12,13 +12,18 @@ class Server:
self.sessionTimeout = sessionTimeout self.sessionTimeout = sessionTimeout
self.availableServer = availableServer self.availableServer = availableServer
self.executor = Executor(homeDirectory) self.executor = Executor(homeDirectory)
self.auth=Authetication()
self.networkInstance = NetWrapper(self.auth.loadUserPublicKeys(),self.auth.loadServerPrivateKey(),self) def initServer(self):
print("Please enter your private key passphrase")
passphrase = input()
self.auth = Authetication()
self.networkInstance = NetWrapper(self.auth.loadUserPublicKeys(), self.auth.loadServerPrivateKey(passphrase),
self)
def login(self, username: str, password: str) -> bool: def login(self, username: str, password: str) -> bool:
self.isAuthenticated = True self.isAuthenticated = True
home_directory = self.auth.login(username, password) home_directory = self.auth.login(username, password)
self.executor.baseDir=Executor(home_directory) self.executor.baseDir = Executor(home_directory)
if not home_directory: if not home_directory:
return False return False
else: else:
@ -28,7 +33,7 @@ class Server:
self.isAuthenticated = False self.isAuthenticated = False
self.availableServer = False self.availableServer = False
self.homeDirectory = "" self.homeDirectory = ""
self.executor.baseDir=Executor(self.homeDirectory) self.executor.baseDir = Executor(self.homeDirectory)
def parseCommand(self, command: str) -> str: def parseCommand(self, command: str) -> str:
if command == "LINOK": if command == "LINOK":
@ -107,14 +112,4 @@ class Server:
def startServer(self): def startServer(self):
while True: while True:
message = self.networkInstance.recieveMessage().decode('UTF-8') message = self.networkInstance.recieveMessage().decode('UTF-8')
command = self.parseCommand(message) self.parseCommand(message)
#ha LINOK vagy LINERROR donothing
if command == "LINERROR" or command == "LINOK" or command == "ERROR":
print("not right commands")
elif len(command) == 1:
execute_message = self.execute(self,command, "", "")
elif len(command) == 2:
execute_message = self.execute(self, command, command[1], "")
elif len(command) == 3:
execute_message = self.execute(self, command, command[1], command[2])
self.networkInstance.sendMessage(self, execute_message)