From e4217afe64bd24d33d7cdd23691804ca1ba44b6c Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 9 Dec 2022 23:43:28 +0100 Subject: [PATCH] optimized cli workflow --- Readme.md | 4 ++++ scripts/classes/Cleanup.py | 6 +++++- scripts/classes/Decryption.py | 3 +++ scripts/main.py | 30 +++++++++++++++++++++++------- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Readme.md b/Readme.md index 270ce04..71074ff 100644 --- a/Readme.md +++ b/Readme.md @@ -20,6 +20,10 @@ street in strasdlasöd END_OF_INPUTS python scripts/main.py --mode decrypt --master-password "ewrwerwerew" && python scripts/main.py --mode decrypt --user "1" + + +python scripts/main.py --mode cleanup --user "1" && python scripts/main.py --mode decrypt --user "1" --user-password "O3ITMWXZED9FKYQ0PB2WNVRWSCSCYVXCD00PJ6GQ4MFPIUWBVDCYSSSX9ZDBW5QU" + ``` # Requirements to know - Amount of People diff --git a/scripts/classes/Cleanup.py b/scripts/classes/Cleanup.py index 03fd367..3de55cc 100644 --- a/scripts/classes/Cleanup.py +++ b/scripts/classes/Cleanup.py @@ -26,7 +26,11 @@ class Cleanup(AbstractSplittedSecret): self.deleteAllFilesInFolder(folder_path) def cleanupForUser(self,user): - self.executeCommand('find "' + self.getFolderPath("encrypted") + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v') + try: + self.executeCommand('find "' + self.getFolderPath("encrypted") + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v') + except: + pass + self.deleteAllFiles("decrypted") def deleteAll(self): self.deleteAllFiles("encrypted") diff --git a/scripts/classes/Decryption.py b/scripts/classes/Decryption.py index 7fb88c1..bb94bb1 100644 --- a/scripts/classes/Decryption.py +++ b/scripts/classes/Decryption.py @@ -20,6 +20,9 @@ class Decryption(AbstractSplittedSecret): file.close() return data + def getNeededEncryptersAmount(self): + return len(str(list(self.user_data['groups'].keys())[0]))-1 + def decryptFile(self,password,input_file_path,output_file_path): self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"') diff --git a/scripts/main.py b/scripts/main.py index 2fa67be..6243af9 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -10,6 +10,7 @@ if __name__ == '__main__': parser.add_argument('--amount',type=int, dest='amount_of_secret_holders',required=False,choices=range(1,9)) parser.add_argument('--quota', type=int, dest='decryption_quota', choices=range(1,101),required=False) parser.add_argument('--master-password',type=str, dest='master_password',required=False) + parser.add_argument('--user-password',type=str, dest='user_password',required=False) parser.add_argument('--user',type=int, dest='user',choices=range(1,9),required=False) parser.add_argument('--add-user-information',type=bool, dest='add_user_information', default=False, required=False, action=argparse.BooleanOptionalAction) args = parser.parse_args() @@ -21,8 +22,10 @@ if __name__ == '__main__': if mode == 'cleanup': cleanup = Cleanup() if args.user is None: + print("Delete all files.") cleanup.deleteAll() exit() + print("Delete files for user <<" + str(args.user) + ">>"); cleanup.cleanupForUser(args.user) exit() @@ -34,18 +37,31 @@ if __name__ == '__main__': decrypt.setUserId(input()) else: decrypt.setUserId(args.user) - while True: - print("Please enter the user password:") - decrypt.setUserPassword(getpass()) + if args.user_password is None: + while True: + print("Please enter the user password:") + decrypt.setUserPassword(getpass()) + print("Decrypting User File...") + try: + decrypt.setUserData(); + break; + except: + print("Wrong password :(") + else: + decrypt.setUserPassword(args.user_password) print("Decrypting User File...") try: decrypt.setUserData(); - break; except: print("Wrong password :(") - print("File decrypted :) ") - print("Please contact ") - print(decrypt.user_data) + exit() + print("File decrypted :) \n") + print("Please contact the following persons and tell them that you need help to encrypt the data: \n") + for contact_id in decrypt.user_data['contacts']: + print("user_id: " + contact_id) + for label in decrypt.user_data['contacts'][contact_id]: + print(label + ": " + decrypt.user_data['contacts'][contact_id][label]) + print("You need at least <<" + str(decrypt.getNeededEncryptersAmount()) +">> aditional people to decrypt the secret.") exit() print("Decrypting accumulated file...") decrypt.setUserPassword(args.master_password)