Class: ACube::SignatureChecker
- Inherits:
-
Object
- Object
- ACube::SignatureChecker
- Defined in:
- lib/acube/signature_checker.rb
Defined Under Namespace
Classes: InvalidSignatureError
Constant Summary collapse
- HASH_ALGORIGHTM =
"sha256"
- DEFAULT_KEY =
"acube"
- DEFAULT_GPG =
<<-GPG -----BEGIN PUBLIC KEY----- MCowBQYDK2VwAyEAvZlhiFh4aORWSC9hKZvZyKYgn2g2VeSguWoxu4fbqRI= -----END PUBLIC KEY----- GPG
Instance Attribute Summary collapse
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#input ⇒ Object
Returns the value of attribute input.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#signature ⇒ Object
Returns the value of attribute signature.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(headers, payload) ⇒ SignatureChecker
constructor
A new instance of SignatureChecker.
- #verify_signature ⇒ Object
Constructor Details
#initialize(headers, payload) ⇒ SignatureChecker
Returns a new instance of SignatureChecker.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/acube/signature_checker.rb', line 19 def initialize(headers, payload) @headers = headers if (!ACube.webhook_secret_key.nil? && !ACube.webhook_secret.nil?) raise InvalidSignatureError unless headers.has_key?("Authorization") && headers["Authorization"] == "#{ACube.webhook_secret_key} #{ACube.webhook_secret}" end raise InvalidSignatureError unless headers.has_key?("signature") && headers.has_key?("signature-input") && headers.has_key?("signature-digest") signature, input, digest = headers["signature"], headers["signature-input"], headers["signature-digest"] @payload = payload end |
Instance Attribute Details
#digest ⇒ Object
Returns the value of attribute digest.
18 19 20 |
# File 'lib/acube/signature_checker.rb', line 18 def digest @digest end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
17 18 19 |
# File 'lib/acube/signature_checker.rb', line 17 def headers @headers end |
#input ⇒ Object
Returns the value of attribute input.
18 19 20 |
# File 'lib/acube/signature_checker.rb', line 18 def input @input end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
17 18 19 |
# File 'lib/acube/signature_checker.rb', line 17 def payload @payload end |
#signature ⇒ Object
Returns the value of attribute signature.
18 19 20 |
# File 'lib/acube/signature_checker.rb', line 18 def signature @signature end |
Class Method Details
.verify_signature(request, payload) ⇒ Object
13 14 15 |
# File 'lib/acube/signature_checker.rb', line 13 def self.verify_signature(request, payload) new(request.headers, payload).verify_signature end |
Instance Method Details
#verify_signature ⇒ Object
31 32 33 34 |
# File 'lib/acube/signature_checker.rb', line 31 def verify_signature raw_data = url + params.sort.join OpenSSL::HMAC.digest(HASH_ALGORITHM, signature_gpg, raw_data) end |