Comments (7)
Hello @gotchahn,
Thank you for reporting this issue to us. I have been unable to reproduce. Could you please provide some more detail about your setup? Here is the code I used to test:
require 'sendgrid-ruby'
include SendGrid
ew = SendGrid::EventWebhook.new
public_key = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIvIW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g=='.freeze
signature = 'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM='.freeze
timestamp = '1600112502'.freeze
payload = "#{[
{
email: '[email protected]',
event: 'dropped',
reason: 'Bounced Address',
sg_event_id: 'ZHJvcC0xMDk5NDkxOS1MUnpYbF9OSFN0T0doUTRrb2ZTbV9BLTA',
sg_message_id: 'LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0',
'smtp-id': '<[email protected]>',
timestamp: 1_600_112_492
}
].to_json}\r\n".freeze
ec_public_key = ew.convert_public_key_to_ecdsa(public_key)
value = ew.verify_signature(ec_public_key, payload, signature, timestamp)
print value
This returned true
.
With best regards,
Elmer
from sendgrid-ruby.
Hi @thinkingserious, I copy pasted your code in my rails console, and gave me false
hmm, weird. I'm using Rails 6.0.3.2
, Ruby 2.6.5
and Sendgrid-ruby 6.3.8
$ rails c
Running via Spring preloader in process 58835
Loading development environment (Rails 6.0.3.2)
irb(main):001:0> ew = SendGrid::EventWebhook.new
=> #<SendGrid::EventWebhook:0x00007faa4fe0c468>
irb(main):002:0> public_key = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIvIW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g=='.freeze
=> "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIvIW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g=="
irb(main):003:0> signature = 'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM='.freeze
=> "MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM="
irb(main):004:0> timestamp = '1600112502'.freeze
=> "1600112502"
irb(main):005:0> payload = "#{[
irb(main):006:1> {
irb(main):007:2> email: '[email protected]',
irb(main):008:2> event: 'dropped',
irb(main):009:2> reason: 'Bounced Address',
irb(main):010:2> sg_event_id: 'ZHJvcC0xMDk5NDkxOS1MUnpYbF9OSFN0T0doUTRrb2ZTbV9BLTA',
irb(main):011:2> sg_message_id: 'LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0',
irb(main):012:2> 'smtp-id': '<[email protected]>',
irb(main):013:2> timestamp: 1_600_112_492
irb(main):014:2> }
irb(main):015:1> ].to_json}\r\n".freeze
=> "[{\"email\":\"[email protected]\",\"event\":\"dropped\",\"reason\":\"Bounced Address\",\"sg_event_id\":\"ZHJvcC0xMDk5NDkxOS1MUnpYbF9OSFN0T0doUTRrb2ZTbV9BLTA\",\"sg_message_id\":\"LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0\",\"smtp-id\":\"\\[email protected]\\u003e\",\"timestamp\":1600112492}]\r\n"
irb(main):016:0> ec_public_key = ew.convert_public_key_to_ecdsa(public_key)
=> #<OpenSSL::PKey::EC:0x00007faa4ffe7f30>
irb(main):017:0> value = ew.verify_signature(ec_public_key, payload, signature, timestamp)
=> false
irb(main):018:0> print value
false=> nil
irb(main):019:0>
from sendgrid-ruby.
BUT, noticed that if I do that code in a plain irb
console, it works! but not on rails console
or in my rails testing suite. Do you have any idea why it works only in a irb
console??
$ irb
irb(main):001:0> require 'sendgrid-ruby'
=> true
irb(main):002:0> include SendGrid
=> Object
irb(main):003:0>
irb(main):004:0> ew = SendGrid::EventWebhook.new
=> #<SendGrid::EventWebhook:0x00007fb08aa6cdd0>
irb(main):005:0> public_key = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIvIW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g=='.freeze
=> "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIvIW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g=="
irb(main):006:0> signature = 'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM='.freeze
=> "MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM="
irb(main):007:0> timestamp = '1600112502'.freeze
=> "1600112502"
irb(main):008:0> payload = "#{[
irb(main):009:1> {
irb(main):010:2> email: '[email protected]',
irb(main):011:2> event: 'dropped',
irb(main):012:2> reason: 'Bounced Address',
irb(main):013:2> sg_event_id: 'ZHJvcC0xMDk5NDkxOS1MUnpYbF9OSFN0T0doUTRrb2ZTbV9BLTA',
irb(main):014:2> sg_message_id: 'LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0',
irb(main):015:2> 'smtp-id': '<[email protected]>',
irb(main):016:2> timestamp: 1_600_112_492
irb(main):017:2> }
irb(main):018:1> ].to_json}\r\n".freeze
=> "[{\"email\":\"[email protected]\",\"event\":\"dropped\",\"reason\":\"Bounced Address\",\"sg_event_id\":\"ZHJvcC0xMDk5NDkxOS1MUnpYbF9OSFN0T0doUTRrb2ZTbV9BLTA\",\"sg_message_id\":\"LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0\",\"smtp-id\":\"<[email protected]>\",\"timestamp\":1600112492}]\r\n"
irb(main):019:0> ec_public_key = ew.convert_public_key_to_ecdsa(public_key)
=> #<OpenSSL::PKey::EC:0x00007fb08aadf4e8>
irb(main):020:0> value = ew.verify_signature(ec_public_key, payload, signature, timestamp)
=> true
irb(main):021:0> print value
true=> nil
from sendgrid-ruby.
Hello @gotchahn,
Here are few things to check:
- What is the return of
RUBY_VERSION
while in the irb console vs rails console. - Perhaps the rails console is using a different version of irb under the hood.
- What happens when you run outside of the console?
Thanks!
With best regards,
Elmer
from sendgrid-ruby.
Hi @thinkingserious,
- Both gave me
2.6.5
as theRUBY_VERSION
. - The ONLY difference I see is that the rails console is using a Spring preloader
Running via Spring preloader in process....
dunno if that has something to do. - Well, I tested it in my test specs, and the result is the same as the
rails console
.
I tested in production, and the endpoint works well with the validation of the REAL key and signature. Is just the made of ones for the tests that gives me false
the verifier.
UPDATE:
I tested the rails console without the Spring preloader, and it returns false still.
from sendgrid-ruby.
Hi @thinkingserious,
I figured it out, it's the payload the cause of the issue, and mainly, the .to_json
method with the 'smtp-id'
section, look:
in irb
console:
$ irb
irb(main):001:0> require 'sendgrid-ruby'
=> true
irb(main):002:0> include SendGrid
=> Object
irb(main):017:0> "'smtp-id': '<[email protected]>'".to_json
=> "\"'smtp-id': '<[email protected]>'\""
in rails console
:
irb(main):001:0> "'smtp-id': '<[email protected]>'".to_json
=> "\"'smtp-id': '\\[email protected]\\u003e'\""
irb(main):002:0>
The <
and >
are converted, so that's why the verifier doesn't returns true. Using JSON.generate
worked:
irb(main):004:0> JSON.generate("'smtp-id': '<[email protected]>'")
=> "\"'smtp-id': '<[email protected]>'\""
But I have another question, If I slightly change the payload, the verifier returns false, any idea of how I can use a custom payload with a different type of event for example, and get the right signature for the public key??
from sendgrid-ruby.
Related Issues (20)
- Duplicate checking when adding email to personalization is not accurate HOT 6
- Request: Make it possible to pass http_options config when initialize API HOT 1
- Ruby 3 support HOT 2
- Is sendgrid-ruby still ruby 2.2. compatible? HOT 2
- [BUG] Filter all messages does not work as described in documentation HOT 5
- How to add/remove contacts to a list via new marketing API? HOT 5
- Adding SendGrid addon on Heroku uses Basic Authentication with Username and Password HOT 4
- How to substitute \n or carriage returns HOT 1
- SendGrid::DuplicatePersonalizationError HOT 1
- BaseInterface class should be inside a module HOT 1
- Bad username / password HOT 5
- EML files turning into multiple attachments when using Inbound Parse HOT 5
- Personalization causes duplicate `to` email and sometimes causes multiple emails HOT 1
- Dynamic Templates overwritting list styles HOT 2
- Priority of sent emails HOT 1
- Helpers do not have all properties HOT 1
- The link to be notified of releases and breaking changes is returning a 500 from Heroku HOT 1
- Multiple Emails HOT 3
- uninitialized constant SendgridService::Personalization HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sendgrid-ruby.