Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require": {
"php": ">=7.3",
"sendgrid/php-http-client": "~4.1",
"starkbank/ecdsa": "0.*",
"starkbank/ecdsa": "^2.1.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down
3 changes: 2 additions & 1 deletion lib/eventwebhook/EventWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use EllipticCurve\Ecdsa;
use EllipticCurve\PublicKey;
use EllipticCurve\Signature;
use EllipticCurve\Utils\Binary;

/**
* This class allows you to use the Event Webhook feature. Read the docs for
Expand All @@ -22,7 +23,7 @@ class EventWebhook
*/
public function convertPublicKeyToECDSA($publicKey)
{
return PublicKey::fromString($publicKey);
return PublicKey::fromDer(Binary::byteStringFromBase64($publicKey));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion test/unit/EventWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class EventWebhookTest extends TestCase
{
private static $PUBLIC_KEY;
private static $SIGNATURE;
private static $BAD_SIGNATURE;
private static $TIMESTAMP;
private static $PAYLOAD;

Expand All @@ -23,6 +24,8 @@ public static function setUpBeforeClass(): void
IW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g==';
self::$SIGNATURE = 'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiE
AyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM=';
self::$BAD_SIGNATURE = 'BADSIGNATURE+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiE
AyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM=';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exception: missing bytes in DER parse is thrown if this bad signature isn't in the right format

self::$TIMESTAMP = '1600112502';
self::$PAYLOAD = \json_encode(
[
Expand Down Expand Up @@ -81,7 +84,7 @@ public function testBadSignature()
$isValidSignature = $this->verify(
self::$PUBLIC_KEY,
self::$PAYLOAD,
'signature',
self::$BAD_SIGNATURE,
self::$TIMESTAMP
);

Expand Down