From 284fec6c1549b4191207890e3e4c660a8f372d5e Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 9 Dec 2022 20:54:33 +0100 Subject: [PATCH] Cleaned code up --- Readme.md | 6 ++++++ scripts/classes/Cleanup.py | 7 +------ scripts/classes/Decryption.py | 10 ++++++---- scripts/classes/Encryption.py | 9 --------- scripts/main.py | 23 ++++++++++++++--------- 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Readme.md b/Readme.md index d55060f..ca46f91 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,12 @@ # Splitted Secret The purpose of this software is to splitt a secret over multiple people. Just if a defined amount of this people meet together they can encrypt the secret and have access to it. +# testing +```bash +python scripts/main.py --mode cleanup && +python scripts/main.py --amount 6 --quota 50 --mode generate --master-password "ewrwerwerew" && +python scripts/main.py --mode decrypt --master-password "ewrwerwerew" +``` # Requirements to know - Amount of People - How much people need to reunite for decrypting diff --git a/scripts/classes/Cleanup.py b/scripts/classes/Cleanup.py index 4eac922..03fd367 100644 --- a/scripts/classes/Cleanup.py +++ b/scripts/classes/Cleanup.py @@ -14,8 +14,6 @@ class Cleanup(AbstractSplittedSecret): def deleteAllFilesInFolder(self,folder_path): try: self.executeCommand('rm -v ' + folder_path + '*') - print(self.getCommandString()) - print(self.getOutputString()) except: pass @@ -28,10 +26,7 @@ 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') - print(self.getCommandString()) - print(self.getOutputString()) - + self.executeCommand('find "' + self.getFolderPath("encrypted") + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v') def deleteAll(self): self.deleteAllFiles("encrypted") diff --git a/scripts/classes/Decryption.py b/scripts/classes/Decryption.py index 00b0913..e9b7fec 100644 --- a/scripts/classes/Decryption.py +++ b/scripts/classes/Decryption.py @@ -14,11 +14,13 @@ class Decryption(AbstractSplittedSecret): def decryptFile(self,password,input_file_path,output_file_path): self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"') - print(self.getCommandString()) - print(self.getOutputString()) def decryptUserFile(self): input_file_path = self.getUserFilePath(self.user_id,"encrypted") output_file_path = self.getUserFilePath(self.user_id,"decrypted") - self.decryptFile(self.user_password, input_file_path,output_file_path) - \ No newline at end of file + self.decryptFile(self.user_password, input_file_path, output_file_path) + + def decryptAccumulatedFile(self): + input_file_path = self.getAccumulatedFilePath("encrypted") + output_file_path = self.getAccumulatedFilePath("decrypted") + self.decryptFile(self.user_password, input_file_path, output_file_path) \ No newline at end of file diff --git a/scripts/classes/Encryption.py b/scripts/classes/Encryption.py index 59fbdec..f2054eb 100644 --- a/scripts/classes/Encryption.py +++ b/scripts/classes/Encryption.py @@ -31,14 +31,6 @@ class Encryption(AbstractSplittedSecret): start_number += str(self.amount_of_secret_holders) index += 1 return int(start_number) - - def savePassword(self,password,password_file_path): - print("Saving password to: " + password_file_path) - master_password_file = open(password_file_path, "a") - master_password_file.seek(0) - master_password_file.truncate() - master_password_file.write(password) - master_password_file.close() def createPassword(self,length): characters = string.ascii_letters + string.digits @@ -85,7 +77,6 @@ class Encryption(AbstractSplittedSecret): def encryptStringToFile(self,text,output_file,password): self.executeCommand('echo \'' + text + '\' | gpg --symmetric --armor --batch --passphrase "' + password + '" -o "' + output_file + '"') - print(self.getCommandString()) def generateEncryptedGroupFiles(self): for password_group_index_int in self.group_mapped_data: diff --git a/scripts/main.py b/scripts/main.py index b307b91..88c930d 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -23,15 +23,20 @@ if __name__ == '__main__': if args.mode == 'decrypt': decrypt = Decryption() - if args.user is None: - print("Please type in the user number:") - decrypt.setUserId(input()) - else: - decrypt.setUser(args.user) - print("Please enter the master password:") - decrypt.setUserPassword(getpass()) - print("Decrypting User File...") - decrypt.decryptUserFile(); + if args.master_password is None: + if args.user is None: + print("Please type in the user number:") + decrypt.setUserId(input()) + else: + decrypt.setUser(args.user) + print("Please enter the user password:") + decrypt.setUserPassword(getpass()) + print("Decrypting User File...") + decrypt.decryptUserFile(); + exit() + print("Decrypting accumulated file...") + decrypt.setUserPassword(args.master_password) + decrypt.decryptAccumulatedFile() exit()