Skip to content

Commit

Permalink
Merge pull request #19 from WesleyE/security-constant-time-comp-on-si…
Browse files Browse the repository at this point in the history
…gnature

Use timing attack safe string comparision
  • Loading branch information
joostfaassen authored Aug 17, 2016
2 parents eb755fa + 48e30d8 commit edebc43
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 74 deletions.
55 changes: 31 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
{
"name": "linkorb/buckaroo",
"description": "Buckaroo BPE3 API client for PHP. PSR-0 Compliant.",
"homepage": "http://www.github.com/linkorb/buckaroo",
"keywords": ["php", "api", "buckaroo", "psp", "payment"],
"type": "library",
"authors": [
{
"name": "Joost Faassen",
"email": "[email protected]",
"role": "Development"
}
],
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-0": {
"LinkORB\\Buckaroo\\": "src/"
}
},
"license": "MIT"
"name": "linkorb/buckaroo",
"description": "Buckaroo BPE3 API client for PHP. PSR-0 Compliant.",
"homepage": "http://www.github.com/linkorb/buckaroo",
"keywords": [
"php",
"api",
"buckaroo",
"psp",
"payment"
],
"type": "library",
"authors": [
{
"name": "Joost Faassen",
"email": "[email protected]",
"role": "Development"
}
],
"require": {
"php": ">=5.3.0",
"sarciszewski/php-future": "^0.4.2"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-0": {
"LinkORB\\Buckaroo\\": "src/"
}
},
"license": "MIT"
}
143 changes: 94 additions & 49 deletions composer.lock

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

9 changes: 8 additions & 1 deletion src/LinkORB/Buckaroo/Response/PostResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use LinkORB\Buckaroo\Response;
use LinkORB\Buckaroo\SignatureComposer\SignatureComposer;
use Sarciszewski\PHPFuture\Security;

/**
* PostResponse can be used to verify and read post and push responses from Buckaroo.
Expand Down Expand Up @@ -60,7 +61,13 @@ public function __construct(array $parameters)
*/
public function isValid(SignatureComposer $composer)
{
return $this->signature === $composer->compose($this->parameters);
// Constant Time String Comparison @see http://php.net/hash_equals
if (!function_exists('hash_equals')) {
// Polyfill for PHP < 5.6
return Security::hashEquals($composer->compose($this->parameters), $this->signature);
} else {
return hash_equals($composer->compose($this->parameters), $this->signature);
}
}

/**
Expand Down

0 comments on commit edebc43

Please sign in to comment.