Refactored

This commit is contained in:
Kevin Veen-Birkenbach 2022-12-09 14:05:54 +01:00
parent fa82f4d5da
commit ee4177a01a

View File

@ -39,7 +39,7 @@ class Generate(AbstractSplittedSecret):
master_password_file.write(password) master_password_file.write(password)
master_password_file.close() master_password_file.close()
def getPassword(self): def createPassword(self):
characters = string.ascii_letters + string.digits characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for i in range(int(64*self.quota_factor))).upper() return ''.join(random.choice(characters) for i in range(int(64*self.quota_factor))).upper()
@ -49,28 +49,50 @@ class Generate(AbstractSplittedSecret):
unvalid_sequenz = re.compile("(.)\\1+") unvalid_sequenz = re.compile("(.)\\1+")
return re.search(valid_numbers, password_group_index_str) and not re.search(unvalid_sequenz, password_group_index_str) return re.search(valid_numbers, password_group_index_str) and not re.search(unvalid_sequenz, password_group_index_str)
def execute(self): def createUserMappedDataFrame(self):
self.user_mapped_data = {}
user_count = 1
while user_count <= self.amount_of_secret_holders:
self.user_mapped_data[str(user_count)] = {}
user_count += 1;
def createGroupMappedDataFrame(self):
self.group_mapped_data = {}
def generateMappedData(self):
self.createUserMappedDataFrame()
self.createGroupMappedDataFrame()
index = self.getStartnumber() index = self.getStartnumber()
password_groups = {}
while index < self.getEndnumber(): while index < self.getEndnumber():
password_group_index_str = ''.join(sorted(str(index))) password_group_index_str = ''.join(sorted(str(index)))
if self.isGroupValid(password_group_index_str): if self.isGroupValid(password_group_index_str):
password_group_index_int = int(password_group_index_str) password_group_index_int = int(password_group_index_str)
if not password_group_index_int in password_groups: if not password_group_index_int in self.group_mapped_data:
password_index = 1 self.group_mapped_data[password_group_index_int] = {}
password_groups[password_group_index_int] = {} self.group_mapped_data[password_group_index_int]['members'] = {}
password_groups[password_group_index_int]['members'] = {} self.group_mapped_data[password_group_index_int]['password'] = ''
password_groups[password_group_index_int]['password'] = ''
password = '' password = ''
for secret_holder_index in password_group_index_str: for secret_holder_index in password_group_index_str:
password_groups[password_group_index_int]['members'][secret_holder_index]={} self.group_mapped_data[password_group_index_int]['members'][secret_holder_index]={}
password_part = self.getPassword() password_part = self.createPassword()
password_groups[password_group_index_int]['members'][secret_holder_index]['password_part'] = password_part self.group_mapped_data[password_group_index_int]['members'][secret_holder_index] = password_part
password_groups[password_group_index_int]['members'][secret_holder_index]['password_index'] = password_index
password += password_part password += password_part
password_index += 1 self.user_mapped_data[secret_holder_index][password_group_index_str] = password_part
password_groups[password_group_index_int]['password'] += password self.group_mapped_data[password_group_index_int]['password'] += password
encrypted_splitted_password_file = AbstractSplittedSecret().encrypted_splitted_password_files_folder + password_group_index_str + ".txt.gpg"
self.executeCommand('gpg --batch --passphrase "' + password + '" -o "' + encrypted_splitted_password_file + '" -c "' + self.decrypted_master_password_file_path + '"')
print(self.getCommandString())
index += 1 index += 1
def generateGroupFiles(self):
for password_group_index_int in self.group_mapped_data:
encrypted_splitted_password_file = AbstractSplittedSecret().encrypted_splitted_password_files_folder + str(password_group_index_int) + ".txt.gpg"
self.executeCommand('gpg --batch --passphrase "' + self.group_mapped_data[password_group_index_int]['password'] + '" -o "' + encrypted_splitted_password_file + '" -c "' + self.decrypted_master_password_file_path + '"')
print(self.getCommandString())
def execute(self):
self.generateMappedData()
self.generateGroupFiles()
def getUserMappedData(self):
return self.user_mapped_data
def getGroupMappedData(self):
return self.group_mapped_data