Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54d7f2d

Browse files
committed
security #17359 do not ship with a custom rng implementation (xabbuh, fabpot)
This PR was merged into the 2.3 branch. Discussion ---------- do not ship with a custom rng implementation Commits ------- b91441c removed obsolete tests, fixed composer.json fcd3160 do not ship with a custom rng implementation
2 parents 5781bbc + b91441c commit 54d7f2d

File tree

4 files changed

+4
-293
lines changed

4 files changed

+4
-293
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"require": {
1919
"php": ">=5.3.3",
2020
"doctrine/common": "~2.4",
21+
"paragonie/random_compat": "~1.0",
2122
"twig/twig": "~1.23|~2.0",
2223
"psr/log": "~1.0"
2324
},

src/Symfony/Component/Security/Core/Util/SecureRandom.php

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Security\Core\Util;
1313

14-
use Psr\Log\LoggerInterface;
15-
1614
/**
1715
* A secure random number generator implementation.
1816
*
@@ -21,98 +19,11 @@
2119
*/
2220
final class SecureRandom implements SecureRandomInterface
2321
{
24-
private $logger;
25-
private $useOpenSsl;
26-
private $seed;
27-
private $seedUpdated;
28-
private $seedLastUpdatedAt;
29-
private $seedFile;
30-
31-
/**
32-
* Constructor.
33-
*
34-
* Be aware that a guessable seed will severely compromise the PRNG
35-
* algorithm that is employed.
36-
*
37-
* @param string $seedFile
38-
* @param LoggerInterface $logger
39-
*/
40-
public function __construct($seedFile = null, LoggerInterface $logger = null)
41-
{
42-
$this->seedFile = $seedFile;
43-
$this->logger = $logger;
44-
45-
$isUnsupportedPhp = '\\' === DIRECTORY_SEPARATOR && PHP_VERSION_ID < 50304;
46-
47-
// determine whether to use OpenSSL
48-
if (!function_exists('random_bytes') && ($isUnsupportedPhp || !function_exists('openssl_random_pseudo_bytes'))) {
49-
if (null !== $this->logger) {
50-
$this->logger->notice('It is recommended that you install the "paragonie/random_compat" library or enable the "openssl" extension for random number generation.');
51-
}
52-
$this->useOpenSsl = false;
53-
} else {
54-
$this->useOpenSsl = true;
55-
}
56-
}
57-
5822
/**
5923
* {@inheritdoc}
6024
*/
6125
public function nextBytes($nbBytes)
6226
{
63-
if (function_exists('random_bytes')) {
64-
return random_bytes($nbBytes);
65-
}
66-
67-
// try OpenSSL
68-
if ($this->useOpenSsl) {
69-
$bytes = openssl_random_pseudo_bytes($nbBytes, $strong);
70-
71-
if (false !== $bytes && true === $strong) {
72-
return $bytes;
73-
}
74-
75-
if (null !== $this->logger) {
76-
$this->logger->info('OpenSSL did not produce a secure random number.');
77-
}
78-
}
79-
80-
// initialize seed
81-
if (null === $this->seed) {
82-
if (null === $this->seedFile) {
83-
throw new \RuntimeException('You need to specify a file path to store the seed.');
84-
}
85-
86-
if (is_file($this->seedFile)) {
87-
list($this->seed, $this->seedLastUpdatedAt) = $this->readSeed();
88-
} else {
89-
$this->seed = uniqid(mt_rand(), true);
90-
$this->updateSeed();
91-
}
92-
}
93-
94-
$bytes = '';
95-
while (strlen($bytes) < $nbBytes) {
96-
static $incr = 1;
97-
$bytes .= hash('sha512', $incr++.$this->seed.uniqid(mt_rand(), true).$nbBytes, true);
98-
$this->seed = base64_encode(hash('sha512', $this->seed.$bytes.$nbBytes, true));
99-
$this->updateSeed();
100-
}
101-
102-
return substr($bytes, 0, $nbBytes);
103-
}
104-
105-
private function readSeed()
106-
{
107-
return json_decode(file_get_contents($this->seedFile));
108-
}
109-
110-
private function updateSeed()
111-
{
112-
if (!$this->seedUpdated && $this->seedLastUpdatedAt < time() - mt_rand(1, 10)) {
113-
file_put_contents($this->seedFile, json_encode(array($this->seed, microtime(true))));
114-
}
115-
116-
$this->seedUpdated = true;
27+
return random_bytes($nbBytes);
11728
}
11829
}

src/Symfony/Component/Security/Tests/Core/Util/SecureRandomTest.php

Lines changed: 0 additions & 201 deletions
This file was deleted.

src/Symfony/Component/Security/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.3",
20+
"paragonie/random_compat": "~1.0",
2021
"symfony/event-dispatcher": "~2.2",
2122
"symfony/http-foundation": "~2.1",
2223
"symfony/http-kernel": "~2.1"
@@ -43,8 +44,7 @@
4344
"symfony/validator": "",
4445
"symfony/routing": "",
4546
"doctrine/dbal": "to use the built-in ACL implementation",
46-
"ircmaxell/password-compat": "",
47-
"paragonie/random_compat": ""
47+
"ircmaxell/password-compat": ""
4848
},
4949
"autoload": {
5050
"psr-0": { "Symfony\\Component\\Security\\": "" },

0 commit comments

Comments
 (0)