Init script extension and key loading for netwrapper

This commit is contained in:
2021-04-25 15:24:24 +02:00
parent a5b77d0306
commit b87e2c3b3d
3 changed files with 65 additions and 16 deletions

View File

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