mirror of
https://github.com/kevinveenbirkenbach/splitted-secret.git
synced 2024-11-26 04:01:08 +01:00
Refactored code
This commit is contained in:
parent
10ad8c3574
commit
5478ef39bc
6
.gitignore
vendored
6
.gitignore
vendored
@ -1 +1,5 @@
|
|||||||
data/
|
data/decrypted/splitted_password_files/*
|
||||||
|
data/decrypted/password_files/*
|
||||||
|
data/encrypted/splitted_password_files/*
|
||||||
|
data/decrypted/password_files/*
|
||||||
|
__pycache__
|
@ -9,10 +9,10 @@ The purpose of this software is to splitt a secret over multiple people. Just if
|
|||||||
- Plattform independend
|
- Plattform independend
|
||||||
- easy to use
|
- easy to use
|
||||||
|
|
||||||
|
# setup
|
||||||
pip install numpy
|
```bash
|
||||||
|
pip install numpy
|
||||||
gpg -c
|
```
|
||||||
|
|
||||||
## Further Information
|
## Further Information
|
||||||
- https://www.tutorialspoint.com/python/python_command_line_arguments.htm
|
- https://www.tutorialspoint.com/python/python_command_line_arguments.htm
|
||||||
|
0
scripts/__init__.py
Normal file
0
scripts/__init__.py
Normal file
30
scripts/classes/Cli.py
Normal file
30
scripts/classes/Cli.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# This class offers easy logik to execute cli commands
|
||||||
|
# @author Kevin Veen-Birkenbach [kevin@veen.world]
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
class Cli:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.command = '';
|
||||||
|
self.output = [];
|
||||||
|
pass
|
||||||
|
|
||||||
|
def executeCommand(self,command):
|
||||||
|
self.command = command
|
||||||
|
process = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||||
|
out, err = process.communicate()
|
||||||
|
stdout = out.splitlines()
|
||||||
|
self.output = []
|
||||||
|
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")
|
||||||
|
return self.output
|
||||||
|
|
||||||
|
def getOutputString(self):
|
||||||
|
return str(' '.join(self.output))
|
||||||
|
|
||||||
|
def getCommandString(self):
|
||||||
|
return self.command
|
1
scripts/cleanup.py
Normal file
1
scripts/cleanup.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
rm -r ""
|
0
scripts/decrypt.py
Normal file
0
scripts/decrypt.py
Normal file
@ -4,28 +4,7 @@ import string
|
|||||||
import math
|
import math
|
||||||
import numpy
|
import numpy
|
||||||
import re
|
import re
|
||||||
import subprocess
|
from classes.Cli import Cli
|
||||||
|
|
||||||
def bash(command):
|
|
||||||
print(command)
|
|
||||||
process = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
|
||||||
out, err = process.communicate()
|
|
||||||
stdout = out.splitlines()
|
|
||||||
output = []
|
|
||||||
for line in stdout:
|
|
||||||
output.append(line.decode("utf-8"))
|
|
||||||
if process.wait() > bool(0):
|
|
||||||
print(command, out, err)
|
|
||||||
raise Exception("Exitcode is greater then 0")
|
|
||||||
return output
|
|
||||||
|
|
||||||
def list_to_string(list):
|
|
||||||
return str(' '.join(list))
|
|
||||||
|
|
||||||
def print_bash(command):
|
|
||||||
output = bash(command)
|
|
||||||
print(list_to_string(output))
|
|
||||||
return output
|
|
||||||
|
|
||||||
def getPassword():
|
def getPassword():
|
||||||
characters = string.ascii_letters + string.digits
|
characters = string.ascii_letters + string.digits
|
||||||
@ -56,23 +35,22 @@ def savePassword(password,password_file_path):
|
|||||||
master_password_file.close()
|
master_password_file.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
master_password_file_path="data/master-password.txt"
|
cli = Cli()
|
||||||
|
decrypted_master_password_file_path="data/decrypted/password_files/master-password.txt"
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-a', '--amount',type=int, dest='amount_of_secret_holders',required=True,choices=range(1,9))
|
parser.add_argument('-a', '--amount',type=int, dest='amount_of_secret_holders',required=True,choices=range(1,9))
|
||||||
parser.add_argument('-q', '--quota', type=int, dest='decryption_quota', choices=range(1,101),required=True)
|
parser.add_argument('-q', '--quota', type=int, dest='decryption_quota', choices=range(1,101),required=True)
|
||||||
parser.add_argument('-p', '--master-password', type=str, dest='master_password', required=False)
|
#parser.add_argument('-p', '--master-password', type=str, dest='master_password', required=False)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
amount_of_secret_holders = args.amount_of_secret_holders
|
amount_of_secret_holders = args.amount_of_secret_holders
|
||||||
master_password = args.master_password
|
#master_password = args.master_password
|
||||||
decryption_quota = args.decryption_quota
|
decryption_quota = args.decryption_quota
|
||||||
|
|
||||||
savePassword(master_password,master_password_file_path)
|
#savePassword(master_password,decrypted_master_password_file_path)
|
||||||
|
|
||||||
quota_factor=decryption_quota/100
|
quota_factor=decryption_quota/100
|
||||||
group_members_amount=math.ceil(amount_of_secret_holders * quota_factor)
|
group_members_amount=math.ceil(amount_of_secret_holders * quota_factor)
|
||||||
amount_of_partner_secrets=(amount_of_secret_holders * group_members_amount)
|
|
||||||
maximum_posible_combinations=amount_of_secret_holders*amount_of_secret_holders
|
|
||||||
width= range(1,(amount_of_secret_holders+1))
|
width= range(1,(amount_of_secret_holders+1))
|
||||||
regex="([" + ','.join([str(x) for x in width]) + "]{" + str(group_members_amount) + "})"
|
regex="([" + ','.join([str(x) for x in width]) + "]{" + str(group_members_amount) + "})"
|
||||||
valid_numbers = re.compile(regex)
|
valid_numbers = re.compile(regex)
|
||||||
@ -97,8 +75,10 @@ if __name__ == '__main__':
|
|||||||
password += password_part
|
password += password_part
|
||||||
password_index += 1
|
password_index += 1
|
||||||
password_groups[password_group_index_int]['password'] += password
|
password_groups[password_group_index_int]['password'] += password
|
||||||
splitted_password_file = "data/" + password_group_index_str + ".splitted_password_file.txt"
|
decrypted_splitted_password_file = "data/decrypted/splitted_password_files/" + password_group_index_str + ".txt"
|
||||||
print_bash('cp -v "' + master_password_file_path + '" "' + splitted_password_file + '" && gpg --batch --passphrase "' + password + '" -c "' + splitted_password_file +'"')
|
encrypted_splitted_password_file = "data/encrypted/splitted_password_files/" + password_group_index_str + ".txt.gpg"
|
||||||
|
cli.executeCommand('cp -v "' + decrypted_master_password_file_path + '" "' + decrypted_splitted_password_file + '" && gpg --batch --passphrase "' + password + '" -c "' + decrypted_splitted_password_file + '"')
|
||||||
|
print(cli.getCommandString())
|
||||||
index += 1
|
index += 1
|
||||||
print(password_groups)
|
print(password_groups)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user