summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGraham Campbell <graham@mineuk.com>2014-11-30 21:18:40 +0000
committerNicolas Grekas <nicolas.grekas@gmail.com>2014-12-30 11:17:11 +0100
commitd278266e82082b8605dffb29151bd77b9f3d334f (patch)
treef03b1102eb11208ab010e3f57ba036e555a167e6
parentcf187660de37c0dc7a4dec4475845c314e8fb91f (diff)
downloadsymfony-security-d278266e82082b8605dffb29151bd77b9f3d334f.zip
symfony-security-d278266e82082b8605dffb29151bd77b9f3d334f.tar.gz
symfony-security-d278266e82082b8605dffb29151bd77b9f3d334f.tar.bz2
[3.0] Removed some old hacks
-rw-r--r--Core/Encoder/BCryptPasswordEncoder.php4
-rw-r--r--Core/Encoder/Pbkdf2PasswordEncoder.php26
-rw-r--r--Core/Tests/Encoder/BCryptPasswordEncoderTest.php11
-rw-r--r--Core/Util/SecureRandom.php4
-rw-r--r--Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php4
-rw-r--r--Csrf/TokenStorage/NativeSessionTokenStorage.php6
6 files changed, 3 insertions, 52 deletions
diff --git a/Core/Encoder/BCryptPasswordEncoder.php b/Core/Encoder/BCryptPasswordEncoder.php
index d2b0319..c0c8fe0 100644
--- a/Core/Encoder/BCryptPasswordEncoder.php
+++ b/Core/Encoder/BCryptPasswordEncoder.php
@@ -34,10 +34,6 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
*/
public function __construct($cost)
{
- if (!function_exists('password_hash')) {
- throw new \RuntimeException('To use the BCrypt encoder, you need to upgrade to PHP 5.5 or install the "ircmaxell/password-compat" via Composer.');
- }
-
$cost = (int) $cost;
if ($cost < 4 || $cost > 31) {
throw new \InvalidArgumentException('Cost must be in the range of 4-31.');
diff --git a/Core/Encoder/Pbkdf2PasswordEncoder.php b/Core/Encoder/Pbkdf2PasswordEncoder.php
index dac1cad..8422a4b 100644
--- a/Core/Encoder/Pbkdf2PasswordEncoder.php
+++ b/Core/Encoder/Pbkdf2PasswordEncoder.php
@@ -64,11 +64,7 @@ class Pbkdf2PasswordEncoder extends BasePasswordEncoder
throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
}
- if (function_exists('hash_pbkdf2')) {
- $digest = hash_pbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length, true);
- } else {
- $digest = $this->hashPbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length);
- }
+ $digest = hash_pbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length, true);
return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest);
}
@@ -80,24 +76,4 @@ class Pbkdf2PasswordEncoder extends BasePasswordEncoder
{
return !$this->isPasswordTooLong($raw) && $this->comparePasswords($encoded, $this->encodePassword($raw, $salt));
}
-
- private function hashPbkdf2($algorithm, $password, $salt, $iterations, $length = 0)
- {
- // Number of blocks needed to create the derived key
- $blocks = ceil($length / strlen(hash($algorithm, null, true)));
- $digest = '';
-
- for ($i = 1; $i <= $blocks; $i++) {
- $ib = $block = hash_hmac($algorithm, $salt.pack('N', $i), $password, true);
-
- // Iterations
- for ($j = 1; $j < $iterations; $j++) {
- $ib ^= ($block = hash_hmac($algorithm, $block, $password, true));
- }
-
- $digest .= $ib;
- }
-
- return substr($digest, 0, $this->length);
- }
}
diff --git a/Core/Tests/Encoder/BCryptPasswordEncoderTest.php b/Core/Tests/Encoder/BCryptPasswordEncoderTest.php
index 2f7b845..4d9ca6d 100644
--- a/Core/Tests/Encoder/BCryptPasswordEncoderTest.php
+++ b/Core/Tests/Encoder/BCryptPasswordEncoderTest.php
@@ -47,8 +47,6 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase
public function testResultLength()
{
- $this->skipIfPhpVersionIsNotSupported();
-
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
$result = $encoder->encodePassword(self::PASSWORD, null);
$this->assertEquals(60, strlen($result));
@@ -56,21 +54,12 @@ class BCryptPasswordEncoderTest extends \PHPUnit_Framework_TestCase
public function testValidation()
{
- $this->skipIfPhpVersionIsNotSupported();
-
$encoder = new BCryptPasswordEncoder(self::VALID_COST);
$result = $encoder->encodePassword(self::PASSWORD, null);
$this->assertTrue($encoder->isPasswordValid($result, self::PASSWORD, null));
$this->assertFalse($encoder->isPasswordValid($result, 'anotherPassword', null));
}
- private function skipIfPhpVersionIsNotSupported()
- {
- if (PHP_VERSION_ID < 50307) {
- $this->markTestSkipped('Requires PHP >= 5.3.7');
- }
- }
-
/**
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
*/
diff --git a/Core/Util/SecureRandom.php b/Core/Util/SecureRandom.php
index aefc888..f4167e4 100644
--- a/Core/Util/SecureRandom.php
+++ b/Core/Util/SecureRandom.php
@@ -43,9 +43,7 @@ final class SecureRandom implements SecureRandomInterface
$this->logger = $logger;
// determine whether to use OpenSSL
- if (defined('PHP_WINDOWS_VERSION_BUILD') && PHP_VERSION_ID < 50304) {
- $this->useOpenSsl = false;
- } elseif (!function_exists('openssl_random_pseudo_bytes')) {
+ if (!function_exists('openssl_random_pseudo_bytes')) {
if (null !== $this->logger) {
$this->logger->notice('It is recommended that you enable the "openssl" extension for random number generation.');
}
diff --git a/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php b/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php
index 0039deb..ef49f2f 100644
--- a/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php
+++ b/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php
@@ -52,10 +52,6 @@ class NativeSessionTokenStorageTest extends \PHPUnit_Framework_TestCase
public function testStoreTokenInClosedSessionWithExistingSessionId()
{
- if (PHP_VERSION_ID < 50400) {
- $this->markTestSkipped('This test requires PHP 5.4 or later.');
- }
-
session_id('foobar');
$this->assertSame(PHP_SESSION_NONE, session_status());
diff --git a/Csrf/TokenStorage/NativeSessionTokenStorage.php b/Csrf/TokenStorage/NativeSessionTokenStorage.php
index 60145c6..4229bb6 100644
--- a/Csrf/TokenStorage/NativeSessionTokenStorage.php
+++ b/Csrf/TokenStorage/NativeSessionTokenStorage.php
@@ -108,11 +108,7 @@ class NativeSessionTokenStorage implements TokenStorageInterface
private function startSession()
{
- if (PHP_VERSION_ID >= 50400) {
- if (PHP_SESSION_NONE === session_status()) {
- session_start();
- }
- } elseif (!session_id()) {
+ if (PHP_SESSION_NONE === session_status()) {
session_start();
}