mirror of
https://github.com/kevinveenbirkenbach/splitted-secret.git
synced 2025-09-09 19:57:17 +02:00
Compare commits
24 Commits
c85c108db5
...
main
Author | SHA1 | Date | |
---|---|---|---|
6f5c04ba11 | |||
a5ada012b6 | |||
69d0592b05 | |||
5e4fe2c01a | |||
b939870c1d | |||
44b2db0cbc | |||
960e14d59e | |||
62f51b449d | |||
09bb6d1e31 | |||
a0c17c9fd6 | |||
b3bd3a0095 | |||
11848ba222 | |||
a88ca6904a | |||
5ad38ab566 | |||
565c5d0961 | |||
07ba9b2164 | |||
63f2d9fd18 | |||
cc943c8c12 | |||
42a5b93d67 | |||
591af85d82 | |||
080b8d66e4 | |||
260d7dfbb7 | |||
4caec4e1dc | |||
4c3661de76 |
7
.github/FUNDING.yml
vendored
Normal file
7
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
github: kevinveenbirkenbach
|
||||||
|
|
||||||
|
patreon: kevinveenbirkenbach
|
||||||
|
|
||||||
|
buy_me_a_coffee: kevinveenbirkenbach
|
||||||
|
|
||||||
|
custom: https://s.veen.world/paypaldonate
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
|
INSTRUCTIONS.md
|
95
README.md
Normal file
95
README.md
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
# Split Secret (sisec) 🔐
|
||||||
|
[](https://github.com/sponsors/kevinveenbirkenbach) [](https://www.patreon.com/c/kevinveenbirkenbach) [](https://buymeacoffee.com/kevinveenbirkenbach) [](https://s.veen.world/paypaldonate)
|
||||||
|
|
||||||
|
|
||||||
|
[](LICENSE) [](https://github.com/kevinveenbirkenbach/split-secret/stargazers)
|
||||||
|
|
||||||
|
Split Secret is a versatile command-line tool for securely splitting a master secret among multiple users. Only when a defined quorum of users combines their secret shares can the original secret be decrypted. The tool also supports robust encryption, decryption, and cleanup operations to ensure sensitive data is managed securely throughout the process.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠 Features
|
||||||
|
|
||||||
|
- **Secret Splitting:** Divide a master secret into shares distributed among users.
|
||||||
|
- **Encryption & Decryption:** Securely encrypt and decrypt data files using strong cryptographic methods.
|
||||||
|
- **User Management:** Add and manage user information along with their secret shares.
|
||||||
|
- **Cleanup Operations:** Remove decrypted files after processing to maintain security.
|
||||||
|
- **Interactive Modes:** Operate in active, preview, or interactive modes to match your workflow.
|
||||||
|
- **Parallel Processing:** Efficiently handles file operations using process pooling.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📥 Installation
|
||||||
|
|
||||||
|
Install Split Secret via [Kevin's Package Manager](https://github.com/kevinveenbirkenbach/package-manager) under the alias `sisec`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
package-manager install sisec
|
||||||
|
```
|
||||||
|
|
||||||
|
This command installs Split Secret globally, making it available as `sisec` in your terminal. 🚀
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Usage
|
||||||
|
|
||||||
|
Split Secret offers several modes for managing your secrets. Here are a few example commands:
|
||||||
|
|
||||||
|
### Cleanup Data
|
||||||
|
To delete all unnecessary decrypted and encrypted files:
|
||||||
|
```bash
|
||||||
|
sisec --mode cleanup
|
||||||
|
```
|
||||||
|
|
||||||
|
### Encrypt Data & Generate Meta Data
|
||||||
|
Encrypt the master secret file and generate encrypted metadata with additional user information:
|
||||||
|
```bash
|
||||||
|
sisec --secret-holders-amount 3 --quota 50 --mode encrypt --add-user-information --master-password "your_master_password" --meta --add-user-information << EOL
|
||||||
|
Alan Turing
|
||||||
|
+12358
|
||||||
|
turing@turing-bomb.world
|
||||||
|
Bletchley Park
|
||||||
|
¯\_(ツ)_/¯
|
||||||
|
Ada Lovelace
|
||||||
|
+132134
|
||||||
|
best@algorythm.ai
|
||||||
|
Somewhere in London
|
||||||
|
:)
|
||||||
|
John von Neumann
|
||||||
|
+5488142
|
||||||
|
test@test3.de
|
||||||
|
Washington D.C.
|
||||||
|
<3 <3 <3
|
||||||
|
EOL
|
||||||
|
```
|
||||||
|
|
||||||
|
### Decrypt Meta Data File
|
||||||
|
To decrypt the accumulated metadata file:
|
||||||
|
```bash
|
||||||
|
sisec --mode decrypt --meta
|
||||||
|
```
|
||||||
|
|
||||||
|
For additional commands and options (such as user-specific decryption, file type filtering, or recursive processing), use:
|
||||||
|
```bash
|
||||||
|
sisec --help
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧑💻 Author
|
||||||
|
|
||||||
|
Developed by **Kevin Veen-Birkenbach**
|
||||||
|
- 📧 [kevin@veen.world](mailto:kevin@veen.world)
|
||||||
|
- 🌐 [https://www.veen.world](https://www.veen.world)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📜 License
|
||||||
|
|
||||||
|
This project is licensed under the **MIT License**.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🤝 Contributions
|
||||||
|
|
||||||
|
Contributions are welcome! Please feel free to fork the repository, submit pull requests, or open issues if you have suggestions or encounter any problems. Let's work together to make secure secret management accessible and efficient! 😊
|
59
Readme.md
59
Readme.md
@@ -1,59 +0,0 @@
|
|||||||
# Splitted Secret
|
|
||||||
The purpose of this software is to splitt a secret over multiple people. Just if a defined amount of this people meet together they can encrypt the secret and have access to it.
|
|
||||||
|
|
||||||
# testing
|
|
||||||
```bash
|
|
||||||
python scripts/main.py --mode cleanup &&
|
|
||||||
python scripts/main.py --amount 3 --quota 50 --mode encrypt --add-user-information --master-password "ewrwerwerew" << END_OF_INPUTS
|
|
||||||
alpha bravo
|
|
||||||
123123812908
|
|
||||||
asfdasd@asdskjd.de
|
|
||||||
street in straat
|
|
||||||
charlie delta
|
|
||||||
1888888
|
|
||||||
sadasfdasd@asdskjd.de
|
|
||||||
street in strutt
|
|
||||||
echo2 foxtrott
|
|
||||||
99999999
|
|
||||||
asfdasd@sdskjd.de
|
|
||||||
street in strasdlasöd
|
|
||||||
END_OF_INPUTS
|
|
||||||
python scripts/main.py --mode decrypt --master-password "ewrwerwerew"
|
|
||||||
|
|
||||||
|
|
||||||
python scripts/main.py --mode cleanup --file-types decrypted && python scripts/main.py --mode decrypt --user "1" --user-password "DDB2QYHP4X0PDR0ZX9LBLACNL6VAXLXMNEZJDOOGUTENSI6UDYGPOR5CV01YLI49" << END_OF_INPUTS
|
|
||||||
2
|
|
||||||
EOQXCYGEY2IMKAJP5VOCRVRH9LPYAPK9IC0ID0GMSJ5KXNXJHPNUBUKEVLE2WHQJ
|
|
||||||
END_OF_INPUTS
|
|
||||||
```
|
|
||||||
# Requirements to know
|
|
||||||
- Amount of People
|
|
||||||
- How much people need to reunite for decrypting
|
|
||||||
|
|
||||||
# Requirements to implement
|
|
||||||
- Plattform independend
|
|
||||||
- easy to use
|
|
||||||
|
|
||||||
# required software
|
|
||||||
```bash
|
|
||||||
pip install numpy
|
|
||||||
gpg
|
|
||||||
ecryptfs-utils
|
|
||||||
ecryptfs-simple
|
|
||||||
python
|
|
||||||
pip
|
|
||||||
```
|
|
||||||
|
|
||||||
## todo
|
|
||||||
- implement tails setup script
|
|
||||||
- add data-input attribut
|
|
||||||
- add data-output attribut
|
|
||||||
|
|
||||||
## Further Information
|
|
||||||
- https://www.tutorialspoint.com/python/python_command_line_arguments.htm
|
|
||||||
- https://docs.python.org/3/library/argparse.html#module-argparse
|
|
||||||
- https://wiki.ubuntuusers.de/GoCryptFS/
|
|
||||||
- https://pynative.com/python-generate-random-string/
|
|
||||||
- https://www.studimup.de/abitur/stochastik/anzahl-der-m%C3%B6glichketen-berechnen-kombinatorik/
|
|
||||||
- https://numpy.org/doc/stable/reference/generated/numpy.base_repr.html?highlight=base_repr#numpy.base_repr
|
|
||||||
- https://linuxconfig.org/how-to-create-compressed-encrypted-archives-with-tar-and-gpg
|
|
2
data/encrypted/user_files/.gitignore
vendored
2
data/encrypted/user_files/.gitignore
vendored
@@ -1 +1 @@
|
|||||||
*.gpg
|
*.json.pgp
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pacman -S gpg tar python pip python-pip
|
||||||
|
pip install numpy
|
@@ -4,13 +4,16 @@ class Cleanup():
|
|||||||
def __init__(self,cli,paths):
|
def __init__(self,cli,paths):
|
||||||
self.cli = cli
|
self.cli = cli
|
||||||
self.paths = paths
|
self.paths = paths
|
||||||
|
|
||||||
def getAllFilePaths(self,file_type):
|
def getMetaFilePaths(self,file_type):
|
||||||
all_file_paths = [
|
return [
|
||||||
self.paths.getGroupFilesFolderPath(file_type),
|
self.paths.getGroupFilesFolderPath(file_type),
|
||||||
self.paths.getUserFilesFolderPath(file_type),
|
self.paths.getUserFilesPath(file_type),
|
||||||
self.paths.getAccumulatedFilePath(file_type)
|
self.paths.getAccumulatedFilePath(file_type)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def getAllFilePaths(self,file_type):
|
||||||
|
all_file_paths = self.getMetaFilePaths(file_type)
|
||||||
if file_type == Paths.TYPE_DECRYPTED:
|
if file_type == Paths.TYPE_DECRYPTED:
|
||||||
all_file_paths.append(self.paths.getDecryptedMainDataStandartFolder())
|
all_file_paths.append(self.paths.getDecryptedMainDataStandartFolder())
|
||||||
return all_file_paths
|
return all_file_paths
|
||||||
@@ -19,7 +22,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,9 +32,13 @@ 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 cleanupMetaData(self,file_type):
|
||||||
|
for folder_path in self.getMetaFilePaths(file_type):
|
||||||
|
self.deleteAllFilesInFolder(folder_path)
|
||||||
|
|
||||||
def deleteAll(self):
|
def deleteAll(self):
|
||||||
self.cleanupFiles(Paths.TYPE_ENCRYPTED)
|
self.cleanupFiles(Paths.TYPE_ENCRYPTED)
|
||||||
self.cleanupFiles(Paths.TYPE_DECRYPTED)
|
self.cleanupFiles(Paths.TYPE_DECRYPTED)
|
@@ -1,5 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import shlex
|
||||||
|
|
||||||
|
class AutomaticIdentificationImpossibleException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class Decryption():
|
class Decryption():
|
||||||
|
|
||||||
@@ -9,6 +14,18 @@ class Decryption():
|
|||||||
self.cli = cli
|
self.cli = cli
|
||||||
self.paths = paths
|
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):
|
def initializeUser(self,user_id):
|
||||||
self.user_id=str(user_id)
|
self.user_id=str(user_id)
|
||||||
self.user_file_decrypted_path = self.paths.getUserFilePath(self.user_id,self.paths.TYPE_DECRYPTED)
|
self.user_file_decrypted_path = self.paths.getUserFilePath(self.user_id,self.paths.TYPE_DECRYPTED)
|
||||||
@@ -19,12 +36,18 @@ class Decryption():
|
|||||||
self.initializeNeededDecryptersAmount()
|
self.initializeNeededDecryptersAmount()
|
||||||
self.initializeValidDecrypterIds()
|
self.initializeValidDecrypterIds()
|
||||||
|
|
||||||
|
def getEscapedMasterPassword(self):
|
||||||
|
return shlex.quote(self.master_password)
|
||||||
|
|
||||||
def initializeGroupDataEncryption(self):
|
def initializeGroupDataEncryption(self):
|
||||||
self.group_name = self.getDecryptersGroupName()
|
self.group_name = self.getDecryptersGroupName()
|
||||||
self.encrypted_group_file_path = self.paths.getGroupFilePath(self.group_name, self.paths.TYPE_DECRYPTED)
|
self.encrypted_group_file_path = self.paths.getGroupFilePath(self.group_name, self.paths.TYPE_DECRYPTED)
|
||||||
self.decryptGroupFile()
|
self.decryptGroupFile()
|
||||||
self.master_password = self.loadTxtFile(self.encrypted_group_file_path).strip()
|
self.master_password = self.loadTxtFile(self.encrypted_group_file_path).strip()
|
||||||
|
|
||||||
|
def getMasterPassword(self):
|
||||||
|
return self.master_password
|
||||||
|
|
||||||
def initializeNeededDecryptersAmount(self):
|
def initializeNeededDecryptersAmount(self):
|
||||||
self.needed_decrypters_amount = len(str(list(self.user_data['groups'].keys())[0]))
|
self.needed_decrypters_amount = len(str(list(self.user_data['groups'].keys())[0]))
|
||||||
|
|
||||||
@@ -54,9 +77,6 @@ class Decryption():
|
|||||||
shared_password += str(self.password_parts[password_share_index])
|
shared_password += str(self.password_parts[password_share_index])
|
||||||
return shared_password
|
return shared_password
|
||||||
|
|
||||||
def getMasterPassword(self):
|
|
||||||
return self.master_password
|
|
||||||
|
|
||||||
def addDecrypterId(self,decrypter_id):
|
def addDecrypterId(self,decrypter_id):
|
||||||
decrypter_id = int(decrypter_id)
|
decrypter_id = int(decrypter_id)
|
||||||
if decrypter_id not in self.valid_decrypter_ids:
|
if decrypter_id not in self.valid_decrypter_ids:
|
||||||
@@ -98,7 +118,7 @@ class Decryption():
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def decryptFile(self,password,input_file_path,output_file_path):
|
def decryptFile(self,password,input_file_path,output_file_path):
|
||||||
self.cli.executeCommand('gpg --batch --passphrase "'+ password + '" -o "' + output_file_path +'" "'+ input_file_path+'"')
|
self.cli.executeCommand('gpg --batch --passphrase '+ shlex.quote(password) + ' -o "' + output_file_path +'" "'+ input_file_path+'"')
|
||||||
|
|
||||||
def decryptUserFile(self):
|
def decryptUserFile(self):
|
||||||
input_file_path = self.paths.getUserFilePath(self.user_id,self.paths.TYPE_ENCRYPTED)
|
input_file_path = self.paths.getUserFilePath(self.user_id,self.paths.TYPE_ENCRYPTED)
|
||||||
@@ -114,4 +134,4 @@ class Decryption():
|
|||||||
self.decryptFile(self.user_password, input_file_path, output_file_path)
|
self.decryptFile(self.user_password, input_file_path, output_file_path)
|
||||||
|
|
||||||
def decryptMainData(self):
|
def decryptMainData(self):
|
||||||
self.cli.executeCommand('gpg --batch --passphrase "' + self.getMasterPassword() + '" -d "' + self.paths.getEncryptedMainDataFile() + '" | tar -xvzf - "' + self.paths.getDecryptedMainDataStandartFolder() + '"')
|
self.cli.executeCommand('gpg --batch --passphrase ' + shlex.quote(self.getMasterPassword()) + ' -d "' + self.paths.getEncryptedMainDataFile() + '" | tar --one-top-level="' + self.paths.getDecryptedMainDataStandartFolder() + '" -xvzf -')
|
@@ -5,6 +5,7 @@ import numpy
|
|||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
from .Paths import Paths
|
from .Paths import Paths
|
||||||
|
import shlex
|
||||||
|
|
||||||
class Encryption():
|
class Encryption():
|
||||||
|
|
||||||
@@ -40,10 +41,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 +85,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)
|
||||||
@@ -104,7 +105,7 @@ class Encryption():
|
|||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
def encryptStringToFile(self,text,output_file,password):
|
def encryptStringToFile(self,text,output_file,password):
|
||||||
self.cli.executeCommand('echo \'' + text + '\' | gpg --symmetric --armor --batch --passphrase "' + password + '" -o "' + output_file + '"')
|
self.cli.executeCommand('echo ' + shlex.quote(text) + ' | gpg --symmetric --armor --batch --passphrase ' + shlex.quote(password) + ' -o "' + output_file + '"')
|
||||||
|
|
||||||
def encryptGroupFiles(self):
|
def encryptGroupFiles(self):
|
||||||
for password_group_index_int in self.group_mapped_data:
|
for password_group_index_int in self.group_mapped_data:
|
||||||
@@ -120,17 +121,33 @@ class Encryption():
|
|||||||
data=self.user_mapped_data[user_id]
|
data=self.user_mapped_data[user_id]
|
||||||
password=self.user_mapped_data[user_id]['user_password']
|
password=self.user_mapped_data[user_id]['user_password']
|
||||||
self.encryptToJsonFile(data,file_path,password)
|
self.encryptToJsonFile(data,file_path,password)
|
||||||
|
'''
|
||||||
def encryptAccumulatedFile(self):
|
This saving as decrypted file is necessary due to the reason that the shell can't deal with unlimited string length.
|
||||||
file_path=self.paths.getAccumulatedFilePath(Paths.TYPE_ENCRYPTED)
|
See: https://stackoverflow.com/questions/30650841/why-am-i-getting-errno-7-argument-list-too-long-and-oserror-errno-24-too-ma
|
||||||
data={"user_mapped": self.user_mapped_data, "group_mapped": self.group_mapped_data}
|
'''
|
||||||
self.encryptToJsonFile(data,file_path,self.master_password)
|
def encryptFileToFile(self,input_file,output_file,password):
|
||||||
|
self.cli.executeCommand('cat \'' + input_file + '\' | gpg --symmetric --armor --batch --passphrase ' + shlex.quote(password) + ' -o "' + output_file + '"')
|
||||||
def encryptMainData(self):
|
|
||||||
self.cli.executeCommand('tar -cvzf - "' + self.paths.getDecryptedMainDataStandartFolder() + '" | gpg -c --batch --passphrase "' + self.master_password +'" > "' + self.paths.getEncryptedMainDataFile() + '"');
|
|
||||||
|
|
||||||
def encryptAll(self):
|
def deleteDecryptedAccumulatedFile(self):
|
||||||
|
self.cli.executeCommand('rm ' + self.paths.getAccumulatedFilePath(Paths.TYPE_DECRYPTED))
|
||||||
|
|
||||||
|
def saveDecryptedAccumulatedFile(self):
|
||||||
|
file_path=self.paths.getAccumulatedFilePath(Paths.TYPE_DECRYPTED)
|
||||||
|
data={"user_mapped": self.user_mapped_data, "group_mapped": self.group_mapped_data}
|
||||||
|
with open(file_path, 'w') as file:
|
||||||
|
json.dump(data, file)
|
||||||
|
|
||||||
|
def encryptAccumulatedFile(self):
|
||||||
|
self.saveDecryptedAccumulatedFile()
|
||||||
|
encrypted_file_path=self.paths.getAccumulatedFilePath(Paths.TYPE_ENCRYPTED)
|
||||||
|
decrypted_file_path=self.paths.getAccumulatedFilePath(Paths.TYPE_DECRYPTED)
|
||||||
|
self.encryptFileToFile(decrypted_file_path,encrypted_file_path,self.master_password)
|
||||||
|
self.deleteDecryptedAccumulatedFile()
|
||||||
|
|
||||||
|
def encryptMainData(self,input_directory):
|
||||||
|
self.cli.executeCommand('tar -C"' + input_directory + '" -cvzf - ./ | gpg -c --batch --passphrase ' + shlex.quote(self.master_password) + ' > "' + self.paths.getEncryptedMainDataFile() + '"')
|
||||||
|
|
||||||
|
def encryptMetaData(self):
|
||||||
self.encryptUserFile()
|
self.encryptUserFile()
|
||||||
self.encryptAccumulatedFile()
|
|
||||||
self.encryptGroupFiles()
|
self.encryptGroupFiles()
|
||||||
self.encryptMainData()
|
self.encryptAccumulatedFile()
|
@@ -16,7 +16,7 @@ class Paths():
|
|||||||
def getGroupFilesFolderPath(self,folder_type):
|
def getGroupFilesFolderPath(self,folder_type):
|
||||||
return self.getDataFolderPath(folder_type) + "group_files/"
|
return self.getDataFolderPath(folder_type) + "group_files/"
|
||||||
|
|
||||||
def getUserFilesFolderPath(self,folder_type):
|
def getUserFilesPath(self,folder_type):
|
||||||
return self.getDataFolderPath(folder_type) + "user_files/"
|
return self.getDataFolderPath(folder_type) + "user_files/"
|
||||||
|
|
||||||
def getEncryptedMainDataFile(self):
|
def getEncryptedMainDataFile(self):
|
||||||
@@ -29,9 +29,12 @@ class Paths():
|
|||||||
if file_type == Paths.TYPE_ENCRYPTED:
|
if file_type == Paths.TYPE_ENCRYPTED:
|
||||||
return '.gpg'
|
return '.gpg'
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def getUserFileSuffix(self,file_type):
|
||||||
|
return '.json' + self.getFileExtension(file_type)
|
||||||
|
|
||||||
def getUserFilePath(self,user_id,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):
|
def getGroupFilePath(self,group_id,file_type):
|
||||||
return self.getGroupFilesFolderPath(file_type) + str(group_id) + '.txt' + self.getFileExtension(file_type);
|
return self.getGroupFilesFolderPath(file_type) + str(group_id) + '.txt' + self.getFileExtension(file_type);
|
||||||
|
172
scripts/main.py
172
scripts/main.py
@@ -1,7 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from classes.Encryption import Encryption
|
from classes.Encryption import Encryption
|
||||||
from classes.Cleanup import Cleanup
|
from classes.Cleanup import Cleanup
|
||||||
from classes.Decryption import Decryption
|
from classes.Decryption import Decryption, AutomaticIdentificationImpossibleException
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
import traceback
|
import traceback
|
||||||
from classes.Cli import Cli
|
from classes.Cli import Cli
|
||||||
@@ -33,15 +33,20 @@ 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('--meta-data',type=bool, dest='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. When mode is decrypt and this flag is set the accumulated file will be decrypted.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print("Application started.")
|
print("Application started.")
|
||||||
|
print("To leave the appplication use the key kombination: <<Ctr>> + <<Alt>> + <<C>>")
|
||||||
|
print("Cleaning up all decrypted files.")
|
||||||
|
cleanup.cleanupFiles(Paths.TYPE_DECRYPTED)
|
||||||
print("Selected Mode: " + args.mode)
|
print("Selected Mode: " + args.mode)
|
||||||
|
|
||||||
if args.mode == 'cleanup':
|
if args.mode == 'cleanup':
|
||||||
@@ -60,78 +65,91 @@ try:
|
|||||||
|
|
||||||
if args.mode == 'decrypt':
|
if args.mode == 'decrypt':
|
||||||
decrypt = Decryption(cli,paths)
|
decrypt = Decryption(cli,paths)
|
||||||
if args.master_password is None:
|
if args.meta_data is True:
|
||||||
if args.user is None:
|
if args.master_password is None:
|
||||||
|
print("Enter the master password:")
|
||||||
|
master_password = getpass()
|
||||||
|
else:
|
||||||
|
master_password = args.master_password
|
||||||
|
decrypt = Decryption(cli,paths)
|
||||||
|
print("Decrypting accumulated data.")
|
||||||
|
decrypt.setUserPassword(master_password)
|
||||||
|
decrypt.decryptAccumulatedFile()
|
||||||
|
dirty_exit()
|
||||||
|
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:")
|
print("Type in the user id:")
|
||||||
decrypt.initializeUser(input())
|
user_id = input()
|
||||||
else:
|
decrypt.initializeUser(user_id)
|
||||||
decrypt.initializeUser(args.user)
|
else:
|
||||||
if args.user_password is None:
|
decrypt.initializeUser(args.user)
|
||||||
while True:
|
if args.user_password is None:
|
||||||
print("Enter the user password:")
|
while True:
|
||||||
decrypt.setUserPassword(getpass())
|
print("Enter the user password:")
|
||||||
print("Decrypting User File...")
|
decrypt.setUserPassword(getpass())
|
||||||
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();
|
||||||
except Exception as error:
|
|
||||||
print("An error occured. Propably you passed a wrong password :( The error is: " + str(error))
|
|
||||||
clean_exit()
|
|
||||||
print("\nContact the following persons and request their password share: \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])
|
|
||||||
while True:
|
|
||||||
print("\nReset password shares.\n")
|
|
||||||
decrypt.resetDecrypterIds()
|
|
||||||
try:
|
|
||||||
password_shares_count = 1
|
|
||||||
while password_shares_count < decrypt.getNeededDecryptersAmount():
|
|
||||||
print(str(password_shares_count) + " password shares had been added.")
|
|
||||||
print("Password shares for the the users " + str(decrypt.getDecrypterIds()) + " been added. ")
|
|
||||||
print("You need to add " + str((decrypt.getNeededDecryptersAmount()-password_shares_count)) +" more password shares.")
|
|
||||||
print("\nType in the user id of another decrypter:")
|
|
||||||
decrypt.addDecrypterId(int(input()))
|
|
||||||
password_shares_count += 1
|
|
||||||
break
|
|
||||||
except Exception as error:
|
|
||||||
print("The following error occured <<" + str(error) + ">> :( \n Try again :)")
|
|
||||||
print("\nYour data is:\n")
|
|
||||||
print("FOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName())
|
|
||||||
print("FOR USER ID: " + decrypt.getUserId())
|
|
||||||
print("PASSWORD SHARE IS: " + decrypt.getPasswordShare() + "\n")
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
decrypt.resetPasswordShare()
|
|
||||||
co_decrypter_ids = decrypt.getCoDecrypterIds()
|
|
||||||
for co_decrypter_id in decrypt.getCoDecrypterIds():
|
|
||||||
print("Type in the password share for: \n")
|
|
||||||
print("FOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName())
|
|
||||||
print("FOR USER: " + str(co_decrypter_id))
|
|
||||||
print("PASSWORD SHARE IS: ")
|
|
||||||
decrypt.addPasswordShare(co_decrypter_id, input())
|
|
||||||
print("\nTHE GROUP PASSWORD IS: " + decrypt.getGroupPassword())
|
|
||||||
print("\nDecrypting group password file.\n")
|
|
||||||
decrypt.initializeGroupDataEncryption()
|
|
||||||
print("THE MASTER PASSWORD IS: " + decrypt.getMasterPassword())
|
|
||||||
break;
|
break;
|
||||||
except:
|
except Exception as error:
|
||||||
print("An unexpected error occured: \n" + traceback.format_exc())
|
print("An error occured. Propably you typed in a wrong password :( The error is: " + str(error))
|
||||||
print("Decrypting main data.")
|
else:
|
||||||
decrypt.decryptMainData()
|
decrypt.setUserPassword(args.user_password)
|
||||||
print("All data decrypted.")
|
print("Decrypting User File...")
|
||||||
dirty_exit()
|
try:
|
||||||
print("Decrypting accumulated data.")
|
decrypt.initializeUserDataDecryption();
|
||||||
decrypt.setUserPassword(args.master_password)
|
except Exception as error:
|
||||||
decrypt.decryptAccumulatedFile()
|
print("An error occured. Propably you passed a wrong password :( The error is: " + str(error))
|
||||||
|
clean_exit()
|
||||||
|
print("\nContact the following persons and request their password share: \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])
|
||||||
|
while True:
|
||||||
|
print("\nReset password shares.\n")
|
||||||
|
decrypt.resetDecrypterIds()
|
||||||
|
try:
|
||||||
|
password_shares_count = 1
|
||||||
|
while password_shares_count < decrypt.getNeededDecryptersAmount():
|
||||||
|
print(str(password_shares_count) + " password shares had been added.")
|
||||||
|
print("Password shares for the the users " + str(decrypt.getDecrypterIds()) + " been added. ")
|
||||||
|
print("You need to add " + str((decrypt.getNeededDecryptersAmount()-password_shares_count)) +" more password shares.")
|
||||||
|
print("\nType in the user id of another decrypter:")
|
||||||
|
decrypt.addDecrypterId(int(input()))
|
||||||
|
password_shares_count += 1
|
||||||
|
break
|
||||||
|
except Exception as error:
|
||||||
|
print("The following error occured <<" + str(error) + ">> :( \n Try again :)")
|
||||||
|
print("\nYour data is:\n")
|
||||||
|
print("FOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName())
|
||||||
|
print("FOR USER ID: " + decrypt.getUserId())
|
||||||
|
print("PASSWORD SHARE IS: " + decrypt.getPasswordShare() + "\n")
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
decrypt.resetPasswordShare()
|
||||||
|
co_decrypter_ids = decrypt.getCoDecrypterIds()
|
||||||
|
for co_decrypter_id in decrypt.getCoDecrypterIds():
|
||||||
|
print("Type in the password share for: \n")
|
||||||
|
print("FOR PASSWORD GROUP: " + decrypt.getDecryptersGroupName())
|
||||||
|
print("FOR USER: " + str(co_decrypter_id))
|
||||||
|
print("PASSWORD SHARE IS: ")
|
||||||
|
decrypt.addPasswordShare(co_decrypter_id, input())
|
||||||
|
print("\nTHE GROUP PASSWORD IS: " + decrypt.getGroupPassword())
|
||||||
|
print("\nDecrypting group password file.\n")
|
||||||
|
decrypt.initializeGroupDataEncryption()
|
||||||
|
print("THE MASTER PASSWORD IS: " + decrypt.getMasterPassword())
|
||||||
|
break;
|
||||||
|
except:
|
||||||
|
print("An unexpected error occured: \n" + traceback.format_exc())
|
||||||
|
print("Decrypting main data.")
|
||||||
|
decrypt.decryptMainData()
|
||||||
|
print("The data was decrypted to: " + paths.getDecryptedMainDataStandartFolder())
|
||||||
dirty_exit()
|
dirty_exit()
|
||||||
|
|
||||||
if args.mode == 'encrypt':
|
if args.mode == 'encrypt':
|
||||||
@@ -141,14 +159,20 @@ 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.meta_data is True:
|
||||||
|
print('Cleaning up encrypted meta data.')
|
||||||
|
cleanup.cleanupMetaData(Paths.TYPE_ENCRYPTED)
|
||||||
|
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.")
|
||||||
|
Reference in New Issue
Block a user