I asked Pierre Joye, from the PHP team, to review our random number generation function (drupal_random_bytes()).

He suggested to use openssl_random_pseudo_bytes() if available (that's available since PHP 5.3), as it seems to be the only reliable source of random numbers of Windows for now.

Comments

damien tournoud’s picture

Status: Active » Needs review
StatusFileSize
new959 bytes

Something like that should do it.

mustanggb’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs security review

Can't see a reason not to include openssl_random_pseudo_bytes() for a better system agnostic solution

dries’s picture

Status: Needs review » Reviewed & tested by the community

This looks RTBC to me.

It could be good to extend the code comment so it mentions that it is the only reliable source of random numbers on Microsoft Windows.

xjm’s picture

Issue tags: +Needs backport to D7

Note that the patch needs a reroll for core/. If we're doing function_exists(), we can also backport this.

droplet’s picture

anyone do a real test, I read this from PHP.net

FYI, openssl_random_pseudo_bytes() can be incredibly slow under Windows, to the point of being unusable. It frequently times out (>30 seconds execution time) on several Windows machines of mine.

Apparently, it's a known problem with OpenSSL (not PHP specifically).

See: http://www.google.com/search?q=openssl_random_pseudo_bytes+slow

and seems fixed on latest PHP version..
http://stackoverflow.com/questions/1940168/openssl-random-pseudo-bytes-i...

catch’s picture

Status: Reviewed & tested by the community » Needs review

Since we only require 5.3.2, we might want to do a version check here. Moving back to needs review.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Tagging as novice for

  1. Rerolling the patch for the new D8 directory structure.
  2. Adding a version check. You can use version_compare() to check the PHP version, and the result can be cached statically because it will not change within a request. Add the version to the condition in elseif (function_exists('openssl_random_pseudo_bytes')). It should be at least 5.3.2 5.3.4.
kotnik’s picture

Status: Needs work » Needs review
StatusFileSize
new1.74 KB

Here's a patch that does what's been requested in #7.

But, shouldn't it check for PHP 5.3.4 since that version fixed openssl_random_pseudo_bytes locking on Windows?

xjm’s picture

Status: Needs review » Needs work

#8: You're correct, 5.3.4, not 5.3.2. Thanks!

kotnik’s picture

Status: Needs work » Needs review
StatusFileSize
new2.07 KB

Ok, here's the re-roll.

marvil07’s picture

Status: Needs review » Reviewed & tested by the community

Patch is doing what was agreed on comment 7 and 9.

droplet’s picture

Manually tested ??

Maybe bump up PHP version again? PHP 5.3.8 and below has hash collision vulnerability. I think all hosting will bump up their PHP version.

damien tournoud’s picture

The hash collision is unrelated to this patch.

droplet’s picture

@#13,
yes, unrelated :)

marvil07’s picture

Manually tested ??

Yes, from a PHP 5.3.9
Since I do not have a non *nix platform to test the exact case, I have just commented the /dev/urandom if and only left the elseif as if; and it works fine.

dries’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed to 8.x. We may be able to remove the version check before we release 8.x. We'll see.

jromine’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.7 KB

Re-rolled patch for Drupal 7.x.

philosurfer’s picture

Status: Needs review » Reviewed & tested by the community

#17 Works!

Drupal v7.12
PHP v5.3.5
Ubuntu v11.10

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Yay for more randomness. :)

Committed and pushed to 7.x. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -Novice, -Needs security review, -Needs backport to D7

Automatically closed -- issue fixed for 2 weeks with no activity.