diff --git a/composer.json b/composer.json index 0fa24640ae43b12e18e5f1a33654b4e88e8bdc0c..a9e71e4b11044065e63828380d9c3203185e9599 100644 --- a/composer.json +++ b/composer.json @@ -69,6 +69,7 @@ "ext-intl": "*", "ext-xsl": "*", "ext-mbstring": "*", + "ext-openssl": "*", "sjparkinson/static-review": "~4.1", "fabpot/php-cs-fixer": "~1.2", "lusitanian/oauth": "~0.3 <=0.7.0" diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php b/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php index 5bb8e80888b6b6e2be74875430165d6e7c0e6169..4fbeaecc85d18ad7c22f386ecfd00d838d5b904d 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php @@ -97,4 +97,9 @@ class ConfigOptionsListConstants * Key for modules */ const KEY_MODULES = 'modules'; + + /** + * Size of random string generated for store's encryption key + */ + const STORE_KEY_RANDOM_STRING_SIZE = 32; } diff --git a/lib/internal/Magento/Framework/Math/Random.php b/lib/internal/Magento/Framework/Math/Random.php index 03c0727efd26e5938e3b3f2c74bcab7131777050..8ed28cb6021a976337e2e8b9cd6da0c5a98d724c 100644 --- a/lib/internal/Magento/Framework/Math/Random.php +++ b/lib/internal/Magento/Framework/Math/Random.php @@ -24,9 +24,10 @@ class Random /** * Get random string * - * @param int $length + * @param int $length * @param null|string $chars * @return string + * @throws \Magento\Framework\Exception\LocalizedException */ public function getRandomString($length, $chars = null) { @@ -53,12 +54,9 @@ class Random } fclose($fp); } else { - // fallback to mt_rand() if all else fails - mt_srand(10000000 * (double)microtime()); - for ($i = 0, $lc = strlen($chars) - 1; $i < $length; $i++) { - $rand = mt_rand(0, $lc); // random integer from 0 to $lc - $str .= $chars[$rand]; // random character in $chars - } + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Please make sure you have 'openssl' extension installed") + ); } return $str; @@ -70,6 +68,7 @@ class Random * @param $min [optional] * @param $max [optional] * @return int A random integer value between min (or 0) and max + * @throws \Magento\Framework\Exception\LocalizedException */ public static function getRandomNumber($min = 0, $max = null) { @@ -91,9 +90,9 @@ class Random $offset = abs(hexdec($hex) % $range); // random integer from 0 to $range fclose($fp); } else { - // fallback to mt_rand() if all else fails - mt_srand(mt_rand() + (100000000 * microtime()) % PHP_INT_MAX); - return mt_rand($min, $max); // random integer from $min to $max + throw new \Magento\Framework\Exception\LocalizedException( + new \Magento\Framework\Phrase("Please make sure you have 'openssl' extension installed") + ); } return $min + $offset; // random integer from $min to $max diff --git a/lib/internal/Magento/Framework/composer.json b/lib/internal/Magento/Framework/composer.json index 061a0f9c765c68772f18406aa59a0f1bb77a6eb8..3e39db19a43cf4ace7b87d7d46ad2970be4add27 100644 --- a/lib/internal/Magento/Framework/composer.json +++ b/lib/internal/Magento/Framework/composer.json @@ -17,6 +17,7 @@ "ext-curl": "*", "ext-iconv": "*", "ext-gd": "*", + "ext-openssl": "*", "lib-libxml": "*", "ext-xsl": "*" }, diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index db1e6727b703f2bf7cae32b9c0c45007c21e80c9..812cbd1830a38c71f1bcfbebfcd2120915984e1e 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -98,7 +98,7 @@ class ConfigGenerator if ($currentKey === null) { $configData->set( ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, - md5($this->random->getRandomString(10)) + md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE)) ); } }