json-jwt 1.10.0 → 1.13.0

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
  SHA256:
3
- metadata.gz: 0f805fa120c4c633a6be48aab961f504aa3e7d5f68aee05f13585e3751201c67
4
- data.tar.gz: bb26869e462704b7ca5ae9109cd07749b76fc6ee53fc99a6db70238dbfa51c77
3
+ metadata.gz: e18796342211bf21448b9bb5b43749894717bc0a270ae7e1679efbbaa387fc4b
4
+ data.tar.gz: 19b56b26f69a78d2b3ac842865571b973426006b371674ebb6f19cfaf9156385
5
5
  SHA512:
6
- metadata.gz: f2673b42a974d7b9d003f48cf17ef15580d948ef5f06ea8d4c7f46e56249d3849e342720974fcca3a979014cfc898753a541ce851099459f559568f3523f5100
7
- data.tar.gz: 749aa5e6eadb127674086f77e05e691a162dddfa4cb2d3b4132a1c96649f7a8001b506169dc45112fca117afa67ca16549b090b2ad70fd7275cae2583db735ee
6
+ metadata.gz: 90e611ff8e6f87f4b4008c15839008b0eaea3abf498e1d40dcfb875c99c7212d558d38ea5e93f74e3dcbfb4c0f05d29d712b8e64152179ccd02602b6ec79c8ca
7
+ data.tar.gz: 82eb46ca549465d81027f9953f2cde953a582a7912e534a828b1114c78e1f469c9e03c9ebfb6b6609bddf11e1686defe10134fe287ed2b5768e05b8a3b53babf
@@ -3,9 +3,9 @@ before_install:
3
3
  - git submodule update --init --recursive
4
4
 
5
5
  rvm:
6
- - 2.3.7
7
- - 2.4.4
8
- - 2.5.1
6
+ - 2.5.8
7
+ - 2.6.6
8
+ - 2.7.1
9
9
 
10
10
  jdk:
11
- - oraclejdk8
11
+ - openjdk11
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.10.0
1
+ 1.13.0
@@ -7,11 +7,12 @@ Gem::Specification.new do |gem|
7
7
  gem.summary = %q{JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby}
8
8
  gem.description = %q{JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby}
9
9
  gem.license = 'MIT'
10
- gem.files = `git ls-files`.split("\n")
11
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
10
+ gem.files = `git ls-files`.split("\n").reject do |f|
11
+ f.match(%r{^(test|spec|features)/})
12
+ end
12
13
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
14
  gem.require_paths = ['lib']
14
- gem.required_ruby_version = '>= 2.3'
15
+ gem.required_ruby_version = '>= 2.4'
15
16
  gem.add_runtime_dependency 'activesupport', '>= 4.2'
16
17
  gem.add_runtime_dependency 'bindata'
17
18
  gem.add_runtime_dependency 'aes_key_wrap'
@@ -7,9 +7,11 @@ module JSON
7
7
  included do
8
8
  extend ClassMethods
9
9
  register_header_keys :alg, :jku, :jwk, :x5u, :x5t, :x5c, :kid, :typ, :cty, :crit
10
+
11
+ # NOTE: not used anymore in this gem, but keeping in case developers are calling it.
10
12
  alias_method :algorithm, :alg
11
13
 
12
- attr_accessor :header
14
+ attr_writer :header
13
15
  def header
14
16
  @header ||= {}
15
17
  end
@@ -26,7 +28,7 @@ module JSON
26
28
  when JSON::JWK::Set
27
29
  key.detect do |jwk|
28
30
  jwk[:kid] && jwk[:kid] == kid
29
- end.try(:to_key) or raise JWK::Set::KidNotFound
31
+ end&.to_key or raise JWK::Set::KidNotFound
30
32
  else
31
33
  key
32
34
  end
@@ -14,9 +14,10 @@ module JSON
14
14
 
15
15
  attr_accessor(
16
16
  :public_key_or_secret, :private_key_or_secret,
17
- :plain_text, :cipher_text, :authentication_tag, :iv, :auth_data,
18
- :content_encryption_key, :jwe_encrypted_key, :encryption_key, :mac_key
17
+ :plain_text, :cipher_text, :iv, :auth_data,
18
+ :content_encryption_key, :encryption_key, :mac_key
19
19
  )
20
+ attr_writer :jwe_encrypted_key, :authentication_tag
20
21
 
