mirror of
				https://github.com/kevinveenbirkenbach/splitted-secret.git
				synced 2025-11-04 03:08:02 +00:00 
			
		
		
		
	Added decryption for master password
This commit is contained in:
		@@ -19,7 +19,7 @@ class Cli(object):
 | 
				
			|||||||
        for line in stdout:
 | 
					        for line in stdout:
 | 
				
			||||||
            self.output.append(line.decode("utf-8"))
 | 
					            self.output.append(line.decode("utf-8"))
 | 
				
			||||||
        if process.wait() > bool(0):
 | 
					        if process.wait() > bool(0):
 | 
				
			||||||
            raise Exception("Error for: \nCommand:<<" + command + ">>\nOutput:<<" + out + ">>\nExitcode:<<" + err + ">>")
 | 
					            raise Exception("Error for: \nCommand:<<" + str(command) + ">>\nOutput:<<" + str(out) + ">>\nExitcode:<<" + str(err) + ">>")
 | 
				
			||||||
        return self.output
 | 
					        return self.output
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def getOutputString(self):
 | 
					    def getOutputString(self):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
from .AbstractSplittedSecret import AbstractSplittedSecret
 | 
					from .AbstractSplittedSecret import AbstractSplittedSecret
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
 | 
					from pathlib import Path
 | 
				
			||||||
