mirror of
https://github.com/kevinveenbirkenbach/splitted-secret.git
synced 2024-11-21 17:51:05 +01:00
Implemented automatic user identification
This commit is contained in:
parent
260d7dfbb7
commit
080b8d66e4
@ -42,8 +42,8 @@ python scripts/main.py --mode cleanup --file-types encrypted
|
||||
|
||||
## decrypt
|
||||
|
||||
### decrypt automatic (todo)
|
||||
To decrypt the data for a defined user type in:
|
||||
### decrypt automatic
|
||||
To decrypt the data type in:
|
||||
|
||||
```bash
|
||||
python scripts/main.py --mode decrypt
|
||||
@ -64,7 +64,7 @@ python scripts/main.py --mode decrypt --user "<<user_id>>"
|
||||
python scripts/main.py --amount 3 --quota 50 --mode encrypt --add-user-information --master-password "{{master_password}}"
|
||||
```
|
||||
|
||||
### encrypt master-password fuile
|
||||
### encrypt master-password file
|
||||
|
||||
## todo
|
||||
- add data-input attribut
|
||||
|
@ -8,7 +8,7 @@ class Cleanup():
|
||||
def getAllFilePaths(self,file_type):
|
||||
all_file_paths = [
|
||||
self.paths.getGroupFilesFolderPath(file_type),
|
||||
self.paths.getUserFilesFolderPath(file_type),
|
||||
self.paths.getUserFilesPath(file_type),
|
||||
self.paths.getAccumulatedFilePath(file_type)
|
||||
]
|
||||
if file_type == Paths.TYPE_DECRYPTED:
|
||||
|
@ -1,6 +1,10 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
class AutomaticIdentificationImpossibleException(Exception):
|
||||
pass
|
||||
|
||||
class Decryption():
|
||||
|
||||
def __init__(self,cli,paths):
|
||||
@ -9,6 +13,18 @@ class Decryption():
|
||||
self.cli = cli
|
||||
self.paths = paths
|
||||
|
||||
def identifyUser(self):
|
||||
file_type = self.paths.TYPE_ENCRYPTED
|
||||
file_names = next(os.walk(self.paths.getUserFilesPath(file_type)), (None, None, []))[2]
|
||||
users = []
|
||||
user_file_suffix = self.paths.getUserFileSuffix(file_type)
|
||||
for file in file_names:
|
||||
if user_file_suffix in file:
|
||||
users.append(file.replace(user_file_suffix, ''))
|
||||
if len(users) < 2:
|
||||
return users[0]
|
||||
raise AutomaticIdentificationImpossibleException()
|
||||
|
||||
def initializeUser(self,user_id):
|
||||
self.user_id=str(user_id)
|
||||
self.user_file_decrypted_path = self.paths.getUserFilePath(self.user_id,self.paths.TYPE_DECRYPTED)
|
||||
|
@ -16,7 +16,7 @@ class Paths():
|
||||
def getGroupFilesFolderPath(self,folder_type):
|
||||
return self.getDataFolderPath(folder_type) + "group_files/"
|
||||
|
||||
def getUserFilesFolderPath(self,folder_type):
|
||||
def getUserFilesPath(self,folder_type):
|
||||
return self.getDataFolderPath(folder_type) + "user_files/"
|
||||
|
||||
def getEncryptedMainDataFile(self):
|
||||
@ -29,9 +29,12 @@ class Paths():
|
||||
if file_type == Paths.TYPE_ENCRYPTED:
|
||||
return '.gpg'
|
||||
return ''
|
||||
|
||||
def getUserFileSuffix(self,file_type):
|
||||
return '.json' + self.getFileExtension(file_type)
|
||||
|
||||
def getUserFilePath(self,user_id,file_type):
|
||||
return self.getUserFilesFolderPath(file_type)+user_id+'.json' + self.getFileExtension(file_type);
|
||||
return self.getUserFilesPath(file_type) + user_id + self.getUserFileSuffix(file_type);
|
||||
|
||||
def getGroupFilePath(self,group_id,file_type):
|
||||
return self.getGroupFilesFolderPath(file_type) + str(group_id) + '.txt' + self.getFileExtension(file_type);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import argparse
|
||||
from classes.Encryption import Encryption
|
||||
from classes.Cleanup import Cleanup
|
||||
from classes.Decryption import Decryption
|
||||
from classes.Decryption import Decryption, AutomaticIdentificationImpossibleException
|
||||
from getpass import getpass
|
||||
import traceback
|
||||
from classes.Cli import Cli
|
||||
@ -61,9 +61,16 @@ try:
|
||||
if args.mode == 'decrypt':
|
||||
decrypt = Decryption(cli,paths)
|
||||
if args.master_password is None:
|
||||
if args.user is None:
|
||||
print("Type in the user id:")
|
||||
decrypt.initializeUser(input())
|
||||
if args.user is None:
|
||||
try:
|
||||
print("Attempt to identify user.")
|
||||
user_id = decrypt.identifyUser()
|
||||
print("The user id is: " + user_id)
|
||||
except:
|
||||
print("A automatic user id identification wasn't possible.")
|
||||
print("Type in the user id:")
|
||||
user_id = input()
|
||||
decrypt.initializeUser(user_id)
|
||||
else:
|
||||
decrypt.initializeUser(args.user)
|
||||
if args.user_password is None:
|
||||
|
Loading…
Reference in New Issue
Block a user