jwt 2.10.2 → 3.2.0
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 +4 -4
- data/CHANGELOG.md +104 -41
- data/CODE_OF_CONDUCT.md +14 -14
- data/CONTRIBUTING.md +11 -12
- data/README.md +190 -221
- data/UPGRADING.md +47 -0
- data/lib/jwt/base64.rb +1 -10
- data/lib/jwt/claims/numeric.rb +0 -32
- data/lib/jwt/claims.rb +0 -7
- data/lib/jwt/configuration/container.rb +0 -1
- data/lib/jwt/configuration/decode_configuration.rb +7 -2
- data/lib/jwt/decode.rb +25 -16
- data/lib/jwt/encoded_token/claims_context.rb +23 -0
- data/lib/jwt/encoded_token.rb +97 -14
- data/lib/jwt/error.rb +0 -3
- data/lib/jwt/jwa/ecdsa.rb +25 -4
- data/lib/jwt/jwa/hmac.rb +28 -10
- data/lib/jwt/jwa/ps.rb +1 -0
- data/lib/jwt/jwa/rsa.rb +1 -0
- data/lib/jwt/jwa/signer_context.rb +19 -0
- data/lib/jwt/jwa/signing_algorithm.rb +0 -1
- data/lib/jwt/jwa/verifier_context.rb +21 -0
- data/lib/jwt/jwa.rb +43 -26
- data/lib/jwt/jwk/ec.rb +52 -62
- data/lib/jwt/jwk/hmac.rb +3 -3
- data/lib/jwt/jwk/key_base.rb +15 -1
- data/lib/jwt/jwk/key_finder.rb +35 -9
- data/lib/jwt/jwk/rsa.rb +6 -2
- data/lib/jwt/jwk.rb +0 -1
- data/lib/jwt/token.rb +26 -7
- data/lib/jwt/version.rb +4 -28
- data/lib/jwt/x5c_key_finder.rb +1 -1
- data/lib/jwt.rb +1 -7
- data/ruby-jwt.gemspec +1 -0
- metadata +21 -13
- data/lib/jwt/claims/verification_methods.rb +0 -20
- data/lib/jwt/claims_validator.rb +0 -18
- data/lib/jwt/deprecations.rb +0 -49
- data/lib/jwt/jwa/compat.rb +0 -32
- data/lib/jwt/jwa/eddsa.rb +0 -35
- data/lib/jwt/jwa/hmac_rbnacl.rb +0 -50
- data/lib/jwt/jwa/hmac_rbnacl_fixed.rb +0 -47
- data/lib/jwt/jwa/wrapper.rb +0 -44
- data/lib/jwt/jwk/okp_rbnacl.rb +0 -109
- data/lib/jwt/verify.rb +0 -40
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jwt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 3.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Rudat
|
|
@@ -51,6 +51,20 @@ dependencies:
|
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: irb
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
54
68
|
- !ruby/object:Gem::Dependency
|
|
55
69
|
name: logger
|
|
56
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -134,6 +148,7 @@ files:
|
|
|
134
148
|
- CONTRIBUTING.md
|
|
135
149
|
- LICENSE
|
|
136
150
|
- README.md
|
|
151
|
+
- UPGRADING.md
|
|
137
152
|
- lib/jwt.rb
|
|
138
153
|
- lib/jwt/base64.rb
|
|
139
154
|
- lib/jwt/claims.rb
|
|
@@ -148,44 +163,37 @@ files:
|
|
|
148
163
|
- lib/jwt/claims/numeric.rb
|
|
149
164
|
- lib/jwt/claims/required.rb
|
|
150
165
|
- lib/jwt/claims/subject.rb
|
|
151
|
-
- lib/jwt/claims/verification_methods.rb
|
|
152
166
|
- lib/jwt/claims/verifier.rb
|
|
153
|
-
- lib/jwt/claims_validator.rb
|
|
154
167
|
- lib/jwt/configuration.rb
|
|
155
168
|
- lib/jwt/configuration/container.rb
|
|
156
169
|
- lib/jwt/configuration/decode_configuration.rb
|
|
157
170
|
- lib/jwt/configuration/jwk_configuration.rb
|
|
158
171
|
- lib/jwt/decode.rb
|
|
159
|
-
- lib/jwt/deprecations.rb
|
|
160
172
|
- lib/jwt/encode.rb
|
|
161
173
|
- lib/jwt/encoded_token.rb
|
|
174
|
+
- lib/jwt/encoded_token/claims_context.rb
|
|
162
175
|
- lib/jwt/error.rb
|
|
163
176
|
- lib/jwt/json.rb
|
|
164
177
|
- lib/jwt/jwa.rb
|
|
165
|
-
- lib/jwt/jwa/compat.rb
|
|
166
178
|
- lib/jwt/jwa/ecdsa.rb
|
|
167
|
-
- lib/jwt/jwa/eddsa.rb
|
|
168
179
|
- lib/jwt/jwa/hmac.rb
|
|
169
|
-
- lib/jwt/jwa/hmac_rbnacl.rb
|
|
170
|
-
- lib/jwt/jwa/hmac_rbnacl_fixed.rb
|
|
171
180
|
- lib/jwt/jwa/none.rb
|
|
172
181
|
- lib/jwt/jwa/ps.rb
|
|
173
182
|
- lib/jwt/jwa/rsa.rb
|
|
183
|
+
- lib/jwt/jwa/signer_context.rb
|
|
174
184
|
- lib/jwt/jwa/signing_algorithm.rb
|
|
175
185
|
- lib/jwt/jwa/unsupported.rb
|
|
176
|
-
- lib/jwt/jwa/
|
|
186
|
+
- lib/jwt/jwa/verifier_context.rb
|
|
177
187
|
- lib/jwt/jwk.rb
|
|
178
188
|
- lib/jwt/jwk/ec.rb
|
|
179
189
|
- lib/jwt/jwk/hmac.rb
|
|
180
190
|
- lib/jwt/jwk/key_base.rb
|
|
181
191
|
- lib/jwt/jwk/key_finder.rb
|
|
182
192
|
- lib/jwt/jwk/kid_as_key_digest.rb
|
|
183
|
-
- lib/jwt/jwk/okp_rbnacl.rb
|
|
184
193
|
- lib/jwt/jwk/rsa.rb
|
|
185
194
|
- lib/jwt/jwk/set.rb
|
|
186
195
|
- lib/jwt/jwk/thumbprint.rb
|
|
187
196
|
- lib/jwt/token.rb
|
|
188
|
-
- lib/jwt/verify.rb
|
|
189
197
|
- lib/jwt/version.rb
|
|
190
198
|
- lib/jwt/x5c_key_finder.rb
|
|
191
199
|
- ruby-jwt.gemspec
|
|
@@ -194,7 +202,7 @@ licenses:
|
|
|
194
202
|
- MIT
|
|
195
203
|
metadata:
|
|
196
204
|
bug_tracker_uri: https://github.com/jwt/ruby-jwt/issues
|
|
197
|
-
changelog_uri: https://github.com/jwt/ruby-jwt/blob/
|
|
205
|
+
changelog_uri: https://github.com/jwt/ruby-jwt/blob/v3.2.0/CHANGELOG.md
|
|
198
206
|
rubygems_mfa_required: 'true'
|
|
199
207
|
rdoc_options: []
|
|
200
208
|
require_paths:
|
|
@@ -210,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
210
218
|
- !ruby/object:Gem::Version
|
|
211
219
|
version: '0'
|
|
212
220
|
requirements: []
|
|
213
|
-
rubygems_version:
|
|
221
|
+
rubygems_version: 4.0.10
|
|
214
222
|
specification_version: 4
|
|
215
223
|
summary: JSON Web Token implementation in Ruby
|
|
216
224
|
test_files: []
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
module Claims
|
|
5
|
-
# @api private
|
|
6
|
-
module VerificationMethods
|
|
7
|
-
def verify_claims!(*options)
|
|
8
|
-
Verifier.verify!(self, *options)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def claim_errors(*options)
|
|
12
|
-
Verifier.errors(self, *options)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def valid_claims?(*options)
|
|
16
|
-
claim_errors(*options).empty?
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
data/lib/jwt/claims_validator.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
# @deprecated Use `Claims.verify_payload!` directly instead.
|
|
5
|
-
class ClaimsValidator
|
|
6
|
-
# @deprecated Use `Claims.verify_payload!` directly instead.
|
|
7
|
-
def initialize(payload)
|
|
8
|
-
Deprecations.warning('The ::JWT::ClaimsValidator class is deprecated and will be removed in the next major version of ruby-jwt')
|
|
9
|
-
@payload = payload
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# @deprecated Use `Claims.verify_payload!` directly instead.
|
|
13
|
-
def validate!
|
|
14
|
-
Claims.verify_payload!(@payload, :numeric)
|
|
15
|
-
true
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
data/lib/jwt/deprecations.rb
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
# Deprecations module to handle deprecation warnings in the gem
|
|
5
|
-
# @api private
|
|
6
|
-
module Deprecations
|
|
7
|
-
class << self
|
|
8
|
-
def context
|
|
9
|
-
yield.tap { emit_warnings }
|
|
10
|
-
ensure
|
|
11
|
-
Thread.current[:jwt_warning_store] = nil
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def warning(message, only_if_valid: false)
|
|
15
|
-
method_name = only_if_valid ? :store : :warn
|
|
16
|
-
case JWT.configuration.deprecation_warnings
|
|
17
|
-
when :once
|
|
18
|
-
return if record_warned(message)
|
|
19
|
-
when :warn
|
|
20
|
-
# noop
|
|
21
|
-
else
|
|
22
|
-
return
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
send(method_name, "[DEPRECATION WARNING] #{message}")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def store(message)
|
|
29
|
-
(Thread.current[:jwt_warning_store] ||= []) << message
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def emit_warnings
|
|
33
|
-
return if Thread.current[:jwt_warning_store].nil?
|
|
34
|
-
|
|
35
|
-
Thread.current[:jwt_warning_store].each { |warning| warn(warning) }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def record_warned(message)
|
|
41
|
-
@warned ||= []
|
|
42
|
-
return true if @warned.include?(message)
|
|
43
|
-
|
|
44
|
-
@warned << message
|
|
45
|
-
false
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
data/lib/jwt/jwa/compat.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
module JWA
|
|
5
|
-
# Provides backwards compatibility for algorithms
|
|
6
|
-
# @api private
|
|
7
|
-
module Compat
|
|
8
|
-
# @api private
|
|
9
|
-
module ClassMethods
|
|
10
|
-
def from_algorithm(algorithm)
|
|
11
|
-
new(algorithm)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def sign(algorithm, msg, key)
|
|
15
|
-
Deprecations.warning('Support for calling sign with positional arguments will be removed in future ruby-jwt versions')
|
|
16
|
-
|
|
17
|
-
from_algorithm(algorithm).sign(data: msg, signing_key: key)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def verify(algorithm, key, signing_input, signature)
|
|
21
|
-
Deprecations.warning('Support for calling verify with positional arguments will be removed in future ruby-jwt versions')
|
|
22
|
-
|
|
23
|
-
from_algorithm(algorithm).verify(data: signing_input, signature: signature, verification_key: key)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def self.included(klass)
|
|
28
|
-
klass.extend(ClassMethods)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
data/lib/jwt/jwa/eddsa.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
module JWA
|
|
5
|
-
# Implementation of the EdDSA family of algorithms
|
|
6
|
-
class Eddsa
|
|
7
|
-
include JWT::JWA::SigningAlgorithm
|
|
8
|
-
|
|
9
|
-
def initialize(alg)
|
|
10
|
-
@alg = alg
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def sign(data:, signing_key:)
|
|
14
|
-
raise_sign_error!("Key given is a #{signing_key.class} but has to be an RbNaCl::Signatures::Ed25519::SigningKey") unless signing_key.is_a?(RbNaCl::Signatures::Ed25519::SigningKey)
|
|
15
|
-
|
|
16
|
-
Deprecations.warning('Using the EdDSA algorithm is deprecated and will be removed in a future version of ruby-jwt. In the future the algorithm will be provided by the jwt-eddsa gem.')
|
|
17
|
-
|
|
18
|
-
signing_key.sign(data)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def verify(data:, signature:, verification_key:)
|
|
22
|
-
raise_verify_error!("key given is a #{verification_key.class} but has to be a RbNaCl::Signatures::Ed25519::VerifyKey") unless verification_key.is_a?(RbNaCl::Signatures::Ed25519::VerifyKey)
|
|
23
|
-
|
|
24
|
-
Deprecations.warning('Using the EdDSA algorithm is deprecated and will be removed in a future version of ruby-jwt. In the future the algorithm will be provided by the jwt-eddsa gem.')
|
|
25
|
-
|
|
26
|
-
verification_key.verify(signature, data)
|
|
27
|
-
rescue RbNaCl::CryptoError
|
|
28
|
-
false
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
register_algorithm(new('ED25519'))
|
|
32
|
-
register_algorithm(new('EdDSA'))
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
data/lib/jwt/jwa/hmac_rbnacl.rb
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
module JWA
|
|
5
|
-
# Implementation of the HMAC family of algorithms (using RbNaCl)
|
|
6
|
-
class HmacRbNaCl
|
|
7
|
-
include JWT::JWA::SigningAlgorithm
|
|
8
|
-
|
|
9
|
-
def self.from_algorithm(algorithm)
|
|
10
|
-
new(algorithm, ::RbNaCl::HMAC.const_get(algorithm.upcase.gsub('HS', 'SHA')))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def initialize(alg, hmac)
|
|
14
|
-
@alg = alg
|
|
15
|
-
@hmac = hmac
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def sign(data:, signing_key:)
|
|
19
|
-
Deprecations.warning("The use of the algorithm #{alg} is deprecated and will be removed in the next major version of ruby-jwt")
|
|
20
|
-
hmac.auth(key_for_rbnacl(hmac, signing_key).encode('binary'), data.encode('binary'))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def verify(data:, signature:, verification_key:)
|
|
24
|
-
Deprecations.warning("The use of the algorithm #{alg} is deprecated and will be removed in the next major version of ruby-jwt")
|
|
25
|
-
hmac.verify(key_for_rbnacl(hmac, verification_key).encode('binary'), signature.encode('binary'), data.encode('binary'))
|
|
26
|
-
rescue ::RbNaCl::BadAuthenticatorError, ::RbNaCl::LengthError
|
|
27
|
-
false
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
register_algorithm(new('HS512256', ::RbNaCl::HMAC::SHA512256))
|
|
31
|
-
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
attr_reader :hmac
|
|
35
|
-
|
|
36
|
-
def key_for_rbnacl(hmac, key)
|
|
37
|
-
key ||= ''
|
|
38
|
-
raise JWT::DecodeError, 'HMAC key expected to be a String' unless key.is_a?(String)
|
|
39
|
-
|
|
40
|
-
return padded_empty_key(hmac.key_bytes) if key == ''
|
|
41
|
-
|
|
42
|
-
key
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def padded_empty_key(length)
|
|
46
|
-
Array.new(length, 0x0).pack('C*').encode('binary')
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
module JWA
|
|
5
|
-
# Implementation of the HMAC family of algorithms (using RbNaCl prior to a certain version)
|
|
6
|
-
class HmacRbNaClFixed
|
|
7
|
-
include JWT::JWA::SigningAlgorithm
|
|
8
|
-
|
|
9
|
-
def self.from_algorithm(algorithm)
|
|
10
|
-
new(algorithm, ::RbNaCl::HMAC.const_get(algorithm.upcase.gsub('HS', 'SHA')))
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def initialize(alg, hmac)
|
|
14
|
-
@alg = alg
|
|
15
|
-
@hmac = hmac
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def sign(data:, signing_key:)
|
|
19
|
-
signing_key ||= ''
|
|
20
|
-
Deprecations.warning("The use of the algorithm #{alg} is deprecated and will be removed in the next major version of ruby-jwt")
|
|
21
|
-
raise JWT::DecodeError, 'HMAC key expected to be a String' unless signing_key.is_a?(String)
|
|
22
|
-
|
|
23
|
-
hmac.auth(padded_key_bytes(signing_key, hmac.key_bytes), data.encode('binary'))
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def verify(data:, signature:, verification_key:)
|
|
27
|
-
verification_key ||= ''
|
|
28
|
-
Deprecations.warning("The use of the algorithm #{alg} is deprecated and will be removed in the next major version of ruby-jwt")
|
|
29
|
-
raise JWT::DecodeError, 'HMAC key expected to be a String' unless verification_key.is_a?(String)
|
|
30
|
-
|
|
31
|
-
hmac.verify(padded_key_bytes(verification_key, hmac.key_bytes), signature.encode('binary'), data.encode('binary'))
|
|
32
|
-
rescue ::RbNaCl::BadAuthenticatorError, ::RbNaCl::LengthError
|
|
33
|
-
false
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
register_algorithm(new('HS512256', ::RbNaCl::HMAC::SHA512256))
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
attr_reader :hmac
|
|
41
|
-
|
|
42
|
-
def padded_key_bytes(key, bytesize)
|
|
43
|
-
key.bytes.fill(0, key.bytesize...bytesize).pack('C*')
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
data/lib/jwt/jwa/wrapper.rb
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
module JWA
|
|
5
|
-
# @api private
|
|
6
|
-
class Wrapper
|
|
7
|
-
include SigningAlgorithm
|
|
8
|
-
|
|
9
|
-
def initialize(algorithm)
|
|
10
|
-
@algorithm = algorithm
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def alg
|
|
14
|
-
return @algorithm.alg if @algorithm.respond_to?(:alg)
|
|
15
|
-
|
|
16
|
-
super
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def valid_alg?(alg_to_check)
|
|
20
|
-
return @algorithm.valid_alg?(alg_to_check) if @algorithm.respond_to?(:valid_alg?)
|
|
21
|
-
|
|
22
|
-
super
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def header(*args, **kwargs)
|
|
26
|
-
return @algorithm.header(*args, **kwargs) if @algorithm.respond_to?(:header)
|
|
27
|
-
|
|
28
|
-
super
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def sign(*args, **kwargs)
|
|
32
|
-
return @algorithm.sign(*args, **kwargs) if @algorithm.respond_to?(:sign)
|
|
33
|
-
|
|
34
|
-
super
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def verify(*args, **kwargs)
|
|
38
|
-
return @algorithm.verify(*args, **kwargs) if @algorithm.respond_to?(:verify)
|
|
39
|
-
|
|
40
|
-
super
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
data/lib/jwt/jwk/okp_rbnacl.rb
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module JWT
|
|
4
|
-
module JWK
|
|
5
|
-
# JSON Web Key (JWK) representation for Ed25519 keys
|
|
6
|
-
class OKPRbNaCl < KeyBase
|
|
7
|
-
KTY = 'OKP'
|
|
8
|
-
KTYS = [KTY, JWT::JWK::OKPRbNaCl, RbNaCl::Signatures::Ed25519::SigningKey, RbNaCl::Signatures::Ed25519::VerifyKey].freeze
|
|
9
|
-
OKP_PUBLIC_KEY_ELEMENTS = %i[kty n x].freeze
|
|
10
|
-
OKP_PRIVATE_KEY_ELEMENTS = %i[d].freeze
|
|
11
|
-
|
|
12
|
-
def initialize(key, params = nil, options = {})
|
|
13
|
-
params ||= {}
|
|
14
|
-
Deprecations.warning('Using the OKP JWK for Ed25519 keys is deprecated and will be removed in a future version of ruby-jwt. Please use the ruby-eddsa gem instead.')
|
|
15
|
-
# For backwards compatibility when kid was a String
|
|
16
|
-
params = { kid: params } if params.is_a?(String)
|
|
17
|
-
|
|
18
|
-
key_params = extract_key_params(key)
|
|
19
|
-
|
|
20
|
-
params = params.transform_keys(&:to_sym)
|
|
21
|
-
check_jwk_params!(key_params, params)
|
|
22
|
-
super(options, key_params.merge(params))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def verify_key
|
|
26
|
-
return @verify_key if defined?(@verify_key)
|
|
27
|
-
|
|
28
|
-
@verify_key = verify_key_from_parameters
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def signing_key
|
|
32
|
-
return @signing_key if defined?(@signing_key)
|
|
33
|
-
|
|
34
|
-
@signing_key = signing_key_from_parameters
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def key_digest
|
|
38
|
-
Thumbprint.new(self).to_s
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def private?
|
|
42
|
-
!signing_key.nil?
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def members
|
|
46
|
-
OKP_PUBLIC_KEY_ELEMENTS.each_with_object({}) { |i, h| h[i] = self[i] }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def export(options = {})
|
|
50
|
-
exported = parameters.clone
|
|
51
|
-
exported.reject! { |k, _| OKP_PRIVATE_KEY_ELEMENTS.include?(k) } unless private? && options[:include_private] == true
|
|
52
|
-
exported
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def extract_key_params(key)
|
|
58
|
-
case key
|
|
59
|
-
when JWT::JWK::KeyBase
|
|
60
|
-
key.export(include_private: true)
|
|
61
|
-
when RbNaCl::Signatures::Ed25519::SigningKey
|
|
62
|
-
@signing_key = key
|
|
63
|
-
@verify_key = key.verify_key
|
|
64
|
-
parse_okp_key_params(@verify_key, @signing_key)
|
|
65
|
-
when RbNaCl::Signatures::Ed25519::VerifyKey
|
|
66
|
-
@signing_key = nil
|
|
67
|
-
@verify_key = key
|
|
68
|
-
parse_okp_key_params(@verify_key)
|
|
69
|
-
when Hash
|
|
70
|
-
key.transform_keys(&:to_sym)
|
|
71
|
-
else
|
|
72
|
-
raise ArgumentError, 'key must be of type RbNaCl::Signatures::Ed25519::SigningKey, RbNaCl::Signatures::Ed25519::VerifyKey or Hash with key parameters'
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def check_jwk_params!(key_params, _given_params)
|
|
77
|
-
raise JWT::JWKError, "Incorrect 'kty' value: #{key_params[:kty]}, expected #{KTY}" unless key_params[:kty] == KTY
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def parse_okp_key_params(verify_key, signing_key = nil)
|
|
81
|
-
params = {
|
|
82
|
-
kty: KTY,
|
|
83
|
-
crv: 'Ed25519',
|
|
84
|
-
x: ::JWT::Base64.url_encode(verify_key.to_bytes)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
params[:d] = ::JWT::Base64.url_encode(signing_key.to_bytes) if signing_key
|
|
88
|
-
|
|
89
|
-
params
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def verify_key_from_parameters
|
|
93
|
-
RbNaCl::Signatures::Ed25519::VerifyKey.new(::JWT::Base64.url_decode(self[:x]))
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def signing_key_from_parameters
|
|
97
|
-
return nil unless self[:d]
|
|
98
|
-
|
|
99
|
-
RbNaCl::Signatures::Ed25519::SigningKey.new(::JWT::Base64.url_decode(self[:d]))
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
class << self
|
|
103
|
-
def import(jwk_data)
|
|
104
|
-
new(jwk_data)
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|
data/lib/jwt/verify.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'error'
|
|
4
|
-
|
|
5
|
-
module JWT
|
|
6
|
-
# @deprecated This class is deprecated and will be removed in the next major version of ruby-jwt.
|
|
7
|
-
class Verify
|
|
8
|
-
DEFAULTS = { leeway: 0 }.freeze
|
|
9
|
-
METHODS = %w[verify_aud verify_expiration verify_iat verify_iss verify_jti verify_not_before verify_sub verify_required_claims].freeze
|
|
10
|
-
|
|
11
|
-
private_constant(:DEFAULTS, :METHODS)
|
|
12
|
-
class << self
|
|
13
|
-
METHODS.each do |method_name|
|
|
14
|
-
define_method(method_name) do |payload, options|
|
|
15
|
-
new(payload, options).send(method_name)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# @deprecated This method is deprecated and will be removed in the next major version of ruby-jwt.
|
|
20
|
-
def verify_claims(payload, options)
|
|
21
|
-
Deprecations.warning('The ::JWT::Verify.verify_claims method is deprecated and will be removed in the next major version of ruby-jwt')
|
|
22
|
-
::JWT::Claims.verify!(payload, options)
|
|
23
|
-
true
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# @deprecated This class is deprecated and will be removed in the next major version of ruby-jwt.
|
|
28
|
-
def initialize(payload, options)
|
|
29
|
-
Deprecations.warning('The ::JWT::Verify class is deprecated and will be removed in the next major version of ruby-jwt')
|
|
30
|
-
@payload = payload
|
|
31
|
-
@options = DEFAULTS.merge(options)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
METHODS.each do |method_name|
|
|
35
|
-
define_method(method_name) do
|
|
36
|
-
::JWT::Claims.verify!(@payload, @options.merge(method_name => true))
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|