From b3c31c0013a6917e0f1f724d14ed1999fd2f195c Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 9 Dec 2022 20:39:00 +0100 Subject: [PATCH] Implemented decryption of user file --- scripts/classes/AbstractSplittedSecret.py | 4 ++-- scripts/classes/Decryption.py | 11 ++++++----- scripts/main.py | 6 ++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/classes/AbstractSplittedSecret.py b/scripts/classes/AbstractSplittedSecret.py index 76037bd..79d50c9 100644 --- a/scripts/classes/AbstractSplittedSecret.py +++ b/scripts/classes/AbstractSplittedSecret.py @@ -17,8 +17,8 @@ class AbstractSplittedSecret(Cli): def getFileExtension(self,file_type): if file_type == "encrypted": - return '' - return '.gpg' + return '.gpg' + return '' def getUserFilePath(self,user_id,file_type): return self.getUserFilesFolderPath(file_type)+user_id+'.json' + self.getFileExtension(file_type); diff --git a/scripts/classes/Decryption.py b/scripts/classes/Decryption.py index 1c2bbe1..00b0913 100644 --- a/scripts/classes/Decryption.py +++ b/scripts/classes/Decryption.py @@ -4,7 +4,7 @@ class Decryption(AbstractSplittedSecret): def __init__(self): self.user_id='0'; self.user_password='' - pass + super(Decryption, self).__init__() def setUserId(self,user_id): self.user_id=str(user_id) @@ -12,12 +12,13 @@ class Decryption(AbstractSplittedSecret): def setUserPassword(self,user_password): self.user_password = str(user_password) - def decryptFile(self,password,input_file_path): - self.executeCommand('gpg --batch --passphrase "'+ password + '" '+ 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+'"') print(self.getCommandString()) print(self.getOutputString()) def decryptUserFile(self): - input_file_path = self.getUserFilePath(self.user_id) - self.decryptFile(self.user_password, file_path) + 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 diff --git a/scripts/main.py b/scripts/main.py index 040ad99..b307b91 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -25,11 +25,13 @@ if __name__ == '__main__': decrypt = Decryption() if args.user is None: print("Please type in the user number:") - decrypt.setUser(int(input())) + decrypt.setUserId(input()) else: decrypt.setUser(args.user) print("Please enter the master password:") - user_password = getpass() + decrypt.setUserPassword(getpass()) + print("Decrypting User File...") + decrypt.decryptUserFile(); exit()