Update Random_Compat to the latest version (1.1.6).

See #35665

Built from https://develop.svn.wordpress.org/trunk@36421


git-svn-id: http://core.svn.wordpress.org/trunk@36388 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2016-01-30 00:57:28 +00:00
parent bb6a068e29
commit 1abb98520b
2 changed files with 48 additions and 16 deletions

View File

@ -50,7 +50,7 @@ if (PHP_VERSION_ID < 70000) {
* In order of preference: * In order of preference:
* 1. Use libsodium if available. * 1. Use libsodium if available.
* 2. fread() /dev/urandom if available (never on Windows) * 2. fread() /dev/urandom if available (never on Windows)
* 3. mcrypt_create_iv($bytes, MCRYPT_CREATE_IV) * 3. mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM)
* 4. COM('CAPICOM.Utilities.1')->GetRandom() * 4. COM('CAPICOM.Utilities.1')->GetRandom()
* 5. openssl_random_pseudo_bytes() (absolute last resort) * 5. openssl_random_pseudo_bytes() (absolute last resort)
* *
@ -64,23 +64,47 @@ if (PHP_VERSION_ID < 70000) {
require_once $RandomCompatDIR.'/random_bytes_libsodium_legacy.php'; require_once $RandomCompatDIR.'/random_bytes_libsodium_legacy.php';
} }
} }
if ( /**
!function_exists('random_bytes') && * Reading directly from /dev/urandom:
DIRECTORY_SEPARATOR === '/' && */
@is_readable('/dev/urandom') if (DIRECTORY_SEPARATOR === '/') {
) {
// DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast // DIRECTORY_SEPARATOR === '/' on Unix-like OSes -- this is a fast
// way to exclude Windows. // way to exclude Windows.
// $RandomCompatUrandom = true;
// Error suppression on is_readable() in case of an open_basedir or $RandomCompat_basedir = ini_get('open_basedir');
// safe_mode failure. All we care about is whether or not we can if (!empty($RandomCompat_basedir)) {
// read it at this point. If the PHP environment is going to panic $RandomCompat_open_basedir = explode(
// over trying to see if the file can be read in the first place, PATH_SEPARATOR,
// that is not helpful to us here. strtolower($RandomCompat_basedir)
);
$RandomCompatUrandom = in_array(
'/dev',
$RandomCompat_open_basedir
);
$RandomCompat_open_basedir = null;
}
if (
!function_exists('random_bytes') &&
$RandomCompatUrandom &&
@is_readable('/dev/urandom')
) {
// Error suppression on is_readable() in case of an open_basedir
// or safe_mode failure. All we care about is whether or not we
// can read it at this point. If the PHP environment is going to
// panic over trying to see if the file can be read in the first
// place, that is not helpful to us here.
// See random_bytes_dev_urandom.php // See random_bytes_dev_urandom.php
require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php'; require_once $RandomCompatDIR.'/random_bytes_dev_urandom.php';
} }
// Unset variables after use
$RandomCompatUrandom = null;
$RandomCompat_basedir = null;
}
/**
* mcrypt_create_iv()
*/
if ( if (
!function_exists('random_bytes') && !function_exists('random_bytes') &&
PHP_VERSION_ID >= 50307 && PHP_VERSION_ID >= 50307 &&
@ -113,6 +137,10 @@ if (PHP_VERSION_ID < 70000) {
$RandomCompat_disabled_classes = null; $RandomCompat_disabled_classes = null;
$RandomCompatCOMtest = null; $RandomCompatCOMtest = null;
} }
/**
* openssl_random_pseudo_bytes()
*/
if ( if (
!function_exists('random_bytes') && !function_exists('random_bytes') &&
extension_loaded('openssl') && extension_loaded('openssl') &&
@ -129,12 +157,16 @@ if (PHP_VERSION_ID < 70000) {
// See random_bytes_openssl.php // See random_bytes_openssl.php
require_once $RandomCompatDIR.'/random_bytes_openssl.php'; require_once $RandomCompatDIR.'/random_bytes_openssl.php';
} }
/**
* throw new Exception
*/
if (!function_exists('random_bytes')) { if (!function_exists('random_bytes')) {
/** /**
* We don't have any more options, so let's throw an exception right now * We don't have any more options, so let's throw an exception right now
* and hope the developer won't let it fail silently. * and hope the developer won't let it fail silently.
*/ */
function random_bytes() function random_bytes($length)
{ {
throw new Exception( throw new Exception(
'There is no suitable CSPRNG installed on your system' 'There is no suitable CSPRNG installed on your system'

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.5-alpha-36420'; $wp_version = '4.5-alpha-36421';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.