json-jwt 0.6.1 → 0.7.0.alpha

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json-jwt might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfafaeda298c56aa5cd5f1056f33b31ed7b31bb8
4
- data.tar.gz: fe6fd7d8d776f0b197add6a79f2b11a03afc9af7
3
+ metadata.gz: de4af966b0dc54f6caf14149295dbb7f8bccd856
4
+ data.tar.gz: 2a93fc7d1d35b3fc7319f31a2fed23392c0ed7d8
5
5
  SHA512:
6
- metadata.gz: f0ead0b472adcf5fab5203765d2b83ea4afeb131510d4765b0f884867de2affeac688d72c8bbc64626498680e0b6c55a1f351d9fcd07fde418342be7ef9ab92c
7
- data.tar.gz: adca33ab7ec94e4a92a70585cf3c3e441f2f22c56701071adc79f1d5ecd6a0bc28fbb9cbb13ce74b9869c8dfe274c3da1d65b49621e5fbe1ce944e1c6204caab
6
+ metadata.gz: d7424823b6791844548cc154beaa9569672c1f7f439770d21f3effed0a3b9a7007de394c2bc2aee627907e97d2a080e48ff51d578a2a0f82ce34979aabcacf08
7
+ data.tar.gz: bbdd062cc11dfc58af47d27969ee42a1c940e7a1646a818458a69d8cbac25b869bd14123f63bf4326913c2b3af3db6b21c30b69d46203db82f91b507dcdffd6a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0.alpha
data/json-jwt.gemspec CHANGED
@@ -18,5 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.add_runtime_dependency "securecompare"
19
19
  gem.add_development_dependency "rake", ">= 0.8"
20
20
  gem.add_development_dependency "simplecov"
21
- gem.add_development_dependency "rspec", ">= 2"
21
+ gem.add_development_dependency "rspec"
22
+ gem.add_development_dependency 'rspec-its'
22
23
  end
data/lib/json/jwe.rb CHANGED
@@ -118,7 +118,7 @@ module JSON
118
118
  end
119
119
 
120
120
  def sha_digest
121
- OpenSSL::Digest::Digest.new "SHA#{sha_size}"
121
+ OpenSSL::Digest.new "SHA#{sha_size}"
122
122
  end
123
123
 
124
124
  def derive_encryption_and_mac_keys_cbc!
data/lib/json/jwk.rb CHANGED
@@ -12,19 +12,6 @@ module JSON
12
12
 
13
13
  private
14
14
 
15
- def ecdsa_curve_name(ecdsa_key)
16
- case ecdsa_key.group.curve_name
17
- when 'secp256k1'
18
- :'P-256'
19
- when 'secp384r1'
20
- :'P-384'
21
- when 'secp521r1'
22
- :'P-521'
23
- else
24
- raise UnknownAlgorithm.new('Unknown ECDSA Curve')
25
- end
26
- end
27
-
28
15
  def ecdsa_coodinates(ecdsa_key)
29
16
  unless @ecdsa_coodinates
30
17
  hex = ecdsa_key.public_key.to_bn.to_s(16)
@@ -33,8 +20,8 @@ module JSON
33
20
  hex_x = hex[2, data_len/2]
34
21
  hex_y = hex[2+data_len/2, data_len/2]
35
22
  @ecdsa_coodinates = {
36
- :x => hex_x,
37
- :y => hex_y,
23
+ :x => [hex_x].pack("H*"),
24
+ :y => [hex_y].pack("H*")
38
25
  }
39
26
  end
40
27
  @ecdsa_coodinates
@@ -51,7 +38,7 @@ module JSON
51
38
  when OpenSSL::PKey::EC
52
39
  {
53
40
  :kty => :EC,
54
- :crv => ecdsa_curve_name(public_key),
41
+ :crv => self.class.ecdsa_curve_identifier_for(public_key.group.curve_name),
55
42
  :x => UrlSafeBase64.encode64(ecdsa_coodinates(public_key)[:x].to_s),
56
43
  :y => UrlSafeBase64.encode64(ecdsa_coodinates(public_key)[:y].to_s),
57
44
  }
@@ -62,6 +49,32 @@ module JSON
62
49
  end
63
50
 
64
51
  class << self
52
+ def ecdsa_curve_name_for(curve_identifier)
53
+ case curve_identifier.to_s
54
+ when 'P-256'
55
+ 'prime256v1'
56
+ when 'P-384'
57
+ 'secp384r1'
58
+ when 'P-521'
59
+ 'secp521r1'
60
+ else
61
+ raise UnknownAlgorithm.new('Unknown ECDSA Curve')
62
+ end
63
+ end
64
+
65
+ def ecdsa_curve_identifier_for(curve_name)
66
+ case curve_name
67
+ when 'prime256v1'
68
+ :'P-256'
69
+ when 'secp384r1'
70
+ :'P-384'
71
+ when 'secp521r1'
72
+ :'P-521'
73
+ else
74
+ raise UnknownAlgorithm.new('Unknown ECDSA Curve')
75
+ end
76
+ end
77
+
65
78
  def decode(jwk)
