mirror of
https://github.com/kevinveenbirkenbach/splitted-secret.git
synced 2024-11-01 00:53:11 +01:00
Optimized code
This commit is contained in:
parent
591af85d82
commit
42a5b93d67
16
Readme.md
16
Readme.md
@ -43,14 +43,14 @@ python scripts/main.py --mode cleanup --file-types encrypted
|
|||||||
## decrypt
|
## decrypt
|
||||||
|
|
||||||
### decrypt automatic
|
### decrypt automatic
|
||||||
To decrypt the data type in:
|
To decrypt the data execute:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python scripts/main.py --mode decrypt
|
python scripts/main.py --mode decrypt
|
||||||
```
|
```
|
||||||
|
|
||||||
### decrypt defined user
|
### decrypt defined user
|
||||||
To decrypt the data for a defined user type in:
|
To decrypt the data for a defined user execute:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python scripts/main.py --mode decrypt --user "<<user_id>>"
|
python scripts/main.py --mode decrypt --user "<<user_id>>"
|
||||||
@ -58,13 +58,19 @@ python scripts/main.py --mode decrypt --user "<<user_id>>"
|
|||||||
|
|
||||||
## encrypt
|
## encrypt
|
||||||
|
|
||||||
### encrypt all data
|
### encrypt main data
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python scripts/main.py --amount 3 --quota 50 --mode encrypt --add-user-information --master-password "{{master_password}}"
|
python scripts/main.py --secret-holders-amount "<<amount>>" --quota "<<quota>>" --mode encrypt --master-password "<<master_password>>" --input-directory "<<input_directory>>"
|
||||||
```
|
```
|
||||||
|
|
||||||
### encrypt master-password file
|
### encrypt master password
|
||||||
|
|
||||||
|
To encrypt the master-password file and to create the neccessary encrypted meta data execute:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python scripts/main.py --secret-holders-amount "<<amount>>" --quota "<<quota>>" --mode encrypt --add-user-information --master-password "<<master_password>>" --create-meta-data
|
||||||
|
```
|
||||||
|
|
||||||
## todo
|
## todo
|
||||||
- add data-input attribut
|
- add data-input attribut
|
||||||
|
1
data/encrypted/user_files/.gitignore
vendored
1
data/encrypted/user_files/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
*.gpg
|
|
@ -19,7 +19,7 @@ class Cleanup():
|
|||||||
try:
|
try:
|
||||||
self.cli.executeCommand('rm -r ' + folder_path + '*')
|
self.cli.executeCommand('rm -r ' + folder_path + '*')
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
pass
|
||||||
|
|
||||||
def cleanupFiles(self,file_type):
|
def cleanupFiles(self,file_type):
|
||||||
for folder_path in self.getAllFilePaths(file_type):
|
for folder_path in self.getAllFilePaths(file_type):
|
||||||
@ -29,7 +29,7 @@ class Cleanup():
|
|||||||
try:
|
try:
|
||||||
self.cli.executeCommand('find "' + self.paths.getDataFolderPath(Paths.TYPE_ENCRYPTED) + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v')
|
self.cli.executeCommand('find "' + self.paths.getDataFolderPath(Paths.TYPE_ENCRYPTED) + '" -not -name "*' + str(user) +'*" -type f -print | xargs rm -v')
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
pass
|
||||||
self.cleanupFiles(Paths.TYPE_DECRYPTED)
|
self.cleanupFiles(Paths.TYPE_DECRYPTED)
|
||||||
|
|
||||||
def deleteAll(self):
|
def deleteAll(self):
|
||||||
|
@ -40,10 +40,10 @@ class Encryption():
|
|||||||
self.user_mapped_data[user_id]['about'][label] = content;
|
self.user_mapped_data[user_id]['about'][label] = content;
|
||||||
|
|
||||||
def getCoSecretHoldersRange():
|
def getCoSecretHoldersRange():
|
||||||
return range(Encryption.MINIMUM_SECRET_HOLDERS,Encryption.MAXIMUM_SECRET_HOLDERS)
|
return range(Encryption.MINIMUM_SECRET_HOLDERS,(Encryption.MAXIMUM_SECRET_HOLDERS+1))
|
||||||
|
|
||||||
def getSecretHoldersRange():
|
def getSecretHoldersRange():
|
||||||
return range(1,Encryption.MAXIMUM_SECRET_HOLDERS)
|
return range(1,(Encryption.MAXIMUM_SECRET_HOLDERS+1))
|
||||||
|
|
||||||
def getStartnumber(self):
|
def getStartnumber(self):
|
||||||
index = 0
|
index = 0
|
||||||
@ -84,7 +84,7 @@ class Encryption():
|
|||||||
def compileData(self):
|
def compileData(self):
|
||||||
self.compileContacts()
|
self.compileContacts()
|
||||||
index = self.getStartnumber()
|
index = self.getStartnumber()
|
||||||
while index < self.getEndnumber():
|
while index <= self.getEndnumber():
|
||||||
password_group_name = ''.join(sorted(str(index)))
|
password_group_name = ''.join(sorted(str(index)))
|
||||||
if self.isGroupValid(password_group_name):
|
if self.isGroupValid(password_group_name):
|
||||||
password_group_index_int = int(password_group_name)
|
password_group_index_int = int(password_group_name)
|
||||||
@ -126,11 +126,10 @@ class Encryption():
|
|||||||
data={"user_mapped": self.user_mapped_data, "group_mapped": self.group_mapped_data}
|
data={"user_mapped": self.user_mapped_data, "group_mapped": self.group_mapped_data}
|
||||||
self.encryptToJsonFile(data,file_path,self.master_password)
|
self.encryptToJsonFile(data,file_path,self.master_password)
|
||||||
|
|
||||||
def encryptMainData(self):
|
def encryptMainData(self,input_directory):
|
||||||
self.cli.executeCommand('tar -C"' + self.paths.getDecryptedMainDataStandartFolder() + '" -cvzf - ./ | gpg -c --batch --passphrase "' + self.master_password +'" > "' + self.paths.getEncryptedMainDataFile() + '"')
|
self.cli.executeCommand('tar -C"' + input_directory + '" -cvzf - ./ | gpg -c --batch --passphrase "' + self.master_password +'" > "' + self.paths.getEncryptedMainDataFile() + '"')
|
||||||
|
|
||||||
def encryptAll(self):
|
def encryptMetaData(self):
|
||||||
self.encryptUserFile()
|
self.encryptUserFile()
|
||||||
self.encryptAccumulatedFile()
|
self.encryptAccumulatedFile()
|
||||||
self.encryptGroupFiles()
|
self.encryptGroupFiles()
|
||||||
self.encryptMainData()
|
|
||||||
|
@ -33,12 +33,14 @@ try:
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--mode',type=str, dest='mode',required=True,choices=['cleanup','encrypt','decrypt'])
|
parser.add_argument('--mode',type=str, dest='mode',required=True,choices=['cleanup','encrypt','decrypt'])
|
||||||
parser.add_argument('--file-types',type=str, dest='file_types',required=False,choices=[Paths.TYPE_DECRYPTED, Paths.TYPE_ENCRYPTED])
|
parser.add_argument('--file-types',type=str, dest='file_types',required=False,choices=[Paths.TYPE_DECRYPTED, Paths.TYPE_ENCRYPTED])
|
||||||
parser.add_argument('--amount',type=int, dest='amount_of_secret_holders',required=False,choices=Encryption.getCoSecretHoldersRange())
|
parser.add_argument('--secret-holders-amount',type=int, dest='amount_of_secret_holders',required=False,choices=Encryption.getCoSecretHoldersRange(),help="Needed for creating of encryption meta data.")
|
||||||
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)
|
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-password',type=str, dest='user_password',required=False)
|
||||||
parser.add_argument('--user',type=int, dest='user',choices=Encryption.getSecretHoldersRange(),required=False)
|
parser.add_argument('--user',type=int, dest='user',choices=Encryption.getSecretHoldersRange(),required=False)
|
||||||
parser.add_argument('--add-user-information',type=bool, dest='add_user_information', default=False, required=False, action=argparse.BooleanOptionalAction)
|
parser.add_argument('--add-user-information',type=bool, dest='add_user_information', default=False, required=False, action=argparse.BooleanOptionalAction, help="Add additional information to users.")
|
||||||
|
parser.add_argument('--input-directory',type=str,dest='input_directory',required=False, help="The directory from which the data should be encrypted.")
|
||||||
|
parser.add_argument('--create-meta-data',type=bool, dest='create_meta_data', default=False, required=False, action=argparse.BooleanOptionalAction, help="When mode is encrypt and this flag is set, the encrypted meta data is created.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print("Application started.")
|
print("Application started.")
|
||||||
@ -149,13 +151,18 @@ try:
|
|||||||
else:
|
else:
|
||||||
master_password = args.master_password
|
master_password = args.master_password
|
||||||
encrypt = Encryption(cli,paths,args.amount_of_secret_holders, args.decryption_quota, master_password)
|
encrypt = Encryption(cli,paths,args.amount_of_secret_holders, args.decryption_quota, master_password)
|
||||||
if args.add_user_information is not None:
|
if args.add_user_information is True:
|
||||||
for user_id in encrypt.user_mapped_data:
|
for user_id in encrypt.user_mapped_data:
|
||||||
for label in ['name','phone','email','address']:
|
for label in ['name','phone','email','address','notes']:
|
||||||
print("Enter attribut <<" + label + ">> for user <<" + user_id+ ">>:" )
|
print("Enter attribut <<" + label + ">> for user <<" + user_id+ ">>:" )
|
||||||
encrypt.addInformationToUser(user_id, label, str(input()))
|
encrypt.addInformationToUser(user_id, label, str(input()))
|
||||||
encrypt.compileData()
|
encrypt.compileData()
|
||||||
encrypt.encryptAll()
|
if args.create_meta_data is True:
|
||||||
|
print("Create and encrypt meta data.")
|
||||||
|
encrypt.encryptMetaData()
|
||||||
|
if args.input_directory is not None:
|
||||||
|
print("Encrypt main data.")
|
||||||
|
encrypt.encryptMainData(args.input_directory)
|
||||||
dirty_exit()
|
dirty_exit()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Program interrupted by user.")
|
print("Program interrupted by user.")
|
||||||
|
Loading…
Reference in New Issue
Block a user