json-jwt 1.13.0 → 1.15.1
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 +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/workflows/test_ruby.yml +30 -0
- data/.gitmodules +1 -1
- data/.travis.yml +3 -3
- data/VERSION +1 -1
- data/bin/console +14 -0
- data/json-jwt.gemspec +2 -0
- data/lib/json/jose.rb +1 -3
- data/lib/json/jwk/set/fetcher/debugger/request_filter.rb +34 -0
- data/lib/json/jwk/set/fetcher.rb +87 -0
- data/lib/json/jwk/set.rb +6 -0
- data/lib/json/jwk.rb +45 -19
- data/lib/json/jws.rb +2 -2
- data/lib/json/jwt.rb +7 -0
- metadata +38 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57ea07157a9156dcf76d2b9f3841fee290e138f13951f278ea960e0fe1f4f304
|
4
|
+
data.tar.gz: 21dd8d7ef8152698da900b8bd7feeb08877083e807bfbf62c211da774f2bd8a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f795d708cc633acbbb844ab082004bd3408d14774dfd74232f371da3c8e6c2d4fadf6bd24309c10005acee0ce56f5ceade59669f2ed79f3e7616dab7517045b0
|
7
|
+
data.tar.gz: c5f41fda437761761c0590f4a5e35c49534b5e614c5341fe57d356ceb8be4fb64fb90de078ee03f63e8163e7155b742effa3667b65cdad507fda37e1cb400d8e
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Test Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
permissions:
|
8
|
+
contents: read
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
test:
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
os: ['ubuntu-18.04', 'ubuntu-20.04']
|
15
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
|
16
|
+
# ubuntu 22.04 only supports ssl 3 and thus only ruby 3.1
|
17
|
+
include:
|
18
|
+
- os: 'ubuntu-22.04'
|
19
|
+
ruby-version: '3.1'
|
20
|
+
runs-on: ${{ matrix.os }}
|
21
|
+
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v3
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby-version }}
|
28
|
+
bundler-cache: true
|
29
|
+
- name: Run tests
|
30
|
+
run: bundle exec rake
|
data/.gitmodules
CHANGED
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.15.1
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "json/jwt"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/json-jwt.gemspec
CHANGED
@@ -16,8 +16,10 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.add_runtime_dependency 'activesupport', '>= 4.2'
|
17
17
|
gem.add_runtime_dependency 'bindata'
|
18
18
|
gem.add_runtime_dependency 'aes_key_wrap'
|
19
|
+
gem.add_runtime_dependency 'httpclient'
|
19
20
|
gem.add_development_dependency 'rake'
|
20
21
|
gem.add_development_dependency 'simplecov'
|
22
|
+
gem.add_development_dependency 'webmock'
|
21
23
|
gem.add_development_dependency 'rspec'
|
22
24
|
gem.add_development_dependency 'rspec-its'
|
23
25
|
end
|
data/lib/json/jose.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
module JSON
|
2
|
+
class JWK
|
3
|
+
class Set
|
4
|
+
module Fetcher
|
5
|
+
module Debugger
|
6
|
+
class RequestFilter
|
7
|
+
# Callback called in HTTPClient (before sending a request)
|
8
|
+
# request:: HTTP::Message
|
9
|
+
def filter_request(request)
|
10
|
+
started = "======= [JSON::JWK::Set::Fetcher] HTTP REQUEST STARTED ======="
|
11
|
+
log started, request.dump
|
12
|
+
end
|
13
|
+
|
14
|
+
# Callback called in HTTPClient (after received a response)
|
15
|
+
# request:: HTTP::Message
|
16
|
+
# response:: HTTP::Message
|
17
|
+
def filter_response(request, response)
|
18
|
+
finished = "======= [JSON::JWK::Set::Fetcher] HTTP REQUEST FINISHED ======="
|
19
|
+
log '-' * 50, response.dump, finished
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def log(*outputs)
|
25
|
+
outputs.each do |output|
|
26
|
+
JSON::JWK::Set::Fetcher.logger.info output
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module JSON
|
2
|
+
class JWK
|
3
|
+
class Set
|
4
|
+
module Fetcher
|
5
|
+
class Cache
|
6
|
+
def fetch(cache_key)
|
7
|
+
yield
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.logger
|
12
|
+
@@logger
|
13
|
+
end
|
14
|
+
def self.logger=(logger)
|
15
|
+
@@logger = logger
|
16
|
+
end
|
17
|
+
self.logger = Logger.new(STDOUT)
|
18
|
+
self.logger.progname = 'JSON::JWK::Set::Fetcher'
|
19
|
+
|
20
|
+
def self.debugging?
|
21
|
+
@@debugging
|
22
|
+
end
|
23
|
+
def self.debugging=(boolean)
|
24
|
+
@@debugging = boolean
|
25
|
+
end
|
26
|
+
def self.debug!
|
27
|
+
self.debugging = true
|
28
|
+
end
|
29
|
+
def self.debug(&block)
|
30
|
+
original = self.debugging?
|
31
|
+
debug!
|
32
|
+
yield
|
33
|
+
ensure
|
34
|
+
self.debugging = original
|
35
|
+
end
|
36
|
+
self.debugging = false
|
37
|
+
|
38
|
+
def self.http_client
|
39
|
+
_http_client_ = HTTPClient.new(
|
40
|
+
agent_name: "JSON::JWK::Set::Fetcher (#{JSON::JWT::VERSION})"
|
41
|
+
)
|
42
|
+
|
43
|
+
# NOTE: httpclient gem seems stopped maintaining root certtificate set, use OS default.
|
44
|
+
_http_client_.ssl_config.clear_cert_store
|
45
|
+
_http_client_.ssl_config.cert_store.set_default_paths
|
46
|
+
|
47
|
+
_http_client_.request_filter << Debugger::RequestFilter.new if debugging?
|
48
|
+
http_config.try(:call, _http_client_)
|
49
|
+
_http_client_
|
50
|
+
end
|
51
|
+
def self.http_config(&block)
|
52
|
+
@@http_config ||= block
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.cache=(cache)
|
56
|
+
@@cache = cache
|
57
|
+
end
|
58
|
+
def self.cache
|
59
|
+
@@cache
|
60
|
+
end
|
61
|
+
self.cache = Cache.new
|
62
|
+
|
63
|
+
def self.fetch(jwks_uri, kid:, auto_detect: true)
|
64
|
+
cache_key = [
|
65
|
+
'json:jwk:set',
|
66
|
+
OpenSSL::Digest::MD5.hexdigest(jwks_uri),
|
67
|
+
kid
|
68
|
+
].collect(&:to_s).join(':')
|
69
|
+
|
70
|
+
jwks = Set.new(
|
71
|
+
JSON.parse(
|
72
|
+
cache.fetch(cache_key) do
|
73
|
+
http_client.get_content(jwks_uri)
|
74
|
+
end
|
75
|
+
)
|
76
|
+
)
|
77
|
+
|
78
|
+
if auto_detect
|
79
|
+
jwks[kid] or raise KidNotFound
|
80
|
+
else
|
81
|
+
jwks
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/json/jwk/set.rb
CHANGED
@@ -19,6 +19,12 @@ module JSON
|
|
19
19
|
'application/jwk-set+json'
|
20
20
|
end
|
21
21
|
|
22
|
+
def [](kid)
|
23
|
+
detect do |jwk|
|
24
|
+
jwk[:kid] && jwk[:kid] == kid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
22
28
|
def as_json(options = {})
|
23
29
|
# NOTE: Array.new wrapper is requied to avoid CircularReferenceError
|
24
30
|
{keys: Array.new(self)}
|
data/lib/json/jwk.rb
CHANGED
@@ -101,22 +101,29 @@ module JSON
|
|
101
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
|
@@ -137,13 +144,32 @@ module JSON
|
|
137
144
|
Base64.urlsafe_decode64(self[key])
|
138
145
|
end
|
139
146
|
end
|
140
|
-
|
141
|
-
|
142
|
-
key.public_key = OpenSSL::PKey::EC::Point.new(
|
147
|
+
|
148
|
+
point = OpenSSL::PKey::EC::Point.new(
|
143
149
|
OpenSSL::PKey::EC::Group.new(curve_name),
|
144
150
|
OpenSSL::BN.new(['04' + x.unpack('H*').first + y.unpack('H*').first].pack('H*'), 2)
|
145
151
|
)
|
146
|
-
|
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)
|
147
173
|
end
|
148
174
|
end
|
149
175
|
end
|
data/lib/json/jws.rb
CHANGED
@@ -156,8 +156,8 @@ module JSON
|
|
156
156
|
when 512
|
157
157
|
:secp521r1
|
158
158
|
end
|
159
|
-
|
160
|
-
|
159
|
+
newkey = OpenSSL::PKey::EC.generate(group_name.to_s)
|
160
|
+
newkey.check_key
|
161
161
|
end
|
162
162
|
|
163
163
|
def raw_to_asn1(signature, public_key)
|
data/lib/json/jwt.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'base64'
|
3
|
+
require 'httpclient'
|
3
4
|
require 'active_support'
|
4
5
|
require 'active_support/core_ext'
|
5
6
|
require 'json/jose'
|
6
7
|
|
7
8
|
module JSON
|
8
9
|
class JWT < ActiveSupport::HashWithIndifferentAccess
|
10
|
+
VERSION = ::File.read(
|
11
|
+
::File.join(::File.dirname(__FILE__), '../../VERSION')
|
12
|
+
).chomp
|
13
|
+
|
9
14
|
attr_accessor :blank_payload
|
10
15
|
attr_accessor :signature
|
11
16
|
|
@@ -132,3 +137,5 @@ require 'json/jwe'
|
|
132
137
|
require 'json/jwk'
|
133
138
|
require 'json/jwk/jwkizable'
|
134
139
|
require 'json/jwk/set'
|
140
|
+
require 'json/jwk/set/fetcher'
|
141
|
+
require 'json/jwk/set/fetcher/debugger/request_filter'
|
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.
|
4
|
+
version: 1.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nov matake
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httpclient
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: rspec
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,10 +140,13 @@ description: JSON Web Token and its family (JSON Web Signature, JSON Web Encrypt
|
|
112
140
|
and JSON Web Key) in Ruby
|
113
141
|
email:
|
114
142
|
- nov@matake.jp
|
115
|
-
executables:
|
143
|
+
executables:
|
144
|
+
- console
|
116
145
|
extensions: []
|
117
146
|
extra_rdoc_files: []
|
118
147
|
files:
|
148
|
+
- ".github/FUNDING.yml"
|
149
|
+
- ".github/workflows/test_ruby.yml"
|
119
150
|
- ".gitignore"
|
120
151
|
- ".gitmodules"
|
121
152
|
- ".rspec"
|
@@ -125,12 +156,15 @@ files:
|
|
125
156
|
- README.md
|
126
157
|
- Rakefile
|
127
158
|
- VERSION
|
159
|
+
- bin/console
|
128
160
|
- json-jwt.gemspec
|
129
161
|
- lib/json/jose.rb
|
130
162
|
- lib/json/jwe.rb
|
131
163
|
- lib/json/jwk.rb
|
132
164
|
- lib/json/jwk/jwkizable.rb
|
133
165
|
- lib/json/jwk/set.rb
|
166
|
+
- lib/json/jwk/set/fetcher.rb
|
167
|
+
- lib/json/jwk/set/fetcher/debugger/request_filter.rb
|
134
168
|
- lib/json/jws.rb
|
135
169
|
- lib/json/jwt.rb
|
136
170
|
homepage: https://github.com/nov/json-jwt
|
@@ -152,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
186
|
- !ruby/object:Gem::Version
|
153
187
|
version: '0'
|
154
188
|
requirements: []
|
155
|
-
rubygems_version: 3.
|
189
|
+
rubygems_version: 3.1.6
|
156
190
|
signing_key:
|
157
191
|
specification_version: 4
|
158
192
|
summary: JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and
|