21
22
  register_header_keys :enc, :epk, :zip, :apu, :apv
22
23
  alias_method :encryption_method, :enc
@@ -98,15 +99,15 @@ module JSON
98
99
  # common
99
100
 
100
101
  def gcm?
101
- [:A128GCM, :A256GCM].include? encryption_method.try(:to_sym)
102
+ [:A128GCM, :A256GCM].include? encryption_method&.to_sym
102
103
  end
103
104
 
104
105
  def cbc?
105
- [:'A128CBC-HS256', :'A256CBC-HS512'].include? encryption_method.try(:to_sym)
106
+ [:'A128CBC-HS256', :'A256CBC-HS512'].include? encryption_method&.to_sym
106
107
  end
107
108
 
108
109
  def dir?
109
- :dir == algorithm.try(:to_sym)
110
+ :dir == alg&.to_sym
110
111
  end
111
112
 
112
113
  def cipher
@@ -115,7 +116,7 @@ module JSON
115
116
  end
116
117
 
117
118
  def cipher_name
118
- case encryption_method.try(:to_sym)
119
+ case encryption_method&.to_sym
119
120
  when :A128GCM
120
121
  'aes-128-gcm'
121
122
  when :A256GCM
@@ -130,7 +131,7 @@ module JSON
130
131
  end
131
132
 
132
133
  def sha_size
133
- case encryption_method.try(:to_sym)
134
+ case encryption_method&.to_sym
134
135
  when :'A128CBC-HS256'
135
136
  256
136
137
  when :'A256CBC-HS512'
@@ -158,7 +159,7 @@ module JSON
158
159
  # encryption
159
160
 
160
161
  def jwe_encrypted_key
161
- @jwe_encrypted_key ||= case algorithm.try(:to_sym)
162
+ @jwe_encrypted_key ||= case alg&.to_sym
162
163
  when :RSA1_5
163
164
  public_key_or_secret.public_encrypt content_encryption_key
164
165
  when :'RSA-OAEP'
@@ -210,7 +211,7 @@ module JSON
210
211
 
211
212
  def decrypt_content_encryption_key
212
213
  fake_content_encryption_key = generate_content_encryption_key # NOTE: do this always not to make timing difference
213
- case algorithm.try(:to_sym)
214
+ case alg&.to_sym
214
215
  when :RSA1_5
215
216
  private_key_or_secret.private_decrypt jwe_encrypted_key
216
217
  when :'RSA-OAEP'
@@ -253,7 +254,7 @@ module JSON
253
254
  raise InvalidFormat.new("Invalid JWE Format. JWE should include #{NUM_OF_SEGMENTS} segments.")
254
255
  end
255
256
  jwe = new
256
- _header_json_, jwe.jwe_encrypted_key, jwe.iv, jwe.cipher_text, jwe.authentication_tag = input.split('.').collect do |segment|
257
+ _header_json_, jwe.jwe_encrypted_key, jwe.iv, jwe.cipher_text, jwe.authentication_tag = input.split('.', NUM_OF_SEGMENTS).collect do |segment|
257
258
  begin
258
259
  Base64.urlsafe_decode64 segment
259
260
  rescue ArgumentError
@@ -50,24 +50,16 @@ module JSON
50
50
  end
51
51
  end
52
52
 
53
- private
54
-
55
53
  def rsa?
56
- self[:kty].try(:to_sym) == :RSA
54
+ self[:kty]&.to_sym == :RSA
57
55
  end
58
56
 
59
57
  def ec?
60
- self[:kty].try(:to_sym) == :EC
58
+ self[:kty]&.to_sym == :EC
61
59
  end
62
60
 
63
61
  def oct?
64
- self[:kty].try(:to_sym) == :oct
65
- end
66
-
67
- def calculate_default_kid
68
- self[:kid] = thumbprint
69
- rescue
70
- # ignore
62
+ self[:kty]&.to_sym == :oct
71
63
  end
72
64
 
73
65
  def normalize
@@ -95,6 +87,14 @@ module JSON
95
87
  end
96
88
  end
97
89
 
90
+ private
91
+
92
+ def calculate_default_kid
93
+ self[:kid] = thumbprint
94
+ rescue
95
+ # ignore
96
+ end
97
+
98
98
  def to_rsa_key
