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
|
||||
pydh
|
||||
unipath
|
@ -11,6 +11,7 @@ from Crypto.Hash import SHA256
|
||||
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
|
||||
from Crypto.PublicKey import RSA
|
||||
from Crypto.PublicKey.RSA import RsaKey
|
||||
from Crypto.Random import get_random_bytes
|
||||
|
||||
auth_logger = logging.getLogger('AUTH APPLICATION ')
|
||||
auth_logger.setLevel(logging.INFO)
|
||||
@ -82,9 +83,10 @@ class Authetication:
|
||||
|
||||
|
||||
def saveUser(self, username: str, password: str) -> bool:
|
||||
user_salt = get_random_bytes(16)
|
||||
bytePass = password.encode('utf-8')
|
||||
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:
|
||||
data = json.load(json_file)
|
||||
|
@ -35,7 +35,7 @@ def testAuth(username: str, password: str):
|
||||
auth.saveUser(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')
|
||||
else:
|
||||
test_logger.info('TEST 1 --> Authentication test with VALID :: FAILED')
|
||||
@ -118,4 +118,4 @@ if __name__ == '__main__':
|
||||
testSaveUser("Diósbejglia", "Diósbejgli")
|
||||
testAuth("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 re
|
||||
|
||||
from unipath import Path
|
||||
|
||||
class Executor:
|
||||
"""This class executes commands recieved by the server"""
|
||||
|
||||
@ -34,21 +36,22 @@ class Executor:
|
||||
|
||||
def setCurrentDirectory(self, dirName: str) -> str:
|
||||
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
|
||||
else:
|
||||
directories = self.currentDirectory.split(os.path.sep)
|
||||
strdirectory = ""
|
||||
for dir in directories:
|
||||
strdirectory += dir + os.path.sep
|
||||
strdirectory = strdirectory[:-3]
|
||||
if os.path.exists(strdirectory):
|
||||
self.currentDirectory = strdirectory
|
||||
if len(str(parentpath).split('/')) < len(self.baseDir.split('/')):
|
||||
return self.currentDirectory
|
||||
newpath = str(parentpath).replace(self.baseDir,'')
|
||||
if os.path.exists(os.path.join(self.baseDir,newpath)):
|
||||
self.currentDirectory = newpath
|
||||
return self.currentDirectory
|
||||
else:
|
||||
dirName = self.sanitizeDirectory(dirName)
|
||||
joinedDir = os.path.join(self.currentDirectory, dirName)
|
||||
if os.path.exists(joinedDir):
|
||||
if os.path.join(self.baseDir, joinedDir):
|
||||
self.currentDirectory = joinedDir
|
||||
return self.currentDirectory
|
||||
|
||||
@ -62,7 +65,7 @@ class Executor:
|
||||
|
||||
def putFileInCurrentDirectory(self, filename: str, content: bytes) -> str:
|
||||
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.write(content)
|
||||
f.close()
|
||||
@ -70,7 +73,7 @@ class Executor:
|
||||
|
||||
def getFileInCurrentDirectory(self, file: str) -> bytes:
|
||||
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):
|
||||
f = open(currentfile, "rb")
|
||||
content = f.read()
|
||||
@ -81,7 +84,10 @@ class Executor:
|
||||
|
||||
def removeFileInCurrentDirectory(self, file: str) -> str:
|
||||
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):
|
||||
os.remove(currentfile)
|
||||
return currentfile
|
||||
|
Reference in New Issue
Block a user