From c69241249e730370697e983673c30281f0e1be6b Mon Sep 17 00:00:00 2001 From: "DESKTOP-DPA61F8\\Benedek" Date: Sun, 25 Apr 2021 15:40:08 +0200 Subject: [PATCH] Source address --- server/config_init.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/config_init.py b/server/config_init.py index c276f4c..411912c 100644 --- a/server/config_init.py +++ b/server/config_init.py @@ -6,7 +6,7 @@ from Crypto.PublicKey import RSA from authentication import Authetication -def generatePrivateKeyForUser(auth: Authetication,username: str, user_passphrase: str, public_server_key: str) -> bool: +def generatePrivateKeyForUser(auth: Authetication,username: str, user_passphrase: str, public_server_key: str,address: str) -> bool: if auth.checkUserExists(username): with open(auth.CONFIG_FILE_LOCATION) as json_file: data = json.load(json_file) @@ -17,7 +17,8 @@ def generatePrivateKeyForUser(auth: Authetication,username: str, user_passphrase public_key_value = bytes.hex(public_key.exportKey('DER', pkcs=8)) ##Save private key in separate file - user_privatekey = {'privateClientKey': private_key_value, + user_privatekey = {'address': address, + 'privateClientKey': private_key_value, 'publicServerKey': public_server_key} with open(auth.PRIVATE_KEY_DIRECTORY_LOCATION + os.path.sep + str(data['index']) + '.txt', 'w+') as outfile: @@ -54,11 +55,17 @@ def generatePrivateKeyForServer(auth: Authetication,passphrase: str) -> str: return public_key_value +def generateSourceAddress(index: str) -> chr: + return chr(ord(index[0]) + 17) + + if __name__ == '__main__': auth = Authetication() auth.initConfig() serverPublicKey = generatePrivateKeyForServer(auth, 'admin') auth.saveUser('alma', 'alma') - generatePrivateKeyForUser(auth, 'alma', 'amla', serverPublicKey) + homeDir = auth.login('alma', 'alma') + generatePrivateKeyForUser(auth, 'alma', 'amla', serverPublicKey, generateSourceAddress(homeDir)) auth.saveUser('citrom', 'citrom') - generatePrivateKeyForUser(auth, 'citrom', 'mortic', serverPublicKey) + homeDir = auth.login('citrom', 'citrom') + generatePrivateKeyForUser(auth, 'citrom', 'mortic', serverPublicKey, generateSourceAddress(homeDir))