99
99
  e, n, d, p, q, dp, dq, qi = [:e, :n, :d, :p, :q, :dp, :dq, :qi].collect do |key|
100
100
  if self[key]
@@ -120,13 +120,15 @@ module JSON
120
120
  end
121
121
 
122
122
  def to_ec_key
123
- curve_name = case self[:crv].try(:to_sym)
123
+ curve_name = case self[:crv]&.to_sym
124
124
  when :'P-256'
125
125
  'prime256v1'
126
126
  when :'P-384'
127
127
  'secp384r1'
128
128
  when :'P-521'
129
129
  'secp521r1'
130
+ when :secp256k1
131
+ 'secp256k1'
130
132
  else
131
133
  raise UnknownAlgorithm.new('Unknown EC Curve')
132
134
  end
@@ -44,6 +44,8 @@ module JSON
44
44
  :'P-384'
45
45
  when 'secp521r1'
46
46
  :'P-521'
47
+ when 'secp256k1'
48
+ :secp256k1
47
49
  else
48
50
  raise UnknownAlgorithm.new('Unknown EC Curve')
49
51
  end
@@ -6,23 +6,23 @@ module JSON
6
6
 
7
7
  NUM_OF_SEGMENTS = 3
8
8
 
9
- attr_accessor :signature_base_string
9
+ attr_writer :signature_base_string
10
10
 
11
11
  def initialize(jwt)
12
12
  update jwt
13
13
  end
14
14
 
15
15
  def sign!(private_key_or_secret)
16
- self.alg = autodetected_algorithm_from(private_key_or_secret) if algorithm == :autodetect
16
+ self.alg = autodetected_algorithm_from(private_key_or_secret) if alg == :autodetect
17
17
  self.signature = sign signature_base_string, private_key_or_secret
18
18
  self
19
19
  end
20
20
 
21
21
  def verify!(public_key_or_secret, algorithms = nil)
22
- if alg.try(:to_sym) == :none
22
+ if alg&.to_sym == :none
23
23
  raise UnexpectedAlgorithm if public_key_or_secret
24
24
  signature == '' or raise VerificationFailed
25
- elsif algorithms.blank? || Array(algorithms).include?(alg.try(:to_sym))
25
+ elsif algorithms.blank? || Array(algorithms).include?(alg&.to_sym)
26
26
  public_key_or_secret && valid?(public_key_or_secret) or
27
27
  raise VerificationFailed
28
28
  else
@@ -43,31 +43,23 @@ module JSON
43
43
  private
44
44
 
45
45
  def digest
46
- OpenSSL::Digest.new "SHA#{algorithm.to_s[2, 3]}"
46
+ OpenSSL::Digest.new "SHA#{alg.to_s[2, 3]}"
47
47
  end
48
48
 
49
49
  def hmac?
50
- [:HS256, :HS384, :HS512].include? algorithm.try(:to_sym)
50
+ [:HS256, :HS384, :HS512].include? alg&.to_sym
51
51
  end
52
52
 
53
53
  def rsa?
54
- [:RS256, :RS384, :RS512].include? algorithm.try(:to_sym)
54
+ [:RS256, :RS384, :RS512].include? alg&.to_sym
55
55
  end
56
56
 
57
57
  def rsa_pss?
58
- if [:PS256, :PS384, :PS512].include? algorithm.try(:to_sym)
59
- if OpenSSL::VERSION < '2.1.0'
60
- raise "#{alg} isn't supported. OpenSSL gem v2.1.0+ is required to use #{alg}."
61
- else
62
- true
63
- end
64
- else
65
- false
66
- end
58
+ [:PS256, :PS384, :PS512].include? alg&.to_sym
67
59
  end
68
60
 
69
61
  def ecdsa?
70
- [:ES256, :ES384, :ES512].include? algorithm.try(:to_sym)
62
+ [:ES256, :ES384, :ES512, :ES256K].include? alg&.to_sym
71
63
  end
72
64
 
73
65
  def autodetected_algorithm_from(private_key_or_secret)
@@ -85,6 +77,8 @@ module JSON
85
77
  :ES384
86
78
  when 'secp521r1'
87
79
  :ES512
80
+ when 'secp256k1'
81
+ :ES256K
88
82
  else
89
83
  raise UnknownAlgorithm.new('Unknown EC Curve')
90
84
  end
@@ -118,8 +112,7 @@ module JSON
118
112
  private_key = private_key_or_secret
