From f748dbd7c49b1a2488347e0fdc1dd5cfcac74252 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 10:45:46 -0400 Subject: [PATCH 01/29] implement raw token option in js lib --- javascript/src/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/javascript/src/index.ts b/javascript/src/index.ts index 09035ef87..dc1a95cb3 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -594,14 +594,18 @@ export class Webhook { private static prefix = "whsec_"; private readonly key: Uint8Array; - constructor(secret: string) { + constructor(secret: string | Uint8Array) { if (!secret) { throw new Error("Secret can't be empty."); } - if (secret.startsWith(Webhook.prefix)) { + if (secret instanceof String && secret.startsWith(Webhook.prefix)) { secret = secret.substring(Webhook.prefix.length); } - this.key = base64.decode(secret); + if (secret instanceof Uint8Array) { + this.key = secret; + } else { + this.key = base64.decode(secret.toString()); + } } public verify( From 979926ed1cefeecc5eff5c5b4432e3106dee6633 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 11:08:14 -0400 Subject: [PATCH 02/29] account for base64 string --- javascript/src/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/javascript/src/index.ts b/javascript/src/index.ts index dc1a95cb3..ae43a218e 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -590,19 +590,25 @@ export interface WebhookUnbrandedRequiredHeaders { "webhook-signature": string; } +export interface WebhookOptions { + raw?: boolean; +} + export class Webhook { private static prefix = "whsec_"; private readonly key: Uint8Array; - constructor(secret: string | Uint8Array) { + constructor(secret: string | Uint8Array, options?: WebhookOptions) { if (!secret) { throw new Error("Secret can't be empty."); } - if (secret instanceof String && secret.startsWith(Webhook.prefix)) { + if (!options?.raw && secret instanceof String && secret.startsWith(Webhook.prefix)) { secret = secret.substring(Webhook.prefix.length); } - if (secret instanceof Uint8Array) { + if (options?.raw && secret instanceof Uint8Array) { this.key = secret; + } else if (options?.raw && secret instanceof String) { + this.key = Uint8Array.from(atob(secret.toString()), (c) => c.charCodeAt(0)); } else { this.key = base64.decode(secret.toString()); } From 6d3a732c95cb383498dccc48c0bdc72e8a0e341e Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 16:44:32 +0000 Subject: [PATCH 03/29] generalize and patch ui8a bug --- javascript/src/index.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/javascript/src/index.ts b/javascript/src/index.ts index ae43a218e..1345fbdd2 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -590,8 +590,10 @@ export interface WebhookUnbrandedRequiredHeaders { "webhook-signature": string; } +const SECRET_FORMAT_RAW = "raw"; + export interface WebhookOptions { - raw?: boolean; + format?: string; } export class Webhook { @@ -602,13 +604,17 @@ export class Webhook { if (!secret) { throw new Error("Secret can't be empty."); } - if (!options?.raw && secret instanceof String && secret.startsWith(Webhook.prefix)) { + if ( + options?.format !== SECRET_FORMAT_RAW && + secret instanceof String && + secret.startsWith(Webhook.prefix) + ) { secret = secret.substring(Webhook.prefix.length); } - if (options?.raw && secret instanceof Uint8Array) { + if (options?.format === SECRET_FORMAT_RAW && secret instanceof Uint8Array) { this.key = secret; - } else if (options?.raw && secret instanceof String) { - this.key = Uint8Array.from(atob(secret.toString()), (c) => c.charCodeAt(0)); + } else if (options?.format === SECRET_FORMAT_RAW && secret instanceof String) { + this.key = Uint8Array.from(secret.toString(), (c) => c.charCodeAt(0)); } else { this.key = base64.decode(secret.toString()); } From ceaec9518ff5b2f2b01098322c98e79dc98d15b8 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 13:02:43 -0400 Subject: [PATCH 04/29] feedback --- javascript/src/index.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/javascript/src/index.ts b/javascript/src/index.ts index 1345fbdd2..deb4e87de 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -590,10 +590,8 @@ export interface WebhookUnbrandedRequiredHeaders { "webhook-signature": string; } -const SECRET_FORMAT_RAW = "raw"; - export interface WebhookOptions { - format?: string; + format?: "raw"; } export class Webhook { @@ -605,18 +603,18 @@ export class Webhook { throw new Error("Secret can't be empty."); } if ( - options?.format !== SECRET_FORMAT_RAW && + options?.format !== "raw" && secret instanceof String && secret.startsWith(Webhook.prefix) ) { secret = secret.substring(Webhook.prefix.length); } - if (options?.format === SECRET_FORMAT_RAW && secret instanceof Uint8Array) { + if (options?.format === "raw" && secret instanceof Uint8Array) { this.key = secret; - } else if (options?.format === SECRET_FORMAT_RAW && secret instanceof String) { - this.key = Uint8Array.from(secret.toString(), (c) => c.charCodeAt(0)); + } else if (options?.format === "raw" && secret instanceof String) { + this.key = Uint8Array.from(secret, (c) => c.charCodeAt(0)); } else { - this.key = base64.decode(secret.toString()); + this.key = base64.decode(secret as string); } } From 52822896aa87419ff131980049dff716b6148c49 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 13:59:22 -0400 Subject: [PATCH 05/29] reformat conditions check --- javascript/src/index.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/javascript/src/index.ts b/javascript/src/index.ts index deb4e87de..a8e2e9a51 100644 --- a/javascript/src/index.ts +++ b/javascript/src/index.ts @@ -602,18 +602,19 @@ export class Webhook { if (!secret) { throw new Error("Secret can't be empty."); } - if ( - options?.format !== "raw" && - secret instanceof String && - secret.startsWith(Webhook.prefix) - ) { - secret = secret.substring(Webhook.prefix.length); - } - if (options?.format === "raw" && secret instanceof Uint8Array) { - this.key = secret; - } else if (options?.format === "raw" && secret instanceof String) { - this.key = Uint8Array.from(secret, (c) => c.charCodeAt(0)); + if (options?.format === "raw") { + if (secret instanceof Uint8Array) { + this.key = secret; + } else { + this.key = Uint8Array.from(secret, (c) => c.charCodeAt(0)); + } } else { + if (!(secret instanceof String)) { + throw new Error("Expected secret to be of type string"); + } + if (secret.startsWith(Webhook.prefix)) { + secret = secret.substring(Webhook.prefix.length); + } this.key = base64.decode(secret as string); } } From b34dacb78639de6f65c8a7f681479cf3f2954e18 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 18:10:15 +0000 Subject: [PATCH 06/29] go implementation --- go/webhook.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/go/webhook.go b/go/webhook.go index fb20ef58c..1aa4b41ea 100644 --- a/go/webhook.go +++ b/go/webhook.go @@ -39,6 +39,18 @@ func NewWebhook(secret string) (*Webhook, error) { }, nil } +func NewWebhookFromRaw(secret []byte) (*Webhook, error) { + return &Webhook { + key: secret + }, nil +} + +func NewWebhookFromRawString(secret string) (*Webhook, error) { + return &Webhook { + key: []byte(secret) + }, nil +} + // Verify validates the payload against the svix signature headers // using the webhooks signing secret. // From 35b451c27a5e88dae77206ba1f1cc0e6ca5165ba Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 18:13:54 +0000 Subject: [PATCH 07/29] patch go linter errors --- go/webhook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/webhook.go b/go/webhook.go index 1aa4b41ea..012931f73 100644 --- a/go/webhook.go +++ b/go/webhook.go @@ -41,13 +41,13 @@ func NewWebhook(secret string) (*Webhook, error) { func NewWebhookFromRaw(secret []byte) (*Webhook, error) { return &Webhook { - key: secret + key: secret, }, nil } func NewWebhookFromRawString(secret string) (*Webhook, error) { return &Webhook { - key: []byte(secret) + key: []byte(secret), }, nil } From 153d865775e612a53149c75f7cee11f2e3108d38 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 18:14:56 +0000 Subject: [PATCH 08/29] god i hate java. attempt java impl. --- java/lib/src/main/java/com/svix/Webhook.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/java/lib/src/main/java/com/svix/Webhook.java b/java/lib/src/main/java/com/svix/Webhook.java index 0e96f8f1b..64626f4ac 100644 --- a/java/lib/src/main/java/com/svix/Webhook.java +++ b/java/lib/src/main/java/com/svix/Webhook.java @@ -35,6 +35,14 @@ public Webhook(final String secret) { } this.key = Base64.getDecoder().decode(sec); } + + public Webhook(final byte[] secret) { + this.key = secret; + } + + public WebhookFromRawString(final String secret) { + this.key = secret.getBytes(); + } public void verify(final String payload, final HttpHeaders headers) throws WebhookVerificationException { Optional msgId = headers.firstValue(SVIX_MSG_ID_KEY); From 79f7ac0b56c936d748efc1b729e076470e5804b1 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 18:18:16 +0000 Subject: [PATCH 09/29] java remove trailing spaces for linter --- java/lib/src/main/java/com/svix/Webhook.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/lib/src/main/java/com/svix/Webhook.java b/java/lib/src/main/java/com/svix/Webhook.java index 64626f4ac..a0f8b87b0 100644 --- a/java/lib/src/main/java/com/svix/Webhook.java +++ b/java/lib/src/main/java/com/svix/Webhook.java @@ -35,11 +35,11 @@ public Webhook(final String secret) { } this.key = Base64.getDecoder().decode(sec); } - + public Webhook(final byte[] secret) { this.key = secret; } - + public WebhookFromRawString(final String secret) { this.key = secret.getBytes(); } From 64e426df2aa3e738820294152369950dcbc1c95d Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 18:19:15 +0000 Subject: [PATCH 10/29] iterate per feedback --- java/lib/src/main/java/com/svix/Webhook.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/lib/src/main/java/com/svix/Webhook.java b/java/lib/src/main/java/com/svix/Webhook.java index a0f8b87b0..be7999ab1 100644 --- a/java/lib/src/main/java/com/svix/Webhook.java +++ b/java/lib/src/main/java/com/svix/Webhook.java @@ -36,11 +36,11 @@ public Webhook(final String secret) { this.key = Base64.getDecoder().decode(sec); } - public Webhook(final byte[] secret) { + public WebhookRaw(final byte[] secret) { this.key = secret; } - public WebhookFromRawString(final String secret) { + public WebhookRaw(final String secret) { this.key = secret.getBytes(); } From f7504df5251acbaeb21b188ac58ce99327fcc244 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 18:28:35 +0000 Subject: [PATCH 11/29] kotlin impl --- kotlin/lib/src/main/kotlin/Webhook.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/kotlin/lib/src/main/kotlin/Webhook.kt b/kotlin/lib/src/main/kotlin/Webhook.kt index 9a4827010..1a7d5b33e 100644 --- a/kotlin/lib/src/main/kotlin/Webhook.kt +++ b/kotlin/lib/src/main/kotlin/Webhook.kt @@ -100,11 +100,20 @@ class Webhook(secret: String) { } } - init { - var sec = secret - if (sec.startsWith(SECRET_PREFIX)) { - sec = sec.substring(SECRET_PREFIX.length) + constructor(secret: String) { + if (secret.startsWith(SECRET_PREFIX)) { + secret = secret.substring(SECRET_PREFIX.length) } - key = Base64.getDecoder().decode(sec) + key = Base64.getDecoder().decode(secret) + } + + constructor(secret: String, format: String) { + if (format === "raw") { + key = secret.toByteArray() + } + } + + constructor(secret: ByteArray) { + key = secret } } From 273f071cd68fa66f71f58c30cd75b33548f2cee8 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 18:42:10 +0000 Subject: [PATCH 12/29] php impl --- php/src/Webhook.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/php/src/Webhook.php b/php/src/Webhook.php index a39dfc55d..16f17b516 100644 --- a/php/src/Webhook.php +++ b/php/src/Webhook.php @@ -16,6 +16,12 @@ public function __construct($secret) $this->secret = base64_decode($secret); } + public static function fromRaw($secret) { + $obj = new self(); + $obj->secret = $secret; + return $obj; + } + public function verify($payload, $headers) { if ( From 5e7776c6c96e4eeafa99b94500457581ba17bd5e Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 18:49:07 +0000 Subject: [PATCH 13/29] php linter patch --- php/src/Webhook.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/php/src/Webhook.php b/php/src/Webhook.php index 16f17b516..645475d92 100644 --- a/php/src/Webhook.php +++ b/php/src/Webhook.php @@ -16,8 +16,9 @@ public function __construct($secret) $this->secret = base64_decode($secret); } - public static function fromRaw($secret) { - $obj = new self(); + public static function fromRaw($secret) + { + $obj = new self(); $obj->secret = $secret; return $obj; } From 7dc40a7e54a106e522eaea0317328ae24548964f Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 19:03:27 +0000 Subject: [PATCH 14/29] python attempt --- python/svix/webhooks.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/svix/webhooks.py b/python/svix/webhooks.py index e4495b157..d4e7f2443 100644 --- a/python/svix/webhooks.py +++ b/python/svix/webhooks.py @@ -29,6 +29,16 @@ def __init__(self, whsecret: str, *, enc_key: t.Optional[str] = None): self._whsecret = base64.b64decode(whsecret) self._enc_key = base64.b64decode(enc_key) if enc_key is not None else None + def from_raw(whsecret: bytes): + wh = Webhook() + wh._whsecret = whsecret + return wh + + def from_raw(whsecret: str): + wh = Webhook() + wh._whsecret = str.encode(whsecret) + return wh + def verify(self, data: t.Union[bytes, str], headers: t.Dict[str, str]) -> t.Any: data = data if isinstance(data, str) else data.decode() headers = {k.lower(): v for (k, v) in headers.items()} From b989735abfcb3ed07f258b955ca9eb196ea3ede5 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 19:17:40 +0000 Subject: [PATCH 15/29] =?UTF-8?q?single=20overloaded=20=E2=80=9Cfrom=20raw?= =?UTF-8?q?=E2=80=9D=20function=20Go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/webhook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/webhook.go b/go/webhook.go index 012931f73..94815f1b6 100644 --- a/go/webhook.go +++ b/go/webhook.go @@ -39,13 +39,13 @@ func NewWebhook(secret string) (*Webhook, error) { }, nil } -func NewWebhookFromRaw(secret []byte) (*Webhook, error) { +func NewWebhookRaw(secret []byte) (*Webhook, error) { return &Webhook { key: secret, }, nil } -func NewWebhookFromRawString(secret string) (*Webhook, error) { +func NewWebhookRaw(secret string) (*Webhook, error) { return &Webhook { key: []byte(secret), }, nil From 2c3eecfa18b24a73d2a5360fe69f146f1c7f47d3 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 19:53:14 +0000 Subject: [PATCH 16/29] use Union to solve python init (and remove stale enc_key) --- python/svix/webhooks.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/python/svix/webhooks.py b/python/svix/webhooks.py index d4e7f2443..91ed6a0e8 100644 --- a/python/svix/webhooks.py +++ b/python/svix/webhooks.py @@ -18,26 +18,18 @@ class WebhookVerificationError(Exception): class Webhook: _SECRET_PREFIX: str = "whsec_" _whsecret: bytes - _enc_key: t.Optional[bytes] - def __init__(self, whsecret: str, *, enc_key: t.Optional[str] = None): + def __init__(self, whsecret: t.Union[str, bytes], *): if not whsecret: raise RuntimeError("Secret can't be empty.") - if whsecret.startswith(self._SECRET_PREFIX): - whsecret = whsecret[len(self._SECRET_PREFIX) :] - self._whsecret = base64.b64decode(whsecret) - self._enc_key = base64.b64decode(enc_key) if enc_key is not None else None - - def from_raw(whsecret: bytes): - wh = Webhook() - wh._whsecret = whsecret - return wh - - def from_raw(whsecret: str): - wh = Webhook() - wh._whsecret = str.encode(whsecret) - return wh + if isinstance(whsecret, str): + if whsecret.startswith(self._SECRET_PREFIX): + whsecret = whsecret[len(self._SECRET_PREFIX) :] + self._whsecret = base64.b64decode(whsecret) + + if isinstance(whsecret, bytes): + self._whsecret = whsecret def verify(self, data: t.Union[bytes, str], headers: t.Dict[str, str]) -> t.Any: data = data if isinstance(data, str) else data.decode() From ca47c1f52401861d875fcdc636cbb85360e7ab3a Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 19:54:54 +0000 Subject: [PATCH 17/29] lint patch --- python/svix/webhooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/svix/webhooks.py b/python/svix/webhooks.py index 91ed6a0e8..f7f5d0b5b 100644 --- a/python/svix/webhooks.py +++ b/python/svix/webhooks.py @@ -19,7 +19,7 @@ class Webhook: _SECRET_PREFIX: str = "whsec_" _whsecret: bytes - def __init__(self, whsecret: t.Union[str, bytes], *): + def __init__(self, whsecret: t.Union[str, bytes]): if not whsecret: raise RuntimeError("Secret can't be empty.") From b5461416a0792a5af4537309f8db5f5e690e04d8 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 19:57:31 +0000 Subject: [PATCH 18/29] python lint --- python/svix/webhooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/svix/webhooks.py b/python/svix/webhooks.py index f7f5d0b5b..410f6cba0 100644 --- a/python/svix/webhooks.py +++ b/python/svix/webhooks.py @@ -27,7 +27,7 @@ def __init__(self, whsecret: t.Union[str, bytes]): if whsecret.startswith(self._SECRET_PREFIX): whsecret = whsecret[len(self._SECRET_PREFIX) :] self._whsecret = base64.b64decode(whsecret) - + if isinstance(whsecret, bytes): self._whsecret = whsecret From 1abff99a6f2224a53ea24764796bf5b507f0821f Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:05:28 +0000 Subject: [PATCH 19/29] ruby attempt --- ruby/lib/svix/webhook.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ruby/lib/svix/webhook.rb b/ruby/lib/svix/webhook.rb index ae33c5bef..7fcfc2953 100644 --- a/ruby/lib/svix/webhook.rb +++ b/ruby/lib/svix/webhook.rb @@ -3,6 +3,14 @@ module Svix class Webhook + def self.new_using_raw_bytes(secret) + self.new(secret.pack('C*').force_encoding('UTF-8')) + end + + def self.new_using_raw_string(secret) + self.new(Base64.encode(secret)) + end + def initialize(secret) if secret.start_with?(SECRET_PREFIX) secret = secret[SECRET_PREFIX.length..-1] From 0f02a78c803452bfc3e4c89c58f43ebd4d39ae6a Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:08:07 +0000 Subject: [PATCH 20/29] rust impl --- rust/src/webhooks.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/src/webhooks.rs b/rust/src/webhooks.rs index e47ea7632..babce1ca0 100644 --- a/rust/src/webhooks.rs +++ b/rust/src/webhooks.rs @@ -53,6 +53,16 @@ impl Webhook { Ok(Webhook { key }) } + pub fn new_raw(secret: Vec) -> Result { + Ok(Webhook { secret }) + } + + pub fn new_raw(secret: String) -> Result { + Ok(Webhook { + key: secret.as_bytes(), + }) + } + pub fn verify(&self, payload: &[u8], headers: &HeaderMap) -> Result<(), WebhookError> { let msg_id = Self::get_header(headers, SVIX_MSG_ID_KEY, UNBRANDED_MSG_ID_KEY, "id")?; let msg_signature = Self::get_header( From ad4eb578dd017580634232209ffaeb1f39c80fda Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:12:34 +0000 Subject: [PATCH 21/29] patch rust --- rust/src/webhooks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/src/webhooks.rs b/rust/src/webhooks.rs index babce1ca0..884f9d10d 100644 --- a/rust/src/webhooks.rs +++ b/rust/src/webhooks.rs @@ -53,11 +53,11 @@ impl Webhook { Ok(Webhook { key }) } - pub fn new_raw(secret: Vec) -> Result { + pub fn new_from_raw_bytes(secret: Vec) -> Result { Ok(Webhook { secret }) } - pub fn new_raw(secret: String) -> Result { + pub fn new_from_raw_string(secret: String) -> Result { Ok(Webhook { key: secret.as_bytes(), }) From eeb4e5656cf3d1c729aa553353aa32810979df5e Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:16:43 +0000 Subject: [PATCH 22/29] patch rust --- rust/src/webhooks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/webhooks.rs b/rust/src/webhooks.rs index 884f9d10d..e79c923eb 100644 --- a/rust/src/webhooks.rs +++ b/rust/src/webhooks.rs @@ -59,7 +59,7 @@ impl Webhook { pub fn new_from_raw_string(secret: String) -> Result { Ok(Webhook { - key: secret.as_bytes(), + key: secret.to_vec(), }) } From 19f1f7f6924b83ed8848e2a4650beed8c9ca0c8a Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:17:51 +0000 Subject: [PATCH 23/29] csharp, a la java approach --- csharp/Svix/Webhook.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/csharp/Svix/Webhook.cs b/csharp/Svix/Webhook.cs index 60eee7eba..1655912cb 100644 --- a/csharp/Svix/Webhook.cs +++ b/csharp/Svix/Webhook.cs @@ -31,6 +31,16 @@ public Webhook(string key) this.key = Convert.FromBase64String(key); } + public WebhookRaw(byte[] key) + { + this.key = key; + } + + public WebhookRaw(string key) + { + this.key = Encoding.ASCII.GetBytes(string); + } + public void Verify(string payload, WebHeaderCollection headers) { string msgId = headers.Get(SVIX_ID_HEADER_KEY); @@ -114,4 +124,4 @@ public string Sign(string msgId, DateTimeOffset timestamp, string payload) } } } -} \ No newline at end of file +} From 579033b9d40d8a74a1c0cb33a3c41261a7612c76 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:18:17 +0000 Subject: [PATCH 24/29] patch Go --- go/webhook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/webhook.go b/go/webhook.go index 94815f1b6..0fb49c6f6 100644 --- a/go/webhook.go +++ b/go/webhook.go @@ -45,7 +45,7 @@ func NewWebhookRaw(secret []byte) (*Webhook, error) { }, nil } -func NewWebhookRaw(secret string) (*Webhook, error) { +func NewWebhookRawString(secret string) (*Webhook, error) { return &Webhook { key: []byte(secret), }, nil From cd53be51a90a8d0629e47baeb368a3f76615704f Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:23:08 +0000 Subject: [PATCH 25/29] string->String->bytes --- rust/src/webhooks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/webhooks.rs b/rust/src/webhooks.rs index e79c923eb..787d9d709 100644 --- a/rust/src/webhooks.rs +++ b/rust/src/webhooks.rs @@ -59,7 +59,7 @@ impl Webhook { pub fn new_from_raw_string(secret: String) -> Result { Ok(Webhook { - key: secret.to_vec(), + key: secret.to_string().as_bytes(), }) } From 1efb72efb8315304472d676ba9715f468b6ad74a Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:29:59 +0000 Subject: [PATCH 26/29] fml ok --- rust/src/webhooks.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/src/webhooks.rs b/rust/src/webhooks.rs index 787d9d709..c1573c7f4 100644 --- a/rust/src/webhooks.rs +++ b/rust/src/webhooks.rs @@ -54,12 +54,12 @@ impl Webhook { } pub fn new_from_raw_bytes(secret: Vec) -> Result { - Ok(Webhook { secret }) + Ok(Webhook { key: secret }) } pub fn new_from_raw_string(secret: String) -> Result { Ok(Webhook { - key: secret.to_string().as_bytes(), + key: secret.as_bytes().to_vec(), }) } From 1a12edf987b36f7ea18e92463589a6d4de8b352b Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 20:33:48 +0000 Subject: [PATCH 27/29] ruby lint patch --- ruby/lib/svix/webhook.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby/lib/svix/webhook.rb b/ruby/lib/svix/webhook.rb index 7fcfc2953..48b8fba46 100644 --- a/ruby/lib/svix/webhook.rb +++ b/ruby/lib/svix/webhook.rb @@ -4,11 +4,11 @@ module Svix class Webhook def self.new_using_raw_bytes(secret) - self.new(secret.pack('C*').force_encoding('UTF-8')) + self.new(secret.pack("C*").force_encoding("UTF-8")) end def self.new_using_raw_string(secret) - self.new(Base64.encode(secret)) + self.new(Base64.encode(secret)) end def initialize(secret) From e6d41d137ac0a2ef182bdbc70292cbe3bc66e77b Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Tue, 12 Jul 2022 23:52:26 +0000 Subject: [PATCH 28/29] remove rawString construction, all libs except js --- csharp/Svix/Webhook.cs | 7 +------ go/webhook.go | 6 ------ java/lib/src/main/java/com/svix/Webhook.java | 6 +----- kotlin/lib/src/main/kotlin/Webhook.kt | 6 ------ ruby/lib/svix/webhook.rb | 4 ---- rust/src/webhooks.rs | 8 +------- 6 files changed, 3 insertions(+), 34 deletions(-) diff --git a/csharp/Svix/Webhook.cs b/csharp/Svix/Webhook.cs index 1655912cb..9c47b3582 100644 --- a/csharp/Svix/Webhook.cs +++ b/csharp/Svix/Webhook.cs @@ -31,16 +31,11 @@ public Webhook(string key) this.key = Convert.FromBase64String(key); } - public WebhookRaw(byte[] key) + public Webhook(byte[] key) { this.key = key; } - public WebhookRaw(string key) - { - this.key = Encoding.ASCII.GetBytes(string); - } - public void Verify(string payload, WebHeaderCollection headers) { string msgId = headers.Get(SVIX_ID_HEADER_KEY); diff --git a/go/webhook.go b/go/webhook.go index 0fb49c6f6..471050f98 100644 --- a/go/webhook.go +++ b/go/webhook.go @@ -45,12 +45,6 @@ func NewWebhookRaw(secret []byte) (*Webhook, error) { }, nil } -func NewWebhookRawString(secret string) (*Webhook, error) { - return &Webhook { - key: []byte(secret), - }, nil -} - // Verify validates the payload against the svix signature headers // using the webhooks signing secret. // diff --git a/java/lib/src/main/java/com/svix/Webhook.java b/java/lib/src/main/java/com/svix/Webhook.java index be7999ab1..f6c2c2283 100644 --- a/java/lib/src/main/java/com/svix/Webhook.java +++ b/java/lib/src/main/java/com/svix/Webhook.java @@ -36,14 +36,10 @@ public Webhook(final String secret) { this.key = Base64.getDecoder().decode(sec); } - public WebhookRaw(final byte[] secret) { + public Webhook(final byte[] secret) { this.key = secret; } - public WebhookRaw(final String secret) { - this.key = secret.getBytes(); - } - public void verify(final String payload, final HttpHeaders headers) throws WebhookVerificationException { Optional msgId = headers.firstValue(SVIX_MSG_ID_KEY); Optional msgSignature = headers.firstValue(SVIX_MSG_SIGNATURE_KEY); diff --git a/kotlin/lib/src/main/kotlin/Webhook.kt b/kotlin/lib/src/main/kotlin/Webhook.kt index 1a7d5b33e..c97734a24 100644 --- a/kotlin/lib/src/main/kotlin/Webhook.kt +++ b/kotlin/lib/src/main/kotlin/Webhook.kt @@ -107,12 +107,6 @@ class Webhook(secret: String) { key = Base64.getDecoder().decode(secret) } - constructor(secret: String, format: String) { - if (format === "raw") { - key = secret.toByteArray() - } - } - constructor(secret: ByteArray) { key = secret } diff --git a/ruby/lib/svix/webhook.rb b/ruby/lib/svix/webhook.rb index 48b8fba46..c5a858047 100644 --- a/ruby/lib/svix/webhook.rb +++ b/ruby/lib/svix/webhook.rb @@ -7,10 +7,6 @@ def self.new_using_raw_bytes(secret) self.new(secret.pack("C*").force_encoding("UTF-8")) end - def self.new_using_raw_string(secret) - self.new(Base64.encode(secret)) - end - def initialize(secret) if secret.start_with?(SECRET_PREFIX) secret = secret[SECRET_PREFIX.length..-1] diff --git a/rust/src/webhooks.rs b/rust/src/webhooks.rs index c1573c7f4..18ed1f283 100644 --- a/rust/src/webhooks.rs +++ b/rust/src/webhooks.rs @@ -53,16 +53,10 @@ impl Webhook { Ok(Webhook { key }) } - pub fn new_from_raw_bytes(secret: Vec) -> Result { + pub fn raw(secret: Vec) -> Result { Ok(Webhook { key: secret }) } - pub fn new_from_raw_string(secret: String) -> Result { - Ok(Webhook { - key: secret.as_bytes().to_vec(), - }) - } - pub fn verify(&self, payload: &[u8], headers: &HeaderMap) -> Result<(), WebhookError> { let msg_id = Self::get_header(headers, SVIX_MSG_ID_KEY, UNBRANDED_MSG_ID_KEY, "id")?; let msg_signature = Self::get_header( From 47f98f7957d833fdcb343e688ab9e1771734fff6 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 13 Jul 2022 12:34:19 +0300 Subject: [PATCH 29/29] Update rust/src/webhooks.rs --- rust/src/webhooks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/webhooks.rs b/rust/src/webhooks.rs index 18ed1f283..6438494c0 100644 --- a/rust/src/webhooks.rs +++ b/rust/src/webhooks.rs @@ -53,7 +53,7 @@ impl Webhook { Ok(Webhook { key }) } - pub fn raw(secret: Vec) -> Result { + pub fn from_bytes(secret: Vec) -> Result { Ok(Webhook { key: secret }) }