json-jwt 1.9.1 → 1.17.2
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 +5 -5
- data/.github/FUNDING.yml +3 -0
- data/.github/workflows/spec.yml +31 -0
- data/.gitmodules +1 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile +1 -1
- data/README.md +11 -2
- data/VERSION +1 -1
- data/json-jwt.gemspec +10 -5
- data/lib/json/jose.rb +22 -11
- data/lib/json/jwe.rb +55 -38
- data/lib/json/jwk/jwkizable.rb +13 -11
- data/lib/json/jwk/set/fetcher.rb +93 -0
- data/lib/json/jwk/set.rb +7 -1
- data/lib/json/jwk.rb +62 -34
- data/lib/json/jws.rb +38 -35
- data/lib/json/jwt.rb +43 -17
- metadata +55 -56
- data/.travis.yml +0 -11
- data/spec/fixtures/ecdsa/256/private_key.pem +0 -5
- data/spec/fixtures/ecdsa/256/public_key.pem +0 -4
- data/spec/fixtures/ecdsa/384/private_key.pem +0 -6
- data/spec/fixtures/ecdsa/384/public_key.pem +0 -5
- data/spec/fixtures/ecdsa/512/private_key.pem +0 -7
- data/spec/fixtures/ecdsa/512/public_key.pem +0 -6
- data/spec/fixtures/rsa/private_key.der +0 -0
- data/spec/fixtures/rsa/private_key.pem +0 -30
- data/spec/fixtures/rsa/public_key.pem +0 -8
- data/spec/helpers/nimbus_spec_helper.rb +0 -22
- data/spec/helpers/sign_key_fixture_helper.rb +0 -52
- data/spec/interop/with_jsrsasign_spec.rb +0 -49
- data/spec/interop/with_nimbus_jose_spec.rb +0 -99
- data/spec/interop/with_rfc_example_spec.rb +0 -19
- data/spec/json/jwe_spec.rb +0 -311
- data/spec/json/jwk/jwkizable_spec.rb +0 -49
- data/spec/json/jwk/set_spec.rb +0 -75
- data/spec/json/jwk_spec.rb +0 -194
- data/spec/json/jws_spec.rb +0 -324
- data/spec/json/jwt_spec.rb +0 -496
- data/spec/spec_helper.rb +0 -28
data/lib/json/jwk.rb
CHANGED
|
@@ -34,7 +34,7 @@ module JSON
|
|
|
34
34
|
else
|
|
35
35
|
raise UnknownAlgorithm.new('Unknown Digest Algorithm')
|
|
36
36
|
end
|
|
37
|
-
|
|
37
|
+
Base64.urlsafe_encode64 digest.digest(normalize.to_json), padding: false
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def to_key
|
|
@@ -50,24 +50,16 @@ module JSON
|
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
private
|
|
54
|
-
|
|
55
53
|
def rsa?
|
|
56
|
-
self[:kty]
|
|
54
|
+
self[:kty]&.to_sym == :RSA
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
def ec?
|
|
60
|
-
self[:kty]
|
|
58
|
+
self[:kty]&.to_sym == :EC
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
def oct?
|
|
64
|
-
self[:kty]
|
|
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,53 +87,89 @@ 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]
|
|
101
|
-
OpenSSL::BN.new
|
|
101
|
+
OpenSSL::BN.new Base64.urlsafe_decode64(self[key]), 2
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
104
|
+
|
|
105
|
+
# Public key
|
|
106
|
+
data_sequence = OpenSSL::ASN1::Sequence([
|
|
107
|
+
OpenSSL::ASN1::Integer(n),
|
|
108
|
+
OpenSSL::ASN1::Integer(e),
|
|
109
|
+
])
|
|
110
|
+
|
|
111
|
+
if d && p && q && dp && dq && qi
|
|
112
|
+
data_sequence = OpenSSL::ASN1::Sequence([
|
|
113
|
+
OpenSSL::ASN1::Integer(0),
|
|
114
|
+
OpenSSL::ASN1::Integer(n),
|
|
115
|
+
OpenSSL::ASN1::Integer(e),
|
|
116
|
+
OpenSSL::ASN1::Integer(d),
|
|
117
|
+
OpenSSL::ASN1::Integer(p),
|
|
118
|
+
OpenSSL::ASN1::Integer(q),
|
|
119
|
+
OpenSSL::ASN1::Integer(dp),
|
|
120
|
+
OpenSSL::ASN1::Integer(dq),
|
|
121
|
+
OpenSSL::ASN1::Integer(qi),
|
|
122
|
+
])
|
|
118
123
|
end
|
|
119
|
-
|
|
124
|
+
|
|
125
|
+
asn1 = OpenSSL::ASN1::Sequence(data_sequence)
|
|
126
|
+
OpenSSL::PKey::RSA.new(asn1.to_der)
|
|
120
127
|
end
|
|
121
128
|
|
|
122
129
|
def to_ec_key
|
|
123
|
-
curve_name = case self[:crv]
|
|
130
|
+
curve_name = case self[:crv]&.to_sym
|
|
124
131
|
when :'P-256'
|
|
125
132
|
'prime256v1'
|
|
126
133
|
when :'P-384'
|
|
127
134
|
'secp384r1'
|
|
128
135
|
when :'P-521'
|
|
129
136
|
'secp521r1'
|
|
137
|
+
when :secp256k1
|
|
138
|
+
'secp256k1'
|
|
130
139
|
else
|
|
131
140
|
raise UnknownAlgorithm.new('Unknown EC Curve')
|
|
132
141
|
end
|
|
133
142
|
x, y, d = [:x, :y, :d].collect do |key|
|
|
134
143
|
if self[key]
|
|
135
|
-
|
|
144
|
+
Base64.urlsafe_decode64(self[key])
|
|
136
145
|
end
|
|
137
146
|
end
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
key.public_key = OpenSSL::PKey::EC::Point.new(
|
|
147
|
+
|
|
148
|
+
point = OpenSSL::PKey::EC::Point.new(
|
|
141
149
|
OpenSSL::PKey::EC::Group.new(curve_name),
|
|
142
150
|
OpenSSL::BN.new(['04' + x.unpack('H*').first + y.unpack('H*').first].pack('H*'), 2)
|
|
143
151
|
)
|
|
144
|
-
|
|
152
|
+
|
|
153
|
+
# Public key
|
|
154
|
+
data_sequence = OpenSSL::ASN1::Sequence([
|
|
155
|
+
OpenSSL::ASN1::Sequence([
|
|
156
|
+
OpenSSL::ASN1::ObjectId("id-ecPublicKey"),
|
|
157
|
+
OpenSSL::ASN1::ObjectId(curve_name)
|
|
158
|
+
]),
|
|
159
|
+
OpenSSL::ASN1::BitString(point.to_octet_string(:uncompressed))
|
|
160
|
+
])
|
|
161
|
+
|
|
162
|
+
if d
|
|
163
|
+
# Private key
|
|
164
|
+
data_sequence = OpenSSL::ASN1::Sequence([
|
|
165
|
+
OpenSSL::ASN1::Integer(1),
|
|
166
|
+
OpenSSL::ASN1::OctetString(OpenSSL::BN.new(d, 2).to_s(2)),
|
|
167
|
+
OpenSSL::ASN1::ObjectId(curve_name, 0, :EXPLICIT),
|
|
168
|
+
OpenSSL::ASN1::BitString(point.to_octet_string(:uncompressed), 1, :EXPLICIT)
|
|
169
|
+
])
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
OpenSSL::PKey::EC.new(data_sequence.to_der)
|
|
145
173
|
end
|
|
146
174
|
end
|
|
147
175
|
end
|
data/lib/json/jws.rb
CHANGED
|
@@ -6,23 +6,24 @@ module JSON
|
|
|
6
6
|
|
|
7
7
|
NUM_OF_SEGMENTS = 3
|
|
8
8
|
|
|
9
|
-
|
|
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
|
|
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
|
|
22
|
+
if alg&.to_sym == :none
|
|
23
|
+
raise UnexpectedAlgorithm unless algorithms.blank? || Array(algorithms).include?(:none)
|
|
23
24
|
raise UnexpectedAlgorithm if public_key_or_secret
|
|
24
25
|
signature == '' or raise VerificationFailed
|
|
25
|
-
elsif algorithms.blank? || Array(algorithms).include?(alg
|
|
26
|
+
elsif algorithms.blank? || Array(algorithms).include?(alg&.to_sym)
|
|
26
27
|
public_key_or_secret && valid?(public_key_or_secret) or
|
|
27
28
|
raise VerificationFailed
|
|
28
29
|
else
|
|
@@ -35,6 +36,7 @@ module JSON
|
|
|
35
36
|
if hash_or_jwt.is_a? JSON::JWT
|
|
36
37
|
self.header.update hash_or_jwt.header
|
|
37
38
|
self.signature = hash_or_jwt.signature
|
|
39
|
+
self.blank_payload = hash_or_jwt.blank_payload
|
|
38
40
|
end
|
|
39
41
|
self
|
|
40
42
|
end
|
|
@@ -42,34 +44,27 @@ module JSON
|
|
|
42
44
|
private
|
|
43
45
|
|
|
44
46
|
def digest
|
|
45
|
-
OpenSSL::Digest.new "SHA#{
|
|
47
|
+
OpenSSL::Digest.new "SHA#{alg.to_s[2, 3]}"
|
|
46
48
|
end
|
|
47
49
|
|
|
48
50
|
def hmac?
|
|
49
|
-
[:HS256, :HS384, :HS512].include?
|
|
51
|
+
[:HS256, :HS384, :HS512].include? alg&.to_sym
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
def rsa?
|
|
53
|
-
[:RS256, :RS384, :RS512].include?
|
|
55
|
+
[:RS256, :RS384, :RS512].include? alg&.to_sym
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
def rsa_pss?
|
|
57
|
-
|
|
58
|
-
if OpenSSL::VERSION < '2.1.0'
|
|
59
|
-
raise "#{alg} isn't supported. OpenSSL gem v2.1.0+ is required to use #{alg}."
|
|
60
|
-
else
|
|
61
|
-
true
|
|
62
|
-
end
|
|
63
|
-
else
|
|
64
|
-
false
|
|
65
|
-
end
|
|
59
|
+
[:PS256, :PS384, :PS512].include? alg&.to_sym
|
|
66
60
|
end
|
|
67
61
|
|
|
68
62
|
def ecdsa?
|
|
69
|
-
[:ES256, :ES384, :ES512].include?
|
|
63
|
+
[:ES256, :ES384, :ES512, :ES256K].include? alg&.to_sym
|
|
70
64
|
end
|
|
71
65
|
|
|
72
66
|
def autodetected_algorithm_from(private_key_or_secret)
|
|
67
|
+
private_key_or_secret = with_jwk_support private_key_or_secret
|
|
73
68
|
case private_key_or_secret
|
|
74
69
|
when String
|
|
75
70
|
:HS256
|
|
@@ -83,6 +78,8 @@ module JSON
|
|
|
83
78
|
:ES384
|
|
84
79
|
when 'secp521r1'
|
|
85
80
|
:ES512
|
|
81
|
+
when 'secp256k1'
|
|
82
|
+
:ES256K
|
|
86
83
|
else
|
|
87
84
|
raise UnknownAlgorithm.new('Unknown EC Curve')
|
|
88
85
|
end
|
|
@@ -96,7 +93,7 @@ module JSON
|
|
|
96
93
|
header.to_json,
|
|
97
94
|
self.to_json
|
|
98
95
|
].collect do |segment|
|
|
99
|
-
|
|
96
|
+
Base64.urlsafe_encode64 segment, padding: false
|
|
100
97
|
end.join('.')
|
|
101
98
|
end
|
|
102
99
|
|
|
@@ -116,7 +113,7 @@ module JSON
|
|
|
116
113
|
private_key = private_key_or_secret
|
|
117
114
|
verify_ecdsa_group! private_key
|
|
118
115
|
asn1_to_raw(
|
|
119
|
-
private_key.
|
|
116
|
+
private_key.sign(digest, signature_base_string),
|
|
120
117
|
private_key
|
|
121
118
|
)
|
|
122
119
|
else
|
|
@@ -128,7 +125,8 @@ module JSON
|
|
|
128
125
|
public_key_or_secret = with_jwk_support public_key_or_secret
|
|
129
126
|
case
|
|
130
127
|
when hmac?
|
|
131
|
-
|
|
128
|
+
secret = public_key_or_secret
|
|
129
|
+
secure_compare sign(signature_base_string, secret), signature
|
|
132
130
|
when rsa?
|
|
133
131
|
public_key = public_key_or_secret
|
|
134
132
|
public_key.verify digest, signature, signature_base_string
|
|
@@ -138,10 +136,7 @@ module JSON
|
|
|
138
136
|
when ecdsa?
|
|
139
137
|
public_key = public_key_or_secret
|
|
140
138
|
verify_ecdsa_group! public_key
|
|
141
|
-
public_key.
|
|
142
|
-
digest.digest(signature_base_string),
|
|
143
|
-
raw_to_asn1(signature, public_key)
|
|
144
|
-
)
|
|
139
|
+
public_key.verify digest, raw_to_asn1(signature, public_key), signature_base_string
|
|
145
140
|
else
|
|
146
141
|
raise UnexpectedAlgorithm.new('Unknown Signature Algorithm')
|
|
147
142
|
end
|
|
@@ -152,14 +147,19 @@ module JSON
|
|
|
152
147
|
def verify_ecdsa_group!(key)
|
|
153
148
|
group_name = case digest.digest_length * 8
|
|
154
149
|
when 256
|
|
155
|
-
|
|
150
|
+
case key.group.curve_name
|
|
151
|
+
when 'secp256k1'
|
|
152
|
+
:secp256k1
|
|
153
|
+
else
|
|
154
|
+
:prime256v1
|
|
155
|
+
end
|
|
156
156
|
when 384
|
|
157
157
|
:secp384r1
|
|
158
158
|
when 512
|
|
159
159
|
:secp521r1
|
|
160
160
|
end
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
newkey = OpenSSL::PKey::EC.generate(group_name.to_s)
|
|
162
|
+
newkey.check_key
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
def raw_to_asn1(signature, public_key)
|
|
@@ -175,25 +175,28 @@ module JSON
|
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
class << self
|
|
178
|
-
def decode_compact_serialized(input, public_key_or_secret, algorithms = nil)
|
|
178
|
+
def decode_compact_serialized(input, public_key_or_secret, algorithms = nil, allow_blank_payload = false)
|
|
179
179
|
unless input.count('.') + 1 == NUM_OF_SEGMENTS
|
|
180
180
|
raise InvalidFormat.new("Invalid JWS Format. JWS should include #{NUM_OF_SEGMENTS} segments.")
|
|
181
181
|
end
|
|
182
|
-
header, claims, signature = input.split('.',
|
|
183
|
-
|
|
182
|
+
header, claims, signature = input.split('.', NUM_OF_SEGMENTS).collect do |segment|
|
|
183
|
+
Base64.urlsafe_decode64 segment.to_s
|
|
184
184
|
end
|
|
185
|
-
header
|
|
186
|
-
|
|
185
|
+
header = JSON.parse(header).with_indifferent_access
|
|
186
|
+
if allow_blank_payload && claims == ''
|
|
187
|
+
claims = nil
|
|
188
|
+
else
|
|
189
|
+
claims = JSON.parse(claims).with_indifferent_access
|
|
187
190
|
end
|
|
188
191
|
jws = new claims
|
|
189
192
|
jws.header = header
|
|
190
193
|
jws.signature = signature
|
|
191
|
-
jws.signature_base_string = input.split('.')[0,
|
|
194
|
+
jws.signature_base_string = input.split('.')[0, NUM_OF_SEGMENTS - 1].join('.')
|
|
192
195
|
jws.verify! public_key_or_secret, algorithms unless public_key_or_secret == :skip_verification
|
|
193
196
|
jws
|
|
194
197
|
end
|
|
195
198
|
|
|
196
|
-
def decode_json_serialized(input, public_key_or_secret, algorithms = nil)
|
|
199
|
+
def decode_json_serialized(input, public_key_or_secret, algorithms = nil, allow_blank_payload = false)
|
|
197
200
|
input = input.with_indifferent_access
|
|
198
201
|
header, payload, signature = if input[:signatures].present?
|
|
199
202
|
[
|
|
@@ -209,7 +212,7 @@ module JSON
|
|
|
209
212
|
end
|
|
210
213
|
end
|
|
211
214
|
compact_serialized = [header, payload, signature].join('.')
|
|
212
|
-
decode_compact_serialized compact_serialized, public_key_or_secret, algorithms
|
|
215
|
+
decode_compact_serialized compact_serialized, public_key_or_secret, algorithms, allow_blank_payload
|
|
213
216
|
end
|
|
214
217
|
end
|
|
215
218
|
end
|
data/lib/json/jwt.rb
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
require 'openssl'
|
|
2
|
-
require '
|
|
2
|
+
require 'base64'
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require 'faraday/follow_redirects'
|
|
3
5
|
require 'active_support'
|
|
4
6
|
require 'active_support/core_ext'
|
|
5
7
|
require 'json/jose'
|
|
6
8
|
|
|
7
9
|
module JSON
|
|
8
10
|
class JWT < ActiveSupport::HashWithIndifferentAccess
|
|
11
|
+
VERSION = ::File.read(
|
|
12
|
+
::File.join(::File.dirname(__FILE__), '../../VERSION')
|
|
13
|
+
).chomp
|
|
14
|
+
|
|
15
|
+
attr_accessor :blank_payload
|
|
9
16
|
attr_accessor :signature
|
|
10
17
|
|
|
11
18
|
class Exception < StandardError; end
|
|
@@ -19,10 +26,12 @@ module JSON
|
|
|
19
26
|
@content_type = 'application/jwt'
|
|
20
27
|
self.typ = :JWT
|
|
21
28
|
self.alg = :none
|
|
22
|
-
[:exp, :nbf, :iat].each do |key|
|
|
23
|
-
claims[key] = claims[key].to_i if claims[key]
|
|
24
|
-
end
|
|
25
29
|
update claims
|
|
30
|
+
unless claims.nil?
|
|
31
|
+
[:exp, :nbf, :iat].each do |key|
|
|
32
|
+
self[key] = self[key].to_i if self[key]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
26
35
|
end
|
|
27
36
|
|
|
28
37
|
def sign(private_key_or_secret, algorithm = :autodetect)
|
|
@@ -46,7 +55,7 @@ module JSON
|
|
|
46
55
|
self.to_json,
|
|
47
56
|
signature
|
|
48
57
|
].collect do |segment|
|
|
49
|
-
|
|
58
|
+
Base64.urlsafe_encode64 segment.to_s, padding: false
|
|
50
59
|
end.join('.')
|
|
51
60
|
end
|
|
52
61
|
|
|
@@ -54,23 +63,39 @@ module JSON
|
|
|
54
63
|
case options[:syntax]
|
|
55
64
|
when :general
|
|
56
65
|
{
|
|
57
|
-
payload:
|
|
66
|
+
payload: Base64.urlsafe_encode64(self.to_json, padding: false),
|
|
58
67
|
signatures: [{
|
|
59
|
-
protected:
|
|
60
|
-
signature:
|
|
68
|
+
protected: Base64.urlsafe_encode64(header.to_json, padding: false),
|
|
69
|
+
signature: Base64.urlsafe_encode64(signature.to_s, padding: false)
|
|
61
70
|
}]
|
|
62
71
|
}
|
|
63
72
|
when :flattened
|
|
64
73
|
{
|
|
65
|
-
protected:
|
|
66
|
-
payload:
|
|
67
|
-
signature:
|
|
74
|
+
protected: Base64.urlsafe_encode64(header.to_json, padding: false),
|
|
75
|
+
payload: Base64.urlsafe_encode64(self.to_json, padding: false),
|
|
76
|
+
signature: Base64.urlsafe_encode64(signature.to_s, padding: false)
|
|
68
77
|
}
|
|
69
78
|
else
|
|
70
79
|
super
|
|
71
80
|
end
|
|
72
81
|
end
|
|
73
82
|
|
|
83
|
+
def to_json *args
|
|
84
|
+
if @blank_payload && args.empty?
|
|
85
|
+
''
|
|
86
|
+
else
|
|
87
|
+
super
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def update claims
|
|
92
|
+
if claims.nil?
|
|
93
|
+
@blank_payload = true
|
|
94
|
+
else
|
|
95
|
+
super
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
74
99
|
def pretty_generate
|
|
75
100
|
[
|
|
76
101
|
JSON.pretty_generate(header),
|
|
@@ -79,23 +104,23 @@ module JSON
|
|
|
79
104
|
end
|
|
80
105
|
|
|
81
106
|
class << self
|
|
82
|
-
def decode_compact_serialized(jwt_string, key_or_secret, algorithms = nil, encryption_methods = nil)
|
|
107
|
+
def decode_compact_serialized(jwt_string, key_or_secret, algorithms = nil, encryption_methods = nil, allow_blank_payload = false)
|
|
83
108
|
case jwt_string.count('.') + 1
|
|
84
109
|
when JWS::NUM_OF_SEGMENTS
|
|
85
|
-
JWS.decode_compact_serialized jwt_string, key_or_secret, algorithms
|
|
110
|
+
JWS.decode_compact_serialized jwt_string, key_or_secret, algorithms, allow_blank_payload
|
|
86
111
|
when JWE::NUM_OF_SEGMENTS
|
|
87
|
-
JWE.decode_compact_serialized jwt_string, key_or_secret, algorithms, encryption_methods
|
|
112
|
+
JWE.decode_compact_serialized jwt_string, key_or_secret, algorithms, encryption_methods, allow_blank_payload
|
|
88
113
|
else
|
|
89
114
|
raise InvalidFormat.new("Invalid JWT Format. JWT should include #{JWS::NUM_OF_SEGMENTS} or #{JWE::NUM_OF_SEGMENTS} segments.")
|
|
90
115
|
end
|
|
91
116
|
end
|
|
92
117
|
|
|
93
|
-
def decode_json_serialized(input, key_or_secret, algorithms = nil, encryption_methods = nil)
|
|
118
|
+
def decode_json_serialized(input, key_or_secret, algorithms = nil, encryption_methods = nil, allow_blank_payload = false)
|
|
94
119
|
input = input.with_indifferent_access
|
|
95
120
|
if (input[:signatures] || input[:signature]).present?
|
|
96
|
-
JWS.decode_json_serialized input, key_or_secret, algorithms
|
|
121
|
+
JWS.decode_json_serialized input, key_or_secret, algorithms, allow_blank_payload
|
|
97
122
|
elsif input[:ciphertext].present?
|
|
98
|
-
JWE.decode_json_serialized input, key_or_secret, algorithms, encryption_methods
|
|
123
|
+
JWE.decode_json_serialized input, key_or_secret, algorithms, encryption_methods, allow_blank_payload
|
|
99
124
|
else
|
|
100
125
|
raise InvalidFormat.new("Unexpected JOSE JSON Serialization Format.")
|
|
101
126
|
end
|
|
@@ -113,3 +138,4 @@ require 'json/jwe'
|
|
|
113
138
|
require 'json/jwk'
|
|
114
139
|
require 'json/jwk/jwkizable'
|
|
115
140
|
require 'json/jwk/set'
|
|
141
|
+
require 'json/jwk/set/fetcher'
|
metadata
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: json-jwt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.17.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- nov matake
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: activesupport
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '4.2'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '4.2'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: base64
|
|
15
28
|
requirement: !ruby/object:Gem::Requirement
|
|
16
29
|
requirements:
|
|
17
30
|
- - ">="
|
|
@@ -25,7 +38,7 @@ dependencies:
|
|
|
25
38
|
- !ruby/object:Gem::Version
|
|
26
39
|
version: '0'
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
41
|
+
name: bindata
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
30
43
|
requirements:
|
|
31
44
|
- - ">="
|
|
@@ -39,7 +52,7 @@ dependencies:
|
|
|
39
52
|
- !ruby/object:Gem::Version
|
|
40
53
|
version: '0'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
55
|
+
name: aes_key_wrap
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
44
57
|
requirements:
|
|
45
58
|
- - ">="
|
|
@@ -53,7 +66,21 @@ dependencies:
|
|
|
53
66
|
- !ruby/object:Gem::Version
|
|
54
67
|
version: '0'
|
|
55
68
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
69
|
+
name: faraday
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '2.0'
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '2.0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: faraday-follow_redirects
|
|
57
84
|
requirement: !ruby/object:Gem::Requirement
|
|
58
85
|
requirements:
|
|
59
86
|
- - ">="
|
|
@@ -94,6 +121,20 @@ dependencies:
|
|
|
94
121
|
- - ">="
|
|
95
122
|
- !ruby/object:Gem::Version
|
|
96
123
|
version: '0'
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: webmock
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
type: :development
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
97
138
|
- !ruby/object:Gem::Dependency
|
|
98
139
|
name: rspec
|
|
99
140
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -130,10 +171,12 @@ executables: []
|
|
|
130
171
|
extensions: []
|
|
131
172
|
extra_rdoc_files: []
|
|
132
173
|
files:
|
|
174
|
+
- ".github/FUNDING.yml"
|
|
175
|
+
- ".github/workflows/spec.yml"
|
|
133
176
|
- ".gitignore"
|
|
134
177
|
- ".gitmodules"
|
|
135
178
|
- ".rspec"
|
|
136
|
-
-
|
|
179
|
+
- CHANGELOG.md
|
|
137
180
|
- Gemfile
|
|
138
181
|
- LICENSE
|
|
139
182
|
- README.md
|
|
@@ -145,34 +188,13 @@ files:
|
|
|
145
188
|
- lib/json/jwk.rb
|
|
146
189
|
- lib/json/jwk/jwkizable.rb
|
|
147
190
|
- lib/json/jwk/set.rb
|
|
191
|
+
- lib/json/jwk/set/fetcher.rb
|
|
148
192
|
- lib/json/jws.rb
|
|
149
193
|
- lib/json/jwt.rb
|
|
150
|
-
- spec/fixtures/ecdsa/256/private_key.pem
|
|
151
|
-
- spec/fixtures/ecdsa/256/public_key.pem
|
|
152
|
-
- spec/fixtures/ecdsa/384/private_key.pem
|
|
153
|
-
- spec/fixtures/ecdsa/384/public_key.pem
|
|
154
|
-
- spec/fixtures/ecdsa/512/private_key.pem
|
|
155
|
-
- spec/fixtures/ecdsa/512/public_key.pem
|
|
156
|
-
- spec/fixtures/rsa/private_key.der
|
|
157
|
-
- spec/fixtures/rsa/private_key.pem
|
|
158
|
-
- spec/fixtures/rsa/public_key.pem
|
|
159
|
-
- spec/helpers/nimbus_spec_helper.rb
|
|
160
|
-
- spec/helpers/sign_key_fixture_helper.rb
|
|
161
|
-
- spec/interop/with_jsrsasign_spec.rb
|
|
162
|
-
- spec/interop/with_nimbus_jose_spec.rb
|
|
163
|
-
- spec/interop/with_rfc_example_spec.rb
|
|
164
|
-
- spec/json/jwe_spec.rb
|
|
165
|
-
- spec/json/jwk/jwkizable_spec.rb
|
|
166
|
-
- spec/json/jwk/set_spec.rb
|
|
167
|
-
- spec/json/jwk_spec.rb
|
|
168
|
-
- spec/json/jws_spec.rb
|
|
169
|
-
- spec/json/jwt_spec.rb
|
|
170
|
-
- spec/spec_helper.rb
|
|
171
194
|
homepage: https://github.com/nov/json-jwt
|
|
172
195
|
licenses:
|
|
173
196
|
- MIT
|
|
174
197
|
metadata: {}
|
|
175
|
-
post_install_message:
|
|
176
198
|
rdoc_options: []
|
|
177
199
|
require_paths:
|
|
178
200
|
- lib
|
|
@@ -180,38 +202,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
180
202
|
requirements:
|
|
181
203
|
- - ">="
|
|
182
204
|
- !ruby/object:Gem::Version
|
|
183
|
-
version: '
|
|
205
|
+
version: '2.4'
|
|
184
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
207
|
requirements:
|
|
186
208
|
- - ">="
|
|
187
209
|
- !ruby/object:Gem::Version
|
|
188
210
|
version: '0'
|
|
189
211
|
requirements: []
|
|
190
|
-
|
|
191
|
-
rubygems_version: 2.6.11
|
|
192
|
-
signing_key:
|
|
212
|
+
rubygems_version: 4.0.10
|
|
193
213
|
specification_version: 4
|
|
194
214
|
summary: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and
|
|
195
215
|
JSON Web Key) in Ruby
|
|
196
|
-
test_files:
|
|
197
|
-
- spec/fixtures/ecdsa/256/private_key.pem
|
|
198
|
-
- spec/fixtures/ecdsa/256/public_key.pem
|
|
199
|
-
- spec/fixtures/ecdsa/384/private_key.pem
|
|
200
|
-
- spec/fixtures/ecdsa/384/public_key.pem
|
|
201
|
-
- spec/fixtures/ecdsa/512/private_key.pem
|
|
202
|
-
- spec/fixtures/ecdsa/512/public_key.pem
|
|
203
|
-
- spec/fixtures/rsa/private_key.der
|
|
204
|
-
- spec/fixtures/rsa/private_key.pem
|
|
205
|
-
- spec/fixtures/rsa/public_key.pem
|
|
206
|
-
- spec/helpers/nimbus_spec_helper.rb
|
|
207
|
-
- spec/helpers/sign_key_fixture_helper.rb
|
|
208
|
-
- spec/interop/with_jsrsasign_spec.rb
|
|
209
|
-
- spec/interop/with_nimbus_jose_spec.rb
|
|
210
|
-
- spec/interop/with_rfc_example_spec.rb
|
|
211
|
-
- spec/json/jwe_spec.rb
|
|
212
|
-
- spec/json/jwk/jwkizable_spec.rb
|
|
213
|
-
- spec/json/jwk/set_spec.rb
|
|
214
|
-
- spec/json/jwk_spec.rb
|
|
215
|
-
- spec/json/jws_spec.rb
|
|
216
|
-
- spec/json/jwt_spec.rb
|
|
217
|
-
- spec/spec_helper.rb
|
|
216
|
+
test_files: []
|
data/.travis.yml
DELETED
|
@@ -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-----
|