2022-12-09 12:03:45 +01:00
|
|
|
import argparse
|
2022-12-09 20:13:48 +01:00
|
|
|
from classes.Encryption import Encryption
|
2022-12-09 13:08:07 +01:00
|
|
|
from classes.Cleanup import Cleanup
|
2022-12-09 20:13:48 +01:00
|
|
|
from classes.Decryption import Decryption
|
2022-12-09 14:52:57 +01:00
|
|
|
from getpass import getpass
|
2022-12-09 12:03:45 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
2022-12-09 21:49:06 +01:00
|
|
|
parser.add_argument('--mode',type=str, dest='mode',required=True,choices=['cleanup','encrypt','decrypt'])
|
2022-12-09 13:22:57 +01:00
|
|
|
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)
|
2022-12-09 14:52:57 +01:00
|
|
|
parser.add_argument('--master-password',type=str, dest='master_password',required=False)
|
2022-12-09 23:43:28 +01:00
|
|
|
parser.add_argument('--user-password',type=str, dest='user_password',required=False)
|
2022-12-09 18:16:31 +01:00
|
|
|
parser.add_argument('--user',type=int, dest='user',choices=range(1,9),required=False)
|
2022-12-09 22:37:29 +01:00
|
|
|
parser.add_argument('--add-user-information',type=bool, dest='add_user_information', default=False, required=False, action=argparse.BooleanOptionalAction)
|
2022-12-09 12:03:45 +01:00
|
|
|
args = parser.parse_args()
|
2022-12-09 21:49:06 +01:00
|
|
|
mode = args.mode
|
2022-12-09 12:03:45 +01:00
|
|
|
|
2022-12-09 21:49:06 +01:00
|
|
|
print("Splitted Secret Interface started.")
|
|
|
|
print("Selected Mode: " + mode)
|
|
|
|
|
|
|
|
if mode == 'cleanup':
|
2022-12-09 13:08:07 +01:00
|
|
|
cleanup = Cleanup()
|
2022-12-09 18:16:31 +01:00
|
|
|
if args.user is None:
|
2022-12-09 23:43:28 +01:00
|
|
|
print("Delete all files.")
|
2022-12-09 18:16:31 +01:00
|
|
|
cleanup.deleteAll()
|
|
|
|
exit()
|
2022-12-09 23:43:28 +01:00
|
|
|
print("Delete files for user <<" + str(args.user) + ">>");
|
2022-12-09 18:16:31 +01:00
|
|
|
cleanup.cleanupForUser(args.user)
|
2022-12-09 20:10:12 +01:00
|
|
|
exit()
|
2022-12-09 13:08:07 +01:00
|
|
|
|
2022-12-09 21:49:06 +01:00
|
|
|
if mode == 'decrypt':
|
2022-12-09 20:13:48 +01:00
|
|
|
decrypt = Decryption()
|
2022-12-09 20:54:33 +01:00
|
|
|
if args.master_password is None:
|
|
|
|
if args.user is None:
|
|
|
|
print("Please type in the user number:")
|
|
|
|
decrypt.setUserId(input())
|
|
|
|
else:
|
2022-12-09 21:49:06 +01:00
|
|
|
decrypt.setUserId(args.user)
|
2022-12-09 23:43:28 +01:00
|
|
|
if args.user_password is None:
|
|
|
|
while True:
|
|
|
|
print("Please enter the user password:")
|
|
|
|
decrypt.setUserPassword(getpass())
|
|
|
|
print("Decrypting User File...")
|
|
|
|
try:
|
2022-12-10 00:00:42 +01:00
|
|
|
decrypt.initializeData();
|
2022-12-09 23:43:28 +01:00
|
|
|
break;
|
|
|
|
except:
|
|
|
|
print("Wrong password :(")
|
|
|
|
else:
|
|
|
|
decrypt.setUserPassword(args.user_password)
|
2022-12-09 21:49:06 +01:00
|
|
|
print("Decrypting User File...")
|
|
|
|
try:
|
2022-12-10 00:00:42 +01:00
|
|
|
decrypt.initializeData();
|
2022-12-09 21:49:06 +01:00
|
|
|
except:
|
|
|
|
print("Wrong password :(")
|
2022-12-09 23:43:28 +01:00
|
|
|
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])
|
2022-12-10 00:00:42 +01:00
|
|
|
print("You need at least <<" + str(decrypt.needed_encrypters_amount) +">> other person to decrypt the secret.")
|
2022-12-09 20:54:33 +01:00
|
|
|
exit()
|
|
|
|
print("Decrypting accumulated file...")
|
|
|
|
decrypt.setUserPassword(args.master_password)
|
|
|
|
decrypt.decryptAccumulatedFile()
|
2022-12-09 20:10:12 +01:00
|
|
|
exit()
|
|
|
|
|
2022-12-09 21:49:06 +01:00
|
|
|
if mode == 'encrypt':
|
2022-12-09 14:52:57 +01:00
|
|
|
if args.master_password is None:
|
|
|
|
print("Please enter the master password:")
|
|
|
|
master_password = getpass()
|
|
|
|
else:
|
|
|
|
master_password = args.master_password
|
2022-12-09 21:49:06 +01:00
|
|
|
encrypt = Encryption(args.amount_of_secret_holders, args.decryption_quota, master_password)
|
2022-12-09 22:37:29 +01:00
|
|
|
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()
|
2022-12-09 21:49:06 +01:00
|
|
|
encrypt.encrypt()
|
2022-12-09 13:08:07 +01:00
|
|
|
exit()
|