authmac 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/circle.yml +3 -0
- data/lib/authmac/hmac_checker.rb +2 -1
- data/lib/authmac/version.rb +1 -1
- data/lib/authmac.rb +1 -2
- data/spec/authmac/hmac_checker_spec.rb +11 -5
- data/spec/authmac_spec.rb +2 -3
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e150851873e527bbdb621d19701b3d4ff7f976c7
|
4
|
+
data.tar.gz: 02bc0a0836b9931e91e3e32d2d532c6bdc5be40b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a68eadb5dc40141d7a165376f577ecec25967ad321d42124b53cd3f8db333f89a3b12b407921cedf60ead0eb001156a87f3ee82eb89186560e07e17d880cdba
|
7
|
+
data.tar.gz: ce5c1ef3d649f8adb7d371c86cb8a9931d84b25927eb5ee349d33ccb7241a68bdf81cf6a4aaee7661a5c17dbaaf121f8238c9362cfa72c5a05ba084f2e75ef39
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/circle.yml
ADDED
data/lib/authmac/hmac_checker.rb
CHANGED
@@ -2,10 +2,11 @@ require 'openssl'
|
|
2
2
|
|
3
3
|
module Authmac
|
4
4
|
class HmacChecker
|
5
|
-
def initialize(secret, parameter_separator = '|', digest_function =
|
5
|
+
def initialize(secret, parameter_separator = '|', digest_function = 'sha1')
|
6
6
|
@secret = secret
|
7
7
|
@digest = digest_function
|
8
8
|
@separator = parameter_separator
|
9
|
+
fail Authmac::SecretError, 'secret too short, see rfc2104' unless @secret.bytes.size >= digester.digest_length * 2
|
9
10
|
end
|
10
11
|
|
11
12
|
def validate(hash, given_hmac)
|
data/lib/authmac/version.rb
CHANGED
data/lib/authmac.rb
CHANGED
@@ -3,8 +3,7 @@ require 'authmac/hmac_checker'
|
|
3
3
|
require 'authmac/timestamp_checker'
|
4
4
|
|
5
5
|
module Authmac
|
6
|
-
class
|
7
|
-
class TimestampError < StandardError; end
|
6
|
+
class SecretError < StandardError; end
|
8
7
|
|
9
8
|
class ValidationResult
|
10
9
|
def initialize(options = {})
|
@@ -2,9 +2,16 @@ require 'authmac/hmac_checker'
|
|
2
2
|
|
3
3
|
module Authmac
|
4
4
|
describe HmacChecker do
|
5
|
-
let(:checker) { HmacChecker.new(
|
5
|
+
let(:checker) { HmacChecker.new('very secret random key of sufficient size', '|', 'sha1') }
|
6
|
+
|
7
|
+
it 'raises an error for a secret shorter than the hmac output' do
|
8
|
+
expect {
|
9
|
+
HmacChecker.new('way too short key', '|', 'sha1')
|
10
|
+
}.to raise_error SecretError, 'secret too short, see rfc2104'
|
11
|
+
end
|
6
12
|
|
7
13
|
describe '#validate' do
|
14
|
+
|
8
15
|
context 'for an empty hash' do
|
9
16
|
let(:hash) { Hash.new }
|
10
17
|
|
@@ -13,13 +20,13 @@ module Authmac
|
|
13
20
|
end
|
14
21
|
|
15
22
|
it 'fails with an incorrect hmac' do
|
16
|
-
expect(checker.validate(hash,
|
23
|
+
expect(checker.validate(hash, 'wrong')).to be_falsey
|
17
24
|
end
|
18
25
|
end
|
19
26
|
|
20
27
|
context 'for a hash with a single parameter' do
|
21
28
|
it 'succeeds with the correct hmac' do
|
22
|
-
expect(checker.validate({single: 'parameter'}, hmacify(
|
29
|
+
expect(checker.validate({single: 'parameter'}, hmacify('parameter'))).to be_truthy
|
23
30
|
end
|
24
31
|
|
25
32
|
it 'fails with incorrect hmac' do
|
@@ -36,7 +43,6 @@ module Authmac
|
|
36
43
|
it 'sorts hash values based on their keys' do
|
37
44
|
expect(checker.validate({second: 'another', first: 'parameter'},
|
38
45
|
hmacify('parameter|another'))).to be_truthy
|
39
|
-
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
@@ -49,7 +55,7 @@ module Authmac
|
|
49
55
|
|
50
56
|
def hmacify(string, method='sha1')
|
51
57
|
digester = OpenSSL::Digest.new(method)
|
52
|
-
OpenSSL::HMAC.hexdigest(digester,
|
58
|
+
OpenSSL::HMAC.hexdigest(digester, 'very secret random key of sufficient size', string)
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
data/spec/authmac_spec.rb
CHANGED
@@ -14,7 +14,7 @@ module Authmac
|
|
14
14
|
auth.validate(hash.merge(hmac: hmac))
|
15
15
|
end
|
16
16
|
|
17
|
-
it '
|
17
|
+
it 'sets the hmac_failure flag when hmac is incorrect' do
|
18
18
|
allow(hmac_checker).to receive(:validate).and_return(false)
|
19
19
|
expect(auth.validate({}).hmac_failure?).to be_truthy
|
20
20
|
end
|
@@ -25,11 +25,10 @@ module Authmac
|
|
25
25
|
auth.validate({timestamp: timestamp.to_s})
|
26
26
|
end
|
27
27
|
|
28
|
-
it '
|
28
|
+
it 'sets the timestamp_failure flag when timestamp is out of bounds' do
|
29
29
|
allow(timestamp_checker).to receive(:validate).and_return(false)
|
30
30
|
expect(auth.validate({}).timestamp_failure?).to be_truthy
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
34
33
|
end
|
35
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authmac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -47,11 +47,14 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CHANGELOG.md
|
50
52
|
- Gemfile
|
51
53
|
- LICENSE.txt
|
52
54
|
- README.md
|
53
55
|
- Rakefile
|
54
56
|
- authmac.gemspec
|
57
|
+
- circle.yml
|
55
58
|
- example/app.rb
|
56
59
|
- example/views/auth_hmac_failure.erb
|
57
60
|
- example/views/auth_success.erb
|
@@ -84,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
87
|
version: '0'
|
85
88
|
requirements: []
|
86
89
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.2.
|
90
|
+
rubygems_version: 2.2.1
|
88
91
|
signing_key:
|
89
92
|
specification_version: 4
|
90
93
|
summary: Single Sign-On implementation based on HMAC.
|