Commit d1533366 authored by Benjamin REED's avatar Benjamin REED

Merge branch 'main' into 'temp_dev'

# Conflicts:
#   main.py
parents d5cd51e4 7589efe9
Pipeline #3050 failed with stages
OPNHYGpmFwa1tM17kGYFowABhqCAAAAAAGdSBM85zx4zTFeOa_FeZpa5eG_UCYuwNUVcP5JtmN4Kw20ZQe3dR1tS5kLuaFbybzMabAHkVgkuOEOsMiv86Mjqv5PSsqZx4EXGbQvqyohhZXB-LQ==
gurt,gAAAAABnUgZWqhD6KqOfi_na5PygL7BE4u9-DHarXn1sYxQkEXjYCH_kb-NJsOHWfQeQktFfljwvH2_IFUCJ-cvsjNdzp_EA7A==
schmurt,gAAAAABnUgZWqhD6KqOfi_na5PygL7BE4u9-DHarXn1sYxQkEXjYCH_kb-NJsOHWfQeQktFfljwvH2_IFUCJ-cvsjNdzp_EA7A==
\ No newline at end of file
......@@ -15,7 +15,7 @@ USAGES = {
"new": "new <length> [ <label> <character set> ] ( 'length' = num characters in password, 'label' = optional name for the password 'charset' = characters that can be in the password (use '-<characters>' to exclude a list of characters))",
"echo": "echo <string content> ( 'string_content' = any text to be echoed )",
"dbg": "dbg ( Prints a debug output of the manager's state )",
"list": "list [ <label> ] (Prints the passwords currently stored 'label' = the password you want to decrypt)",
"list": "list [ <label> <password> ](Prints the passwords currently stored 'label' = the password you want to decrypt)",
"save": "save - Saves the state to the file originally inputted.", # TODO: make it possible to save to a new file
"drop": "drop <label> - deletes the selected label from the list of passwords. This can be undone with the 'undo' command, however if 'drop' is used on an already deleted password, the password is removed forever from the database.",
"undo": "undo - undoes the latest deletion/modification",
......@@ -88,16 +88,16 @@ class State:
lines = content.split('\n')
head = lines[0]
try:
key, decrypt = password_decrypt(head, password)
except:
print("Password does not match for this database, and as such it cannot be decrypted.")
raise Exception
# try:
# key, decrypt = password_decrypt(head, password)
# except:
# print("Password does not match for this database, and as such it cannot be decrypted.")
# raise Exception
self.passwords = {}
self.to_remove = []
self.key = bytes(0)
self.overwritten = []
self.key = key
self.head = head
if content == "":
......@@ -106,7 +106,7 @@ class State:
for i, line in enumerate(lines):
if i == 0:
continue # lmao so hacky! whaddeva!!
continue
if line == "":
continue
parts = line.split(",")
......@@ -126,16 +126,31 @@ class State:
file.close()
def add_password(self, label, password):
def add_password(self, label, password_in, password):
if label == "":
label = str(len(self.passwords) + 1)
pourmoi = self.key
self.passwords[label] = Fernet(self.key).encrypt(password.encode())
try:
(key, _) = password_decrypt(self.head, password)
self.passwords[label] = password_encrypt(password_in.encode(), password)
self.key = key
except:
if self.key:
self.passwords[label] = Fernet(self.key).encrypt(password_in.encode())
return
raise Exception
#self.passwords[label] = encrypt(password.encode, self.key)
def get_password(self, label):
def get_password(self, label, password):
if label in self.passwords:
return Fernet(self.key).decrypt(self.passwords[label])
try:
dec = Fernet(self.key).decrypt(self.passwords[label])
return dec
except:
(key, decoded) = password_decrypt(self.passwords[label], password)
self.key = key
return decoded
else:
return b"[ERROR: no such label found]"
......@@ -358,23 +373,36 @@ def main():
return
else:
filepath = sys.argv[1]
if len(sys.argv) < 3:
print(f"No password supplied. Usage: {sys.argv[0]} <database path> <password>");
return
password = sys.argv[2]
try:
state = handle_args(filepath, password)
state = handle_args(filepath, "TODO: REMOVE THIS SHEISSE")
except FileNotFoundError:
print(f"Error while opening database file, {filepath} does not exist or cannot be opened.")
ask = input(f"Create {filepath}? (Y/N)")
ask = ask.strip()
ask = ask.lower()
if ask == "y":
password = ""
while True:
# TODO: make this print asterisks or waddeva
ask = input(f"Please input a password for {filepath} (Note: password cannot contain spaces): ")
ask = ask.strip()
if ask == "q":
print("Cancelling.")
return
elif len(ask) > 100 or len(ask) < 8 or ask == "":
print("Password is too long/short, please try again.")
else:
print("Type password again to confirm:")
conf = input(f"Confirmation: ")
conf = conf.strip()
if conf != ask:
print("Error, passwords do not match.")
continue
break
password = ask
file = open(filepath, "xb")
salt = secrets.token_bytes(16)
key = password_encrypt("super secret hihi >_>".encode(), password)
file.write(key)
file.write('\n'.encode())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment