Merge pull request #292 from PR0M3TH3AN/codex/fix-incorrect-checksum-display-in-stats

Improve checksum reporting in stats
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2025-07-05 15:55:20 -04:00
commit 6c9b3c2d5b
2 files changed
+24 -3

No files matched your search

+3 -1
View File
@@ -328,7 +328,9 @@ Back in the Settings menu you can:
* Select `11` to change the inactivity timeout.
* Choose `12` to lock the vault and require re-entry of your password.
* Select `13` to view seed profile stats. The summary lists counts for
passwords, TOTP codes, SSH keys, seed phrases, and PGP keys.
passwords, TOTP codes, SSH keys, seed phrases, and PGP keys. It also shows
whether both the encrypted database and the script itself pass checksum
validation.
* Choose `14` to toggle Secret Mode and set the clipboard clear delay.
* Select `15` to return to the main menu.
+21 -2
View File
@@ -2497,7 +2497,7 @@ class PasswordManager:
stats["entries"] = counts
stats["total_entries"] = len(entries)
# Schema version and checksum status
# Schema version and database checksum status
stats["schema_version"] = data.get("schema_version")
json_content = json.dumps(data, indent=4)
current_checksum = hashlib.sha256(json_content.encode("utf-8")).hexdigest()
@@ -2510,6 +2510,19 @@ class PasswordManager:
stats["checksum_ok"] = False
stats["checksum"] = stored
# Script checksum status
script_path = Path(__file__).resolve()
try:
script_checksum = calculate_checksum(str(script_path))
except Exception:
script_checksum = None
if SCRIPT_CHECKSUM_FILE.exists() and script_checksum:
stored_script = SCRIPT_CHECKSUM_FILE.read_text().strip()
stats["script_checksum_ok"] = stored_script == script_checksum
else:
stats["script_checksum_ok"] = False
# Relay info
cfg = self.config_manager.load_config(require_pin=False)
relays = cfg.get("relays", [])
@@ -2582,7 +2595,13 @@ class PasswordManager:
print(colored(f"Schema version: {stats['schema_version']}", "cyan"))
print(
colored(
f"Checksum ok: {'yes' if stats['checksum_ok'] else 'no'}",
f"Database checksum ok: {'yes' if stats['checksum_ok'] else 'no'}",
"cyan",
)
)
print(
colored(
f"Script checksum ok: {'yes' if stats['script_checksum_ok'] else 'no'}",
"cyan",
)
)