Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: verify signature from event webhook #1010

Merged
merged 6 commits into from
Jun 22, 2020
Merged

Conversation

childish-sambino
Copy link
Contributor

When enabling the "Signed Event Webhook Requests" feature in Mail Settings, Twilio SendGrid will generate a private and public key pair using the Elliptic Curve Digital Signature Algorithm (ECDSA). Once that is successfully enabled, all new event posts will have two new headers: X-Twilio-Email-Event-Webhook-Signature and X-Twilio-Email-Event-Webhook-Timestamp, which can be used to validate your events.

This SDK update will make it easier to verify signatures from signed event webhook requests by using the VerifySignature method. Pass in the public key, event payload, signature, and timestamp to validate. Note: You will need to convert your public key string to an elliptic public key object in order to use the VerifySignature method.

Fixes #1004
Blocked by starkbank/ecdsa-dotnet#4

When enabling the "Signed Event Webhook Requests" feature in Mail Settings, Twilio SendGrid will generate a private and public key pair using the Elliptic Curve Digital Signature Algorithm (ECDSA). Once that is successfully enabled, all new event posts will have two new headers: X-Twilio-Email-Event-Webhook-Signature and X-Twilio-Email-Event-Webhook-Timestamp, which can be used to validate your events.

This SDK update will make it easier to verify signatures from signed event webhook requests by using the VerifySignature method. Pass in the public key, event payload, signature, and timestamp to validate. Note: You will need to convert your public key string to an elliptic public key object in order to use the VerifySignature method.
@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Jun 5, 2020
Copy link
Contributor

@thinkingserious thinkingserious left a comment

Choose a reason for hiding this comment

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

👍 ... just a few minor issues.

examples/eventwebhook/RequestValidator.cs Outdated Show resolved Hide resolved
src/SendGrid/Helpers/EventWebhook/RequestValidator.cs Outdated Show resolved Hide resolved
src/SendGrid/Helpers/EventWebhook/RequestValidator.cs Outdated Show resolved Hide resolved
src/SendGrid/Helpers/EventWebhook/RequestValidator.cs Outdated Show resolved Hide resolved
@ivangalbans
Copy link

hello @childish-sambino ,
Why did you choose https://github.com/starkbank/ecdsa-dotnet instead of working directly with https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.ecdsa?view=netcore-3.1 ?

@childish-sambino
Copy link
Contributor Author

@ivangalbans Simplicity. Very few lines of code to get it working. If you have a working example without this added dependency I can take a look.

@childish-sambino childish-sambino merged commit 131706b into master Jun 22, 2020
@childish-sambino childish-sambino deleted the event-webhook branch June 22, 2020 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: code review request requesting a community code review or review from Twilio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add support to validate requests coming from SendGrid webhooks
3 participants