Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 94c13a2

Browse files
committed
Merge branch 'security/zf2016-01'
Patch for ZF2016-01
2 parents 3b045d0 + dbb9c8e commit 94c13a2

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

library/Zend/Crypt/Math.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,8 @@ public static function randBytes($length, $strong = false)
7777
if ($length <= 0) {
7878
return false;
7979
}
80-
if (function_exists('openssl_random_pseudo_bytes')) {
81-
$bytes = openssl_random_pseudo_bytes($length, $usable);
82-
if ($strong === $usable) {
83-
return $bytes;
84-
}
80+
if (function_exists('random_bytes')) { // available in PHP 7
81+
return random_bytes($length);
8582
}
8683
if (function_exists('mcrypt_create_iv')) {
8784
$bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
@@ -134,6 +131,9 @@ public static function randInteger($min, $max, $strong = false)
134131
'The supplied range is too great to generate'
135132
);
136133
}
134+
if (function_exists('random_int')) { // available in PHP 7
135+
return random_int($min, $max);
136+
}
137137
// calculate number of bits required to store range on this machine
138138
$r = $range;
139139
$bits = 0;

library/Zend/Filter/Encrypt/Mcrypt.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
require_once 'Zend/Filter/Encrypt/Interface.php';
2626

27+
/** @see Zend_Crypt_Math */
28+
require_once 'Zend/Crypt/Math.php';
29+
2730
/**
2831
* Encryption adapter for mcrypt
2932
*
@@ -355,9 +358,8 @@ protected function _srand()
355358
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
356359
return;
357360
}
358-
359361
if (!self::$_srandCalled) {
360-
srand((double) microtime() * 1000000);
362+
srand(Zend_Crypt_Math::randInteger(0, PHP_INT_MAX));
361363
self::$_srandCalled = true;
362364
}
363365
}

library/Zend/Form/Element/Hash.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
/** Zend_Form_Element_Xhtml */
2323
require_once 'Zend/Form/Element/Xhtml.php';
2424

25+
/** @see Zend_Crypt_Math */
26+
require_once 'Zend/Crypt/Math.php';
27+
2528
/**
2629
* CSRF form protection
2730
*
@@ -249,10 +252,7 @@ public function render(Zend_View_Interface $view = null)
249252
protected function _generateHash()
250253
{
251254
$this->_hash = md5(
252-
mt_rand(1,1000000)
253-
. $this->getSalt()
254-
. $this->getName()
255-
. mt_rand(1,1000000)
255+
Zend_Crypt_Math::randBytes(32)
256256
);
257257
$this->setValue($this->_hash);
258258
}

library/Zend/Gdata/HttpClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
*/
2626
require_once 'Zend/Http/Client.php';
2727

28+
/** @see Zend_Crypt_Math */
29+
require_once 'Zend/Crypt/Math.php';
30+
2831
/**
2932
* Gdata Http Client object.
3033
*
@@ -210,7 +213,7 @@ public function filterHttpRequest($method, $url, $headers = array(), $body = nul
210213
if ($this->getAuthSubPrivateKeyId() != null) {
211214
// secure AuthSub
212215
$time = time();
213-
$nonce = mt_rand(0, 999999999);
216+
$nonce = Zend_Crypt_Math::randInteger(0, 999999999);
214217
$dataToSign = $method . ' ' . $url . ' ' . $time . ' ' . $nonce;
215218

216219
// compute signature

library/Zend/Ldap/Attribute.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
require_once 'Zend/Ldap/Converter.php';
2626

27+
/** @see Zend_Crypt_Math */
28+
require_once 'Zend/Crypt/Math.php';
29+
2730
/**
2831
* Zend_Ldap_Attribute is a collection of LDAP attribute related functions.
2932
*
@@ -311,7 +314,7 @@ public static function createPassword($password, $hashType = self::PASSWORD_HASH
311314
}
312315
return $password;
313316
case self::PASSWORD_HASH_SSHA:
314-
$salt = substr(sha1(uniqid(mt_rand(), true), true), 0, 4);
317+
$salt = Zend_Crypt_Math::randBytes(4);
315318
$rawHash = sha1($password . $salt, true) . $salt;
316319
$method = '{SSHA}';
317320
break;
@@ -320,7 +323,7 @@ public static function createPassword($password, $hashType = self::PASSWORD_HASH
320323
$method = '{SHA}';
321324
break;
322325
case self::PASSWORD_HASH_SMD5:
323-
$salt = substr(sha1(uniqid(mt_rand(), true), true), 0, 4);
326+
$salt = Zend_Crypt_Math::randBytes(4);
324327
$rawHash = md5($password . $salt, true) . $salt;
325328
$method = '{SMD5}';
326329
break;

library/Zend/OpenId.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
*/
2626
require_once "Zend/Controller/Response/Abstract.php";
2727

28+
/** @see Zend_Crypt_Math */
29+
require_once 'Zend/Crypt/Math.php';
30+
2831
/**
2932
* Static class that contains common utility functions for
3033
* {@link Zend_OpenId_Consumer} and {@link Zend_OpenId_Provider}.
@@ -474,11 +477,7 @@ static public function redirect($url, $params = null,
474477
*/
475478
static public function randomBytes($len)
476479
{
477-
$key = '';
478-
for($i=0; $i < $len; $i++) {
479-
$key .= chr(mt_rand(0, 255));
480-
}
481-
return $key;
480+
return (string) Zend_Crypt_Math::randBytes($len);
482481
}
483482

484483
/**

0 commit comments

Comments
 (0)