diff --git a/Readme.md b/Readme.md index 626a17d..b30a495 100644 --- a/Readme.md +++ b/Readme.md @@ -3,8 +3,8 @@ The purpose of this software is to splitt a secret over multiple people. Just if # testing ```bash -python splitted-secret/scripts/main.py --mode cleanup && -python splitted-secret/scripts/main.py --amount 3 --quota 50 --mode encrypt --add-user-information --master-password "ewrwerwerew" << END_OF_INPUTS +python scripts/main.py --mode cleanup && +python scripts/main.py --amount 3 --quota 50 --mode encrypt --add-user-information --master-password "ewrwerwerew" << END_OF_INPUTS alpha bravo 123123812908 asfdasd@asdskjd.de @@ -46,7 +46,6 @@ END_OF_INPUTS ## todo - implement tails setup script -- implement tmp mount for decrypted files - add data-input attribut - add data-output attribut diff --git a/scripts/classes/AbstractSplittedSecret.py b/scripts/classes/AbstractSplittedSecret.py index 6b9c6e3..6636907 100644 --- a/scripts/classes/AbstractSplittedSecret.py +++ b/scripts/classes/AbstractSplittedSecret.py @@ -1,9 +1,6 @@ -from .Cli import Cli import os -class AbstractSplittedSecret(Cli): - USER_PASSWORD_LENGTHS = 64 - OVERALL_PASSWORD_LENGTHS = 128 +class AbstractSplittedSecret(): # At the moment the programm can only deal with one digit numbers. MAXIMUM_SECRET_HOLDERS = 9 @@ -15,7 +12,6 @@ class AbstractSplittedSecret(Cli): ROOT_PATH= os.path.join(os.path.dirname(os.path.abspath(__file__)),"../","../") def __init__(self): - super(Cli, self).__init__() self.data_folder = os.path.join(self.ROOT_PATH,"data") + '/' diff --git a/scripts/classes/Cleanup.py b/scripts/classes/Cleanup.py index d371b4c..36970dd 100644 --- a/scripts/classes/Cleanup.py +++ b/scripts/classes/Cleanup.py @@ -1,6 +1,8 @@ from .AbstractSplittedSecret import AbstractSplittedSecret + class Cleanup(AbstractSplittedSecret): - def __init__(self): + def __init__(self,cli): + self.cli = cli super(Cleanup, self).__init__() def getAllFilePaths(self,file_type): @@ -15,7 +17,7 @@ class Cleanup(AbstractSplittedSecret): def deleteAllFilesInFolder(self,folder_path): try: - self.executeCommand('rm -r ' + folder_path + '*') + self.cli.executeCommand('rm -r ' + folder_path + '*') except Exception as error: print(error) @@ -25,7 +27,7 @@ class Cleanup(AbstractSplittedSecret): def cleanupForUser(self,user): try: - self.executeCommand('find "' + self.getDataFolderPath(AbstractSplittedSecret.TYPE_ENCRYPTED) + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v') + self.cli.executeCommand('find "' + self.getDataFolderPath(AbstractSplittedSecret.TYPE_ENCRYPTED) + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v') except Exception as error: print(error) self.cleanupFiles(AbstractSplittedSecret.TYPE_DECRYPTED) diff --git a/scripts/classes/Decryption.py b/scripts/classes/Decryption.py index f88865e..9aab184 100644 --- a/scripts/classes/Decryption.py +++ b/scripts/classes/Decryption.py @@ -1,11 +1,13 @@ from .AbstractSplittedSecret import AbstractSplittedSecret import json from pathlib import Path + class Decryption(AbstractSplittedSecret): - def __init__(self): + def __init__(self,cli): self.user_id='0'; self.user_password='' + self.cli = cli super(Decryption, self).__init__() def initializeUser(self,user_id): @@ -97,7 +99,7 @@ class Decryption(AbstractSplittedSecret): return data def decryptFile(self,password,input_file_path,output_file_path): - self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"') + self.cli.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"') def decryptUserFile(self): input_file_path = self.getUserFilePath(self.user_id,AbstractSplittedSecret.TYPE_ENCRYPTED) @@ -113,4 +115,4 @@ class Decryption(AbstractSplittedSecret): self.decryptFile(self.user_password, input_file_path, output_file_path) def decryptMainData(self): - self.executeCommand('gpg --batch --passphrase "' + self.getMasterPassword() + '" -d "' + self.getEncryptedMainDataFile() + '" | tar -xvzf - "' + self.getDecryptedMainDataStandartFolder() + '"') \ No newline at end of file + self.cli.executeCommand('gpg --batch --passphrase "' + self.getMasterPassword() + '" -d "' + self.getEncryptedMainDataFile() + '" | tar -xvzf - "' + self.getDecryptedMainDataStandartFolder() + '"') \ No newline at end of file diff --git a/scripts/classes/Encryption.py b/scripts/classes/Encryption.py index 4f5c513..221c050 100644 --- a/scripts/classes/Encryption.py +++ b/scripts/classes/Encryption.py @@ -8,7 +8,10 @@ from .AbstractSplittedSecret import AbstractSplittedSecret class Encryption(AbstractSplittedSecret): - def __init__(self, amount_of_secret_holders, decryption_quota,master_password): + USER_PASSWORD_LENGTHS = 64 + OVERALL_PASSWORD_LENGTHS = 128 + + def __init__(self, cli, amount_of_secret_holders, decryption_quota,master_password): super(Encryption, self).__init__() self.amount_of_secret_holders = amount_of_secret_holders self.decryption_quota = decryption_quota @@ -17,6 +20,7 @@ class Encryption(AbstractSplittedSecret): self.group_members_amount=math.ceil(self.amount_of_secret_holders * self.quota_factor) self.initializeUserData() self.initializeGroupData() + self.cli = cli def initializeUserData(self): self.user_mapped_data = {} @@ -90,7 +94,7 @@ class Encryption(AbstractSplittedSecret): index += 1 def encryptStringToFile(self,text,output_file,password): - self.executeCommand('echo \'' + text + '\' | gpg --symmetric --armor --batch --passphrase "' + password + '" -o "' + output_file + '"') + self.cli.executeCommand('echo \'' + text + '\' | gpg --symmetric --armor --batch --passphrase "' + password + '" -o "' + output_file + '"') def encryptGroupFiles(self): for password_group_index_int in self.group_mapped_data: @@ -113,7 +117,7 @@ class Encryption(AbstractSplittedSecret): self.encryptToJsonFile(data,file_path,self.master_password) def encryptMainData(self): - self.executeCommand('tar -cvzf - "' + self.getDecryptedMainDataStandartFolder() + '" | gpg -c --batch --passphrase "' + self.master_password +'" > "' + self.getEncryptedMainDataFile() + '"'); + self.cli.executeCommand('tar -cvzf - "' + self.getDecryptedMainDataStandartFolder() + '" | gpg -c --batch --passphrase "' + self.master_password +'" > "' + self.getEncryptedMainDataFile() + '"'); def encryptAll(self): self.encryptUserFile() diff --git a/scripts/main.py b/scripts/main.py index ff6de84..547e617 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -5,8 +5,10 @@ from classes.Decryption import Decryption from getpass import getpass from classes.AbstractSplittedSecret import AbstractSplittedSecret import traceback +from classes.Cli import Cli -cleanup = Cleanup() +cli = Cli() +cleanup = Cleanup(cli) def clean_exit(): print("Cleaning up.") @@ -56,7 +58,7 @@ try: standard_exit() if args.mode == 'decrypt': - decrypt = Decryption() + decrypt = Decryption(cli) if args.master_password is None: if args.user is None: print("Type in the user id:") @@ -137,7 +139,7 @@ try: master_password = getpass() else: master_password = args.master_password - encrypt = Encryption(args.amount_of_secret_holders, args.decryption_quota, master_password) + encrypt = Encryption(cli,args.amount_of_secret_holders, args.decryption_quota, master_password) if args.add_user_information is not None: for user_id in encrypt.user_mapped_data: for label in ['name','phone','email','address']: