Skip to content

Harden passcode hashing with PBKDF2#25

Open
batyka2001 wants to merge 1 commit into
teidesu:mainfrom
Dristal-Kakals:fix
Open

Harden passcode hashing with PBKDF2#25
batyka2001 wants to merge 1 commit into
teidesu:mainfrom
Dristal-Kakals:fix

Conversation

@batyka2001

@batyka2001 batyka2001 commented Jul 16, 2026

Copy link
Copy Markdown

SecretHash now uses PBKDF2-HMAC-SHA256 (120k iterations) instead of a single salted SHA-256 round, and compares in constant time. Guards the fork-local passcodes, panic code and hidden-chats exit code against offline brute force if the prefs file is extracted.

Old salted-SHA-256 records (same layout across all prior versions) are detected by the pbkdf2 prefix being absent, verified against the legacy scheme, and transparently rehashed to PBKDF2 on the next correct entry — no user is locked out.

Summary by CodeRabbit

  • Security Enhancements
    • Secrets are now protected using a stronger PBKDF2-HMAC-SHA256 hashing method.
    • Existing secrets remain compatible and are automatically upgraded to the stronger format after successful verification.
    • Hash verification now uses constant-time comparisons to improve protection against timing attacks.

SecretHash now uses PBKDF2-HMAC-SHA256 (120k iterations) instead of a
single salted SHA-256 round, and compares in constant time. Guards the
fork-local passcodes, panic code and hidden-chats exit code against
offline brute force if the prefs file is extracted.

Old salted-SHA-256 records (same layout across all prior versions) are
detected by the pbkdf2 prefix being absent, verified against the legacy
scheme, and transparently rehashed to PBKDF2 on the next correct entry
— no user is locked out.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SecretHash replaces new salted SHA-256 hashes with versioned PBKDF2-HMAC-SHA256 hashes, verifies both formats using constant-time comparison, and upgrades successful legacy verifications.

Changes

Secret hash migration

Layer / File(s) Summary
PBKDF2 format and generation
src/kotlin/helpers/security/SecretHash.kt
Adds PBKDF2 parameters and encoded hash generation while retaining legacy SHA-256 verification; storage now writes PBKDF2 hashes with the existing random salt.
Verification and legacy migration
src/kotlin/helpers/security/SecretHash.kt
Verification detects PBKDF2 hashes, parses their iteration count, compares results in constant time, and re-stores matching legacy hashes in the new format.

Estimated code review effort: 3 (Moderate) | ~15 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: upgrading passcode hashing to PBKDF2.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/kotlin/helpers/security/SecretHash.kt`:
- Around line 13-15: Rename the Kotlin helper object SecretHash to
SecretHashUtils and rename its source file accordingly. Update every reference
to the object so callers continue using the renamed algorithm helper without
changing its behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20450aa8-9698-4a46-bb1f-072f431bbcd8

📥 Commits

Reviewing files that changed from the base of the PR and between 55495fe and d2a6cde.

📒 Files selected for processing (1)
  • src/kotlin/helpers/security/SecretHash.kt

Comment thread src/kotlin/helpers/security/SecretHash.kt
@teidesu

teidesu commented Jul 17, 2026

Copy link
Copy Markdown
Owner

one mild issue with this: in paranoia mode, the exit code is hashed using the same SecretHelper. sha256 is ~free, but pbkdf2 is kinda not, and re-hashing input on every keystroke will inevitably cause jank. can we do something about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants