Skip to content

Commit

Permalink
chore: Fix usage of validateHMAC (#679)
Browse files Browse the repository at this point in the history
Co-authored-by: jillingk <[email protected]>
  • Loading branch information
cjobeilicampings and jillingk authored Jul 29, 2024
1 parent 9d29759 commit 883a33e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Adyen/Util/HmacSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class HmacSignature
*/
public function validateHMAC(string $hmacKey, string $hmacSign, string $webhook): bool
{
if (!ctype_xdigit($hmacSign)) {
if (!ctype_xdigit($hmacKey)) {
throw new AdyenException("Invalid HMAC key: $hmacKey");
}
$expectedSign = base64_encode(hash_hmac(
'sha256',
$webhook,
pack("H*", $hmacSign),
pack("H*", $hmacKey),
true
));
return hash_equals($expectedSign, $hmacKey);
return hash_equals($expectedSign, $hmacSign);
}
/**
* @param string $hmacKey Can be found in Customer Area
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Util/HmacSignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ public function testBankingWebhookHmacValidation()
. "\"test\",\"type\":\"balancePlatform.balanceAccountSweep.updated\"}";
$hmac = new HmacSignature();
$result = $hmac->validateHMAC(
"9Qz9S/0xpar1klkniKdshxpAhRKbiSAewPpWoxKefQA=",
"D7DD5BA6146493707BF0BE7496F6404EC7A63616B7158EC927B9F54BB436765F",
"9Qz9S/0xpar1klkniKdshxpAhRKbiSAewPpWoxKefQA=",
$params
);
self::assertTrue($result);
Expand Down

0 comments on commit 883a33e

Please sign in to comment.