mirror of
https://github.com/kevinveenbirkenbach/splitted-secret.git
synced 2024-11-22 02:01:05 +01:00
Implemented further decription steps
This commit is contained in:
parent
47af457162
commit
b54723448d
@ -22,8 +22,9 @@ python scripts/main.py --mode decrypt --master-password "ewrwerwerew" &&
|
|||||||
python scripts/main.py --mode decrypt --user "1"
|
python scripts/main.py --mode decrypt --user "1"
|
||||||
|
|
||||||
|
|
||||||
python scripts/main.py --mode cleanup --user "1" && python scripts/main.py --mode decrypt --user "1" --user-password "O3ITMWXZED9FKYQ0PB2WNVRWSCSCYVXCD00PJ6GQ4MFPIUWBVDCYSSSX9ZDBW5QU"
|
python scripts/main.py --mode cleanup --user "1" && python scripts/main.py --mode decrypt --user "1" --user-password "O3ITMWXZED9FKYQ0PB2WNVRWSCSCYVXCD00PJ6GQ4MFPIUWBVDCYSSSX9ZDBW5QU" << END_OF_INPUTS
|
||||||
|
2
|
||||||
|
END_OF_INPUTS
|
||||||
```
|
```
|
||||||
# Requirements to know
|
# Requirements to know
|
||||||
- Amount of People
|
- Amount of People
|
||||||
@ -42,8 +43,9 @@ python scripts/main.py --mode cleanup --user "1" && python scripts/main.py --mo
|
|||||||
```
|
```
|
||||||
|
|
||||||
## todo
|
## todo
|
||||||
- Implement cleanup
|
- implement tails setup script
|
||||||
- implement relativ call
|
- implement relativ call
|
||||||
|
- implement tmp mount for decrypted files
|
||||||
|
|
||||||
## Further Information
|
## Further Information
|
||||||
- https://www.tutorialspoint.com/python/python_command_line_arguments.htm
|
- https://www.tutorialspoint.com/python/python_command_line_arguments.htm
|
||||||
|
@ -32,6 +32,19 @@ class Decryption(AbstractSplittedSecret):
|
|||||||
def resetDecrypterIds(self):
|
def resetDecrypterIds(self):
|
||||||
self.decrypter_ids = []
|
self.decrypter_ids = []
|
||||||
self.addDecrypterId(self.user_id)
|
self.addDecrypterId(self.user_id)
|
||||||
|
|
||||||
|
def resetPasswordShare(self):
|
||||||
|
self.password_parts = {}
|
||||||
|
self.addPasswordShare(self.user_id,self.getPasswordShare())
|
||||||
|
|
||||||
|
def addPasswordShare(self,user_id,password_share):
|
||||||
|
self.password_parts[str(user_id)] = password_share
|
||||||
|
|
||||||
|
def getSharedPassword(self):
|
||||||
|
shared_password = ''
|
||||||
|
for password_share_index in sorted(self.password_parts):
|
||||||
|
shared_password += str(self.password_parts[password_share_index])
|
||||||
|
return shared_password
|
||||||
|
|
||||||
def addDecrypterId(self,decrypter_id):
|
def addDecrypterId(self,decrypter_id):
|
||||||
decrypter_id = int(decrypter_id)
|
decrypter_id = int(decrypter_id)
|
||||||
@ -42,9 +55,24 @@ class Decryption(AbstractSplittedSecret):
|
|||||||
if decrypter_id in self.decrypter_ids:
|
if decrypter_id in self.decrypter_ids:
|
||||||
raise Exception("The decrypter is already in the list.")
|
raise Exception("The decrypter is already in the list.")
|
||||||
self.decrypter_ids.append(decrypter_id)
|
self.decrypter_ids.append(decrypter_id)
|
||||||
|
|
||||||
def getDecryptersIds(self):
|
def getUserId(self):
|
||||||
|
return self.user_id
|
||||||
|
|
||||||
|
def getCoDecrypterIds(self):
|
||||||
|
co_decrypter_ids = self.decrypter_ids[:]
|
||||||
|
co_decrypter_ids.remove(int(self.user_id))
|
||||||
|
return co_decrypter_ids
|
||||||
|
|
||||||
|
def getDecrypterIds(self):
|
||||||
return self.decrypter_ids
|
return self.decrypter_ids
|
||||||
|
|
||||||
|
def getDecryptersGroupName(self):
|
||||||
|
self.decrypter_ids.sort()
|
||||||
|
return ''.join(str(x) for x in self.decrypter_ids)
|
||||||
|
|
||||||
|
def getPasswordShare(self):
|
||||||
|
return self.user_data['groups'][str(self.getDecryptersGroupName())]
|
||||||
|
|
||||||
def getNeededCoDecryptersAmount(self):
|
def getNeededCoDecryptersAmount(self):
|
||||||
return self.needed_decrypters_amount -1
|
return self.needed_decrypters_amount -1
|
||||||
|
@ -51,11 +51,11 @@ class Encryption(AbstractSplittedSecret):
|
|||||||
characters = string.ascii_letters + string.digits
|
characters = string.ascii_letters + string.digits
|
||||||
return (''.join(random.choice(characters) for i in range(length)).upper())
|
return (''.join(random.choice(characters) for i in range(length)).upper())
|
||||||
|
|
||||||
def isGroupValid(self,password_group_index_str):
|
def isGroupValid(self,password_group_name):
|
||||||
secret_stakeholders_range=range(1,(self.amount_of_secret_holders+1))
|
secret_stakeholders_range=range(1,(self.amount_of_secret_holders+1))
|
||||||
valid_numbers = re.compile("([" + ','.join([str(x) for x in secret_stakeholders_range]) + "]{" + str(self.group_members_amount) + "})")
|
valid_numbers = re.compile("([" + ','.join([str(x) for x in secret_stakeholders_range]) + "]{" + str(self.group_members_amount) + "})")
|
||||||
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_name) and not re.search(unvalid_sequenz, password_group_name)
|
||||||
|
|
||||||
def compileContacts(self):
|
def compileContacts(self):
|
||||||
contacts = {}
|
contacts = {}
|
||||||
@ -71,21 +71,21 @@ class Encryption(AbstractSplittedSecret):
|
|||||||
self.compileContacts()
|
self.compileContacts()
|
||||||
index = self.getStartnumber()
|
index = self.getStartnumber()
|
||||||
while index < self.getEndnumber():
|
while index < self.getEndnumber():
|
||||||
password_group_index_str = ''.join(sorted(str(index)))
|
password_group_name = ''.join(sorted(str(index)))
|
||||||
if self.isGroupValid(password_group_index_str):
|
if self.isGroupValid(password_group_name):
|
||||||
password_group_index_int = int(password_group_index_str)
|
password_group_index_int = int(password_group_name)
|
||||||
if not password_group_index_int in self.group_mapped_data:
|
if not password_group_index_int in self.group_mapped_data:
|
||||||
self.group_mapped_data[password_group_index_int] = {}
|
self.group_mapped_data[password_group_index_int] = {}
|
||||||
self.group_mapped_data[password_group_index_int]['members'] = {}
|
self.group_mapped_data[password_group_index_int]['members'] = {}
|
||||||
self.group_mapped_data[password_group_index_int]['password'] = ''
|
self.group_mapped_data[password_group_index_int]['password'] = ''
|
||||||
password = ''
|
password = ''
|
||||||
for secret_holder_index in password_group_index_str:
|
for secret_holder_index in password_group_name:
|
||||||
self.group_mapped_data[password_group_index_int]['members'][secret_holder_index]={}
|
self.group_mapped_data[password_group_index_int]['members'][secret_holder_index]={}
|
||||||
particial_password_length= int(self.OVERALL_PASSWORD_LENGTHS*self.quota_factor);
|
particial_password_length= int(self.OVERALL_PASSWORD_LENGTHS*self.quota_factor);
|
||||||
password_part = self.createPassword(particial_password_length)
|
password_part = self.createPassword(particial_password_length)
|
||||||
self.group_mapped_data[password_group_index_int]['members'][secret_holder_index] = password_part
|
self.group_mapped_data[password_group_index_int]['members'][secret_holder_index] = password_part
|
||||||
password += password_part
|
password += password_part
|
||||||
self.user_mapped_data[secret_holder_index]['groups'][password_group_index_str] = password_part
|
self.user_mapped_data[secret_holder_index]['groups'][password_group_name] = password_part
|
||||||
self.group_mapped_data[password_group_index_int]['password'] += password
|
self.group_mapped_data[password_group_index_int]['password'] += password
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
|
185
scripts/main.py
185
scripts/main.py
@ -4,6 +4,7 @@ from classes.Cleanup import Cleanup
|
|||||||
from classes.Decryption import Decryption
|
from classes.Decryption import Decryption
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from classes.AbstractSplittedSecret import AbstractSplittedSecret
|
from classes.AbstractSplittedSecret import AbstractSplittedSecret
|
||||||
|
import traceback
|
||||||
|
|
||||||
cleanup = Cleanup()
|
cleanup = Cleanup()
|
||||||
|
|
||||||
@ -13,96 +14,112 @@ def clean_exit():
|
|||||||
print("Leaving program. Goodby :)")
|
print("Leaving program. Goodby :)")
|
||||||
exit();
|
exit();
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--mode',type=str, dest='mode',required=True,choices=['cleanup','encrypt','decrypt'])
|
||||||
|
parser.add_argument('--amount',type=int, dest='amount_of_secret_holders',required=False,choices=AbstractSplittedSecret.getCoSecretHoldersRange())
|
||||||
|
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)
|
||||||
|
parser.add_argument('--user-password',type=str, dest='user_password',required=False)
|
||||||
|
parser.add_argument('--user',type=int, dest='user',choices=AbstractSplittedSecret.getSecretHoldersRange(),required=False)
|
||||||
|
parser.add_argument('--add-user-information',type=bool, dest='add_user_information', default=False, required=False, action=argparse.BooleanOptionalAction)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
print("Splitted Secret Interface started.")
|
||||||
parser = argparse.ArgumentParser()
|
print("Selected Mode: " + args.mode)
|
||||||
parser.add_argument('--mode',type=str, dest='mode',required=True,choices=['cleanup','encrypt','decrypt'])
|
|
||||||
parser.add_argument('--amount',type=int, dest='amount_of_secret_holders',required=False,choices=AbstractSplittedSecret.getCoSecretHoldersRange())
|
|
||||||
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)
|
|
||||||
parser.add_argument('--user-password',type=str, dest='user_password',required=False)
|
|
||||||
parser.add_argument('--user',type=int, dest='user',choices=AbstractSplittedSecret.getSecretHoldersRange(),required=False)
|
|
||||||
parser.add_argument('--add-user-information',type=bool, dest='add_user_information', default=False, required=False, action=argparse.BooleanOptionalAction)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
print("Splitted Secret Interface started.")
|
|
||||||
print("Selected Mode: " + args.mode)
|
|
||||||
|
|
||||||
if args.mode == 'cleanup':
|
|
||||||
if args.user is None:
|
|
||||||
print("Delete all files.")
|
|
||||||
cleanup.deleteAll()
|
|
||||||
clean_exit()
|
|
||||||
print("Delete files for user <<" + str(args.user) + ">>");
|
|
||||||
cleanup.cleanupForUser(args.user)
|
|
||||||
clean_exit()
|
|
||||||
|
|
||||||
if args.mode == 'decrypt':
|
if args.mode == 'cleanup':
|
||||||
decrypt = Decryption()
|
|
||||||
if args.master_password is None:
|
|
||||||
if args.user is None:
|
if args.user is None:
|
||||||
print("Please type in the user number:")
|
print("Delete all files.")
|
||||||
decrypt.initializeUser(input())
|
cleanup.deleteAll()
|
||||||
else:
|
clean_exit()
|
||||||
decrypt.initializeUser(args.user)
|
print("Delete files for user <<" + str(args.user) + ">>");
|
||||||
if args.user_password is None:
|
cleanup.cleanupForUser(args.user)
|
||||||
while True:
|
clean_exit()
|
||||||
print("Please enter the user password:")
|
|
||||||
decrypt.setUserPassword(getpass())
|
if args.mode == 'decrypt':
|
||||||
|
decrypt = Decryption()
|
||||||
|
if args.master_password is None:
|
||||||
|
if args.user is None:
|
||||||
|
print("Please type in the user number:")
|
||||||
|
decrypt.initializeUser(input())
|
||||||
|
else:
|
||||||
|
decrypt.initializeUser(args.user)
|
||||||
|
if args.user_password is None:
|
||||||
|
while True:
|
||||||
|
print("Please enter the user password:")
|
||||||
|
decrypt.setUserPassword(getpass())
|
||||||
|
print("Decrypting User File...")
|
||||||
|
try:
|
||||||
|
decrypt.initializeUserDataDecryption();
|
||||||
|
break;
|
||||||
|
except Exception as error:
|
||||||
|
print("An error occured. Propably you typed in a wrong password :( The error is: " + str(error))
|
||||||
|
else:
|
||||||
|
decrypt.setUserPassword(args.user_password)
|
||||||
print("Decrypting User File...")
|
print("Decrypting User File...")
|
||||||
try:
|
try:
|
||||||
decrypt.initializeUserDataDecryption();
|
decrypt.initializeUserDataDecryption();
|
||||||
break;
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print("An error occured. Propably you typed in a wrong password :( The error is: " + str(error))
|
print("An error occured. Propably you passed a wrong password :( The error is: " + str(error))
|
||||||
|
clean_exit()
|
||||||
|
print("File decrypted :) \n")
|
||||||
|
print("Please contact the following persons and tell them that you need help to encrypt the data: \n")
|
||||||
|
for contact_id in decrypt.user_data['contacts']:
|
||||||
|
print("user_id: " + contact_id)
|
||||||
|
for label in decrypt.user_data['contacts'][contact_id]:
|
||||||
|
print(label + ": " + decrypt.user_data['contacts'][contact_id][label])
|
||||||
|
print("--------------------------------\n")
|
||||||
|
while True:
|
||||||
|
decrypt.resetDecrypterIds()
|
||||||
|
try:
|
||||||
|
person_counter = 1
|
||||||
|
while person_counter <= decrypt.getNeededCoDecryptersAmount():
|
||||||
|
print("The following user id's are in the decryption list: " + str(decrypt.getDecrypterIds()))
|
||||||
|
print("You need at least <<" + str(decrypt.getNeededCoDecryptersAmount()) +">> other person to decrypt the secret.")
|
||||||
|
print("Type in the user id of another encrypter:")
|
||||||
|
decrypt.addDecrypterId(int(input()))
|
||||||
|
person_counter += 1
|
||||||
|
break
|
||||||
|
except Exception as error:
|
||||||
|
print("The following error occured <<" + str(error) + ">> :( \n Please try again :)")
|
||||||
|
print("\nFOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName())
|
||||||
|
print("FOR USER ID: " + decrypt.getUserId())
|
||||||
|
print("PASSWORD SHARE IS: " + decrypt.getPasswordShare() + "\n")
|
||||||
|
while True:
|
||||||
|
decrypt.resetPasswordShare()
|
||||||
|
co_decrypter_ids = decrypt.getCoDecrypterIds()
|
||||||
|
print("Please execute this script at the users " + str(co_decrypter_ids) + ".")
|
||||||
|
for co_decrypter_id in decrypt.getCoDecrypterIds():
|
||||||
|
print("\nFOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName())
|
||||||
|
print("FOR USER: " + str(co_decrypter_id))
|
||||||
|
print("PASSWORD SHARE IS: ")
|
||||||
|
decrypt.addPasswordShare(co_decrypter_id, input())
|
||||||
|
print("\nTHE SHARED PASSWORD IS: " + decrypt.getSharedPassword())
|
||||||
|
break;
|
||||||
|
|
||||||
|
clean_exit()
|
||||||
|
print("Decrypting accumulated file...")
|
||||||
|
decrypt.setUserPassword(args.master_password)
|
||||||
|
decrypt.decryptAccumulatedFile()
|
||||||
|
clean_exit()
|
||||||
|
|
||||||
|
if args.mode == 'encrypt':
|
||||||
|
if args.master_password is None:
|
||||||
|
print("Please enter the master password:")
|
||||||
|
master_password = getpass()
|
||||||
else:
|
else:
|
||||||
decrypt.setUserPassword(args.user_password)
|
master_password = args.master_password
|
||||||
print("Decrypting User File...")
|
encrypt = Encryption(args.amount_of_secret_holders, args.decryption_quota, master_password)
|
||||||
try:
|
if args.add_user_information is not None:
|
||||||
decrypt.initializeUserDataDecryption();
|
for user_id in encrypt.user_mapped_data:
|
||||||
except Exception as error:
|
for label in ['name','phone','email','address']:
|
||||||
print("An error occured. Propably you passed a wrong password :( The error is: " + str(error))
|
print("Please enter attribut <<" + label + ">> for user <<" + user_id+ ">>:" )
|
||||||
clean_exit()
|
encrypt.addInformationToUser(user_id, label, str(input()))
|
||||||
print("File decrypted :) \n")
|
encrypt.compileData()
|
||||||
print("Please contact the following persons and tell them that you need help to encrypt the data: \n")
|
encrypt.encrypt()
|
||||||
for contact_id in decrypt.user_data['contacts']:
|
clean_exit()
|
||||||
print("user_id: " + contact_id)
|
except Exception:
|
||||||
for label in decrypt.user_data['contacts'][contact_id]:
|
print(traceback.format_exc())
|
||||||
print(label + ": " + decrypt.user_data['contacts'][contact_id][label])
|
|
||||||
print("--------------------------------\n")
|
|
||||||
while True:
|
|
||||||
decrypt.resetDecrypterIds()
|
|
||||||
try:
|
|
||||||
person_counter = 1
|
|
||||||
while person_counter <= decrypt.getNeededCoDecryptersAmount():
|
|
||||||
print("The following user id's are in the decryption list: " + str(decrypt.getDecryptersIds()))
|
|
||||||
print("You need at least <<" + str(decrypt.getNeededCoDecryptersAmount()) +">> other person to decrypt the secret.")
|
|
||||||
print("Type in the user id of another encrypter:")
|
|
||||||
decrypt.addDecrypterId(int(input()))
|
|
||||||
person_counter += 1
|
|
||||||
break
|
|
||||||
except Exception as error:
|
|
||||||
print("The following error occured <<" + str(error) + ">> :( \n Please try again :)")
|
|
||||||
|
|
||||||
clean_exit()
|
|
||||||
print("Decrypting accumulated file...")
|
|
||||||
decrypt.setUserPassword(args.master_password)
|
|
||||||
decrypt.decryptAccumulatedFile()
|
|
||||||
clean_exit()
|
|
||||||
|
|
||||||
if args.mode == 'encrypt':
|
|
||||||
if args.master_password is None:
|
|
||||||
print("Please enter the master password:")
|
|
||||||
master_password = getpass()
|
|
||||||
else:
|
|
||||||
master_password = args.master_password
|
|
||||||
encrypt = Encryption(args.amount_of_secret_holders, args.decryption_quota, master_password)
|
|
||||||
if args.add_user_information is not None:
|
|
||||||
for user_id in encrypt.user_mapped_data:
|
|
||||||
for label in ['name','phone','email','address']:
|
|
||||||
print("Please enter attribut <<" + label + ">> for user <<" + user_id+ ">>:" )
|
|
||||||
encrypt.addInformationToUser(user_id, label, str(input()))
|
|
||||||
encrypt.compileData()
|
|
||||||
encrypt.encrypt()
|
|
||||||
clean_exit()
|
|
||||||
clean_exit()
|
clean_exit()
|
Loading…
Reference in New Issue
Block a user