hsign 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/hsign/digest.rb +4 -2
- data/lib/hsign/extensions.rb +20 -0
- data/lib/hsign/version.rb +1 -1
- data/test/digest_test.rb +19 -0
- metadata +31 -22
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3940bbd06c9e29a88b3229828e7ee56368adb80c
|
4
|
+
data.tar.gz: 9a5c525e4e2027d63eaddb57d69fa6f1483a30b0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 531b62729e465de31a89e7bf48645cb3797c4d12bdbcea9893b005a71644b42f82cb077df7f1067ee893e06981f23fa61157c96c0c64f0f3866786ba9a52cf1f
|
7
|
+
data.tar.gz: bc06a65d57a12b2613a2ef5e3671dd5ca0f49a53eafece782b5d962338a940b8f0a1d2797e5d14830abe724c06a5c11d8676b057eb765b9dd2db9a4f457ee644
|
data/lib/hsign/digest.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'rack/utils'
|
3
|
+
require 'hsign/extensions'
|
4
|
+
|
3
5
|
module HSign
|
4
6
|
class Digest
|
5
7
|
attr_accessor :hmac_key
|
6
8
|
attr_reader :params
|
7
9
|
|
8
10
|
def initialize(secret, salt = nil)
|
9
|
-
@digest = OpenSSL::Digest
|
11
|
+
@digest = OpenSSL::Digest.new('sha1')
|
10
12
|
@hmac_key = '_hmac'
|
11
13
|
@secret = secret
|
12
14
|
@salt = salt
|
@@ -16,7 +18,7 @@ module HSign
|
|
16
18
|
hmac = OpenSSL::HMAC.new @secret, @digest
|
17
19
|
hmac << @salt if @salt
|
18
20
|
# Normalize all params
|
19
|
-
@params = Rack::Utils.parse_query(Rack::Utils.build_nested_query(request_params.
|
21
|
+
@params = Rack::Utils.parse_query(Rack::Utils.build_nested_query(request_params.to_hsign_string_values))
|
20
22
|
@params.delete(hmac_key)
|
21
23
|
|
22
24
|
@params.to_a.sort_by{|k,v| k.to_s}.each do |k,v|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Object
|
2
|
+
def to_hsign_string_values
|
3
|
+
to_s
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Array
|
8
|
+
def to_hsign_string_values
|
9
|
+
map(&:to_hsign_string_values)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Hash
|
14
|
+
def to_hsign_string_values
|
15
|
+
other = dup
|
16
|
+
other.each do |k, v|
|
17
|
+
other[k] = v.to_hsign_string_values
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/hsign/version.rb
CHANGED
data/test/digest_test.rb
CHANGED
@@ -56,4 +56,23 @@ class DigestTest < Test::Unit::TestCase
|
|
56
56
|
equivalent_params = {'prefill[ns][name]' => 'hello', 'prefill[key2]' => 'world', 'terra' => 'incognita'}
|
57
57
|
assert_equal @hsign.sign(params), @hsign.sign(equivalent_params)
|
58
58
|
end
|
59
|
+
|
60
|
+
test "non string nested parameters" do
|
61
|
+
params = { prefill: {key1: 1, key2: 2} }
|
62
|
+
equivalent_params = {'prefill[key1]' => '1', 'prefill[key2]' => '2'}
|
63
|
+
assert_equal @hsign.sign(params), @hsign.sign(equivalent_params)
|
64
|
+
end
|
65
|
+
|
66
|
+
test "agregate signed params hash" do
|
67
|
+
params = { key1: 1, key2: 2 }
|
68
|
+
equivalent_params = { 'key1' => '1', 'key2' => '2' }
|
69
|
+
@hsign.sign(params)
|
70
|
+
assert_equal @hsign.params, equivalent_params.merge('_hmac' => @hsign.sign(params))
|
71
|
+
end
|
72
|
+
|
73
|
+
test "verify string and non string values" do
|
74
|
+
params = { key1: 1, key2: 2 }
|
75
|
+
equivalent_params = { 'key1' => '1', 'key2' => '2', '_hmac' => @hsign.sign(params) }
|
76
|
+
assert @hsign.verify?(equivalent_params)
|
77
|
+
end
|
59
78
|
end
|
metadata
CHANGED
@@ -1,49 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hsign
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Helios Technologies Ltd.
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rack
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: test-unit
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
description: Web Digital Signature
|
48
56
|
email:
|
49
57
|
- hery@heliostech.hk
|
@@ -51,7 +59,7 @@ executables: []
|
|
51
59
|
extensions: []
|
52
60
|
extra_rdoc_files: []
|
53
61
|
files:
|
54
|
-
- .gitignore
|
62
|
+
- ".gitignore"
|
55
63
|
- Gemfile
|
56
64
|
- LICENSE.txt
|
57
65
|
- README.md
|
@@ -59,33 +67,34 @@ files:
|
|
59
67
|
- hsign.gemspec
|
60
68
|
- lib/hsign.rb
|
61
69
|
- lib/hsign/digest.rb
|
70
|
+
- lib/hsign/extensions.rb
|
62
71
|
- lib/hsign/version.rb
|
63
72
|
- test/digest_test.rb
|
64
73
|
- test/test_helper.rb
|
65
74
|
homepage: ''
|
66
75
|
licenses: []
|
76
|
+
metadata: {}
|
67
77
|
post_install_message:
|
68
78
|
rdoc_options: []
|
69
79
|
require_paths:
|
70
80
|
- lib
|
71
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
82
|
requirements:
|
74
|
-
- -
|
83
|
+
- - ">="
|
75
84
|
- !ruby/object:Gem::Version
|
76
85
|
version: '0'
|
77
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
87
|
requirements:
|
80
|
-
- -
|
88
|
+
- - ">="
|
81
89
|
- !ruby/object:Gem::Version
|
82
90
|
version: '0'
|
83
91
|
requirements: []
|
84
92
|
rubyforge_project:
|
85
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.2.0
|
86
94
|
signing_key:
|
87
|
-
specification_version:
|
95
|
+
specification_version: 4
|
88
96
|
summary: Web Digital Signature
|
89
97
|
test_files:
|
90
98
|
- test/digest_test.rb
|
91
99
|
- test/test_helper.rb
|
100
|
+
has_rdoc:
|