Init script extension and key loading for netwrapper
This commit is contained in:
@@ -7,13 +7,15 @@ from base64 import b64encode
|
||||
|
||||
from Crypto.Hash import SHA256
|
||||
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
|
||||
from Crypto.PublicKey import RSA
|
||||
from Crypto.PublicKey.RSA import RsaKey
|
||||
|
||||
auth_logger = logging.getLogger('AUTH APPLICATION ')
|
||||
auth_logger.root.setLevel(logging.INFO)
|
||||
|
||||
class Authetication:
|
||||
ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
|
||||
HOME_DIRECTORY_LOCATION = ABSOLUTE_PATH + os.path.sep +"home"
|
||||
HOME_DIRECTORY_LOCATION = ABSOLUTE_PATH + os.path.sep + "home"
|
||||
CONFIG_DIRECTORY_LOCATION = ABSOLUTE_PATH + os.path.sep + "config"
|
||||
CONFIG_FILE_LOCATION = ABSOLUTE_PATH + os.path.sep + "config" + os.path.sep + "config.txt"
|
||||
PRIVATE_KEY_DIRECTORY_LOCATION = CONFIG_DIRECTORY_LOCATION + os.path.sep + "private_keys"
|
||||
@@ -111,3 +113,34 @@ class Authetication:
|
||||
auth_logger.debug("User NOT saved! Home directory already exists")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def loadUserPublicKeys(self) -> dict:
|
||||
with open(self.CONFIG_FILE_LOCATION) as json_file:
|
||||
data = json.load(json_file)
|
||||
|
||||
dictionary: dict
|
||||
|
||||
for user in data['user']:
|
||||
key = data['publicKey']
|
||||
key = bytes.fromhex(key)
|
||||
try:
|
||||
rsaKey = RSA.import_key(key)
|
||||
dictionary[user['username']] = rsaKey
|
||||
except ValueError:
|
||||
print('Invalid server public key!')
|
||||
|
||||
return dictionary
|
||||
|
||||
|
||||
def loadServerPrivateKey(self) -> RsaKey:
|
||||
with open(self.CONFIG_FILE_LOCATION) as json_file:
|
||||
data = json.load(json_file)
|
||||
|
||||
key = data['serverPrivateKey']
|
||||
key = bytes.fromhex(key)
|
||||
try:
|
||||
rsaKey = RSA.import_key(key)
|
||||
except ValueError:
|
||||
print('Invalid server private key!')
|
||||
return rsaKey
|
||||
|
||||
Reference in New Issue
Block a user