json-jwt 0.5.5 → 0.5.6

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: 7649be617fc501060e8befd700c60cdb8ce8a12d
4
- data.tar.gz: 9651a7ce62ff0b6f6d2871d7efca3c59d643dce4
3
+ metadata.gz: f19422f66eb5b83b9e0bd358351adae0079ef23b
4
+ data.tar.gz: 9fcfb99e7aefa37537925233bf1669706ec30b9a
5
5
  SHA512:
6
- metadata.gz: c42db1a5ec52bd3ed4c9ef99c96eeffa03c9f2eef67390ad95afbf9d7b6a126d8dacc58ec6f09a50acd65b8f775a5d4829754ef94455f8a864bc353397b375d3
7
- data.tar.gz: 6f73a187ff937ed434af26029ba8af42d6b6a0a523171c18006bd2db53b29128ff81eb6bc8517e35d973783421a88cc946ad2bc6756aa97e88a62eeee27e7ef9
6
+ metadata.gz: 43e31546b57bcf852d496a588d444669ca48060191cec2c5283eadca9c6da5c7e69d337df9f40a240798a88c9e14316d9ad0a20c2bcbe7f7d0ede3e4cad6daee
7
+ data.tar.gz: 867b59f52a7937a7c86fe6b159038506e2821899872b7e4bb9bbcc6ac6d18310ee6e7cd31216180eabaff1072b3cb487253fb20e26ccdb163efde2a57005fed6
@@ -1,5 +1,4 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
3
  - 2.0.0
5
4
 
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ namespace :cover_me do
12
12
  end
13
13
  end
14
14
  task :spec do
