Skip to content

Commit dea8f08

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: removed obsolete tests, fixed composer.json do not ship with a custom rng implementation
2 parents 5c29e71 + 54d7f2d commit dea8f08

File tree

4 files changed

+4
-291
lines changed

4 files changed

+4
-291
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.9",
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/Tests/Util/SecureRandomTest.php

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

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

Lines changed: 1 addition & 88 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,96 +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-
// determine whether to use OpenSSL
46-
if (!function_exists('random_bytes') && !function_exists('openssl_random_pseudo_bytes')) {
47-
if (null !== $this->logger) {
48-
$this->logger->notice('It is recommended that you install the "paragonie/random_compat" library or enable the "openssl" extension for random number generation.');
49-
}
50-
$this->useOpenSsl = false;
51-
} else {
52-
$this->useOpenSsl = true;
53-
}
54-
}
55-
5622
/**
5723
* {@inheritdoc}
5824
*/
5925
public function nextBytes($nbBytes)
6026
{
61-
if (function_exists('random_bytes')) {
62-
return random_bytes($nbBytes);
63-
}
64-
65-
// try OpenSSL
66-
if ($this->useOpenSsl) {
67-
$bytes = openssl_random_pseudo_bytes($nbBytes, $strong);
68-
69-
if (false !== $bytes && true === $strong) {
70-
return $bytes;
71-
}
72-
73-
if (null !== $this->logger) {
74-
$this->logger->info('OpenSSL did not produce a secure random number.');
75-
}
76-
}
77-
78-
// initialize seed
79-
if (null === $this->seed) {
80-
if (null === $this->seedFile) {
81-
throw new \RuntimeException('You need to specify a file path to store the seed.');
82-
}
83-
84-
if (is_file($this->seedFile)) {
85-
list($this->seed, $this->seedLastUpdatedAt) = $this->readSeed();
86-
} else {
87-
$this->seed = uniqid(mt_rand(), true);
88-
$this->updateSeed();
89-
}
90-
}
91-
92-
$bytes = '';
93-
while (strlen($bytes) < $nbBytes) {
94-
static $incr = 1;
95-
$bytes .= hash('sha512', $incr++.$this->seed.uniqid(mt_rand(), true).$nbBytes, true);
96-
$this->seed = base64_encode(hash('sha512', $this->seed.$bytes.$nbBytes, true));
97-
$this->updateSeed();
98-
}
99-
100-
return substr($bytes, 0, $nbBytes);
101-
}
102-
103-
private function readSeed()
104-
{
105-
return json_decode(file_get_contents($this->seedFile));
106-
}
107-
108-
private function updateSeed()
109-
{
110-
if (!$this->seedUpdated && $this->seedLastUpdatedAt < time() - mt_rand(1, 10)) {
111-
file_put_contents($this->seedFile, json_encode(array($this->seed, microtime(true))));
112-
}
113-
114-
$this->seedUpdated = true;
27+
return random_bytes($nbBytes);
11528
}
11629
}

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.9",
20+
"paragonie/random_compat": "~1.0",
2021
"symfony/event-dispatcher": "~2.2",
2122
"symfony/http-foundation": "~2.1",
2223
"symfony/http-kernel": "~2.4"
@@ -46,8 +47,7 @@
4647
"symfony/routing": "For using the HttpUtils class to create sub-requests, redirect the user, and match URLs",
4748
"doctrine/dbal": "For using the built-in ACL implementation",
4849
"symfony/expression-language": "For using the expression voter",
49-
"ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5",
50-
"paragonie/random_compat": ""
50+
"ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5"
5151
},
5252
"autoload": {
5353
"psr-4": { "Symfony\\Component\\Security\\": "" },

0 commit comments

Comments
 (0)