Merged
Conversation
paolino
approved these changes
Mar 11, 2025
| => PBKDF2Config h | ||
| -> ByteString | ||
| -- ^ payload | ||
| -- ^ password |
| \(TestCase algo' iters' keyL' ivL' passwd' salt') -> do | ||
| let nulsToAdd = 64 - BS.length passwd' | ||
| let passwdPadded = passwd' <> BS.replicate nulsToAdd 0 | ||
| generateKey (PBKDF2Config algo' iters' keyL' ivL') passwd' salt' |
| fromHexToM :: Text -> Maybe ByteString | ||
| fromHexToM = rightToMaybe . convertFromBase Base16 . T.encodeUtf8 | ||
|
|
||
| newtype MetadataPassword = MetadataPassword {unPassword :: ByteString} |
Collaborator
There was a problem hiding this comment.
Can we just use a generator and avoid creating types ? Just 2c
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.
The bug was triggered when metadata password shorter than 64 bytes was compared with the same password padded with /NUL (in hex 0x00). It turn out that this is corner case that could appear, indeed!
Reason:
In impl of KDF we are using, ie. PBKDF2 (https://www.ietf.org/rfc/rfc2898.txt) is about successive hashing of the message. And here password (P) and salt (S) are undergoing :
The culprit is bitwise OR operation. As /NUL is 0x00 it is the same as automatic padding that is done when P is not 64 bytes!
cyrptographic-primitivesMetadataPasswordwas introduced inMetadataEncryptionSpecto enforce using alphanumeric character (btw. recommended by openssl):-> see https://docs.openssl.org/3.1/man1/openssl-kdf/#options
Comments
Issue Number
fix #5017