-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from swlodarski-sumoheavy/10.0.x
SP-966 - Validate incoming webhooks
- Loading branch information
Showing
14 changed files
with
363 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Bitpay\BPCheckout\Exception; | ||
|
||
class HMACVerificationException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Bitpay\BPCheckout\Model\Ipn; | ||
|
||
class WebhookVerifier | ||
{ | ||
/** | ||
* Verify the validity of webhooks (HMAC) | ||
* | ||
* @see https://developer.bitpay.com/reference/hmac-verification | ||
* | ||
* @param string $signingKey | ||
* @param string $sigHeader | ||
* @param string $webhookBody | ||
* | ||
* @return bool | ||
*/ | ||
public function isValidHmac(string $signingKey, string $sigHeader, string $webhookBody): bool | ||
{ | ||
$hmac = base64_encode( | ||
hash_hmac( | ||
'sha256', | ||
$webhookBody, | ||
$signingKey, | ||
true | ||
) | ||
); | ||
|
||
return $sigHeader === $hmac; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.