class Decryption(AbstractSplittedSecret):
 | 
					class Decryption(AbstractSplittedSecret):
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
@@ -17,6 +18,12 @@ class Decryption(AbstractSplittedSecret):
 | 
				
			|||||||
        self.initializeNeededDecryptersAmount()
 | 
					        self.initializeNeededDecryptersAmount()
 | 
				
			||||||
        self.initializeValidDecrypterIds()
 | 
					        self.initializeValidDecrypterIds()
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def initializeGroupDataEncryption(self):
 | 
				
			||||||
 | 
					        self.group_name = self.getDecryptersGroupName()
 | 
				
			||||||
 | 
					        self.encrypted_group_file_path = self.getGroupFilePath(self.group_name, AbstractSplittedSecret.TYPE_DECRYPTED)
 | 
				
			||||||
 | 
					        self.decryptGroupFile()
 | 
				
			||||||
 | 
					        self.master_password = self.loadTxtFile(self.encrypted_group_file_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def initializeNeededDecryptersAmount(self):
 | 
					    def initializeNeededDecryptersAmount(self):
 | 
				
			||||||
        self.needed_decrypters_amount = len(str(list(self.user_data['groups'].keys())[0]))
 | 
					        self.needed_decrypters_amount = len(str(list(self.user_data['groups'].keys())[0]))
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -40,12 +47,15 @@ class Decryption(AbstractSplittedSecret):
 | 
				
			|||||||
    def addPasswordShare(self,user_id,password_share):
 | 
					    def addPasswordShare(self,user_id,password_share):
 | 
				
			||||||
        self.password_parts[str(user_id)] = password_share
 | 
					        self.password_parts[str(user_id)] = password_share
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    def getSharedPassword(self):
 | 
					    def getGroupPassword(self):
 | 
				
			||||||
        shared_password = ''
 | 
					        shared_password = ''
 | 
				
			||||||
        for password_share_index in sorted(self.password_parts):
 | 
					        for password_share_index in sorted(self.password_parts):
 | 
				
			||||||
            shared_password += str(self.password_parts[password_share_index])
 | 
					            shared_password += str(self.password_parts[password_share_index])
 | 
				
			||||||
        return shared_password
 | 
					        return shared_password
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def getMasterPassword(self):
 | 
				
			||||||
 | 
					        return self.master_password
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    def addDecrypterId(self,decrypter_id):
 | 
					    def addDecrypterId(self,decrypter_id):
 | 
				
			||||||
        decrypter_id = int(decrypter_id)
 | 
					        decrypter_id = int(decrypter_id)
 | 
				
			||||||
        if decrypter_id not in self.valid_decrypter_ids:
 | 
					        if decrypter_id not in self.valid_decrypter_ids:
 | 
				
			||||||
@@ -77,6 +87,9 @@ class Decryption(AbstractSplittedSecret):
 | 
				
			|||||||
    def getNeededCoDecryptersAmount(self):
 | 
					    def getNeededCoDecryptersAmount(self):
 | 
				
			||||||
        return self.needed_decrypters_amount -1
 | 
					        return self.needed_decrypters_amount -1
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def loadTxtFile(self,file_path):
 | 
				
			||||||
 | 
					        return Path(file_path).read_text()
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    def loadJsonFile(self,file_path):
 | 
					    def loadJsonFile(self,file_path):
 | 
				
			||||||
        file = open(file_path)
 | 
					        file = open(file_path)
 | 
				
			||||||
        data = json.load(file)
 | 
					        data = json.load(file)
 | 
				
			||||||
@@ -90,6 +103,10 @@ class Decryption(AbstractSplittedSecret):
 | 
				
			|||||||
        input_file_path = self.getUserFilePath(self.user_id,AbstractSplittedSecret.TYPE_ENCRYPTED)
 | 
					        input_file_path = self.getUserFilePath(self.user_id,AbstractSplittedSecret.TYPE_ENCRYPTED)
 | 
				
			||||||
        self.decryptFile(self.user_password, input_file_path, self.user_file_decrypted_path)
 | 
					        self.decryptFile(self.user_password, input_file_path, self.user_file_decrypted_path)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					    def decryptGroupFile(self):
 | 
				
			||||||
 | 
					        input_file_path = self.getGroupFilePath(self.group_name, AbstractSplittedSecret.TYPE_ENCRYPTED)
 | 
				
			||||||
 | 
					        self.decryptFile(self.getGroupPassword(), input_file_path, self.encrypted_group_file_path)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
    def decryptAccumulatedFile(self):
 | 
					    def decryptAccumulatedFile(self):
 | 
				
			||||||
        input_file_path = self.getAccumulatedFilePath(AbstractSplittedSecret.TYPE_ENCRYPTED)
 | 
					        input_file_path = self.getAccumulatedFilePath(AbstractSplittedSecret.TYPE_ENCRYPTED)
 | 
				
			||||||
        output_file_path = self.getAccumulatedFilePath(AbstractSplittedSecret.TYPE_DECRYPTED)
 | 
					        output_file_path = self.getAccumulatedFilePath(AbstractSplittedSecret.TYPE_DECRYPTED)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,7 @@ def clean_exit():
 | 
				
			|||||||
    print("Cleaning up.")
 | 
					    print("Cleaning up.")
 | 
				
			||||||
    cleanup.cleanupFiles(AbstractSplittedSecret.TYPE_DECRYPTED)
 | 
					    cleanup.cleanupFiles(AbstractSplittedSecret.TYPE_DECRYPTED)
 | 
				
			||||||
    print("Leaving program. Goodby :)")
 | 
					    print("Leaving program. Goodby :)")
 | 
				
			||||||
    exit();
 | 
					    exit()
 | 
				
			||||||
    pass
 | 
					    pass
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
    if __name__ == '__main__':
 | 
					    if __name__ == '__main__':
 | 
				
			||||||
@@ -42,13 +42,13 @@ try:
 | 
				
			|||||||
            decrypt = Decryption()
 | 
					            decrypt = Decryption()
 | 
				
			||||||
            if args.master_password is None:
 | 
					            if args.master_password is None:
 | 
				
			||||||
                if args.user is None: 
 | 
					                if args.user is None: 
 | 
				
			||||||
                    print("Please type in the user number:")
 | 
					                    print("Type in the user id:")
 | 
				
			||||||
                    decrypt.initializeUser(input())
 | 
					                    decrypt.initializeUser(input())
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    decrypt.initializeUser(args.user)
 | 
					                    decrypt.initializeUser(args.user)
 | 
				
			||||||
                if args.user_password is None:
 | 
					                if args.user_password is None:
 | 
				
			||||||
                    while True:
 | 
					                    while True:
 | 
				
			||||||
                        print("Please enter the user password:")
 | 
					                        print("Enter the user password:")
 | 
				
			||||||
                        decrypt.setUserPassword(getpass())
 | 
					                        decrypt.setUserPassword(getpass())
 | 
				
			||||||
                        print("Decrypting User File...")
 | 
					                        print("Decrypting User File...")
 | 
				
			||||||
                        try:
 | 
					                        try:
 | 
				
			||||||
@@ -64,13 +64,12 @@ try:
 | 
				
			|||||||
                    except Exception as error:
 | 
					                    except Exception as error:
 | 
				
			||||||
                        print("An error occured. Propably you passed a wrong password :( The error is: " + str(error))
 | 
					                        print("An error occured. Propably you passed a wrong password :( The error is: " + str(error))
 | 
				
			||||||
                        clean_exit()
 | 
					                        clean_exit()
 | 
				
			||||||
                print("File decrypted :) \n")
 | 
					                print("Contact the following persons and tell them that you need help to encrypt the data: \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']:
 | 
					                for contact_id in decrypt.user_data['contacts']:
 | 
				
			||||||
                    print("user_id: " + contact_id)
 | 
					                    print("user_id: " + contact_id)
 | 
				
			||||||
                    for label in decrypt.user_data['contacts'][contact_id]:
 | 
					                    for label in decrypt.user_data['contacts'][contact_id]:
 | 
				
			||||||
                        print(label + ": " + decrypt.user_data['contacts'][contact_id][label])
 | 
					                        print(label + ": " + decrypt.user_data['contacts'][contact_id][label])
 | 
				
			||||||
                    print("--------------------------------\n")
 | 
					                    print()
 | 
				
			||||||
                while True:
 | 
					                while True:
 | 
				
			||||||
                    decrypt.resetDecrypterIds()
 | 
					                    decrypt.resetDecrypterIds()
 | 
				
			||||||
                    try:
 | 
					                    try:
 | 
				
			||||||
@@ -83,22 +82,29 @@ try:
 | 
				
			|||||||
                            person_counter += 1
 | 
					                            person_counter += 1
 | 
				
			||||||
                        break
 | 
					                        break
 | 
				
			||||||
                    except Exception as error:
 | 
					                    except Exception as error:
 | 
				
			||||||
                        print("The following error occured <<" + str(error) + ">> :( \n Please try again :)")
 | 
					                        print("The following error occured <<" + str(error) + ">> :( \n Try again :)")
 | 
				
			||||||
                print("\nFOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName()) 
 | 
					                print("\nYour data is:\n")
 | 
				
			||||||
 | 
					                print("FOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName()) 
 | 
				
			||||||
                print("FOR USER ID: "  + decrypt.getUserId())
 | 
					                print("FOR USER ID: "  + decrypt.getUserId())
 | 
				
			||||||
                print("PASSWORD SHARE IS: " + decrypt.getPasswordShare() + "\n")
 | 
					                print("PASSWORD SHARE IS: " + decrypt.getPasswordShare() + "\n")
 | 
				
			||||||
                while True:
 | 
					                while True:
 | 
				
			||||||
                    decrypt.resetPasswordShare()
 | 
					                    try:
 | 
				
			||||||
                    co_decrypter_ids = decrypt.getCoDecrypterIds()
 | 
					                        decrypt.resetPasswordShare()
 | 
				
			||||||
                    print("Please execute this script at the users " + str(co_decrypter_ids) + ".")
 | 
					                        co_decrypter_ids = decrypt.getCoDecrypterIds()
 | 
				
			||||||
                    for co_decrypter_id in decrypt.getCoDecrypterIds():
 | 
					                        for co_decrypter_id in decrypt.getCoDecrypterIds():
 | 
				
			||||||
                        print("\nFOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName()) 
 | 
					                            print("Execute this script for user: " + str(co_decrypter_id) + ".")
 | 
				
			||||||
                        print("FOR USER: " + str(co_decrypter_id)) 
 | 
					                            print("Type in the password share.\n")
 | 
				
			||||||
                        print("PASSWORD SHARE IS: ")
 | 
					                            print("\nFOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName()) 
 | 
				
			||||||
                        decrypt.addPasswordShare(co_decrypter_id, input())
 | 
					                            print("FOR USER: " + str(co_decrypter_id)) 
 | 
				
			||||||
                    print("\nTHE SHARED PASSWORD IS: " + decrypt.getSharedPassword())
 | 
					                            print("PASSWORD SHARE IS: ")
 | 
				
			||||||
                    break;
 | 
					                            decrypt.addPasswordShare(co_decrypter_id, input())
 | 
				
			||||||
                        
 | 
					                        print("\nTHE GROUP PASSWORD IS: " + decrypt.getGroupPassword())
 | 
				
			||||||
 | 
					                        print("\nDecrypting group password file.\n")
 | 
				
			||||||
 | 
					                        decrypt.initializeGroupDataEncryption()
 | 
				
			||||||
 | 
					                        print("THE MASTER PASSWORD IS: " + decrypt.getMasterPassword())
 | 
				
			||||||
 | 
					                        break;
 | 
				
			||||||
 | 
					                    except:
 | 
				
			||||||
 | 
					                        print("An unexpected error occured: \n" + traceback.format_exc())
 | 
				
			||||||
                clean_exit()
 | 
					                clean_exit()
 | 
				
			||||||
            print("Decrypting accumulated file...")
 | 
					            print("Decrypting accumulated file...")
 | 
				
			||||||
            decrypt.setUserPassword(args.master_password)
 | 
					            decrypt.setUserPassword(args.master_password)
 | 
				
			||||||
@@ -107,7 +113,7 @@ try:
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
        if args.mode == 'encrypt':
 | 
					        if args.mode == 'encrypt':
 | 
				
			||||||
            if args.master_password is None:
 | 
					            if args.master_password is None:
 | 
				
			||||||
                print("Please enter the master password:")
 | 
					                print("Enter the master password:")
 | 
				
			||||||
                master_password = getpass()
 | 
					                master_password = getpass()
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                master_password = args.master_password
 | 
					                master_password = args.master_password
 | 
				
			||||||
@@ -115,11 +121,13 @@ try:
 | 
				
			|||||||
            if args.add_user_information is not None:
 | 
					            if args.add_user_information is not None:
 | 
				
			||||||
                for user_id in encrypt.user_mapped_data:
 | 
					                for user_id in encrypt.user_mapped_data:
 | 
				
			||||||
                    for label in ['name','phone','email','address']:
 | 
					                    for label in ['name','phone','email','address']:
 | 
				
			||||||
                        print("Please enter attribut <<" + label + ">> for user <<" + user_id+ ">>:" )
 | 
					                        print("Enter attribut <<" + label + ">> for user <<" + user_id+ ">>:" )
 | 
				
			||||||
                        encrypt.addInformationToUser(user_id, label, str(input()))
 | 
					                        encrypt.addInformationToUser(user_id, label, str(input()))
 | 
				
			||||||
            encrypt.compileData()
 | 
					            encrypt.compileData()
 | 
				
			||||||
            encrypt.encrypt()
 | 
					            encrypt.encrypt()
 | 
				
			||||||
            clean_exit()
 | 
					            clean_exit()
 | 
				
			||||||
except Exception:
 | 
					except KeyboardInterrupt:
 | 
				
			||||||
    print(traceback.format_exc())
 | 
					    print("Program interrupted by user.")
 | 
				
			||||||
 | 
					except:
 | 
				
			||||||
 | 
					    print("An unexpected error occured: \n" + traceback.format_exc())
 | 
				
			||||||
clean_exit()
 | 
					clean_exit()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user