mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 15:58:48 +00:00
Remove unused encryption mode setting
This commit is contained in:
54
src/main.py
54
src/main.py
@@ -17,7 +17,7 @@ import traceback
|
||||
from password_manager.manager import PasswordManager
|
||||
from nostr.client import NostrClient
|
||||
from constants import INACTIVITY_TIMEOUT
|
||||
from utils.key_derivation import EncryptionMode
|
||||
|
||||
|
||||
colorama_init()
|
||||
|
||||
@@ -491,14 +491,13 @@ def handle_settings(password_manager: PasswordManager) -> None:
|
||||
print("1. Profiles")
|
||||
print("2. Nostr")
|
||||
print("3. Change password")
|
||||
print("4. Change encryption mode")
|
||||
print("5. Verify Script Checksum")
|
||||
print("6. Backup Parent Seed")
|
||||
print("7. Export database")
|
||||
print("8. Import database")
|
||||
print("9. Set inactivity timeout")
|
||||
print("10. Lock Vault")
|
||||
print("11. Back")
|
||||
print("4. Verify Script Checksum")
|
||||
print("5. Backup Parent Seed")
|
||||
print("6. Export database")
|
||||
print("7. Import database")
|
||||
print("8. Set inactivity timeout")
|
||||
print("9. Lock Vault")
|
||||
print("10. Back")
|
||||
choice = input("Select an option: ").strip()
|
||||
if choice == "1":
|
||||
handle_profiles_menu(password_manager)
|
||||
@@ -507,29 +506,22 @@ def handle_settings(password_manager: PasswordManager) -> None:
|
||||
elif choice == "3":
|
||||
password_manager.change_password()
|
||||
elif choice == "4":
|
||||
try:
|
||||
mode = password_manager.prompt_encryption_mode()
|
||||
password_manager.change_encryption_mode(mode)
|
||||
except Exception as exc:
|
||||
logging.error(f"Error changing encryption mode: {exc}", exc_info=True)
|
||||
print(colored(f"Error: Failed to change encryption mode: {exc}", "red"))
|
||||
elif choice == "5":
|
||||
password_manager.handle_verify_checksum()
|
||||
elif choice == "6":
|
||||
elif choice == "5":
|
||||
password_manager.handle_backup_reveal_parent_seed()
|
||||
elif choice == "7":
|
||||
elif choice == "6":
|
||||
password_manager.handle_export_database()
|
||||
elif choice == "8":
|
||||
elif choice == "7":
|
||||
path = input("Enter path to backup file: ").strip()
|
||||
if path:
|
||||
password_manager.handle_import_database(Path(path))
|
||||
elif choice == "9":
|
||||
elif choice == "8":
|
||||
handle_set_inactivity_timeout(password_manager)
|
||||
elif choice == "10":
|
||||
elif choice == "9":
|
||||
password_manager.lock_vault()
|
||||
print(colored("Vault locked. Please re-enter your password.", "yellow"))
|
||||
password_manager.unlock_vault()
|
||||
elif choice == "11":
|
||||
elif choice == "10":
|
||||
break
|
||||
else:
|
||||
print(colored("Invalid choice.", "red"))
|
||||
@@ -622,12 +614,6 @@ if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
sub = parser.add_subparsers(dest="command")
|
||||
|
||||
parser.add_argument(
|
||||
"--encryption-mode",
|
||||
choices=[m.value for m in EncryptionMode],
|
||||
help="Select encryption mode",
|
||||
)
|
||||
|
||||
exp = sub.add_parser("export")
|
||||
exp.add_argument("--file")
|
||||
|
||||
@@ -636,19 +622,9 @@ if __name__ == "__main__":
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
mode_value = cfg.get("encryption_mode", EncryptionMode.SEED_ONLY.value)
|
||||
if args.encryption_mode:
|
||||
mode_value = args.encryption_mode
|
||||
try:
|
||||
enc_mode = EncryptionMode(mode_value)
|
||||
except ValueError:
|
||||
logger.error(f"Invalid encryption mode: {mode_value}")
|
||||
print(colored(f"Error: Invalid encryption mode '{mode_value}'", "red"))
|
||||
sys.exit(1)
|
||||
|
||||
# Initialize PasswordManager and proceed with application logic
|
||||
try:
|
||||
password_manager = PasswordManager(encryption_mode=enc_mode)
|
||||
password_manager = PasswordManager()
|
||||
logger.info("PasswordManager initialized successfully.")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to initialize PasswordManager: {e}", exc_info=True)
|
||||
|
@@ -12,10 +12,7 @@ import bcrypt
|
||||
|
||||
from password_manager.vault import Vault
|
||||
from nostr.client import DEFAULT_RELAYS as DEFAULT_NOSTR_RELAYS
|
||||
from utils.key_derivation import (
|
||||
EncryptionMode,
|
||||
DEFAULT_ENCRYPTION_MODE,
|
||||
)
|
||||
|
||||
from constants import INACTIVITY_TIMEOUT
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -46,7 +43,6 @@ class ConfigManager:
|
||||
"relays": list(DEFAULT_NOSTR_RELAYS),
|
||||
"pin_hash": "",
|
||||
"password_hash": "",
|
||||
"encryption_mode": DEFAULT_ENCRYPTION_MODE.value,
|
||||
"inactivity_timeout": INACTIVITY_TIMEOUT,
|
||||
}
|
||||
try:
|
||||
@@ -57,7 +53,6 @@ class ConfigManager:
|
||||
data.setdefault("relays", list(DEFAULT_NOSTR_RELAYS))
|
||||
data.setdefault("pin_hash", "")
|
||||
data.setdefault("password_hash", "")
|
||||
data.setdefault("encryption_mode", DEFAULT_ENCRYPTION_MODE.value)
|
||||
data.setdefault("inactivity_timeout", INACTIVITY_TIMEOUT)
|
||||
|
||||
# Migrate legacy hashed_password.enc if present and password_hash is missing
|
||||
@@ -123,12 +118,6 @@ class ConfigManager:
|
||||
config["password_hash"] = password_hash
|
||||
self.save_config(config)
|
||||
|
||||
def set_encryption_mode(self, mode: EncryptionMode) -> None:
|
||||
"""Persist the selected encryption mode in the config."""
|
||||
config = self.load_config(require_pin=False)
|
||||
config["encryption_mode"] = mode.value
|
||||
self.save_config(config)
|
||||
|
||||
def set_inactivity_timeout(self, timeout_seconds: float) -> None:
|
||||
"""Persist the inactivity timeout in seconds."""
|
||||
if timeout_seconds <= 0:
|
||||
|
@@ -696,7 +696,6 @@ class PasswordManager:
|
||||
)
|
||||
|
||||
self.store_hashed_password(password)
|
||||
self.config_manager.set_encryption_mode(self.encryption_mode)
|
||||
logging.info("User password hashed and stored successfully.")
|
||||
|
||||
seed_mgr.encrypt_parent_seed(seed)
|
||||
@@ -1463,7 +1462,6 @@ class PasswordManager:
|
||||
self.vault.set_encryption_manager(new_mgr)
|
||||
self.vault.save_index(index_data)
|
||||
self.config_manager.vault = self.vault
|
||||
config_data["encryption_mode"] = new_mode.value
|
||||
self.config_manager.save_config(config_data)
|
||||
|
||||
self.encryption_manager = new_mgr
|
||||
|
@@ -1,35 +0,0 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import argparse
|
||||
import pytest
|
||||
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
import main
|
||||
from utils.key_derivation import EncryptionMode
|
||||
from password_manager.manager import PasswordManager
|
||||
|
||||
|
||||
def _get_mode(monkeypatch, args=None, cfg=None):
|
||||
if args is None:
|
||||
args = []
|
||||
if cfg is None:
|
||||
cfg = {}
|
||||
monkeypatch.setattr(main, "load_global_config", lambda: cfg)
|
||||
monkeypatch.setattr(sys, "argv", ["prog"] + args)
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--encryption-mode",
|
||||
choices=[m.value for m in EncryptionMode],
|
||||
help="Select encryption mode",
|
||||
)
|
||||
parsed = parser.parse_args()
|
||||
mode_value = cfg.get("encryption_mode", EncryptionMode.SEED_ONLY.value)
|
||||
if parsed.encryption_mode:
|
||||
mode_value = parsed.encryption_mode
|
||||
return EncryptionMode(mode_value)
|
||||
|
||||
|
||||
def test_default_mode_is_seed_only(monkeypatch):
|
||||
mode = _get_mode(monkeypatch)
|
||||
assert mode is EncryptionMode.SEED_ONLY
|
@@ -15,7 +15,7 @@ def _run(argv, monkeypatch):
|
||||
monkeypatch.setattr(main, "load_global_config", lambda: {})
|
||||
called = {}
|
||||
|
||||
def fake_init(self, encryption_mode):
|
||||
def fake_init(self, *args, **kwargs):
|
||||
called["init"] = True
|
||||
|
||||
def fake_export(self, dest):
|
||||
|
11
src/tests/test_default_encryption_mode.py
Normal file
11
src/tests/test_default_encryption_mode.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from password_manager.manager import PasswordManager
|
||||
from utils.key_derivation import DEFAULT_ENCRYPTION_MODE
|
||||
|
||||
|
||||
def test_default_encryption_mode():
|
||||
assert PasswordManager.__init__.__defaults__[0] is DEFAULT_ENCRYPTION_MODE
|
Reference in New Issue
Block a user