modified: main.py

modified:   packages/vault.py
This commit is contained in:
ousmblueninja 2023-09-21 19:48:54 -05:00
parent 3a5972c968
commit e905832868
2 changed files with 78 additions and 100 deletions

48
main.py
View File

@ -14,43 +14,6 @@ import signal
import requests import requests
import subprocess import subprocess
import requests
from bs4 import BeautifulSoup
import subprocess
# Hardcoded GitHub URL
github_url = "https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/"
def githublist(command: list):
if len(command) != 0:
print("Usage: githublist")
return
try:
response = requests.get(github_url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
files = [a['href'] for a in soup.find_all('a', href=True)]
# Filter out directories and unwanted links
files = [file for file in files if not file.startswith("../") and not file.endswith("/")]
if files:
print("Files in the directory:")
for file in files:
print(file)
else:
print("No files found in the directory.")
else:
print(f"Failed to retrieve content from {github_url}.")
except Exception as e:
print(f"An error occurred: {str(e)}")
try:
subprocess.run(["listgithub", github_url], check=True)
except subprocess.CalledProcessError:
print("Failed to list files using 'listgithub'. Make sure the 'listgithub' plugin is available.")
helper = '''import ast helper = '''import ast
class color: class color:
@ -237,8 +200,7 @@ class packagemanager:
install <package name> | installs package install <package name> | installs package
list | lists installed packages list | lists installed packages
remove <package name> | uninstall packages remove <package name> | uninstall packages
available | lists available commands available | lists available commands""")
downloadable | lists all packages on the server/db""")
elif args[1] == "install": elif args[1] == "install":
self.install(args[2]) self.install(args[2])
@ -248,20 +210,14 @@ class packagemanager:
self.uninstall(args[2:]) self.uninstall(args[2:])
elif args[1] == "available": elif args[1] == "available":
self.commands("./packages") self.commands("./packages")
elif args[1] == "downloadable":
self.listDownloadable)
else: else:
print("""Options: print("""Options:
install <package name> | installs package install <package name> | installs package
list | lists installed packages list | lists installed packages
remove <package name> | uninstall packages remove <package name> | uninstall packages
available | lists available commands available | lists available commands""")
downloadable | lists all packages on the server/db""")
return return
def listDownloadable(self):
githublist()
def commands(self, directory): def commands(self, directory):

View File

@ -4,79 +4,101 @@ import getpass
from cryptography.fernet import Fernet from cryptography.fernet import Fernet
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC import base64
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.hazmat.primitives import hashes
# Initialize the Fernet symmetric key # Global variables
key = None key = None
cipher_suite = None passwords = []
def initialize_vault(): def initialize_vault():
global key, cipher_suite global key
print("Welcome to the Vault!") print("Welcome to the Vault!")
while True: master_password = getpass.getpass("Enter your master password: ")
master_password = getpass.getpass("Enter your master password: ") salt = b'some_salt_here' # Replace with a secure salt value
salt = b'some_salt_here' # Replace with a secure salt value kdf = PBKDF2HMAC(
kdf = PBKDF2HMAC( algorithm=hashes.SHA256(),
algorithm=hashes.SHA256(), iterations=100000, # Adjust the number of iterations as needed for security
iterations=100000, # Adjust the number of iterations as needed for security salt=salt,
salt=salt, length=32 # Use a fixed key length (256 bits)
) )
key = Fernet(base64.urlsafe_b64encode(kdf.derive(master_password.encode()))) key = base64.urlsafe_b64encode(kdf.derive(master_password.encode()))
cipher_suite = Fernet(key) print("Vault initialized successfully.")
print("Vault initialized successfully.") def save_vault():
break global key, passwords
if key is None:
print("You must log in first to access the vault.")
return
# Dictionary to store encrypted passwords (service as key, encrypted password as value) cipher_suite = Fernet(key)
passwords = {} encrypted_passwords = [cipher_suite.encrypt(password.encode()) for password in passwords]
with open("vault.txt", "wb") as file:
for encrypted_password in encrypted_passwords:
file.write(encrypted_password + b'\n')
def load_vault():
global key, passwords
if key is None:
print("You must log in first to access the vault.")
return
try:
with open("vault.txt", "rb") as file:
lines = file.read().splitlines()
cipher_suite = Fernet(key)
passwords = [cipher_suite.decrypt(line).decode() for line in lines]
except FileNotFoundError:
passwords = []
def vault_add(password):
global key, passwords
if key is None:
print("You must log in first to access the vault.")
return
passwords.append(password)
print("Password added to the vault.")
def vault_retrieve():
global key, passwords
if key is None:
print("You must log in first to access the vault.")
return
for i, password in enumerate(passwords):
print(f"Password {i + 1}: {password}")
def vault(command: list): def vault(command: list):
if len(command) != 1: if len(command) < 1:
print("Usage: vault login") print("Usage: vault [login|add|retrieve|save|load]")
return return
action = command[0].lower() action = command[0].lower()
if action == "login": if action == "login":
initialize_vault() initialize_vault()
elif action == "add" and len(command) == 2:
elif action == "add": password = command[1]
if key is None: vault_add(password)
print("You must log in first to access the vault.")
return
service = input("Enter the service or website name: ")
password = getpass.getpass("Enter the password: ")
# Encrypt the password before storing it
encrypted_password = cipher_suite.encrypt(password.encode())
passwords[service] = encrypted_password
print(f"Password for {service} added and encrypted.")
elif action == "retrieve": elif action == "retrieve":
if key is None: vault_retrieve()
print("You must log in first to access the vault.") elif action == "save":
return save_vault()
print("Vault saved.")
service = input("Enter the service or website name: ") elif action == "load":
load_vault()
if service in passwords: print("Vault loaded.")
# Decrypt and display the password
decrypted_password = cipher_suite.decrypt(passwords[service]).decode()
print(f"Password for {service}: {decrypted_password}")
else:
print(f"No password found for {service}.")
else: else:
print("Invalid action. Use 'login', 'add', or 'retrieve'.") print("Invalid action or arguments. Usage: vault [login|add|retrieve|save|load]")
# Example usage:
# vault ["login"]
# vault ["add", "secretpassword"]
# vault ["retrieve"]
# vault ["save"]
# vault ["load"]