-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
186 lines (136 loc) · 5.24 KB
/
Copy pathmain.py
File metadata and controls
186 lines (136 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
try:
import banner
print()
import password_verification
import save_and_backup
import ui
import color_functions
import argparse
from pyperclip import copy
import generator
import sys
import file_path
import pyfastfile
from padding import pad
import time
from config import config_data
import base64
except ModuleNotFoundError:
import sys
import ui
ui.error("The dependencies required for the program could not be found.")
ui.info("Recommended: pip install -r requirements.txt")
print()
sys.exit()
config = config_data()
length = config["key"]["length"]
master_key_length = config["key"]["master_key_length"]
mode = config["encryption"]["encryption_mode"]
security_mode = config["advanced_settings"]["security_mode"]
if config["advanced_settings"]["print_secure_mod_information"]:
if security_mode:
ui.info(f"Security mode {color_functions.green('activated')}.")
else:
ui.info(f"Security mode {color_functions.red('deactivated')}.")
ui.info("If you want to make changes, you need to edit config.toml. \n")
parser = argparse.ArgumentParser()
if not password_verification.master_key_is_valid():
parser.add_argument("--new-master-key", action="store_true", help="Create master key.")
parser.add_argument("--random", action="store_true", help="Create random data.")
args = parser.parse_args()
if (not args.new_master_key) and (not args.random):
ui.error(data=f"Master key {color_functions.red('not found')}. Create a new master key: --new-master-key")
ui.info(data=f"Suggested key: --random")
sys.exit()
if args.new_master_key:
ui.info("Enter the Master Password.")
ui.error("If you forget, there is no turning back.")
key = ui.pinput()
print()
save_and_backup.save_master_key(key=key, security_mode=security_mode)
ui.info("Master key saved.")
ui.info("Welcome aboard!")
print()
sys.exit()
if args.random:
ui.info("Unique, random data suitable for use as a key.")
data = generator.create(20)
ui.info(f"Data: {color_functions.green(data=data)}")
copy(data)
ui.info("Copied to clipboard!")
sys.exit()
parser.add_argument("--delete-all", action="store_true", help="Reset all data.")
parser.add_argument("--list-keys", action="store_true", help="List keys.")
args = parser.parse_args()
if args.delete_all:
ui.info("Password to reset.")
ui.error(data=color_functions.red(data="WARNING: THIS ACTION CANNOT BE UNDONE!!!"))
password = ui.pinput()
print()
if password_verification.check(password=password, security_mode=security_mode):
verification_code = generator.create(3)
ui.info(f"Type this for additional verification: {color_functions.green(verification_code)}")
input_code = ui.pinput(is_name=True)
print()
if input_code == verification_code:
pyfastfile.delete(file_path.backup_file)
pyfastfile.delete(file_path.enc_keys_file)
pyfastfile.overwrite(file_path.key_file, data="")
ui.info("Data has been reset.")
sys.exit()
ui.error("Verification is failed.")
sys.exit()
ui.error("Your password is incorrect.")
time.sleep(config["advanced_settings"]["delete_all_operation_sleep_time"])
sys.exit()
if args.list_keys:
ui.info("Password to list keys.")
password = ui.pinput()
print()
if password_verification.check(password=password, security_mode=security_mode):
try:
encoded = pyfastfile.read(file_path.enc_keys_file).strip()
if not encoded:
ui.info("No keys found.")
sys.exit()
encrypted = base64.b64decode(encoded)
decrypted = pyfastfile.decrypt_bytes(
data=encrypted,
key=pad(password)
).decode()
print(decrypted.strip())
sys.exit()
except Exception as e:
ui.error(f"Failed to decrypt keys: {e}")
sys.exit(1)
ui.error("Your password is incorrect.")
time.sleep(config["advanced_settings"]["list_all_operation_sleep_time"])
sys.exit()
new_hex = generator.create(length=length)
copy(new_hex)
if config["advanced_settings"]["print_key"]:
ui.info(f"New key is: {color_functions.green(new_hex)}")
else:
ui.info("Key is generated.")
ui.info("Copied to clipboard!")
print()
if not config["advanced_settings"]["save"]:
ui.info("See you later.")
sys.exit()
ui.info("Password to save.")
ui.info("If you do not want to save, simply press Enter.")
password = ui.pinput()
if not password:
print()
ui.info("See you later!")
sys.exit()
if not password_verification.check(password, security_mode=security_mode):
ui.error("Your password is incorrect.")
time.sleep(config["advanced_settings"]["add_key_sleep_time"])
sys.exit()
ui.info("Name to save.")
name = ui.pinput(is_name=True)
save_and_backup.save(hex=new_hex, name=name, key=password, mode=mode)
print()
ui.info("Key is saved!")
ui.info("See you later.")