Skip to content

[SECURITY] Randomness updates#4

Open
wiredfool wants to merge 3 commits intopyramation:masterfrom
wiredfool:randomness-updates
Open

[SECURITY] Randomness updates#4
wiredfool wants to merge 3 commits intopyramation:masterfrom
wiredfool:randomness-updates

Conversation

@wiredfool
Copy link

@wiredfool wiredfool commented Sep 30, 2022

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.

* 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)
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.

random() is not suitable for cryptographic use

1 participant