119
113
  verify_ecdsa_group! private_key
120
114
  asn1_to_raw(
121
- private_key.dsa_sign_asn1(digest.digest signature_base_string),
122
- # private_key.sign(digest, signature_base_string), # NOTE: this causes `undefined method `private?'` error in ruby 2.3
115
+ private_key.sign(digest, signature_base_string),
123
116
  private_key
124
117
  )
125
118
  else
@@ -152,7 +145,12 @@ module JSON
152
145
  def verify_ecdsa_group!(key)
153
146
  group_name = case digest.digest_length * 8
154
147
  when 256
155
- :prime256v1
148
+ case key.group.curve_name
149
+ when 'secp256k1'
150
+ :secp256k1
151
+ else
152
+ :prime256v1
153
+ end
156
154
  when 384
157
155
  :secp384r1
158
156
  when 512
@@ -179,7 +177,7 @@ module JSON
179
177
  unless input.count('.') + 1 == NUM_OF_SEGMENTS
180
178
  raise InvalidFormat.new("Invalid JWS Format. JWS should include #{NUM_OF_SEGMENTS} segments.")
181
179
  end
182
- header, claims, signature = input.split('.', JWS::NUM_OF_SEGMENTS).collect do |segment|
180
+ header, claims, signature = input.split('.', NUM_OF_SEGMENTS).collect do |segment|
183
181
  Base64.urlsafe_decode64 segment.to_s
184
182
  end
185
183
  header = JSON.parse(header).with_indifferent_access
@@ -191,7 +189,7 @@ module JSON
191
189
  jws = new claims
192
190
  jws.header = header
193
191
  jws.signature = signature
194
- jws.signature_base_string = input.split('.')[0, JWS::NUM_OF_SEGMENTS - 1].join('.')
192
+ jws.signature_base_string = input.split('.')[0, NUM_OF_SEGMENTS - 1].join('.')
195
193
  jws.verify! public_key_or_secret, algorithms unless public_key_or_secret == :skip_verification
196
194
  jws
197
195
  end
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: 1.10.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-14 00:00:00.000000000 Z
11
+ date: 2020-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -133,27 +133,6 @@ files:
133
133
  - lib/json/jwk/set.rb
134
134
  - lib/json/jws.rb
135
135
  - lib/json/jwt.rb
136
- - spec/fixtures/ecdsa/256/private_key.pem
137
- - spec/fixtures/ecdsa/256/public_key.pem
138
- - spec/fixtures/ecdsa/384/private_key.pem
139
- - spec/fixtures/ecdsa/384/public_key.pem
140
- - spec/fixtures/ecdsa/512/private_key.pem
141
- - spec/fixtures/ecdsa/512/public_key.pem
142
- - spec/fixtures/rsa/private_key.der
143
- - spec/fixtures/rsa/private_key.pem
144
- - spec/fixtures/rsa/public_key.pem
145
- - spec/helpers/nimbus_spec_helper.rb
146
- - spec/helpers/sign_key_fixture_helper.rb
147
- - spec/interop/with_jsrsasign_spec.rb
148
- - spec/interop/with_nimbus_jose_spec.rb
149
- - spec/interop/with_rfc_example_spec.rb
150
- - spec/json/jwe_spec.rb
151
- - spec/json/jwk/jwkizable_spec.rb
152
- - spec/json/jwk/set_spec.rb
153
- - spec/json/jwk_spec.rb
154
- - spec/json/jws_spec.rb
155
- - spec/json/jwt_spec.rb
156
- - spec/spec_helper.rb
157
136
  homepage: https://github.com/nov/json-jwt
158
137
  licenses:
159
138
  - MIT
@@ -166,38 +145,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
145
  requirements:
167
146
  - - ">="
168
147
  - !ruby/object:Gem::Version
169
- version: '2.3'
148
+ version: '2.4'
170
149
  required_rubygems_version: !ruby/object:Gem::Requirement
171
150
  requirements:
172
151
  - - ">="
173
152
  - !ruby/object:Gem::Version
174
153
  version: '0'
175
154
  requirements: []
176
- rubyforge_project:
177
- rubygems_version: 2.7.6
155
+ rubygems_version: 3.0.3
178
156
  signing_key:
179
157
  specification_version: 4
180
158
  summary: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and
181
159
  JSON Web Key) in Ruby
