mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 07:48:57 +00:00
11
src/main.py
11
src/main.py
@@ -358,7 +358,7 @@ def handle_reset_relays(password_manager: PasswordManager) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def handle_settings(password_manager: PasswordManager) -> None:
|
def handle_settings(password_manager: PasswordManager) -> None:
|
||||||
"""Interactive settings menu for relay list and PIN changes."""
|
"""Interactive settings menu for relay list and password changes."""
|
||||||
cfg_mgr = password_manager.config_manager
|
cfg_mgr = password_manager.config_manager
|
||||||
if cfg_mgr is None:
|
if cfg_mgr is None:
|
||||||
print(colored("Configuration manager unavailable.", "red"))
|
print(colored("Configuration manager unavailable.", "red"))
|
||||||
@@ -375,7 +375,7 @@ def handle_settings(password_manager: PasswordManager) -> None:
|
|||||||
print("2. Add a relay URL")
|
print("2. Add a relay URL")
|
||||||
print("3. Remove a relay by number")
|
print("3. Remove a relay by number")
|
||||||
print("4. Reset to default relays")
|
print("4. Reset to default relays")
|
||||||
print("5. Change settings PIN")
|
print("5. Change password")
|
||||||
print("6. Back")
|
print("6. Back")
|
||||||
choice = input("Select an option: ").strip()
|
choice = input("Select an option: ").strip()
|
||||||
if choice == "1":
|
if choice == "1":
|
||||||
@@ -387,12 +387,7 @@ def handle_settings(password_manager: PasswordManager) -> None:
|
|||||||
elif choice == "4":
|
elif choice == "4":
|
||||||
handle_reset_relays(password_manager)
|
handle_reset_relays(password_manager)
|
||||||
elif choice == "5":
|
elif choice == "5":
|
||||||
old_pin = getpass.getpass("Current PIN: ")
|
password_manager.change_password()
|
||||||
new_pin = getpass.getpass("New PIN: ")
|
|
||||||
if cfg_mgr.change_pin(old_pin, new_pin):
|
|
||||||
print(colored("PIN changed successfully.", "green"))
|
|
||||||
else:
|
|
||||||
print(colored("Incorrect current PIN.", "red"))
|
|
||||||
elif choice == "6":
|
elif choice == "6":
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@@ -200,6 +200,7 @@ class PasswordManager:
|
|||||||
# Initialize BIP85 and other managers
|
# Initialize BIP85 and other managers
|
||||||
self.initialize_bip85()
|
self.initialize_bip85()
|
||||||
self.initialize_managers()
|
self.initialize_managers()
|
||||||
|
self.sync_index_from_nostr_if_missing()
|
||||||
print(
|
print(
|
||||||
colored(
|
colored(
|
||||||
f"Fingerprint {fingerprint} selected and managers initialized.",
|
f"Fingerprint {fingerprint} selected and managers initialized.",
|
||||||
@@ -311,6 +312,7 @@ class PasswordManager:
|
|||||||
# Initialize BIP85 and other managers
|
# Initialize BIP85 and other managers
|
||||||
self.initialize_bip85()
|
self.initialize_bip85()
|
||||||
self.initialize_managers()
|
self.initialize_managers()
|
||||||
|
self.sync_index_from_nostr_if_missing()
|
||||||
print(colored(f"Switched to fingerprint {selected_fingerprint}.", "green"))
|
print(colored(f"Switched to fingerprint {selected_fingerprint}.", "green"))
|
||||||
|
|
||||||
# Re-initialize NostrClient with the new fingerprint
|
# Re-initialize NostrClient with the new fingerprint
|
||||||
@@ -483,6 +485,7 @@ class PasswordManager:
|
|||||||
|
|
||||||
self.initialize_bip85()
|
self.initialize_bip85()
|
||||||
self.initialize_managers()
|
self.initialize_managers()
|
||||||
|
self.sync_index_from_nostr_if_missing()
|
||||||
return fingerprint # Return the generated or added fingerprint
|
return fingerprint # Return the generated or added fingerprint
|
||||||
else:
|
else:
|
||||||
logging.error("Invalid BIP-85 seed phrase. Exiting.")
|
logging.error("Invalid BIP-85 seed phrase. Exiting.")
|
||||||
@@ -613,6 +616,7 @@ class PasswordManager:
|
|||||||
|
|
||||||
self.initialize_bip85()
|
self.initialize_bip85()
|
||||||
self.initialize_managers()
|
self.initialize_managers()
|
||||||
|
self.sync_index_from_nostr_if_missing()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to encrypt and save parent seed: {e}")
|
logging.error(f"Failed to encrypt and save parent seed: {e}")
|
||||||
logging.error(traceback.format_exc())
|
logging.error(traceback.format_exc())
|
||||||
@@ -679,6 +683,19 @@ class PasswordManager:
|
|||||||
print(colored(f"Error: Failed to initialize managers: {e}", "red"))
|
print(colored(f"Error: Failed to initialize managers: {e}", "red"))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def sync_index_from_nostr_if_missing(self) -> None:
|
||||||
|
"""Retrieve the password database from Nostr if it doesn't exist locally."""
|
||||||
|
index_file = self.fingerprint_dir / "seedpass_passwords_db.json.enc"
|
||||||
|
if index_file.exists():
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
encrypted = self.nostr_client.retrieve_json_from_nostr_sync()
|
||||||
|
if encrypted:
|
||||||
|
self.encryption_manager.decrypt_and_save_index_from_nostr(encrypted)
|
||||||
|
logger.info("Initialized local database from Nostr.")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Unable to sync index from Nostr: {e}")
|
||||||
|
|
||||||
def handle_generate_password(self) -> None:
|
def handle_generate_password(self) -> None:
|
||||||
try:
|
try:
|
||||||
website_name = input("Enter the website name: ").strip()
|
website_name = input("Enter the website name: ").strip()
|
||||||
@@ -1132,6 +1149,49 @@ class PasswordManager:
|
|||||||
print(colored(f"Error: Failed to store hashed password: {e}", "red"))
|
print(colored(f"Error: Failed to store hashed password: {e}", "red"))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def change_password(self) -> None:
|
||||||
|
"""Change the master password used for encryption."""
|
||||||
|
try:
|
||||||
|
current = prompt_existing_password("Enter your current master password: ")
|
||||||
|
if not self.verify_password(current):
|
||||||
|
print(colored("Incorrect password.", "red"))
|
||||||
|
return
|
||||||
|
|
||||||
|
new_password = prompt_for_password()
|
||||||
|
|
||||||
|
# Load data with existing encryption manager
|
||||||
|
index_data = self.entry_manager.encryption_manager.load_json_data()
|
||||||
|
config_data = self.config_manager.load_config(require_pin=False)
|
||||||
|
|
||||||
|
# Create a new encryption manager with the new password
|
||||||
|
new_key = derive_key_from_password(new_password)
|
||||||
|
new_enc_mgr = EncryptionManager(new_key, self.fingerprint_dir)
|
||||||
|
|
||||||
|
# Re-encrypt sensitive files using the new manager
|
||||||
|
new_enc_mgr.encrypt_parent_seed(self.parent_seed)
|
||||||
|
new_enc_mgr.save_json_data(index_data)
|
||||||
|
self.config_manager.encryption_manager = new_enc_mgr
|
||||||
|
self.config_manager.save_config(config_data)
|
||||||
|
|
||||||
|
# Update hashed password and replace managers
|
||||||
|
self.encryption_manager = new_enc_mgr
|
||||||
|
self.entry_manager.encryption_manager = new_enc_mgr
|
||||||
|
self.password_generator.encryption_manager = new_enc_mgr
|
||||||
|
self.store_hashed_password(new_password)
|
||||||
|
|
||||||
|
relay_list = config_data.get("relays", list(DEFAULT_RELAYS))
|
||||||
|
self.nostr_client = NostrClient(
|
||||||
|
encryption_manager=self.encryption_manager,
|
||||||
|
fingerprint=self.current_fingerprint,
|
||||||
|
relays=relay_list,
|
||||||
|
)
|
||||||
|
|
||||||
|
print(colored("Master password changed successfully.", "green"))
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Failed to change password: {e}")
|
||||||
|
logging.error(traceback.format_exc())
|
||||||
|
print(colored(f"Error: Failed to change password: {e}", "red"))
|
||||||
|
|
||||||
|
|
||||||
# Example usage (this part should be removed or commented out when integrating into the larger application)
|
# Example usage (this part should be removed or commented out when integrating into the larger application)
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user