Open
Conversation
* Breaking changes -- function signatures all take a bytea for secrets now. * [SECURITY] random_base32 is removed, this was giving n characters of 5 bytes of entropy, NOT n characters * 8 bits of entropy * Generate_secret now returns a raw bytea of n bits of randomness * Verify/generate now take a bytea of raw key text, not a base32 version. * The URL function returns the base32 version. * Pad_secret was unused, and was removed * base32_to_hex was unused after passing bytea around, so removed. * Anything with a variable default is volatile (now(), we'd expect different results every time it's called, in a different transaction anyway)
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.
Fixes #2, #3, and additional security issue.
So, a couple of things here -- Added pgcrypto's get_random_bytes, then removed it because your random_base32 was giving n random characters from the base32 alphabet, not encoding 8*n bits of entropy in a base32 string.
There's an implementation here of a constant time comparison in pure sql that fixes that issues as well.
Finally, to get this working with existing (not generated here) keys and matching an existing python implementation, I've ripped out all of the text<->base32 in the generation and verification path, leaving it as native bytea. The url reporting then is changed to base32 encode the key, so that it's usable there.
I looked at your base32 implementation, but I'm pretty sure that it's incorrect when attempting to base32 encode a bytea, it appears that you're base32 encoding the text representation of a bytea.