182
- test_files:
183
- - spec/fixtures/ecdsa/256/private_key.pem
184
- - spec/fixtures/ecdsa/256/public_key.pem
185
- - spec/fixtures/ecdsa/384/private_key.pem
186
- - spec/fixtures/ecdsa/384/public_key.pem
187
- - spec/fixtures/ecdsa/512/private_key.pem
188
- - spec/fixtures/ecdsa/512/public_key.pem
189
- - spec/fixtures/rsa/private_key.der
190
- - spec/fixtures/rsa/private_key.pem
191
- - spec/fixtures/rsa/public_key.pem
192
- - spec/helpers/nimbus_spec_helper.rb
193
- - spec/helpers/sign_key_fixture_helper.rb
194
- - spec/interop/with_jsrsasign_spec.rb
195
- - spec/interop/with_nimbus_jose_spec.rb
196
- - spec/interop/with_rfc_example_spec.rb
197
- - spec/json/jwe_spec.rb
198
- - spec/json/jwk/jwkizable_spec.rb
199
- - spec/json/jwk/set_spec.rb
200
- - spec/json/jwk_spec.rb
201
- - spec/json/jws_spec.rb
202
- - spec/json/jwt_spec.rb
203
- - spec/spec_helper.rb
160
+ test_files: []
@@ -1,5 +0,0 @@
1
- -----BEGIN EC PRIVATE KEY-----
2
- MHcCAQEEIHo5LvIgMVpOlEKjjZiE5n+xYtTxLm4Eumx7FRMgICyDoAoGCCqGSM49
3
- AwEHoUQDQgAEsaPyrO4Lh9kh2FxrF9y1QVmZznWnRRJwpr12UHqzrVYwzPhb3POq
4
- WsmGqv4nKum+WdogjJlAToN+uA+TEwDDUw==
5
- -----END EC PRIVATE KEY-----
@@ -1,4 +0,0 @@
1
- -----BEGIN PUBLIC KEY-----
2
- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEsaPyrO4Lh9kh2FxrF9y1QVmZznWn
3
- RRJwpr12UHqzrVYwzPhb3POqWsmGqv4nKum+WdogjJlAToN+uA+TEwDDUw==
4
- -----END PUBLIC KEY-----
@@ -1,6 +0,0 @@
1
- -----BEGIN EC PRIVATE KEY-----
2
- MIGkAgEBBDB1NRLzYeQa7oRUwWrnQFZOBVqzlyJ9n654/PFjCLJh/A/uGWeECoM2
3
- 1hXEvp80pqGgBwYFK4EEACKhZANiAASmXMCnIWcrurOGDlechlsWPaFmgfZV2Xj5
4
- EWbsOew0wb23Kqul+rZHKN8oAFtwVG2LEHN9+GTd9xuZ6KkYuS9AE0LN42bpAveE
5
- 5RMfogUHM4vRjsewZOik1NOykuOWK9s=
6
- -----END EC PRIVATE KEY-----
@@ -1,5 +0,0 @@
1
- -----BEGIN PUBLIC KEY-----
2
- MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEplzApyFnK7qzhg5XnIZbFj2hZoH2Vdl4
3
- +RFm7DnsNMG9tyqrpfq2RyjfKABbcFRtixBzffhk3fcbmeipGLkvQBNCzeNm6QL3
4
- hOUTH6IFBzOL0Y7HsGTopNTTspLjlivb
5
- -----END PUBLIC KEY-----
@@ -1,7 +0,0 @@
1
- -----BEGIN EC PRIVATE KEY-----
2
- MIHcAgEBBEIBBpwKqvGEZGpE3wX1fDzJjrrM4uXr16WKsijjqjRP8tHdnvr5p2fO
3
- zrPVyDVbiQDulOhSh9aouunuwmbudKjWvZagBwYFK4EEACOhgYkDgYYABAHDAg/m
4
- tGuq5xPU7wtJjqhfwxl0YOWN4k2+HhzcE5tpA+oro8fTP3/HfxRh69DoaasxJ+K2
5
- D2GaLhrGyDxIC9Kv/wFC2BHfJfm1fwSNvPWns4Ui2dUQxdpbYAzxMvWO2LamGuHC
6
- XKYss1QzKV1sAaenI4Ok1yDZKFa1V2YTeNOIobuCNg==
7
- -----END EC PRIVATE KEY-----