15
- Rake::Task['cover_me:report'].invoke
15
+ Rake::Task['cover_me:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
16
16
  end
17
17
 
18
18
  task default: :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.5.6
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.require_paths = ["lib"]
13
13
  s.add_runtime_dependency "multi_json", ">= 1.3"
14
14
  s.add_runtime_dependency "url_safe_base64"
15
- s.add_runtime_dependency "activesupport", "< 4"
15
+ s.add_runtime_dependency "activesupport"
16
16
  s.add_runtime_dependency "bindata"
17
17
  s.add_development_dependency "rake", ">= 0.8"
18
18
  s.add_development_dependency "cover_me", ">= 1.2.0"
@@ -0,0 +1,7 @@
1
+ module JSON
2
+ class JOSE < JWT
3
+ def content_type
4
+ 'application/jose'
5
+ end
6
+ end
7
+ end
@@ -2,7 +2,7 @@ require 'securerandom'
2
2
  require 'bindata'
3
3
 
4
4
  module JSON
5
- class JWE < JWT
5
+ class JWE < JOSE
6
6
  class InvalidFormat < JWT::InvalidFormat; end
7
7
  class DecryptionFailed < JWT::VerificationFailed; end
8
8
  class UnexpectedAlgorithm < JWT::UnexpectedAlgorithm; end
@@ -20,6 +20,10 @@ module JSON
20
20
  self.input = input.to_s
21
21
  end
22
22
 
23
+ def content_type
24
+ 'application/jose'
25
+ end
26
+
23
27
  def encrypt!(public_key_or_secret)
24
28
  self.mode = :encyption
25
29
  self.plain_text = input
@@ -78,6 +78,12 @@ module JSON
78
78
  raise UnknownAlgorithm.new('Unknown Algorithm')
79
79
  end
80
80
  end
81
+
82
+ # NOTE: Ugly hack to avoid this ActiveSupport 4.0 bug.
83
+ # https://github.com/rails/rails/issues/11087
84
+ def new_from_hash_copying_default(hash)
85
+ superclass.new_from_hash_copying_default hash
86
+ end
81
87
  end
82
88
  end
83
89
  end
@@ -1,5 +1,5 @@
1
1
  module JSON
2
- class JWS < JWT
2
+ class JWS < JOSE
3
3
  class InvalidFormat < JWT::InvalidFormat; end
4
4
  class VerificationFailed < JWT::VerificationFailed; end
5
5
  class UnexpectedAlgorithm < JWT::UnexpectedAlgorithm; end
@@ -12,10 +12,6 @@ module JSON
12
12
  class VerificationFailed < Exception; end
13
13
  class UnexpectedAlgorithm < VerificationFailed; end
14
14
 
15
- def header
16
- @header ||= {}
17
- end
18
-
19
15
  class << self
20
16
  def register_header_keys(*keys)
21
17
  keys.each do |header_key|
@@ -40,6 +36,14 @@ module JSON
40
36
  replace claims
41
37
  end
42
38
 
39
+ def content_type
40
+ 'application/jwt'
41
+ end
42
+
43
+ def header
44
+ @header ||= {}
45
+ end
46
+
43
47
  def sign(private_key_or_secret, algorithm = :HS256)
44
48
  jws = JWS.new(self)
45
49
  jws.alg = algorithm
@@ -62,10 +66,6 @@ module JSON
62
66
  jwe.encrypt! public_key_or_secret
63
67
  end
64
68
 
65
- def content_type
66
- "application/#{self.class.name.split('::').last.downcase}"
67
- end
68
-
69
69
  def to_s
70
70
  [
71
71
  header.to_json,
@@ -101,17 +101,25 @@ module JSON
101
101
  jwe.header = MultiJson.load(
102
102
  UrlSafeBase64.decode64 jwt_string.split('.').first
103
103
  ).with_indifferent_access
104
- jwe.decrypt! key_or_secret
104
+ jwe.decrypt! key_or_secret unless key_or_secret == :skip_decryption
105
+ jwe
105
106
  else
106
107
  raise InvalidFormat.new('Invalid JWT Format. JWT should include 2 or 3 dots.')
107
108
  end
108
109
  rescue MultiJson::DecodeError
109
110
  raise InvalidFormat.new("Invalid JSON Format")
110
111
  end
112
+
113
+ # NOTE: Ugly hack to avoid this ActiveSupport 4.0 bug.
114
+ # https://github.com/rails/rails/issues/11087
115
+ def new_from_hash_copying_default(hash)
116
+ superclass.new_from_hash_copying_default hash
117
+ end
111
118
  end
112
119
  end
113
120
  end
114
121
 
122
+ require 'json/jose'
115
123
  require 'json/jws'
116
124
  require 'json/jwe'
117
125
  require 'json/jwk'
@@ -11,7 +11,7 @@ describe JSON::JWE do
11
11
  describe '#content_type' do
12
12
  let(:jwe) { JSON::JWE.new 'hello' }
13
13
  it do
14
- jwe.content_type.should == 'application/jwe'
14
+ jwe.content_type.should == 'application/jose'
15
15
  end
16
16
  end
17
17
 
@@ -10,14 +10,14 @@ describe JSON::JWK do
10
10
 
11
11
  context 'when RSA public key given' do
12
12
  let(:jwk) { JSON::JWK.new public_key }
13
- it { jwk.keys.should include :kty, :e, :n }
13
+ it { jwk.keys.collect(&:to_sym).should include :kty, :e, :n }
14
14
  its(:kty) { jwk[:kty].should == :RSA }
15
15
  its(:e) { jwk[:e].should == UrlSafeBase64.encode64(public_key.e.to_s(2)) }
16
16
  its(:n) { jwk[:n].should == UrlSafeBase64.encode64(public_key.n.to_s(2)) }
17
17
 
18
18
  context 'when kid/use options given' do
19
19
  let(:jwk) { JSON::JWK.new public_key, kid: '12345', use: :sig }
20
- it { jwk.keys.should include :kid, :use }
20
+ it { jwk.keys.collect(&:to_sym).should include :kid, :use }
21
21
  its(:kid) { jwk[:kid].should == '12345' }
22
22
  its(:use) { jwk[:use].should == :sig }
23
23
  end
@@ -43,7 +43,7 @@ describe JSON::JWK do
43
43
  [256, 384, 512].each do |digest_length|
44
44
  describe "EC#{digest_length}" do
45
45
  let(:jwk) { JSON::JWK.new public_key(:ecdsa, digest_length: digest_length) }
46
- it { jwk.keys.should include :kty, :crv, :x, :y }
46
+ it { jwk.keys.collect(&:to_sym).should include :kty, :crv, :x, :y }
47
47
  its(:kty) { jwk[:kty].should == :EC }
48
48
  its(:x) { jwk[:x].should == expected_coodinates[digest_length][:x] }
49
49
  its(:y) { jwk[:y].should == expected_coodinates[digest_length][:y] }
@@ -41,7 +41,7 @@ describe JSON::JWS do
41
41
 
42
42
  describe '#content_type' do
43
43
  it do
44
- jws.content_type.should == 'application/jws'
44
+ jws.content_type.should == 'application/jose'
45
45
  end
46
46
  end
47
47
 
@@ -149,6 +149,7 @@ describe JSON::JWT do
149
149
  it 'should skip verification' do
150
150
  expect do
151
151
  jwt = JSON::JWT.decode jws.to_s, :skip_verification
152
+ jwt.header.should == {'alg' => 'HS256', 'typ' => 'JWT'}
152
153
  end.not_to raise_error
153
154
  end
154
155
  end
@@ -161,6 +162,15 @@ describe JSON::JWT do
161
162
  it 'should decryptable' do
162
163
  JSON::JWT.decode(input, private_key).should be_a JSON::JWE
163
164
  end
165
+
166
+ context 'when :skip_decryption given as secret/key' do
167
+ it 'should skip verification' do
168
+ expect do
169
+ jwe = JSON::JWT.decode input, :skip_decryption
170
+ jwe.header.should == {'alg' => 'RSA1_5', 'enc' => 'A128CBC+HS256'}
171
+ end.not_to raise_error
172
+ end
173
+ end
164
174
  end
165
175
 
166
176
  context 'when JSON parse failed' do
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.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-29 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - <
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '4'
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - <
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '4'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bindata
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +126,7 @@ files:
126
126
  - Rakefile
127
127
  - VERSION
128
128
  - json-jwt.gemspec
129
+ - lib/json/jose.rb
129
130
  - lib/json/jwe.rb
130
131
  - lib/json/jwk.rb
131
132
  - lib/json/jwk/set.rb
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  version: '0'
168
169
  requirements: []
169
170
  rubyforge_project:
170
- rubygems_version: 2.0.2
171
+ rubygems_version: 2.0.3
171
172
  signing_key:
172
173
  specification_version: 4
173
174
  summary: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and