Skip to content

Commit edebc43

Browse files
authored
Merge pull request #19 from WesleyE/security-constant-time-comp-on-signature
Use timing attack safe string comparision
2 parents eb755fa + 48e30d8 commit edebc43

File tree

3 files changed

+133
-74
lines changed

3 files changed

+133
-74
lines changed

composer.json

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
{
2-
"name": "linkorb/buckaroo",
3-
"description": "Buckaroo BPE3 API client for PHP. PSR-0 Compliant.",
4-
"homepage": "http://www.github.com/linkorb/buckaroo",
5-
"keywords": ["php", "api", "buckaroo", "psp", "payment"],
6-
"type": "library",
7-
"authors": [
8-
{
9-
"name": "Joost Faassen",
10-
"email": "j.faassen@linkorb.com",
11-
"role": "Development"
12-
}
13-
],
14-
"require": {
15-
"php": ">=5.3.0"
16-
},
17-
"require-dev": {
18-
"phpunit/phpunit": "3.7.*"
19-
},
20-
"autoload": {
21-
"psr-0": {
22-
"LinkORB\\Buckaroo\\": "src/"
23-
}
24-
},
25-
"license": "MIT"
2+
"name": "linkorb/buckaroo",
3+
"description": "Buckaroo BPE3 API client for PHP. PSR-0 Compliant.",
4+
"homepage": "http://www.github.com/linkorb/buckaroo",
5+
"keywords": [
6+
"php",
7+
"api",
8+
"buckaroo",
9+
"psp",
10+
"payment"
11+
],
12+
"type": "library",
13+
"authors": [
14+
{
15+
"name": "Joost Faassen",
16+
"email": "j.faassen@linkorb.com",
17+
"role": "Development"
18+
}
19+
],
20+
"require": {
21+
"php": ">=5.3.0",
22+
"sarciszewski/php-future": "^0.4.2"
23+
},
24+
"require-dev": {
25+
"phpunit/phpunit": "3.7.*"
26+
},
27+
"autoload": {
28+
"psr-0": {
29+
"LinkORB\\Buckaroo\\": "src/"
30+
}
31+
},
32+
"license": "MIT"
2633
}

composer.lock

Lines changed: 94 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LinkORB/Buckaroo/Response/PostResponse.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use LinkORB\Buckaroo\Response;
66
use LinkORB\Buckaroo\SignatureComposer\SignatureComposer;
7+
use Sarciszewski\PHPFuture\Security;
78

89
/**
910
* PostResponse can be used to verify and read post and push responses from Buckaroo.
@@ -60,7 +61,13 @@ public function __construct(array $parameters)
6061
*/
6162
public function isValid(SignatureComposer $composer)
6263
{
63-
return $this->signature === $composer->compose($this->parameters);
64+
// Constant Time String Comparison @see http://php.net/hash_equals
65+
if (!function_exists('hash_equals')) {
66+
// Polyfill for PHP < 5.6
67+
return Security::hashEquals($composer->compose($this->parameters), $this->signature);
68+
} else {
69+
return hash_equals($composer->compose($this->parameters), $this->signature);
70+
}
6471
}
6572

6673
/**

0 commit comments

Comments
 (0)