mirror of
https://github.com/kevinveenbirkenbach/splitted-secret.git
synced 2024-11-01 00:53:11 +01:00
implemented json file safe and dynamic master password
This commit is contained in:
parent
ee4177a01a
commit
f5e290df65
@ -4,3 +4,4 @@ class AbstractSplittedSecret(Cli):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Cli, self).__init__()
|
super(Cli, self).__init__()
|
||||||
self.encrypted_splitted_password_files_folder = "data/encrypted/splitted_password_files/"
|
self.encrypted_splitted_password_files_folder = "data/encrypted/splitted_password_files/"
|
||||||
|
self.decrypted_password_files_folder="data/decrypted/password_files/"
|
@ -3,6 +3,9 @@ class Cleanup(AbstractSplittedSecret):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Cleanup, self).__init__()
|
super(Cleanup, self).__init__()
|
||||||
def deleteAllEncryptedFiles(self):
|
def deleteAllEncryptedFiles(self):
|
||||||
|
self.executeCommand('rm -v ' + self.decrypted_password_files_folder + '*')
|
||||||
|
print(self.getCommandString())
|
||||||
|
print(self.getOutputString())
|
||||||
self.executeCommand('rm -v ' + self.encrypted_splitted_password_files_folder + '*')
|
self.executeCommand('rm -v ' + self.encrypted_splitted_password_files_folder + '*')
|
||||||
print(self.getCommandString())
|
print(self.getCommandString())
|
||||||
print(self.getOutputString())
|
print(self.getOutputString())
|
||||||
|
@ -3,15 +3,16 @@ import string
|
|||||||
import math
|
import math
|
||||||
import numpy
|
import numpy
|
||||||
import re
|
import re
|
||||||
|
import json
|
||||||
from .AbstractSplittedSecret import AbstractSplittedSecret
|
from .AbstractSplittedSecret import AbstractSplittedSecret
|
||||||
|
|
||||||
class Generate(AbstractSplittedSecret):
|
class Generate(AbstractSplittedSecret):
|
||||||
|
|
||||||
def __init__(self, amount_of_secret_holders, decryption_quota):
|
def __init__(self, amount_of_secret_holders, decryption_quota,master_password):
|
||||||
super(Generate, self).__init__()
|
super(Generate, self).__init__()
|
||||||
self.amount_of_secret_holders = amount_of_secret_holders
|
self.amount_of_secret_holders = amount_of_secret_holders
|
||||||
self.decryption_quota = decryption_quota
|
self.decryption_quota = decryption_quota
|
||||||
self.decrypted_master_password_file_path="data/decrypted/password_files/master-password.txt"
|
self.master_password = master_password
|
||||||
self.quota_factor=self.decryption_quota/100
|
self.quota_factor=self.decryption_quota/100
|
||||||
self.group_members_amount=math.ceil(self.amount_of_secret_holders * self.quota_factor)
|
self.group_members_amount=math.ceil(self.amount_of_secret_holders * self.quota_factor)
|
||||||
|
|
||||||
@ -81,15 +82,33 @@ class Generate(AbstractSplittedSecret):
|
|||||||
self.group_mapped_data[password_group_index_int]['password'] += password
|
self.group_mapped_data[password_group_index_int]['password'] += password
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
def generateGroupFiles(self):
|
def generateEncryptedGroupFiles(self):
|
||||||
for password_group_index_int in self.group_mapped_data:
|
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"
|
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 + '"')
|
self.executeCommand('echo "' + self.master_password + '" | gpg --symmetric --armor --batch --passphrase "' + self.group_mapped_data[password_group_index_int]['password'] + '" -o "' + encrypted_splitted_password_file + '"')
|
||||||
print(self.getCommandString())
|
print(self.getCommandString())
|
||||||
|
|
||||||
def execute(self):
|
def saveJsonFile(self,file_path,data):
|
||||||
|
with open(file_path, 'w', encoding='utf-8') as file:
|
||||||
|
json.dump(data, file, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
def saveUserMappedData(self):
|
||||||
|
for user_id in self.user_mapped_data:
|
||||||
|
file_path=self.decrypted_password_files_folder+user_id+'.json'
|
||||||
|
self.saveJsonFile(file_path, self.user_mapped_data[user_id])
|
||||||
|
|
||||||
|
def saveGroupMappedData(self):
|
||||||
|
file_path=self.decrypted_password_files_folder+'group_mapped.json'
|
||||||
|
self.saveJsonFile(file_path, self.group_mapped_data)
|
||||||
|
|
||||||
|
def saveMappedData(self):
|
||||||
|
self.saveUserMappedData()
|
||||||
|
self.saveGroupMappedData();
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
self.generateMappedData()
|
self.generateMappedData()
|
||||||
self.generateGroupFiles()
|
self.saveMappedData()
|
||||||
|
self.generateEncryptedGroupFiles()
|
||||||
|
|
||||||
def getUserMappedData(self):
|
def getUserMappedData(self):
|
||||||
return self.user_mapped_data
|
return self.user_mapped_data
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from classes.Generate import Generate
|
from classes.Generate import Generate
|
||||||
from classes.Cleanup import Cleanup
|
from classes.Cleanup import Cleanup
|
||||||
|
from getpass import getpass
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--mode',type=str, dest='mode',required=True,choices=['cleanup','generate'])
|
parser.add_argument('--mode',type=str, dest='mode',required=True,choices=['cleanup','generate'])
|
||||||
parser.add_argument('--amount',type=int, dest='amount_of_secret_holders',required=False,choices=range(1,9))
|
parser.add_argument('--amount',type=int, dest='amount_of_secret_holders',required=False,choices=range(1,9))
|
||||||
parser.add_argument('--quota', type=int, dest='decryption_quota', choices=range(1,101),required=False)
|
parser.add_argument('--quota', type=int, dest='decryption_quota', choices=range(1,101),required=False)
|
||||||
|
parser.add_argument('--master-password',type=str, dest='master_password',required=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.mode == 'cleanup':
|
if args.mode == 'cleanup':
|
||||||
@ -15,6 +17,11 @@ if __name__ == '__main__':
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
if args.mode == 'generate':
|
if args.mode == 'generate':
|
||||||
generate = Generate(args.amount_of_secret_holders, args.decryption_quota)
|
if args.master_password is None:
|
||||||
generate.execute()
|
print("Please enter the master password:")
|
||||||
|
master_password = getpass()
|
||||||
|
else:
|
||||||
|
master_password = args.master_password
|
||||||
|
generate = Generate(args.amount_of_secret_holders, args.decryption_quota,master_password)
|
||||||
|
generate.generate()
|
||||||
exit()
|
exit()
|
Loading…
Reference in New Issue
Block a user