Class: SendGrid::EventWebhook
- Inherits:
-
Object
- Object
- SendGrid::EventWebhook
show all
- Defined in:
- lib/sendgrid/helpers/eventwebhook/eventwebhook.rb
Overview
Defined Under Namespace
Classes: Error, NotSupportedError
Instance Method Summary
collapse
Instance Method Details
#convert_public_key_to_ecdsa(public_key) ⇒ Object
-
Args :
public_key -> verification key under Mail Settings
12
13
14
15
|
# File 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb', line 12
def convert_public_key_to_ecdsa(public_key)
verify_engine
OpenSSL::PKey::EC.new(Base64.decode64(public_key))
end
|
#verify_engine ⇒ Object
32
33
34
35
|
# File 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb', line 32
def verify_engine
raise NotSupportedError, "Event Webhook verification is not supported by JRuby" if RUBY_PLATFORM == "java"
end
|
#verify_signature(public_key, payload, signature, timestamp) ⇒ Object
-
Args :
public_key -> elliptic curve public key
payload -> event payload in the request body
signature -> signature value obtained from the 'X-Twilio-Email-Event-Webhook-Signature' header
timestamp -> timestamp value obtained from the 'X-Twilio-Email-Event-Webhook-Timestamp' header
22
23
24
25
26
27
28
29
30
|
# File 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb', line 22
def verify_signature(public_key, payload, signature, timestamp)
verify_engine
timestamped_playload = "#{timestamp}#{payload}"
payload_digest = Digest::SHA256.digest(timestamped_playload)
decoded_signature = Base64.decode64(signature)
public_key.dsa_verify_asn1(payload_digest, decoded_signature)
rescue StandardError
false
end
|