66
79
  jwk = jwk.with_indifferent_access
67
80
  case jwk[:kty].to_s
@@ -73,7 +86,13 @@ module JSON
73
86
  key.n = n
74
87
  key
75
88
  when 'EC'
76
- raise NotImplementedError.new('Not Implemented Yet')
89
+ key = OpenSSL::PKey::EC.new ecdsa_curve_name_for(jwk[:crv])
90
+ x, y = [jwk[:x], jwk[:y]].collect do |decoded|
91
+ UrlSafeBase64.decode64(decoded).unpack('H*').first
92
+ end
93
+ key_bn = OpenSSL::BN.new ['04', x, y].join, 16
94
+ key.public_key = OpenSSL::PKey::EC::Point.new key.group, key_bn
95
+ key
77
96
  else
78
97
  raise UnknownAlgorithm.new('Unknown Algorithm')
79
98
  end
data/lib/json/jws.rb CHANGED
@@ -24,7 +24,7 @@ module JSON
24
24
  private
25
25
 
26
26
  def digest
27
- OpenSSL::Digest::Digest.new "SHA#{algorithm.to_s[2, 3]}"
27
+ OpenSSL::Digest.new "SHA#{algorithm.to_s[2, 3]}"
28
28
  end
29
29
 
30
30
  def hmac?
@@ -84,7 +84,7 @@ module JSON
84
84
  def verify_ecdsa_group!(key)
85
85
  group_name = case digest.digest_length * 8
86
86
  when 256
87
- :secp256k1
87
+ :prime256v1
88
88
  when 384
89
89
  :secp384r1
90
90
  when 512
@@ -1,5 +1,5 @@
1
1
  -----BEGIN EC PRIVATE KEY-----
2
- MHQCAQEEIAm5+R4izRn6OHBl59IL9ow1txjto6gD21IDdDyhXmOWoAcGBSuBBAAK
3
- oUQDQgAElSHlYujXQEFMiiuZ1Gb91eXwxTGvTKbBFmzOxTtf0w8CCk1UB6G750Br
4
- xiIbllGmVmkoiuWKVkxnB9X9nccJtw==
2
+ MHcCAQEEIHo5LvIgMVpOlEKjjZiE5n+xYtTxLm4Eumx7FRMgICyDoAoGCCqGSM49
3
+ AwEHoUQDQgAEsaPyrO4Lh9kh2FxrF9y1QVmZznWnRRJwpr12UHqzrVYwzPhb3POq
4
+ WsmGqv4nKum+WdogjJlAToN+uA+TEwDDUw==
5
5
  -----END EC PRIVATE KEY-----
@@ -1,4 +1,4 @@
1
1
  -----BEGIN PUBLIC KEY-----
2
- MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAElSHlYujXQEFMiiuZ1Gb91eXwxTGvTKbB
3
- FmzOxTtf0w8CCk1UB6G750BrxiIbllGmVmkoiuWKVkxnB9X9nccJtw==
2
+ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEsaPyrO4Lh9kh2FxrF9y1QVmZznWn
3
+ RRJwpr12UHqzrVYwzPhb3POqWsmGqv4nKum+WdogjJlAToN+uA+TEwDDUw==
4
4
  -----END PUBLIC KEY-----
@@ -27,16 +27,16 @@ describe JSON::JWK do
27
27
  let(:expected_coodinates) do
