ey-hmac 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/lib/ey-hmac/adapter.rb +21 -5
- data/lib/ey-hmac/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea57d603aa108a1bf510fcf6e61aa45b1d1d0fca0ba7aa1b97681396fae9a7c
|
4
|
+
data.tar.gz: 7ad6caf49126be2b2a4b75acbc97ecf9d1898307a896f909493850be26d8261e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c790db93637c36fe752759cdb1aac1a70d3f1378ca5c2ae6b4132b8115d97b5e75b15e75de7dc069800980846d83524dbbe58903d9fd4b2006499e0ff8f9826
|
7
|
+
data.tar.gz: 6d8745e27b9c8d01d01d9f6bc608eba2f6fd6f8476a28eba9097dda9765944b8d5ba535be0901f151e69f4b66b9e1a2d022bdd29cbc38fc68a3ec9cacfaf2500
|
data/.rubocop.yml
CHANGED
data/lib/ey-hmac/adapter.rb
CHANGED
@@ -4,11 +4,19 @@
|
|
4
4
|
# @abstract override methods {#method}, {#path}, {#body}, {#content_type} and {#content_digest}
|
5
5
|
class Ey::Hmac::Adapter
|
6
6
|
AUTHORIZATION_REGEXP = /\w+ ([^:]+):(.+)$/.freeze
|
7
|
+
DEFAULT_CANONICALIZE_WITH = %i[method content_type content_digest date path].freeze
|
7
8
|
|
8
9
|
autoload :Rack, 'ey-hmac/adapter/rack'
|
9
10
|
autoload :Faraday, 'ey-hmac/adapter/faraday'
|
10
11
|
|
11
|
-
attr_reader :request,
|
12
|
+
attr_reader :request,
|
13
|
+
:options,
|
14
|
+
:authorization_header,
|
15
|
+
:service,
|
16
|
+
:sign_with,
|
17
|
+
:accept_digests,
|
18
|
+
:include_query_string,
|
19
|
+
:canonicalize_with
|
12
20
|
|
13
21
|
# @param [Object] request signer-specific request implementation
|
14
22
|
# @option options [Integer] :version signature version
|
@@ -16,6 +24,7 @@ class Ey::Hmac::Adapter
|
|
16
24
|
# @option options [String] :authorization_header ('Authorization') Authorization header key.
|
17
25
|
# @option options [String] :server ('EyHmac') service name prefixed to {#authorization}. set to {#service}
|
18
26
|
# @option options [Symbol] :sign_with (:sha_256) outgoing signature digest algorithm. See {OpenSSL::Digest#new}
|
27
|
+
# @option options [Symbol] :include_query_string (false) canonicalize with the request query string.
|
19
28
|
# @option options [Array] :accepted_digests ([:sha_256]) accepted incoming signature digest algorithm. See {OpenSSL::Digest#new}
|
20
29
|
def initialize(request, options = {})
|
21
30
|
@request = request
|
@@ -25,7 +34,11 @@ class Ey::Hmac::Adapter
|
|
25
34
|
@authorization_header = options[:authorization_header] || 'Authorization'
|
26
35
|
@service = options[:service] || 'EyHmac'
|
27
36
|
@sign_with = options[:sign_with] || :sha256
|
28
|
-
@
|
37
|
+
@include_query_string = options.fetch(:include_query_string, false)
|
38
|
+
@accept_digests = Array(options[:accept_digests] || :sha256)
|
39
|
+
|
40
|
+
@canonicalize_with = DEFAULT_CANONICALIZE_WITH
|
41
|
+
@canonicalize_with += :query_string if include_query_string
|
29
42
|
end
|
30
43
|
|
31
44
|
# In order for the server to correctly authorize the request, the client and server MUST AGREE on this format
|
@@ -33,7 +46,7 @@ class Ey::Hmac::Adapter
|
|
33
46
|
# default canonical string formation is '{#method}\\n{#content_type}\\n{#content_digest}\\n{#date}\\n{#path}'
|
34
47
|
# @return [String] canonical string used to form the {#signature}
|
35
48
|
def canonicalize
|
36
|
-
|
49
|
+
canonicalize_with.map { |message| public_send(message) }.join("\n")
|
37
50
|
end
|
38
51
|
|
39
52
|
# @param [String] key_secret private HMAC key
|
@@ -129,8 +142,11 @@ class Ey::Hmac::Adapter
|
|
129
142
|
|
130
143
|
check_ttl!
|
131
144
|
|
132
|
-
|
133
|
-
|
145
|
+
matching_signature =
|
146
|
+
accept_digests
|
147
|
+
.lazy
|
148
|
+
.map { |ad| signature(key_secret, ad) }
|
149
|
+
.any? { |cs| secure_compare(signature_value, cs) }
|
134
150
|
|
135
151
|
raise Ey::Hmac::SignatureMismatch unless matching_signature
|
136
152
|
|
data/lib/ey-hmac/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ey-hmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|