From 782d1155c62c0a879bf587c7e40c3a13bcf6879c Mon Sep 17 00:00:00 2001 From: David Rothstein Date: Wed, 20 Nov 2013 15:45:59 -0500 Subject: Drupal 7.24 --- modules/openid/openid.inc | 23 +++++------------------ modules/openid/openid.test | 7 ------- modules/openid/tests/openid_test.install | 2 +- 3 files changed, 6 insertions(+), 26 deletions(-) (limited to 'modules/openid') diff --git a/modules/openid/openid.inc b/modules/openid/openid.inc index 74a08d576..d7ef663b4 100644 --- a/modules/openid/openid.inc +++ b/modules/openid/openid.inc @@ -380,6 +380,9 @@ function _openid_parse_message($message) { /** * Return a nonce value - formatted per OpenID spec. + * + * NOTE: This nonce is not cryptographically secure and only suitable for use + * by the test framework. */ function _openid_nonce() { // YYYY-MM-DDThh:mm:ssZ, plus some optional extra unique characters. @@ -549,7 +552,7 @@ function _openid_dh_rand($stop) { } do { - $bytes = "\x00" . _openid_get_bytes($nbytes); + $bytes = "\x00" . drupal_random_bytes($nbytes); $n = _openid_dh_binary_to_long($bytes); // Keep looping if this value is in the low duplicated range. } while (_openid_math_cmp($n, $duplicate) < 0); @@ -558,23 +561,7 @@ function _openid_dh_rand($stop) { } function _openid_get_bytes($num_bytes) { - $f = &drupal_static(__FUNCTION__); - $bytes = ''; - if (!isset($f)) { - $f = @fopen(OPENID_RAND_SOURCE, "r"); - } - if (!$f) { - // pseudorandom used - $bytes = ''; - for ($i = 0; $i < $num_bytes; $i += 4) { - $bytes .= pack('L', mt_rand()); - } - $bytes = substr($bytes, 0, $num_bytes); - } - else { - $bytes = fread($f, $num_bytes); - } - return $bytes; + return drupal_random_bytes($num_bytes); } function _openid_response($str = NULL) { diff --git a/modules/openid/openid.test b/modules/openid/openid.test index 292c5317c..41af3f82f 100644 --- a/modules/openid/openid.test +++ b/modules/openid/openid.test @@ -694,13 +694,6 @@ class OpenIDTestCase extends DrupalWebTestCase { $this->assertEqual(_openid_dh_xorsecret('123456790123456790123456790', "abc123ABC\x00\xFF"), "\xa4'\x06\xbe\xf1.\x00y\xff\xc2\xc1", '_openid_dh_xorsecret() returned expected result.'); } - /** - * Test _openid_get_bytes(). - */ - function testOpenidGetBytes() { - $this->assertEqual(strlen(_openid_get_bytes(20)), 20, '_openid_get_bytes() returned expected result.'); - } - /** * Test _openid_signature(). */ diff --git a/modules/openid/tests/openid_test.install b/modules/openid/tests/openid_test.install index 3bd4978f1..d30e2dc4d 100644 --- a/modules/openid/tests/openid_test.install +++ b/modules/openid/tests/openid_test.install @@ -13,5 +13,5 @@ function openid_test_install() { // Generate a MAC key (Message Authentication Code) used for signing messages. // The variable is base64-encoded, because variables cannot contain non-UTF-8 // data. - variable_set('openid_test_mac_key', base64_encode(_openid_get_bytes(20))); + variable_set('openid_test_mac_key', drupal_random_key(20)); } -- cgit v1.2.3