28
28
  {
29
29
  256 => {
30
- x: 'OTUyMUU1NjJFOEQ3NDA0MTRDOEEyQjk5RDQ2NkZERDVFNUYwQzUzMUFGNENBNkMxMTY2Q0NFQzUzQjVGRDMwRg',
31
- y: 'MDIwQTRENTQwN0ExQkJFNzQwNkJDNjIyMUI5NjUxQTY1NjY5Mjg4QUU1OEE1NjRDNjcwN0Q1RkQ5REM3MDlCNw'
30
+ x: 'saPyrO4Lh9kh2FxrF9y1QVmZznWnRRJwpr12UHqzrVY',
31
+ y: 'MMz4W9zzqlrJhqr-JyrpvlnaIIyZQE6DfrgPkxMAw1M'
32
32
  },
33
33
  384 => {
34
- x: 'QTY1Q0MwQTcyMTY3MkJCQUIzODYwRTU3OUM4NjVCMTYzREExNjY4MUY2NTVEOTc4RjkxMTY2RUMzOUVDMzRDMUJEQjcyQUFCQTVGQUI2NDcyOERGMjgwMDVCNzA1NDZE',
35
- y: 'OEIxMDczN0RGODY0RERGNzFCOTlFOEE5MThCOTJGNDAxMzQyQ0RFMzY2RTkwMkY3ODRFNTEzMUZBMjA1MDczMzhCRDE4RUM3QjA2NEU4QTRENEQzQjI5MkUzOTYyQkRC'
34
+ x: 'plzApyFnK7qzhg5XnIZbFj2hZoH2Vdl4-RFm7DnsNMG9tyqrpfq2RyjfKABbcFRt',
35
+ y: 'ixBzffhk3fcbmeipGLkvQBNCzeNm6QL3hOUTH6IFBzOL0Y7HsGTopNTTspLjlivb'
36
36
  },
37
37
  512 => {
38
- x: 'MDFDMzAyMEZFNkI0NkJBQUU3MTNENEVGMEI0OThFQTg1RkMzMTk3NDYwRTU4REUyNERCRTFFMUNEQzEzOUI2OTAzRUEyQkEzQzdEMzNGN0ZDNzdGMTQ2MUVCRDBFODY5QUIzMTI3RTJCNjBGNjE5QTJFMUFDNkM4M0M0ODBCRDJBRkZG',
39
- y: 'MDE0MkQ4MTFERjI1RjlCNTdGMDQ4REJDRjVBN0IzODUyMkQ5RDUxMEM1REE1QjYwMENGMTMyRjU4RUQ4QjZBNjFBRTFDMjVDQTYyQ0IzNTQzMzI5NUQ2QzAxQTdBNzIzODNBNEQ3MjBEOTI4NTZCNTU3NjYxMzc4RDM4OEExQkI4MjM2'
38
+ x: 'AcMCD-a0a6rnE9TvC0mOqF_DGXRg5Y3iTb4eHNwTm2kD6iujx9M_f8d_FGHr0OhpqzEn4rYPYZouGsbIPEgL0q__',
39
+ y: 'AULYEd8l-bV_BI289aezhSLZ1RDF2ltgDPEy9Y7YtqYa4cJcpiyzVDMpXWwBp6cjg6TXINkoVrVXZhN404ihu4I2'
40
40
  }
41
41
  }
42
42
  end
@@ -121,14 +121,12 @@ NrqoxoakrPo1NI1u+ET8oWGmnjB/nJFAPwIDAQAB
121
121
 
122
122
  context 'when ECDSA' do
123
123
  it do
124
- expect do
125
- JSON::JWK.decode(
126
- kty: :EC,
127
- crv: 'crv',
128
- x: 'x',
129
- y: 'y'
130
- )
131
- end.to raise_error NotImplementedError
124
+ JSON::JWK.decode(
125
+ kty: :EC,
126
+ crv: 'P-256',
127
+ x: 'MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4',
128
+ y: '4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM'
129
+ ).should be_instance_of OpenSSL::PKey::EC
132
130
  end
133
131
  end
134
132
 
@@ -67,7 +67,7 @@ describe JSON::JWT do
67
67
 
68
68
  context 'when no signature nor public_key_or_secret given' do
69
69
  it do
70
- jwt.verify(signature_base_string).should be_true
70
+ jwt.verify(signature_base_string).should == true
71
71
  end
72
72
  end
73
73
 
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,14 @@ SimpleCov.start do
5
5
  end
6
6
 
7
7
  require 'rspec'
8
+ require 'rspec/its'
8
9
  require 'json/jwt'
9
10
 
11
+ RSpec.configure do |config|
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = [:should, :expect]
14
+ end
15
+ end
16
+
10
17
  require 'helpers/sign_key_fixture_helper'
11
18
  require 'helpers/nimbus_spec_helper'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-jwt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-20 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -114,14 +114,28 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '2'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '2'
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-its
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption
126
140
  and JSON Web Key) in Ruby
127
141
  email:
@@ -178,12 +192,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
192
  version: '0'
179
193
  required_rubygems_version: !ruby/object:Gem::Requirement
180
194
  requirements:
181
- - - ">="
195
+ - - ">"
182
196
  - !ruby/object:Gem::Version
183
- version: '0'
197
+ version: 1.3.1
184
198
  requirements: []
185
199
  rubyforge_project:
186
- rubygems_version: 2.2.1
200
+ rubygems_version: 2.2.2
187
201
  signing_key:
188
202
  specification_version: 4
189
203
  summary: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and