fix: use PBKDF2-derived key for legacy Fernet decryption#186
Open
Grizouforever wants to merge 1 commit intolatent-to:mainfrom
Open
fix: use PBKDF2-derived key for legacy Fernet decryption#186Grizouforever wants to merge 1 commit intolatent-to:mainfrom
Grizouforever wants to merge 1 commit intolatent-to:mainfrom
Conversation
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>
a1edb0c to
7b1cb04
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #185
legacy_decryptderives a key from the user's password via PBKDF2 (line 304-306) but then completely ignores it. It callsFernet::generate_key()which creates a random key, making decryption always fail regardless of the correct password.Changes
src/keyfile.rs: ReplaceFernet::generate_key()with URL-safe base64 encoding of the PBKDF2-derived key bytes, constructing a valid Fernet key that matches the Pythoncryptographylibrary'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.