Compare commits

..

14 Commits

Author SHA1 Message Date
228230bb1b Config
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-30 11:00:16 +02:00
9d3c011816 Config files
All checks were successful
continuous-integration/drone/push Build is passing
2021-04-29 20:15:27 +02:00
18bfac4a86 Bcrypt salting
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 20:09:37 +02:00
6d2441d931 dirty workaround
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 18:05:37 +02:00
841c5d4c20 asd
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:52:54 +02:00
0e3ba17a8e basedir
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:52:34 +02:00
ec5a36c700 do not allow getting out
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:45:23 +02:00
fe26bd1727 asd
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:38:28 +02:00
4466ee6172 use unipath
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:33:15 +02:00
7f1a5f1013 now
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:22:14 +02:00
3bcb7e18ce maybe this
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:18:41 +02:00
37d2e06a18 OK
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:16:08 +02:00
978d7cf092 Merge branch 'master' of https://git.kmlabz.com/BiztProtoBois/server
Some checks failed
continuous-integration/drone/push Build is failing
2021-04-29 17:11:41 +02:00
73c91d1426 OK 2021-04-29 17:11:33 +02:00
7 changed files with 29 additions and 20 deletions

View File

@ -1,2 +1,3 @@
pycryptodome
pydh
pydh
unipath

View File

@ -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)
@ -51,7 +52,7 @@ class Authetication:
b64pwd = b64encode(SHA256.new(password.encode('utf-8')).digest())
bcrypt_check(b64pwd, user['password'].encode('utf-8'))
auth_logger.debug("User logged in: " + username)
return user['homeDir']
return self.HOME_DIRECTORY_LOCATION + os.path.sep + user['homeDir']
except ValueError:
auth_logger.debug("User NOT logged in: " + username)
return ''
@ -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)

View 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

View File

@ -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