Compare commits
12 Commits
978d7cf092
...
master
Author | SHA1 | Date | |
---|---|---|---|
228230bb1b | |||
9d3c011816 | |||
18bfac4a86 | |||
6d2441d931
|
|||
841c5d4c20
|
|||
0e3ba17a8e
|
|||
ec5a36c700
|
|||
fe26bd1727
|
|||
4466ee6172
|
|||
7f1a5f1013
|
|||
3bcb7e18ce
|
|||
37d2e06a18 |
@ -1,2 +1,3 @@
|
|||||||
pycryptodome
|
pycryptodome
|
||||||
pydh
|
pydh
|
||||||
|
unipath
|
@ -11,6 +11,7 @@ from Crypto.Hash import SHA256
|
|||||||
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
|
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
from Crypto.PublicKey.RSA import RsaKey
|
from Crypto.PublicKey.RSA import RsaKey
|
||||||
|
from Crypto.Random import get_random_bytes
|
||||||
|
|
||||||
auth_logger = logging.getLogger('AUTH APPLICATION ')
|
auth_logger = logging.getLogger('AUTH APPLICATION ')
|
||||||
auth_logger.setLevel(logging.INFO)
|
auth_logger.setLevel(logging.INFO)
|
||||||
@ -82,9 +83,10 @@ class Authetication:
|
|||||||
|
|
||||||
|
|
||||||
def saveUser(self, username: str, password: str) -> bool:
|
def saveUser(self, username: str, password: str) -> bool:
|
||||||
|
user_salt = get_random_bytes(16)
|
||||||
bytePass = password.encode('utf-8')
|
bytePass = password.encode('utf-8')
|
||||||
b64pwd = b64encode(SHA256.new(bytePass).digest())
|
b64pwd = b64encode(SHA256.new(bytePass).digest())
|
||||||
bcrypt_hash = bcrypt(b64pwd, 12)
|
bcrypt_hash = bcrypt(password=b64pwd, cost=12, salt=user_salt)
|
||||||
|
|
||||||
with open(self.CONFIG_FILE_LOCATION) as json_file:
|
with open(self.CONFIG_FILE_LOCATION) as json_file:
|
||||||
data = json.load(json_file)
|
data = json.load(json_file)
|
||||||
|
@ -35,7 +35,7 @@ def testAuth(username: str, password: str):
|
|||||||
auth.saveUser(username, password)
|
auth.saveUser(username, password)
|
||||||
homeDir = auth.login(username, password)
|
homeDir = auth.login(username, password)
|
||||||
|
|
||||||
if homeDir == '1':
|
if homeDir == auth.HOME_DIRECTORY_LOCATION + os.path.sep + '1':
|
||||||
test_logger.info('TEST 1 --> Authentication test with VALID :: PASSED')
|
test_logger.info('TEST 1 --> Authentication test with VALID :: PASSED')
|
||||||
else:
|
else:
|
||||||
test_logger.info('TEST 1 --> Authentication test with VALID :: FAILED')
|
test_logger.info('TEST 1 --> Authentication test with VALID :: FAILED')
|
||||||
@ -118,4 +118,4 @@ if __name__ == '__main__':
|
|||||||
testSaveUser("Diósbejglia", "Diósbejgli")
|
testSaveUser("Diósbejglia", "Diósbejgli")
|
||||||
testAuth("Diósbejglia", "Diósbejgli")
|
testAuth("Diósbejglia", "Diósbejgli")
|
||||||
testUserExists("Diósbejglia", "Diósbejgli")
|
testUserExists("Diósbejglia", "Diósbejgli")
|
||||||
testPersistency()
|
#testPersistency()
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -3,6 +3,8 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from unipath import Path
|
||||||
|
|
||||||
class Executor:
|
class Executor:
|
||||||
"""This class executes commands recieved by the server"""
|
"""This class executes commands recieved by the server"""
|
||||||
|
|
||||||
@ -34,21 +36,22 @@ class Executor:
|
|||||||
|
|
||||||
def setCurrentDirectory(self, dirName: str) -> str:
|
def setCurrentDirectory(self, dirName: str) -> str:
|
||||||
if dirName == "..":
|
if dirName == "..":
|
||||||
if self.currentDirectory == self.baseDir:
|
p = Path(os.path.join(self.baseDir, self.currentDirectory))
|
||||||
|
parentpath = p.parent
|
||||||
|
if (str(parentpath) + os.path.sep)== self.baseDir:
|
||||||
|
self.currentDirectory = ""
|
||||||
return self.currentDirectory
|
return self.currentDirectory
|
||||||
else:
|
else:
|
||||||
directories = self.currentDirectory.split(os.path.sep)
|
if len(str(parentpath).split('/')) < len(self.baseDir.split('/')):
|
||||||
strdirectory = ""
|
return self.currentDirectory
|
||||||
for dir in directories:
|
newpath = str(parentpath).replace(self.baseDir,'')
|
||||||
strdirectory += dir + os.path.sep
|
if os.path.exists(os.path.join(self.baseDir,newpath)):
|
||||||
strdirectory = strdirectory[:-3]
|
self.currentDirectory = newpath
|
||||||
if os.path.exists(strdirectory):
|
|
||||||
self.currentDirectory = strdirectory
|
|
||||||
return self.currentDirectory
|
return self.currentDirectory
|
||||||
else:
|
else:
|
||||||
dirName = self.sanitizeDirectory(dirName)
|
dirName = self.sanitizeDirectory(dirName)
|
||||||
joinedDir = os.path.join(self.currentDirectory, dirName)
|
joinedDir = os.path.join(self.currentDirectory, dirName)
|
||||||
if os.path.exists(joinedDir):
|
if os.path.join(self.baseDir, joinedDir):
|
||||||
self.currentDirectory = joinedDir
|
self.currentDirectory = joinedDir
|
||||||
return self.currentDirectory
|
return self.currentDirectory
|
||||||
|
|
||||||
@ -62,7 +65,7 @@ class Executor:
|
|||||||
|
|
||||||
def putFileInCurrentDirectory(self, filename: str, content: bytes) -> str:
|
def putFileInCurrentDirectory(self, filename: str, content: bytes) -> str:
|
||||||
filename = self.sanitizeFile(filename)
|
filename = self.sanitizeFile(filename)
|
||||||
currenctfile = os.path.join(self.currentDirectory, filename)
|
currenctfile = os.path.join(self.baseDir, self.currentDirectory, filename)
|
||||||
f = open(currenctfile, "wb")
|
f = open(currenctfile, "wb")
|
||||||
f.write(content)
|
f.write(content)
|
||||||
f.close()
|
f.close()
|
||||||
@ -70,7 +73,7 @@ class Executor:
|
|||||||
|
|
||||||
def getFileInCurrentDirectory(self, file: str) -> bytes:
|
def getFileInCurrentDirectory(self, file: str) -> bytes:
|
||||||
file = self.sanitizeFile(file)
|
file = self.sanitizeFile(file)
|
||||||
currentfile = os.path.join(self.currentDirectory, file)
|
currentfile = os.path.join(self.baseDir, self.currentDirectory, file)
|
||||||
if os.path.exists(currentfile):
|
if os.path.exists(currentfile):
|
||||||
f = open(currentfile, "rb")
|
f = open(currentfile, "rb")
|
||||||
content = f.read()
|
content = f.read()
|
||||||
@ -81,7 +84,10 @@ class Executor:
|
|||||||
|
|
||||||
def removeFileInCurrentDirectory(self, file: str) -> str:
|
def removeFileInCurrentDirectory(self, file: str) -> str:
|
||||||
file = self.sanitizeFile(file)
|
file = self.sanitizeFile(file)
|
||||||
currentfile = os.path.join(self.currentDirectory, file)
|
if self.currentDirectory == "":
|
||||||
|
currentfile = os.path.join(self.baseDir, file)
|
||||||
|
else:
|
||||||
|
currentfile = os.path.join(self.baseDir, self.currentDirectory, file)
|
||||||
if os.path.exists(currentfile):
|
if os.path.exists(currentfile):
|
||||||
os.remove(currentfile)
|
os.remove(currentfile)
|
||||||
return currentfile
|
return currentfile
|
||||||
|
Reference in New Issue
Block a user