2022-12-09 20:10:12 +01:00
|
|
|
from .AbstractSplittedSecret import AbstractSplittedSecret
|
2022-12-09 22:55:33 +01:00
|
|
|
import json
|
2022-12-09 20:13:48 +01:00
|
|
|
class Decryption(AbstractSplittedSecret):
|
2022-12-09 20:10:12 +01:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.user_id='0';
|
|
|
|
self.user_password=''
|
2022-12-09 20:39:00 +01:00
|
|
|
super(Decryption, self).__init__()
|
2022-12-09 20:10:12 +01:00
|
|
|
|
|
|
|
def setUserId(self,user_id):
|
|
|
|
self.user_id=str(user_id)
|
2022-12-09 22:55:33 +01:00
|
|
|
self.user_file_decrypted_path = self.getUserFilePath(self.user_id,"decrypted")
|
2022-12-09 20:10:12 +01:00
|
|
|
|
|
|
|
def setUserPassword(self,user_password):
|
|
|
|
self.user_password = str(user_password)
|
|
|
|
|
2022-12-09 22:55:33 +01:00
|
|
|
def loadJsonFile(self,file_path):
|
|
|
|
file = open(file_path)
|
|
|
|
data = json.load(file)
|
|
|
|
file.close()
|
|
|
|
return data
|
|
|
|
|
2022-12-10 00:00:42 +01:00
|
|
|
def setNeededEncryptersAmount(self):
|
|
|
|
self.needed_encrypters_amount = len(str(list(self.user_data['groups'].keys())[0]))-1
|
2022-12-09 23:43:28 +01:00
|
|
|
|
2022-12-09 20:39:00 +01:00
|
|
|
def decryptFile(self,password,input_file_path,output_file_path):
|
|
|
|
self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"')
|
2022-12-09 20:10:12 +01:00
|
|
|
|
|
|
|
def decryptUserFile(self):
|
2022-12-09 20:39:00 +01:00
|
|
|
input_file_path = self.getUserFilePath(self.user_id,"encrypted")
|
2022-12-09 22:55:33 +01:00
|
|
|
self.decryptFile(self.user_password, input_file_path, self.user_file_decrypted_path)
|
2022-12-09 20:54:33 +01:00
|
|
|
|
|
|
|
def decryptAccumulatedFile(self):
|
|
|
|
input_file_path = self.getAccumulatedFilePath("encrypted")
|
|
|
|
output_file_path = self.getAccumulatedFilePath("decrypted")
|
2022-12-09 22:55:33 +01:00
|
|
|
self.decryptFile(self.user_password, input_file_path, output_file_path)
|
|
|
|
|
2022-12-10 00:00:42 +01:00
|
|
|
def initializeData(self):
|
2022-12-09 22:55:33 +01:00
|
|
|
self.decryptUserFile()
|
2022-12-10 00:00:42 +01:00
|
|
|
self.user_data = self.loadJsonFile(self.user_file_decrypted_path)
|
|
|
|
self.setNeededEncryptersAmount()
|