Changeset 36886 for trunk/src/wp-includes/random_compat/random.php
- Timestamp:
- 03/08/2016 05:14:52 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/random_compat/random.php
r36421 r36886 1 1 <?php 2 2 /** 3 * Random_* Compatibility Library 3 * Random_* Compatibility Library 4 4 * for using the new PHP 7 random_* API in PHP 5 projects 5 * 5 * 6 * @version 1.2.1 7 * @released 2016-02-29 8 * 6 9 * The MIT License (MIT) 7 * 10 * 8 11 * Copyright (c) 2015 Paragon Initiative Enterprises 9 * 12 * 10 13 * Permission is hereby granted, free of charge, to any person obtaining a copy 11 14 * of this software and associated documentation files (the "Software"), to deal … … 14 17 * copies of the Software, and to permit persons to whom the Software is 15 18 * furnished to do so, subject to the following conditions: 16 * 19 * 17 20 * The above copyright notice and this permission notice shall be included in 18 21 * all copies or substantial portions of the Software. 19 * 22 * 20 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, … … 30 33 // This constant was introduced in PHP 5.2.7 31 34 $RandomCompatversion = explode('.', PHP_VERSION); 32 define('PHP_VERSION_ID', ($RandomCompatversion[0] * 10000 + $RandomCompatversion[1] * 100 + $RandomCompatversion[2])); 35 define( 36 'PHP_VERSION_ID', 37 $RandomCompatversion[0] * 10000 38 + $RandomCompatversion[1] * 100 39 + $RandomCompatversion[2] 40 ); 33 41 $RandomCompatversion = null; 34 42 } 43 35 44 if (PHP_VERSION_ID < 70000) { 45 36 46 if (!defined('RANDOM_COMPAT_READ_BUFFER')) { 37 47 define('RANDOM_COMPAT_READ_BUFFER', 8); 38 48 } 49 39 50 $RandomCompatDIR = dirname(__FILE__); 51 40 52 require_once $RandomCompatDIR.'/byte_safe_strings.php'; 41 53 require_once $RandomCompatDIR.'/cast_to_int.php'; 42 54 require_once $RandomCompatDIR.'/error_polyfill.php'; 55 43 56 if (!function_exists('random_bytes')) { 44 57 /** 45 58 * PHP 5.2.0 - 5.6.x way to implement random_bytes() 46 * 59 * 47 60 * We use conditional statements here to define the function in accordance 48 61 * to the operating environment. It's a micro-optimization. 49 * 62 * 50 63 * In order of preference: 51 64 * 1. Use libsodium if available. … … 54 67 * 4. COM('CAPICOM.Utilities.1')->GetRandom() 55 68 * 5. openssl_random_pseudo_bytes() (absolute last resort) 56 * 69 * 57 70 * See ERRATA.md for our reasoning behind this particular order 58 71 */ … … 65 78 } 66 79 } 80 67 81 /** 68 82 * Reading directly from /dev/urandom: … … 73 87 $RandomCompatUrandom = true; 74 88 $RandomCompat_basedir = ini_get('open_basedir'); 89 75 90 if (!empty($RandomCompat_basedir)) { 76 91 $RandomCompat_open_basedir = explode( … … 84 99 $RandomCompat_open_basedir = null; 85 100 } 101 86 102 if ( 87 !function_exists('random_bytes') && 88 $RandomCompatUrandom && 103 !function_exists('random_bytes') 104 && 105 $RandomCompatUrandom 106 && 89 107 @is_readable('/dev/urandom') 90 108 ) { 91 109 // Error suppression on is_readable() in case of an open_basedir 92 110 // or safe_mode failure. All we care about is whether or not we 93 // can read it at this point. If the PHP environment is going to 94 // panic over trying to see if the file can be read in the first 111 // can read it at this point. If the PHP environment is going to 112 // panic over trying to see if the file can be read in the first 95 113 // place, that is not helpful to us here. 96 114 … … 99 117 } 100 118 // Unset variables after use 119 $RandomCompat_basedir = null; 101 120 $RandomCompatUrandom = null; 102 $RandomCompat_basedir = null; 103 } 104 121 } 122 105 123 /** 106 124 * mcrypt_create_iv() 107 125 */ 108 126 if ( 109 !function_exists('random_bytes') && 110 PHP_VERSION_ID >= 50307 && 127 !function_exists('random_bytes') 128 && 129 PHP_VERSION_ID >= 50307 130 && 111 131 extension_loaded('mcrypt') 112 132 ) { 113 // See random_bytes_mcrypt.php 114 require_once $RandomCompatDIR.'/random_bytes_mcrypt.php'; 115 } 133 // Prevent this code from hanging indefinitely on non-Windows; 134 // see https://bugs.php.net/bug.php?id=69833 135 if ( 136 DIRECTORY_SEPARATOR !== '/' || 137 (PHP_VERSION_ID <= 50609 || PHP_VERSION_ID >= 50613) 138 ) { 139 // See random_bytes_mcrypt.php 140 require_once $RandomCompatDIR.'/random_bytes_mcrypt.php'; 141 } 142 } 143 116 144 if ( 117 !function_exists('random_bytes') && 118 extension_loaded('com_dotnet') && 145 !function_exists('random_bytes') 146 && 147 extension_loaded('com_dotnet') 148 && 119 149 class_exists('COM') 120 150 ) { 121 151 $RandomCompat_disabled_classes = preg_split( 122 '#\s*,\s*#', 152 '#\s*,\s*#', 123 153 strtolower(ini_get('disable_classes')) 124 154 ); 125 155 126 156 if (!in_array('com', $RandomCompat_disabled_classes)) { 127 157 try { … … 138 168 $RandomCompatCOMtest = null; 139 169 } 140 170 141 171 /** 142 172 * openssl_random_pseudo_bytes() 143 173 */ 144 174 if ( 145 !function_exists('random_bytes') &&146 extension_loaded('openssl') &&147 175 ( 148 176 // Unix-like with PHP >= 5.3.0 or 149 177 ( 150 DIRECTORY_SEPARATOR === '/' && 178 DIRECTORY_SEPARATOR === '/' 179 && 151 180 PHP_VERSION_ID >= 50300 152 ) || 181 ) 182 || 153 183 // Windows with PHP >= 5.4.1 154 184 PHP_VERSION_ID >= 50401 155 185 ) 186 && 187 !function_exists('random_bytes') 188 && 189 extension_loaded('openssl') 156 190 ) { 157 191 // See random_bytes_openssl.php 158 192 require_once $RandomCompatDIR.'/random_bytes_openssl.php'; 159 193 } 160 194 161 195 /** 162 196 * throw new Exception … … 175 209 } 176 210 } 211 177 212 if (!function_exists('random_int')) { 178 213 require_once $RandomCompatDIR.'/random_int.php'; 179 214 } 215 180 216 $RandomCompatDIR = null; 181 217 }
Note: See TracChangeset
for help on using the changeset viewer.