-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
SecureRandom security #10759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Here is a quick mockup about secure random number generation: https://gist.github.com/timoh6/11169328 |
I'd wager openssl is much more commonly installed than mcrypt. We'll definitively need one of these two for Windows support (BTW Maybe @ircmaxell could offer a more informed opinion. |
The difference between mcrypt_create_iv and openssl_random_pseudo_bytes is that mcrypt_create_iv is not a userspace CSPRNG and openssl_random_pseudo_bytes is. Ideally we should indeed avoid userspace CSPRNGs. It is a shame there is no universal functionality in PHP core to gather secure random bytes, but we can do pretty good with mcrypt_create_iv or reading straight from /dev/urandom. I'm not too happy to recommend the use of openssl_random_pseudo_bytes, but maybe if we must satisfy broader compatibility the openssl_random_pseudo_bytes might come to question. This needs more discussion. |
@realityking first off, @timoh6's opinion is typically quite informed (to say the least), so ;-). With that said, I've found that the typical case is that mcrypt/openssl support is typically pretty co-related. As in users typically have either neither or both of them installed. The internal method that's used is actually quite significantly weak, as it only ever uses a minimal amount of entropy. See The "php security book"'s chapter on insufficient entropy. Basically, the problem comes that That means the actual entropy contained in the "seed file" will be trivially small. My suggestion would be to either:
OR
As far as the "mcrypt vs openssl" debate, mcrypt is a very thin proxy over |
Just to preemptively prevent any bad blood, I meant more informed than my opinion, not @timoh6's. |
Closing as we are now using |
The SecureRandom class (from Symfony\Component\Security\Core\Util) falls back to a home made crypto construction if openssl_random_pseudo_bytes() is not available.
This should not be the case, but instead we should try to gather secure random bytes from the OS (via reading from /dev/urandom or using mcrypt_create_iv() with MCRYPT_DEV_URANDOM).
The current implementation tries to use secure random bytes from OpenSSL (before falling back to the home made construction), but this is also questionable, because of the added complexity that the OpenSSL extension has (and OpenSSL has had its share of security issues).
We should follow "the standard" and gather the random bytes straight from the OS (no need to use OpenSSL as a middleman). This way there is no added surface for implementation errors and bugs, and we can benefit from the security audits that the OS level random number generatos has had.
With that said, I suggest we update the current nextBytes() method to try first mcrypt_create_iv and then /dev/urandom. If both attempts fail, exit immediately with an error (otherwise it is probably just a false sense of security).
The text was updated successfully, but these errors were encountered: