Skip to content

Commit

Permalink
Pull in Symfony's PHP 5.6 polyfill to consistently use hash_equals
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Nov 12, 2015
1 parent 11a1462 commit 611ab24
Show file tree
Hide file tree
Showing 14 changed files with 583 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ Desktop.ini
/libraries/vendor/psr/log/.gitignore
/libraries/vendor/psr/log/composer.json
/libraries/vendor/psr/log/README.md
/libraries/vendor/symfony/polyfill-php56/composer.json
/libraries/vendor/symfony/polyfill-php56/README.md
/libraries/vendor/symfony/polyfill-util/composer.json
/libraries/vendor/symfony/polyfill-util/README.md
/libraries/vendor/symfony/polyfill-util/TestListener.php
/libraries/vendor/symfony/yaml/Tests
/libraries/vendor/symfony/yaml/.gitignore
/libraries/vendor/symfony/yaml/CHANGELOG.md
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"leafo/lessphp": "0.3.9",
"paragonie/random_compat": "~1.0",
"phpmailer/phpmailer": "5.2.9",
"symfony/polyfill-php56": "~1.0",
"symfony/yaml": "2.*"
},
"require-dev": {
Expand Down
112 changes: 110 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 2 additions & 25 deletions libraries/joomla/crypt/crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,8 @@ public static function genRandomBytes($length = 16)
*/
public static function timingSafeCompare($known, $unknown)
{
// Prefer PHP's hash_equals function (PHP 5.6+) if available
if (function_exists('hash_equals'))
{
return hash_equals((string) $known, (string) $unknown);
}

// Prevent issues if string length is 0
$known .= chr(0);
$unknown .= chr(0);

$knownLength = static::safeStrlen($known);
$unknownLength = static::safeStrlen($unknown);

// Set the result to the difference between the lengths
$result = $knownLength - $unknownLength;

// Note that we ALWAYS iterate over the user-supplied length to prevent leaking length info.
for ($i = 0; $i < $unknownLength; $i++)
{
// Using % here is a trick to prevent notices. It's safe, since if the lengths are different, $result is already non-0
$result |= (ord($known[$i % $knownLength]) ^ ord($unknown[$i]));
}

// They are only identical strings if $result is exactly 0...
return $result === 0;
// This function is native in PHP as of 5.6 and backported via the symfony/polyfill-56 library
return hash_equals((string) $known, (string) $unknown);
}

/**
Expand Down
1 change: 1 addition & 0 deletions libraries/vendor/composer/autoload_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
return array(
$vendorDir . '/ircmaxell/password-compat/lib/password.php',
$vendorDir . '/paragonie/random_compat/lib/random.php',
$vendorDir . '/symfony/polyfill-php56/bootstrap.php',
);
2 changes: 2 additions & 0 deletions libraries/vendor/composer/autoload_psr4.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
$baseDir = dirname(dirname($vendorDir));

return array(
'Symfony\\Polyfill\\Util\\' => array($vendorDir . '/symfony/polyfill-util'),
'Symfony\\Polyfill\\Php56\\' => array($vendorDir . '/symfony/polyfill-php56'),
'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'),
'Joomla\\Utilities\\Tests\\' => array($vendorDir . '/joomla/utilities/Tests'),
'Joomla\\Utilities\\' => array($vendorDir . '/joomla/utilities/src'),
Expand Down
112 changes: 112 additions & 0 deletions libraries/vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -813,5 +813,117 @@
"pseudorandom",
"random"
]
},
{
"name": "symfony/polyfill-util",
"version": "v1.0.0",
"version_normalized": "1.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-util.git",
"reference": "4271c55cbc0a77b2641f861b978123e46b3da969"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-util/zipball/4271c55cbc0a77b2641f861b978123e46b3da969",
"reference": "4271c55cbc0a77b2641f861b978123e46b3da969",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"time": "2015-11-04 20:28:58",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Util\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "[email protected]"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony utilities for portability of PHP codes",
"homepage": "https://symfony.com",
"keywords": [
"compat",
"compatibility",
"polyfill",
"shim"
]
},
{
"name": "symfony/polyfill-php56",
"version": "v1.0.0",
"version_normalized": "1.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php56.git",
"reference": "a6bd4770a6967517e6610529e14afaa3111094a3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/a6bd4770a6967517e6610529e14afaa3111094a3",
"reference": "a6bd4770a6967517e6610529e14afaa3111094a3",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"symfony/polyfill-util": "~1.0"
},
"time": "2015-11-04 20:28:58",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php56\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "[email protected]"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
]
}
]
19 changes: 19 additions & 0 deletions libraries/vendor/symfony/polyfill-php56/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2014-2015 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading

0 comments on commit 611ab24

Please sign in to comment.