mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 07:18:47 +00:00
Fix profile switching to reload parent seed
This commit is contained in:
@@ -121,7 +121,6 @@ class EncryptionManager:
|
||||
logger.error(
|
||||
"Invalid encryption key or corrupted data while decrypting parent seed."
|
||||
)
|
||||
print(colored("Error: Invalid encryption key or corrupted data.", "red"))
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to decrypt parent seed: {e}", exc_info=True)
|
||||
@@ -159,7 +158,6 @@ class EncryptionManager:
|
||||
logger.error(
|
||||
"Invalid encryption key or corrupted data while decrypting data."
|
||||
)
|
||||
print(colored("Error: Invalid encryption key or corrupted data.", "red"))
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to decrypt data: {e}", exc_info=True)
|
||||
@@ -230,7 +228,6 @@ class EncryptionManager:
|
||||
logger.error(
|
||||
"Invalid encryption key or corrupted data while decrypting file."
|
||||
)
|
||||
print(colored("Error: Invalid encryption key or corrupted data.", "red"))
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
@@ -306,27 +303,16 @@ class EncryptionManager:
|
||||
logger.error(
|
||||
f"Failed to decode JSON data from '{file_path}': {e}", exc_info=True
|
||||
)
|
||||
print(
|
||||
colored(
|
||||
f"Error: Failed to decode JSON data from '{file_path}': {e}", "red"
|
||||
)
|
||||
)
|
||||
raise
|
||||
except InvalidToken:
|
||||
logger.error(
|
||||
"Invalid encryption key or corrupted data while decrypting JSON data."
|
||||
)
|
||||
print(colored("Error: Invalid encryption key or corrupted data.", "red"))
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Failed to load JSON data from '{file_path}': {e}", exc_info=True
|
||||
)
|
||||
print(
|
||||
colored(
|
||||
f"Error: Failed to load JSON data from '{file_path}': {e}", "red"
|
||||
)
|
||||
)
|
||||
raise
|
||||
|
||||
def update_checksum(self, relative_path: Optional[Path] = None) -> None:
|
||||
|
@@ -256,22 +256,28 @@ class PasswordManager:
|
||||
sys.exit(1)
|
||||
|
||||
def setup_encryption_manager(
|
||||
self, fingerprint_dir: Path, password: Optional[str] = None
|
||||
) -> None:
|
||||
self,
|
||||
fingerprint_dir: Path,
|
||||
password: Optional[str] = None,
|
||||
*,
|
||||
exit_on_fail: bool = True,
|
||||
) -> bool:
|
||||
"""Set up encryption for the current fingerprint and load the seed."""
|
||||
|
||||
try:
|
||||
if password is None:
|
||||
password = prompt_existing_password("Enter your master password: ")
|
||||
|
||||
if not self.parent_seed:
|
||||
seed_key = derive_key_from_password(password)
|
||||
seed_mgr = EncryptionManager(seed_key, fingerprint_dir)
|
||||
try:
|
||||
self.parent_seed = seed_mgr.decrypt_parent_seed()
|
||||
except Exception:
|
||||
print(colored("Invalid password. Exiting.", "red"))
|
||||
raise
|
||||
seed_key = derive_key_from_password(password)
|
||||
seed_mgr = EncryptionManager(seed_key, fingerprint_dir)
|
||||
try:
|
||||
self.parent_seed = seed_mgr.decrypt_parent_seed()
|
||||
except Exception:
|
||||
msg = "Invalid password for selected seed profile."
|
||||
print(colored(msg, "red"))
|
||||
if exit_on_fail:
|
||||
sys.exit(1)
|
||||
return False
|
||||
|
||||
key = derive_index_key(
|
||||
self.parent_seed,
|
||||
@@ -289,12 +295,17 @@ class PasswordManager:
|
||||
|
||||
self.fingerprint_dir = fingerprint_dir
|
||||
if not self.verify_password(password):
|
||||
print(colored("Invalid password. Exiting.", "red"))
|
||||
sys.exit(1)
|
||||
print(colored("Invalid password.", "red"))
|
||||
if exit_on_fail:
|
||||
sys.exit(1)
|
||||
return False
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to set up EncryptionManager: {e}", exc_info=True)
|
||||
print(colored(f"Error: Failed to set up encryption: {e}", "red"))
|
||||
sys.exit(1)
|
||||
if exit_on_fail:
|
||||
sys.exit(1)
|
||||
return False
|
||||
|
||||
def load_parent_seed(
|
||||
self, fingerprint_dir: Path, password: Optional[str] = None
|
||||
@@ -354,10 +365,15 @@ class PasswordManager:
|
||||
return False # Return False to indicate failure
|
||||
|
||||
# Prompt for master password for the selected seed profile
|
||||
password = prompt_existing_password("Enter your master password: ")
|
||||
password = prompt_existing_password(
|
||||
"Enter the master password for the selected seed profile: "
|
||||
)
|
||||
|
||||
# Set up the encryption manager with the new password and seed profile directory
|
||||
self.setup_encryption_manager(self.fingerprint_dir, password)
|
||||
if not self.setup_encryption_manager(
|
||||
self.fingerprint_dir, password, exit_on_fail=False
|
||||
):
|
||||
return False
|
||||
|
||||
# Initialize BIP85 and other managers
|
||||
self.initialize_bip85()
|
||||
|
@@ -34,7 +34,7 @@ def test_add_and_switch_fingerprint(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
PasswordManager,
|
||||
"setup_encryption_manager",
|
||||
lambda self, d, password=None: None,
|
||||
lambda self, d, password=None, exit_on_fail=True: True,
|
||||
)
|
||||
monkeypatch.setattr(PasswordManager, "load_parent_seed", lambda self, d: None)
|
||||
monkeypatch.setattr(PasswordManager, "initialize_bip85", lambda self: None)
|
||||
|
Reference in New Issue
Block a user