recurly 4.23.0 → 4.24.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3425e11a326e6886fe09606f3cd02f155ded5fb774f639d20f47f2a4def65f3
4
- data.tar.gz: 39d0917188e796d37e7179a86e78427dab022cf94ea3d6c13b734153d54f2b0c
3
+ metadata.gz: 5f585c84e359302293e13409b5162b2ad56241f342b0c9e9c2c4200f29782a32
4
+ data.tar.gz: d8908b9d5e9cefcce7a9fa6cfa0d75b69dcd8b885ac6ce6dacc2ec416f56c1a1
5
5
  SHA512:
6
- metadata.gz: c06705fdd51268f7f1a298dc6b92ab65c4a972106d32d2e7909ac6852d780ab0024170da9c0f028d43695fe17706371684f93366217bbf3577fd9e1200068854
7
- data.tar.gz: 63565f407525519ff2594677070a394675c7500d03565d704c0bd07e4ef7afa94ffb2d9839efd07f527bc65fc9979090d4ab4cf1166d988d7879fcbb757576e9
6
+ metadata.gz: 3d42081e4d4e095850d9b1158e8c798ab0cc11d9f9d68bb895ba77808a2d6f4f1a0bdfeac2c6394d704ea74add4df4ba63ca2eca70d1c05c1b3499e3c9bbbb76
7
+ data.tar.gz: 1bb51683c999694c1843c378754ba2fb6556d205db5f50ebf93cde4cb46997548cd31f3062b75f6b1db7d3bb575a3040ddea88276f1172fca424785e96b92304
data/.bumpversion.cfg CHANGED
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 4.23.0
2
+ current_version = 4.24.0
3
3
  parse = (?P<major>\d+)
4
4
  \.(?P<minor>\d+)
5
5
  \.(?P<patch>\d+)
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.24.0](https://github.com/recurly/recurly-client-ruby/tree/4.24.0) (2022-11-03)
4
+
5
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/4.23.0...4.24.0)
6
+
7
+
8
+
9
+
10
+
3
11
  ## [4.23.0](https://github.com/recurly/recurly-client-ruby/tree/4.23.0) (2022-10-27)
4
12
 
5
13
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/4.22.0...4.23.0)
data/GETTING_STARTED.md CHANGED
@@ -5,7 +5,7 @@ This repository houses the official ruby client for Recurly's V3 API.
5
5
  In your Gemfile, add `recurly` as a dependency.
6
6
 
7
7
  ```ruby
8
- gem 'recurly', '~> 4.23'
8
+ gem 'recurly', '~> 4.24'
9
9
  ```
10
10
 
11
11
  > *Note*: We try to follow [semantic versioning](https://semver.org/) and will only apply breaking changes to major versions.
@@ -0,0 +1,5 @@
1
+ module Recurly
2
+ module Errors
3
+ class SignatureVerificationError < StandardError; end
4
+ end
5
+ end
@@ -48,4 +48,5 @@ module Recurly
48
48
 
49
49
  require_relative "./errors/api_errors"
50
50
  require_relative "./errors/network_errors"
51
+ require_relative "./errors/webhooks_errors"
51
52
  end
@@ -1,3 +1,3 @@
1
1
  module Recurly
2
- VERSION = "4.23.0"
2
+ VERSION = "4.24.0"
3
3
  end
@@ -0,0 +1,52 @@
1
+ module Recurly
2
+ module Webhooks
3
+ DEFAULT_TOLERANCE = 5 * 60 * 1000
4
+
5
+ # Verify webhook signature
6
+ #
7
+ # @param header [String] recurly-signature header from request
8
+ # @param secret [String] Shared secret for notification endpoint
9
+ # @param body [String] Request POST body
10
+ # @param tolerance [Integer] Allowed notification time drift in milliseconds
11
+ # @example
12
+ # begin
13
+ # Recurly::Webhooks.verify_signature(header,
14
+ # ENV['WEBHOOKS_KEY'],
15
+ # request.body)
16
+ # rescue Recurly::Errors::SignatureVerificationError => e
17
+ # puts e.message
18
+ # end
19
+ #
20
+ def self.verify_signature(header, secret, body, tolerance: DEFAULT_TOLERANCE)
21
+ s_timestamp, *signatures = header.split(",")
22
+ timestamp = Integer(s_timestamp)
23
+ now = (Time.now.to_f * 1000).to_i
24
+
25
+ if (now - timestamp).abs > tolerance
26
+ raise Recurly::Errors::SignatureVerificationError.new(
27
+ "Notification (#{Time.at(timestamp / 1000.0)}) is more than #{tolerance / 1000.0}s out of date"
28
+ )
29
+ end
30
+
31
+ expected = OpenSSL::HMAC.hexdigest("sha256", secret, "#{timestamp}.#{body}")
32
+
33
+ unless signatures.any? { |s| secure_compare(expected, s) }
34
+ raise Recurly::Errors::SignatureVerificationError.new(
35
+ "No matching signatures found for payload"
36
+ )
37
+ end
38
+ end
39
+
40
+ # https://github.com/rack/rack/blob/2-2-stable/lib/rack/utils.rb#L374
41
+ # https://github.com/heartcombo/devise/blob/4-1-stable/lib/devise.rb#L477
42
+ def self.secure_compare(a, b)
43
+ return false if a.bytesize != b.bytesize
44
+ l = a.unpack("C#{a.bytesize}")
45
+
46
+ res = 0
47
+ b.each_byte { |byte| res |= byte ^ l.shift }
48
+ res == 0
49
+ end
50
+ private_class_method :secure_compare
51
+ end
52
+ end
data/lib/recurly.rb CHANGED
@@ -9,6 +9,7 @@ require "recurly/http"
9
9
  require "recurly/errors"
10
10
  require "recurly/connection_pool"
11
11
  require "recurly/client"
12
+ require "recurly/webhooks"
12
13
 
13
14
  module Recurly
14
15
  STRICT_MODE = ENV["RECURLY_STRICT_MODE"] && ENV["RECURLY_STRICT_MODE"].downcase == "true"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recurly
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.23.0
4
+ version: 4.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Recurly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2022-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -141,6 +141,7 @@ files:
141
141
  - lib/recurly/errors.rb
142
142
  - lib/recurly/errors/api_errors.rb
143
143
  - lib/recurly/errors/network_errors.rb
144
+ - lib/recurly/errors/webhooks_errors.rb
144
145
  - lib/recurly/http.rb
145
146
  - lib/recurly/pager.rb
146
147
  - lib/recurly/request.rb
@@ -304,6 +305,7 @@ files:
304
305
  - lib/recurly/schema/schema_factory.rb
305
306
  - lib/recurly/schema/schema_validator.rb
306
307
  - lib/recurly/version.rb
308
+ - lib/recurly/webhooks.rb
307
309
  - openapi/api.yaml
308
310
  - recurly.gemspec
309
311
  - scripts/build
@@ -320,7 +322,7 @@ metadata:
320
322
  changelog_uri: https://github.com/recurly/recurly-client-ruby/blob/master/CHANGELOG.md
321
323
  documentation_uri: https://recurly.github.io/recurly-client-ruby/
322
324
  homepage_uri: https://github.com/recurly/recurly-client-ruby
323
- source_code_uri: https://github.com/recurly/recurly-client-ruby/tree/4.23.0
325
+ source_code_uri: https://github.com/recurly/recurly-client-ruby/tree/4.24.0
324
326
  post_install_message:
325
327
  rdoc_options: []
326
328
  require_paths: