mirror of
				https://github.com/kevinveenbirkenbach/splitted-secret.git
				synced 2025-11-04 11:18:03 +00:00 
			
		
		
		
	Cleaned code up
This commit is contained in:
		@@ -1,6 +1,12 @@
 | 
				
			|||||||
# Splitted Secret
 | 
					# 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. 
 | 
					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
 | 
					# Requirements to know
 | 
				
			||||||
- Amount of People
 | 
					- Amount of People
 | 
				
			||||||
- How much people need to reunite for decrypting
 | 
					- How much people need to reunite for decrypting
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,8 +14,6 @@ class Cleanup(AbstractSplittedSecret):
 | 
				
			|||||||
    def deleteAllFilesInFolder(self,folder_path):
 | 
					    def deleteAllFilesInFolder(self,folder_path):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.executeCommand('rm -v ' + folder_path + '*')
 | 
					            self.executeCommand('rm -v ' + folder_path + '*')
 | 
				
			||||||
            print(self.getCommandString())
 | 
					 | 
				
			||||||
            print(self.getOutputString())
 | 
					 | 
				
			||||||
        except:
 | 
					        except:
 | 
				
			||||||
            pass    
 | 
					            pass    
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -28,10 +26,7 @@ class Cleanup(AbstractSplittedSecret):
 | 
				
			|||||||
            self.deleteAllFilesInFolder(folder_path)
 | 
					            self.deleteAllFilesInFolder(folder_path)
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
    def cleanupForUser(self,user):
 | 
					    def cleanupForUser(self,user):
 | 
				
			||||||
        self.executeCommand('find "' + self.getFolderPath("encrypted") + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v')
 | 
					        self.executeCommand('find "' + self.getFolderPath("encrypted") + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v')    
 | 
				
			||||||
        print(self.getCommandString())
 | 
					 | 
				
			||||||
        print(self.getOutputString())
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def deleteAll(self):
 | 
					    def deleteAll(self):
 | 
				
			||||||
        self.deleteAllFiles("encrypted")
 | 
					        self.deleteAllFiles("encrypted")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,11 +14,13 @@ class Decryption(AbstractSplittedSecret):
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    def decryptFile(self,password,input_file_path,output_file_path):
 | 
					    def decryptFile(self,password,input_file_path,output_file_path):
 | 
				
			||||||
        self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"')
 | 
					        self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"')
 | 
				
			||||||
        print(self.getCommandString())
 | 
					 | 
				
			||||||
        print(self.getOutputString())
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def decryptUserFile(self):
 | 
					    def decryptUserFile(self):
 | 
				
			||||||
        input_file_path = self.getUserFilePath(self.user_id,"encrypted")
 | 
					        input_file_path = self.getUserFilePath(self.user_id,"encrypted")
 | 
				
			||||||
        output_file_path = self.getUserFilePath(self.user_id,"decrypted")
 | 
					        output_file_path = self.getUserFilePath(self.user_id,"decrypted")
 | 
				
			||||||
        self.decryptFile(self.user_password, input_file_path,output_file_path)
 | 
					        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)
 | 
				
			||||||
@@ -31,14 +31,6 @@ class Encryption(AbstractSplittedSecret):
 | 
				
			|||||||
            start_number += str(self.amount_of_secret_holders)
 | 
					            start_number += str(self.amount_of_secret_holders)
 | 
				
			||||||
            index += 1
 | 
					            index += 1
 | 
				
			||||||
        return int(start_number)
 | 
					        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):
 | 
					    def createPassword(self,length):
 | 
				
			||||||
        characters = string.ascii_letters + string.digits
 | 
					        characters = string.ascii_letters + string.digits
 | 
				
			||||||
@@ -85,7 +77,6 @@ class Encryption(AbstractSplittedSecret):
 | 
				
			|||||||
            
 | 
					            
 | 
				
			||||||
    def encryptStringToFile(self,text,output_file,password):
 | 
					    def encryptStringToFile(self,text,output_file,password):
 | 
				
			||||||
        self.executeCommand('echo \'' + text + '\' | gpg --symmetric --armor --batch --passphrase "' + password + '" -o "' + output_file + '"')
 | 
					        self.executeCommand('echo \'' + text + '\' | gpg --symmetric --armor --batch --passphrase "' + password + '" -o "' + output_file + '"')
 | 
				
			||||||
        print(self.getCommandString())
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def generateEncryptedGroupFiles(self):
 | 
					    def generateEncryptedGroupFiles(self):
 | 
				
			||||||
        for password_group_index_int in self.group_mapped_data:
 | 
					        for password_group_index_int in self.group_mapped_data:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,15 +23,20 @@ if __name__ == '__main__':
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
    if args.mode == 'decrypt':
 | 
					    if args.mode == 'decrypt':
 | 
				
			||||||
        decrypt = Decryption()
 | 
					        decrypt = Decryption()
 | 
				
			||||||
        if args.user is None: 
 | 
					        if args.master_password is None:
 | 
				
			||||||
            print("Please type in the user number:")
 | 
					            if args.user is None: 
 | 
				
			||||||
            decrypt.setUserId(input())
 | 
					                print("Please type in the user number:")
 | 
				
			||||||
        else:
 | 
					                decrypt.setUserId(input())
 | 
				
			||||||
            decrypt.setUser(args.user)
 | 
					            else:
 | 
				
			||||||
        print("Please enter the master password:")
 | 
					                decrypt.setUser(args.user)
 | 
				
			||||||
        decrypt.setUserPassword(getpass())
 | 
					            print("Please enter the user password:")
 | 
				
			||||||
        print("Decrypting User File...")
 | 
					            decrypt.setUserPassword(getpass())
 | 
				
			||||||
        decrypt.decryptUserFile();
 | 
					            print("Decrypting User File...")
 | 
				
			||||||
 | 
					            decrypt.decryptUserFile();
 | 
				
			||||||
 | 
					            exit()
 | 
				
			||||||
 | 
					        print("Decrypting accumulated file...")
 | 
				
			||||||
 | 
					        decrypt.setUserPassword(args.master_password)
 | 
				
			||||||
 | 
					        decrypt.decryptAccumulatedFile()
 | 
				
			||||||
        exit()
 | 
					        exit()
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user