Continued implementation of decryption

This commit is contained in:
2022-12-10 12:21:43 +01:00
parent e5806992ce
commit f182e3226a
6 changed files with 83 additions and 27 deletions

View File

@@ -1,11 +1,23 @@
from .Cli import Cli
class AbstractSplittedSecret(Cli):
USER_PASSWORD_LENGTHS = 64
OVERALL_PASSWORD_LENGTHS = 128
# At the moment the programm can used deal with one digit numbers.
MAXIMUM_SECRET_HOLDERS = 9
MINIMUM_SECRET_HOLDERS = 2
def __init__(self):
super(Cli, self).__init__()
self.data_folder = "data/"
def getCoSecretHoldersRange():
return range(AbstractSplittedSecret.MINIMUM_SECRET_HOLDERS,AbstractSplittedSecret.MAXIMUM_SECRET_HOLDERS)
def getSecretHoldersRange():
return range(1,AbstractSplittedSecret.MAXIMUM_SECRET_HOLDERS)
def getFolderPath(self,folder_type):
return self.data_folder + folder_type + "/"

View File

@@ -19,8 +19,7 @@ class Cli(object):
for line in stdout:
self.output.append(line.decode("utf-8"))
if process.wait() > bool(0):
print(command, out, err)
raise Exception("Exitcode is greater then 0")
raise Exception("Error for: \nCommand:<<" + command + ">>\nOutput:<<" + out + ">>\nExitcode:<<" + err + ">>")
return self.output
def getOutputString(self):

View File

@@ -7,12 +7,47 @@ class Decryption(AbstractSplittedSecret):
self.user_password=''
super(Decryption, self).__init__()
def setUserId(self,user_id):
def initializeUser(self,user_id):
self.user_id=str(user_id)
self.user_file_decrypted_path = self.getUserFilePath(self.user_id,"decrypted")
def initializeUserDataDecryption(self):
self.decryptUserFile()
self.user_data = self.loadJsonFile(self.user_file_decrypted_path)
self.initializeNeededDecryptersAmount()
self.initializeValidDecrypterIds()
def initializeNeededDecryptersAmount(self):
self.needed_decrypters_amount = len(str(list(self.user_data['groups'].keys())[0]))
def initializeValidDecrypterIds(self):
self.valid_decrypter_ids = []
self.valid_decrypter_ids.append(int(self.user_id))
for contact_id in self.user_data['contacts']:
self.valid_decrypter_ids.append(int(contact_id))
def setUserPassword(self,user_password):
self.user_password = str(user_password)
def resetDecrypterIds(self):
self.decrypter_ids = []
self.addDecrypterId(self.user_id)
def addDecrypterId(self,decrypter_id):
decrypter_id = int(decrypter_id)
if decrypter_id not in self.valid_decrypter_ids:
raise Exception("The encrypter id is not valid. Valid encrypter ids are: " + str(self.valid_decrypter_ids))
if len(self.decrypter_ids) >= self.needed_decrypters_amount:
raise Exception("There are already sufficients decrypters (" + str(len(self.decrypter_ids)) + ") defined!")
if decrypter_id in self.decrypter_ids:
raise Exception("The decrypter is already in the list.")
self.decrypter_ids.append(decrypter_id)
def getDecryptersIds(self):
return self.decrypter_ids
def getNeededCoDecryptersAmount(self):
return self.needed_decrypters_amount -1
def loadJsonFile(self,file_path):
file = open(file_path)
@@ -20,9 +55,6 @@ class Decryption(AbstractSplittedSecret):
file.close()
return data
def setNeededEncryptersAmount(self):
self.needed_encrypters_amount = len(str(list(self.user_data['groups'].keys())[0]))-1
def decryptFile(self,password,input_file_path,output_file_path):
self.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"')
@@ -33,9 +65,4 @@ class Decryption(AbstractSplittedSecret):
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)
def initializeData(self):
self.decryptUserFile()
self.user_data = self.loadJsonFile(self.user_file_decrypted_path)
self.setNeededEncryptersAmount()
self.decryptFile(self.user_password, input_file_path, output_file_path)

View File

@@ -22,7 +22,7 @@ class Encryption(AbstractSplittedSecret):
self.user_mapped_data = {}
user_count = 1
while user_count <= self.amount_of_secret_holders:
self.user_mapped_data[str(user_count)] = {"groups":{},"user_password":self.createPassword(64),"about":{}}
self.user_mapped_data[str(user_count)] = {"groups":{},"user_password":self.createPassword(self.USER_PASSWORD_LENGTHS),"about":{}}
user_count += 1;
def initializeGroupData(self):
@@ -81,7 +81,7 @@ class Encryption(AbstractSplittedSecret):
password = ''
for secret_holder_index in password_group_index_str:
self.group_mapped_data[password_group_index_int]['members'][secret_holder_index]={}
particial_password_length= int(128*self.quota_factor);
particial_password_length= int(self.OVERALL_PASSWORD_LENGTHS*self.quota_factor);
password_part = self.createPassword(particial_password_length)
self.group_mapped_data[password_group_index_int]['members'][secret_holder_index] = password_part
password += password_part