Skip to content

fix: use PBKDF2-derived key for legacy Fernet decryption#186

Open
Grizouforever wants to merge 1 commit intolatent-to:mainfrom
Grizouforever:fix/legacy-decrypt-use-derived-key
Open

fix: use PBKDF2-derived key for legacy Fernet decryption#186
Grizouforever wants to merge 1 commit intolatent-to:mainfrom
Grizouforever:fix/legacy-decrypt-use-derived-key

Conversation

@Grizouforever
Copy link
Copy Markdown

Summary

Fixes #185

legacy_decrypt derives a key from the user's password via PBKDF2 (line 304-306) but then completely ignores it. It calls Fernet::generate_key() which creates a random key, making decryption always fail regardless of the correct password.

Changes

src/keyfile.rs: Replace Fernet::generate_key() with URL-safe base64 encoding of the PBKDF2-derived key bytes, constructing a valid Fernet key that matches the Python cryptography library's format used by the original bittensor wallet.

Impact

Without this fix, legacy-encrypted keyfiles cannot be decrypted through the Rust wallet implementation. Users migrating from the Python wallet would be unable to access their funds.

The legacy_decrypt function was generating a new random Fernet key via
Fernet::generate_key() instead of using the key derived from PBKDF2.
This made it impossible to decrypt any legacy-encrypted keyfiles since
each decryption attempt would use a different random key.

Fix: encode the derived key bytes as base64url to construct the Fernet
instance, matching the behavior expected for legacy keyfile decryption.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Grizouforever Grizouforever force-pushed the fix/legacy-decrypt-use-derived-key branch from a1edb0c to 7b1cb04 Compare April 11, 2026 19:48
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.

Bug: legacy_decrypt uses random Fernet key instead of password-derived key

1 participant