authmac 1.0.1 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4b7bd1e6888d9396a2b8625350f3626575facb4
4
- data.tar.gz: c868726a7655dd6063eea99029a2b09296d1b405
3
+ metadata.gz: e150851873e527bbdb621d19701b3d4ff7f976c7
4
+ data.tar.gz: 02bc0a0836b9931e91e3e32d2d532c6bdc5be40b
5
5
  SHA512:
6
- metadata.gz: 864d917472213fda96505a9b093a24954805023619b6725b259dc26b9a705605a95156f9914944ec6716e4f348f3f05e211c24bff74069e8bedcdb34eb1164cc
7
- data.tar.gz: 9501f5e4860c67f36f2fb0c9c758207c89090c1d10cfc6dc55accbf8f9b5eb81123101ab7728960b60ab392dc1d7063781d700e71f44754b1c785747c91aa0d4
6
+ metadata.gz: 8a68eadb5dc40141d7a165376f577ecec25967ad321d42124b53cd3f8db333f89a3b12b407921cedf60ead0eb001156a87f3ee82eb89186560e07e17d880cdba
7
+ data.tar.gz: ce5c1ef3d649f8adb7d371c86cb8a9931d84b25927eb5ee349d33ccb7241a68bdf81cf6a4aaee7661a5c17dbaaf121f8238c9362cfa72c5a05ba084f2e75ef39
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - '2.1.0'
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## Version 1.0.3 / 2014-5-12
2
+
3
+ * Raise error when insecure key is being used, assuming all keys are hex values (see rfc2104)
4
+ * Only compatible with ruby 2
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.1.0
@@ -2,10 +2,11 @@ require 'openssl'
2
2
 
3
3
  module Authmac
4
4
  class HmacChecker
5
- def initialize(secret, parameter_separator = '|', digest_function = "sha1")
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)
@@ -1,3 +1,3 @@
1
1
  module Authmac
2
- VERSION = "1.0.1"
2
+ VERSION = '1.0.3'
3
3
  end
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 HmacError < StandardError; end
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("very secret key", "|", "sha1") }
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, "wrong")).to be_falsey
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("parameter"))).to be_truthy
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, "very secret key", string)
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 'raises HmacError if hmac is incorrect' do
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 'raises TimestampError if timestamp is out of bounds' do
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.1
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-01-22 00:00:00.000000000 Z
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.0
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.