hmac_auth 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -1
- data/.travis.yml +2 -3
- data/Dockerfile +8 -0
- data/README.md +24 -29
- data/docker-compose.yml +4 -0
- data/hmac_auth.gemspec +1 -3
- data/lib/hmac_auth.rb +4 -1
- data/lib/hmac_auth/signature.rb +20 -3
- data/lib/hmac_auth/version.rb +1 -1
- data/spec/signature_spec.rb +44 -13
- data/vendor/cache/activesupport-5.0.1.gem +0 -0
- data/vendor/cache/concurrent-ruby-1.0.5.gem +0 -0
- data/vendor/cache/coveralls-0.8.19.gem +0 -0
- data/vendor/cache/diff-lcs-1.3.gem +0 -0
- data/vendor/cache/docile-1.1.5.gem +0 -0
- data/vendor/cache/i18n-0.8.1.gem +0 -0
- data/vendor/cache/json-2.0.3.gem +0 -0
- data/vendor/cache/minitest-5.10.1.gem +0 -0
- data/vendor/cache/rake-12.0.0.gem +0 -0
- data/vendor/cache/rspec-3.5.0.gem +0 -0
- data/vendor/cache/rspec-core-3.5.4.gem +0 -0
- data/vendor/cache/rspec-expectations-3.5.0.gem +0 -0
- data/vendor/cache/rspec-mocks-3.5.0.gem +0 -0
- data/vendor/cache/rspec-support-3.5.0.gem +0 -0
- data/vendor/cache/simplecov-0.12.0.gem +0 -0
- data/vendor/cache/simplecov-html-0.10.0.gem +0 -0
- data/vendor/cache/term-ansicolor-1.4.0.gem +0 -0
- data/vendor/cache/thor-0.19.4.gem +0 -0
- data/vendor/cache/thread_safe-0.3.6.gem +0 -0
- data/vendor/cache/tins-1.13.2.gem +0 -0
- data/vendor/cache/tzinfo-1.2.2.gem +0 -0
- metadata +26 -7
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/Gemfile.lock +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 73a1a89fb2b9e884e48e63010b1789adbec35875addf7a31f4b2f23db18df0b7
|
4
|
+
data.tar.gz: 34e220446f3a001004b9b30baf0e43999fc05f73d3fed0b6e136bf10e13dba7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b04e5f129f440990890465f6937374092516733f1f128abaae1b5a334450a437fa27aa75bfb0d035d18874edc5beff0242117fe6246b60043c022698f0c30254
|
7
|
+
data.tar.gz: 658deb0eb376fa9c03618c2c82ef3d406443a7c5db45887b8e0b2fcff0f409f4d02db7175a7772ba2161c2434121972a5b4be7855433c4f1f58348bdfbcca3b7
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Dockerfile
ADDED
data/README.md
CHANGED
@@ -3,50 +3,45 @@
|
|
3
3
|
[](https://travis-ci.org/gewo/hmac_auth/)
|
4
4
|
[](https://coveralls.io/r/gewo/hmac_auth)
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
/ /
|
10
|
-
|
11
|
-
/_/ /_/_/ /_/_/ |_\____/_/ |_\__,_/\__/_/ /_/
|
6
|
+
__ ____ ______ _________ __ __
|
7
|
+
/ / / / |/ / | / ____/ | __ __/ /_/ /_
|
8
|
+
/ /_/ / /|_/ / /| |/ / / /| |/ / / / __/ __ \
|
9
|
+
/ __ / / / / ___ / /___/ ___ / /_/ / /_/ / / /
|
10
|
+
/_/ /_/_/ /_/_/ |_\____/_/ |_\__,_/\__/_/ /_/
|
12
11
|
|
13
|
-
```
|
14
12
|
|
15
13
|
Ruby gem providing HMAC based message signing and verification. Without
|
16
14
|
fancy Rails integration.
|
17
15
|
|
18
16
|
## Installation
|
19
17
|
|
20
|
-
|
21
|
-
gem
|
22
|
-
gem install hmac_auth # manual
|
23
|
-
```
|
18
|
+
gem 'hmac_auth' # Gemfile
|
19
|
+
gem install hmac_auth # manual
|
24
20
|
|
25
21
|
## Usage
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
HMACAuth.
|
30
|
-
HMACAuth.
|
31
|
-
HMACAuth.
|
23
|
+
# Configuration
|
24
|
+
HMACAuth.secret = 't0p_s3cr3!!eins1'
|
25
|
+
HMACAuth.reject_keys = %w(action controller format)
|
26
|
+
HMACAuth.valid_for = 15.minutes
|
27
|
+
HMACAuth.keep_values_type = false
|
32
28
|
|
33
|
-
to_be_signed = {
|
34
|
-
|
35
|
-
|
36
|
-
}
|
29
|
+
to_be_signed = {
|
30
|
+
b: 2,
|
31
|
+
a: { d: 4, c: 3 }
|
32
|
+
}
|
37
33
|
|
38
|
-
signed = HMACAuth::Signature.sign to_be_signed
|
39
|
-
# => Hash including 'timestamp' and 'signature'
|
34
|
+
signed = HMACAuth::Signature.sign to_be_signed
|
35
|
+
# => Hash including 'timestamp' and 'signature'
|
40
36
|
|
41
|
-
HMACAuth::Signature.verify(signed) # => true
|
42
|
-
HMACAuth::Signature.verify(signed.merge(evil: 'yes')) # => false
|
43
|
-
HMACAuth::Signature.verify(signed, secret: 'good guess?') # => false
|
37
|
+
HMACAuth::Signature.verify(signed) # => true
|
38
|
+
HMACAuth::Signature.verify(signed.merge(evil: 'yes')) # => false
|
39
|
+
HMACAuth::Signature.verify(signed, secret: 'good guess?') # => false
|
44
40
|
|
45
|
-
sleep 20.minutes
|
46
|
-
HMACAuth::Signature.verify(signed) # => false
|
41
|
+
sleep 20.minutes
|
42
|
+
HMACAuth::Signature.verify(signed) # => false
|
47
43
|
|
48
|
-
# That's it. Nothing more, nothing less.
|
49
|
-
```
|
44
|
+
# That's it. Nothing more, nothing less.
|
50
45
|
|
51
46
|
## Contributing
|
52
47
|
|
data/docker-compose.yml
ADDED
data/hmac_auth.gemspec
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'hmac_auth/version'
|
2
|
+
require File.expand_path('../lib/hmac_auth/version', __FILE__)
|
5
3
|
|
6
4
|
Gem::Specification.new do |gem|
|
7
5
|
gem.name = 'hmac_auth'
|
data/lib/hmac_auth.rb
CHANGED
@@ -11,7 +11,8 @@ require 'hmac_auth/signature'
|
|
11
11
|
module HMACAuth
|
12
12
|
mattr_accessor :secret,
|
13
13
|
:reject_keys,
|
14
|
-
:valid_for
|
14
|
+
:valid_for,
|
15
|
+
:keep_values_type
|
15
16
|
|
16
17
|
# The shared secret.
|
17
18
|
self.secret = nil
|
@@ -22,4 +23,6 @@ module HMACAuth
|
|
22
23
|
# Time the signature is valid when verifying
|
23
24
|
self.valid_for = 15.minutes
|
24
25
|
|
26
|
+
# Keep or not the values type when signing
|
27
|
+
self.keep_values_type = false
|
25
28
|
end
|
data/lib/hmac_auth/signature.rb
CHANGED
@@ -16,6 +16,8 @@ module HMACAuth
|
|
16
16
|
@secret = options.delete(:secret) || HMACAuth.secret
|
17
17
|
@valid_for = options.delete(:valid_for) || HMACAuth.valid_for
|
18
18
|
@reject_keys = options.delete(:reject_keys) || HMACAuth.reject_keys
|
19
|
+
@keep_values_type = options.delete(:keep_values_type) ||
|
20
|
+
HMACAuth.keep_values_type
|
19
21
|
@_params = params
|
20
22
|
|
21
23
|
raise Error.new 'You *must* tell me a secret!' unless @secret
|
@@ -50,6 +52,12 @@ module HMACAuth
|
|
50
52
|
end]
|
51
53
|
end
|
52
54
|
|
55
|
+
def deep_stringify_skip_values(hash)
|
56
|
+
Hash[hash.map do |k, v|
|
57
|
+
[k.to_s, v.is_a?(Hash) ? deep_stringify_skip_values(v) : v]
|
58
|
+
end]
|
59
|
+
end
|
60
|
+
|
53
61
|
def valid_timestamp
|
54
62
|
timestamp && timestamp >= valid_for.ago.to_i
|
55
63
|
end
|
@@ -69,11 +77,20 @@ module HMACAuth
|
|
69
77
|
end
|
70
78
|
|
71
79
|
def params
|
72
|
-
|
80
|
+
reject_keys!
|
81
|
+
@params ||= if keep_values_type
|
82
|
+
deep_stringify_skip_values(reject_keys!)
|
83
|
+
else
|
84
|
+
deep_stringify(reject_keys!)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def reject_keys!
|
89
|
+
@_params.reject do |k, v|
|
73
90
|
reject_keys.include? k
|
74
|
-
end
|
91
|
+
end
|
75
92
|
end
|
76
93
|
|
77
|
-
attr_reader :secret, :valid_for, :reject_keys
|
94
|
+
attr_reader :secret, :valid_for, :reject_keys, :keep_values_type
|
78
95
|
end
|
79
96
|
end
|
data/lib/hmac_auth/version.rb
CHANGED
data/spec/signature_spec.rb
CHANGED
@@ -24,38 +24,38 @@ module HMACAuth
|
|
24
24
|
|
25
25
|
context 'valid' do
|
26
26
|
let(:timestamp) { 10.minutes.ago.to_i.to_s }
|
27
|
-
it { should
|
27
|
+
it { should be_truthy }
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'invalid' do
|
31
31
|
let(:timestamp) { 20.minutes.ago.to_i }
|
32
|
-
it { should
|
32
|
+
it { should be_falsy }
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '.sign' do
|
38
|
-
def signature(hash)
|
39
|
-
HMACAuth::Signature.sign(hash, secret: secret)['signature']
|
40
|
-
end
|
41
|
-
|
42
38
|
describe 'hash' do
|
43
39
|
subject { HMACAuth::Signature.sign(params, secret: secret) }
|
44
40
|
|
45
|
-
it {
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
it { expect(subject).to be_a Hash }
|
42
|
+
it { expect(subject['signature']).to be_a String }
|
43
|
+
it { expect(subject['timestamp']).to be }
|
44
|
+
it { expect(subject['b']).to be_a String }
|
49
45
|
|
50
46
|
context 'nested hash' do
|
51
47
|
subject { HMACAuth::Signature.sign(params, secret: secret)['a'] }
|
52
|
-
it {
|
53
|
-
|
54
|
-
|
48
|
+
it { expect(subject).to be_a Hash }
|
49
|
+
it { expect(subject['d']).to eq '4' }
|
50
|
+
it { expect(subject['c']).to eq '3' }
|
55
51
|
end
|
56
52
|
end
|
57
53
|
|
58
54
|
describe 'unsorted input' do
|
55
|
+
def signature(hash)
|
56
|
+
HMACAuth::Signature.sign(hash, secret: secret)['signature']
|
57
|
+
end
|
58
|
+
|
59
59
|
let(:hasha) { { a: 1, b: { c: 3, d: 4 } } }
|
60
60
|
let(:hashd) { { b: { d: 4, c: 3 }, a: 1 } }
|
61
61
|
|
@@ -63,6 +63,37 @@ module HMACAuth
|
|
63
63
|
signature(hasha).should == signature(hashd)
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
context 'when keep_values_type is true' do
|
68
|
+
describe 'hash' do
|
69
|
+
subject do
|
70
|
+
HMACAuth::Signature.sign(
|
71
|
+
params,
|
72
|
+
secret: secret,
|
73
|
+
keep_values_type: true
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
it { expect(subject).to be_a Hash }
|
78
|
+
it { expect(subject['signature']).to be_a String }
|
79
|
+
it { expect(subject['timestamp']).to be }
|
80
|
+
it { expect(subject['b']).to be_a Integer }
|
81
|
+
|
82
|
+
context 'nested hash' do
|
83
|
+
subject do
|
84
|
+
HMACAuth::Signature.sign(
|
85
|
+
params,
|
86
|
+
secret: secret,
|
87
|
+
keep_values_type: true
|
88
|
+
)['a']
|
89
|
+
end
|
90
|
+
|
91
|
+
it { expect(subject).to be_a Hash }
|
92
|
+
it { expect(subject['d']).to eq 4 }
|
93
|
+
it { expect(subject['c']).to eq 3 }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
66
97
|
end
|
67
98
|
end
|
68
99
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hmac_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gebhard Wöstemeyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -90,14 +90,13 @@ files:
|
|
90
90
|
- ".coveralls.yml"
|
91
91
|
- ".gitignore"
|
92
92
|
- ".rspec"
|
93
|
-
- ".ruby-gemset"
|
94
|
-
- ".ruby-version"
|
95
93
|
- ".travis.yml"
|
94
|
+
- Dockerfile
|
96
95
|
- Gemfile
|
97
|
-
- Gemfile.lock
|
98
96
|
- LICENSE.txt
|
99
97
|
- README.md
|
100
98
|
- Rakefile
|
99
|
+
- docker-compose.yml
|
101
100
|
- hmac_auth.gemspec
|
102
101
|
- lib/hmac_auth.rb
|
103
102
|
- lib/hmac_auth/error.rb
|
@@ -105,6 +104,27 @@ files:
|
|
105
104
|
- lib/hmac_auth/version.rb
|
106
105
|
- spec/signature_spec.rb
|
107
106
|
- spec/spec_helper.rb
|
107
|
+
- vendor/cache/activesupport-5.0.1.gem
|
108
|
+
- vendor/cache/concurrent-ruby-1.0.5.gem
|
109
|
+
- vendor/cache/coveralls-0.8.19.gem
|
110
|
+
- vendor/cache/diff-lcs-1.3.gem
|
111
|
+
- vendor/cache/docile-1.1.5.gem
|
112
|
+
- vendor/cache/i18n-0.8.1.gem
|
113
|
+
- vendor/cache/json-2.0.3.gem
|
114
|
+
- vendor/cache/minitest-5.10.1.gem
|
115
|
+
- vendor/cache/rake-12.0.0.gem
|
116
|
+
- vendor/cache/rspec-3.5.0.gem
|
117
|
+
- vendor/cache/rspec-core-3.5.4.gem
|
118
|
+
- vendor/cache/rspec-expectations-3.5.0.gem
|
119
|
+
- vendor/cache/rspec-mocks-3.5.0.gem
|
120
|
+
- vendor/cache/rspec-support-3.5.0.gem
|
121
|
+
- vendor/cache/simplecov-0.12.0.gem
|
122
|
+
- vendor/cache/simplecov-html-0.10.0.gem
|
123
|
+
- vendor/cache/term-ansicolor-1.4.0.gem
|
124
|
+
- vendor/cache/thor-0.19.4.gem
|
125
|
+
- vendor/cache/thread_safe-0.3.6.gem
|
126
|
+
- vendor/cache/tins-1.13.2.gem
|
127
|
+
- vendor/cache/tzinfo-1.2.2.gem
|
108
128
|
homepage: https://github.com/gewo/hmac_auth
|
109
129
|
licenses:
|
110
130
|
- MIT
|
@@ -124,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
144
|
- !ruby/object:Gem::Version
|
125
145
|
version: '0'
|
126
146
|
requirements: []
|
127
|
-
|
128
|
-
rubygems_version: 2.2.2
|
147
|
+
rubygems_version: 3.0.6
|
129
148
|
signing_key:
|
130
149
|
specification_version: 4
|
131
150
|
summary: Ruby gem providing HMAC based message signing and verification. Without fancy
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
hmac_auth
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.1.0
|
data/Gemfile.lock
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
hmac_auth (0.1.2)
|
5
|
-
activesupport
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (4.1.8)
|
11
|
-
i18n (~> 0.6, >= 0.6.9)
|
12
|
-
json (~> 1.7, >= 1.7.7)
|
13
|
-
minitest (~> 5.1)
|
14
|
-
thread_safe (~> 0.1)
|
15
|
-
tzinfo (~> 1.1)
|
16
|
-
coveralls (0.7.0)
|
17
|
-
multi_json (~> 1.3)
|
18
|
-
rest-client
|
19
|
-
simplecov (>= 0.7)
|
20
|
-
term-ansicolor
|
21
|
-
thor
|
22
|
-
diff-lcs (1.2.5)
|
23
|
-
docile (1.1.1)
|
24
|
-
i18n (0.6.11)
|
25
|
-
json (1.8.1)
|
26
|
-
mime-types (2.0)
|
27
|
-
minitest (5.5.0)
|
28
|
-
multi_json (1.8.4)
|
29
|
-
rake (10.1.1)
|
30
|
-
rest-client (1.6.7)
|
31
|
-
mime-types (>= 1.16)
|
32
|
-
rspec (2.14.1)
|
33
|
-
rspec-core (~> 2.14.0)
|
34
|
-
rspec-expectations (~> 2.14.0)
|
35
|
-
rspec-mocks (~> 2.14.0)
|
36
|
-
rspec-core (2.14.7)
|
37
|
-
rspec-expectations (2.14.4)
|
38
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
39
|
-
rspec-mocks (2.14.4)
|
40
|
-
simplecov (0.8.2)
|
41
|
-
docile (~> 1.1.0)
|
42
|
-
multi_json
|
43
|
-
simplecov-html (~> 0.8.0)
|
44
|
-
simplecov-html (0.8.0)
|
45
|
-
term-ansicolor (1.2.2)
|
46
|
-
tins (~> 0.8)
|
47
|
-
thor (0.18.1)
|
48
|
-
thread_safe (0.3.4)
|
49
|
-
tins (0.13.1)
|
50
|
-
tzinfo (1.2.2)
|
51
|
-
thread_safe (~> 0.1)
|
52
|
-
|
53
|
-
PLATFORMS
|
54
|
-
ruby
|
55
|
-
|
56
|
-
DEPENDENCIES
|
57
|
-
coveralls
|
58
|
-
hmac_auth!
|
59
|
-
rake
|
60
|
-
rspec
|
61
|
-
simplecov
|