jwt 2.2.1 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS +79 -44
  3. data/CHANGELOG.md +305 -20
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/CONTRIBUTING.md +99 -0
  6. data/README.md +268 -40
  7. data/lib/jwt/base64.rb +16 -2
  8. data/lib/jwt/claims_validator.rb +13 -9
  9. data/lib/jwt/configuration/container.rb +32 -0
  10. data/lib/jwt/configuration/decode_configuration.rb +46 -0
  11. data/lib/jwt/configuration/jwk_configuration.rb +27 -0
  12. data/lib/jwt/configuration.rb +15 -0
  13. data/lib/jwt/decode.rb +80 -18
  14. data/lib/jwt/deprecations.rb +29 -0
  15. data/lib/jwt/encode.rb +24 -19
  16. data/lib/jwt/error.rb +17 -14
  17. data/lib/jwt/jwa/ecdsa.rb +76 -0
  18. data/lib/jwt/jwa/eddsa.rb +42 -0
  19. data/lib/jwt/jwa/hmac.rb +75 -0
  20. data/lib/jwt/jwa/hmac_rbnacl.rb +50 -0
  21. data/lib/jwt/jwa/hmac_rbnacl_fixed.rb +46 -0
  22. data/lib/jwt/jwa/none.rb +19 -0
  23. data/lib/jwt/jwa/ps.rb +30 -0
  24. data/lib/jwt/jwa/rsa.rb +25 -0
  25. data/lib/jwt/{algos → jwa}/unsupported.rb +8 -5
  26. data/lib/jwt/jwa/wrapper.rb +26 -0
  27. data/lib/jwt/jwa.rb +62 -0
  28. data/lib/jwt/jwk/ec.rb +251 -0
  29. data/lib/jwt/jwk/hmac.rb +103 -0
  30. data/lib/jwt/jwk/key_base.rb +57 -0
  31. data/lib/jwt/jwk/key_finder.rb +19 -30
  32. data/lib/jwt/jwk/kid_as_key_digest.rb +15 -0
  33. data/lib/jwt/jwk/okp_rbnacl.rb +110 -0
  34. data/lib/jwt/jwk/rsa.rb +181 -25
  35. data/lib/jwt/jwk/set.rb +80 -0
  36. data/lib/jwt/jwk/thumbprint.rb +26 -0
  37. data/lib/jwt/jwk.rb +39 -15
  38. data/lib/jwt/verify.rb +25 -6
  39. data/lib/jwt/version.rb +24 -3
  40. data/lib/jwt/x5c_key_finder.rb +52 -0
  41. data/lib/jwt.rb +6 -4
  42. data/ruby-jwt.gemspec +18 -10
  43. metadata +45 -76
  44. data/.codeclimate.yml +0 -20
  45. data/.ebert.yml +0 -18
  46. data/.gitignore +0 -11
  47. data/.rspec +0 -1
  48. data/.rubocop.yml +0 -98
  49. data/.travis.yml +0 -20
  50. data/Appraisals +0 -14
  51. data/Gemfile +0 -3
  52. data/Rakefile +0 -11
  53. data/lib/jwt/algos/ecdsa.rb +0 -35
  54. data/lib/jwt/algos/eddsa.rb +0 -23
  55. data/lib/jwt/algos/hmac.rb +0 -33
  56. data/lib/jwt/algos/ps.rb +0 -43
  57. data/lib/jwt/algos/rsa.rb +0 -19
  58. data/lib/jwt/default_options.rb +0 -15
  59. data/lib/jwt/security_utils.rb +0 -57
  60. data/lib/jwt/signature.rb +0 -52
data/lib/jwt/version.rb CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  # Moments version builder module
@@ -12,13 +11,35 @@ module JWT
12
11
  # major version
13
12
  MAJOR = 2
14
13
  # minor version
15
- MINOR = 2
14
+ MINOR = 8
16
15
  # tiny version
17
16
  TINY = 1
18
17
  # alpha, beta, etc. tag
19
18
  PRE = nil
20
19
 
21
20
  # Build version string
22
- STRING = [[MAJOR, MINOR, TINY].compact.join('.'), PRE].compact.join('-')
21
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
22
+ end
23
+
24
+ def self.openssl_3?
25
+ return false if OpenSSL::OPENSSL_VERSION.include?('LibreSSL')
26
+
27
+ true if 3 * 0x10000000 <= OpenSSL::OPENSSL_VERSION_NUMBER
28
+ end
29
+
30
+ def self.rbnacl?
31
+ defined?(::RbNaCl)
32
+ end
33
+
34
+ def self.rbnacl_6_or_greater?
35
+ rbnacl? && ::Gem::Version.new(::RbNaCl::VERSION) >= ::Gem::Version.new('6.0.0')
36
+ end
37
+
38
+ def self.openssl_3_hmac_empty_key_regression?
39
+ openssl_3? && openssl_version <= ::Gem::Version.new('3.0.0')
40
+ end
41
+
42
+ def self.openssl_version
43
+ @openssl_version ||= ::Gem::Version.new(OpenSSL::VERSION)
23
44
  end
24
45
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JWT
4
+ # If the x5c header certificate chain can be validated by trusted root
5
+ # certificates, and none of the certificates are revoked, returns the public
6
+ # key from the first certificate.
7
+ # See https://tools.ietf.org/html/rfc7515#section-4.1.6
8
+ class X5cKeyFinder
9
+ def initialize(root_certificates, crls = nil)
10
+ raise(ArgumentError, 'Root certificates must be specified') unless root_certificates
11
+
12
+ @store = build_store(root_certificates, crls)
13
+ end
14
+
15
+ def from(x5c_header_or_certificates)
16
+ signing_certificate, *certificate_chain = parse_certificates(x5c_header_or_certificates)
17
+ store_context = OpenSSL::X509::StoreContext.new(@store, signing_certificate, certificate_chain)
18
+
19
+ if store_context.verify
20
+ signing_certificate.public_key
21
+ else
22
+ error = "Certificate verification failed: #{store_context.error_string}."
23
+ if (current_cert = store_context.current_cert)
24
+ error = "#{error} Certificate subject: #{current_cert.subject}."
25
+ end
26
+
27
+ raise(JWT::VerificationError, error)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def build_store(root_certificates, crls)
34
+ store = OpenSSL::X509::Store.new
35
+ store.purpose = OpenSSL::X509::PURPOSE_ANY
36
+ store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK | OpenSSL::X509::V_FLAG_CRL_CHECK_ALL
37
+ root_certificates.each { |certificate| store.add_cert(certificate) }
38
+ crls&.each { |crl| store.add_crl(crl) }
39
+ store
40
+ end
41
+
42
+ def parse_certificates(x5c_header_or_certificates)
43
+ if x5c_header_or_certificates.all? { |obj| obj.is_a?(OpenSSL::X509::Certificate) }
44
+ x5c_header_or_certificates
45
+ else
46
+ x5c_header_or_certificates.map do |encoded|
47
+ OpenSSL::X509::Certificate.new(::JWT::Base64.url_decode(encoded))
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
data/lib/jwt.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'jwt/version'
3
4
  require 'jwt/base64'
4
5
  require 'jwt/json'
5
6
  require 'jwt/decode'
6
- require 'jwt/default_options'
7
+ require 'jwt/configuration'
8
+ require 'jwt/deprecations'
7
9
  require 'jwt/encode'
8
10
  require 'jwt/error'
9
11
  require 'jwt/jwk'
@@ -13,7 +15,7 @@ require 'jwt/jwk'
13
15
  # Should be up to date with the latest spec:
14
16
  # https://tools.ietf.org/html/rfc7519
15
17
  module JWT
16
- include JWT::DefaultOptions
18
+ extend ::JWT::Configuration
17
19
 
18
20
  module_function
19
21
 
@@ -24,7 +26,7 @@ module JWT
24
26
  headers: header_fields).segments
25
27
  end
26
28
 
27
- def decode(jwt, key = nil, verify = true, options = {}, &keyfinder)
28
- Decode.new(jwt, key, verify, DEFAULT_OPTIONS.merge(options), &keyfinder).decode_segments
29
+ def decode(jwt, key = nil, verify = true, options = {}, &keyfinder) # rubocop:disable Style/OptionalBooleanParameter
30
+ Decode.new(jwt, key, verify, configuration.decode.to_h.merge(options), &keyfinder).decode_segments
29
31
  end
30
32
  end
data/ruby-jwt.gemspec CHANGED
@@ -1,4 +1,6 @@
1
- lib = File.expand_path('../lib/', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'jwt/version'
4
6
 
@@ -13,22 +15,28 @@ Gem::Specification.new do |spec|
13
15
  spec.description = 'A pure ruby implementation of the RFC 7519 OAuth JSON Web Token (JWT) standard.'
14
16
  spec.homepage = 'https://github.com/jwt/ruby-jwt'
15
17
  spec.license = 'MIT'
16
- spec.required_ruby_version = '>= 2.1'
18
+ spec.required_ruby_version = '>= 2.5'
19
+ spec.metadata = {
20
+ 'bug_tracker_uri' => 'https://github.com/jwt/ruby-jwt/issues',
21
+ 'changelog_uri' => "https://github.com/jwt/ruby-jwt/blob/v#{JWT.gem_version}/CHANGELOG.md",
22
+ 'rubygems_mfa_required' => 'true'
23
+ }
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(spec|gemfiles|coverage|bin)/}) || # Irrelevant folders
27
+ f.match(/^\.+/) || # Files and folders starting with .
28
+ f.match(/^(Appraisals|Gemfile|Rakefile)$/) # Irrelevant files
29
+ end
17
30
 
18
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|gemfiles|coverage|bin)/}) }
19
31
  spec.executables = []
20
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
32
  spec.require_paths = %w[lib]
22
33
 
34
+ spec.add_dependency 'base64'
35
+
23
36
  spec.add_development_dependency 'appraisal'
24
37
  spec.add_development_dependency 'bundler'
25
38
  spec.add_development_dependency 'rake'
26
39
  spec.add_development_dependency 'rspec'
40
+ spec.add_development_dependency 'rubocop'
27
41
  spec.add_development_dependency 'simplecov'
28
- spec.add_development_dependency 'simplecov-json'
29
- spec.add_development_dependency 'codeclimate-test-reporter'
30
- spec.add_development_dependency 'codacy-coverage'
31
- spec.add_development_dependency 'rbnacl'
32
- # RSASSA-PSS support provided by OpenSSL +2.1
33
- spec.add_development_dependency 'openssl', '~> 2.1'
34
42
  end
metadata CHANGED
@@ -1,51 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rudat
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-24 00:00:00.000000000 Z
11
+ date: 2024-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: appraisal
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
14
+ name: base64
43
15
  requirement: !ruby/object:Gem::Requirement
44
16
  requirements:
45
17
  - - ">="
46
18
  - !ruby/object:Gem::Version
47
19
  version: '0'
48
- type: :development
20
+ type: :runtime
49
21
  prerelease: false
50
22
  version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
@@ -53,7 +25,7 @@ dependencies:
53
25
  - !ruby/object:Gem::Version
54
26
  version: '0'
55
27
  - !ruby/object:Gem::Dependency
56
- name: rspec
28
+ name: appraisal
57
29
  requirement: !ruby/object:Gem::Requirement
58
30
  requirements:
59
31
  - - ">="
@@ -67,7 +39,7 @@ dependencies:
67
39
  - !ruby/object:Gem::Version
68
40
  version: '0'
69
41
  - !ruby/object:Gem::Dependency
70
- name: simplecov
42
+ name: bundler
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
45
  - - ">="
@@ -81,7 +53,7 @@ dependencies:
81
53
  - !ruby/object:Gem::Version
82
54
  version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
- name: simplecov-json
56
+ name: rake
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - ">="
@@ -95,7 +67,7 @@ dependencies:
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
- name: codeclimate-test-reporter
70
+ name: rspec
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - ">="
@@ -109,7 +81,7 @@ dependencies:
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
83
  - !ruby/object:Gem::Dependency
112
- name: codacy-coverage
84
+ name: rubocop
113
85
  requirement: !ruby/object:Gem::Requirement
114
86
  requirements:
115
87
  - - ">="
@@ -123,7 +95,7 @@ dependencies:
123
95
  - !ruby/object:Gem::Version
124
96
  version: '0'
125
97
  - !ruby/object:Gem::Dependency
126
- name: rbnacl
98
+ name: simplecov
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
101
  - - ">="
@@ -136,20 +108,6 @@ dependencies:
136
108
  - - ">="
137
109
  - !ruby/object:Gem::Version
138
110
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: openssl
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '2.1'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '2.1'
153
111
  description: A pure ruby implementation of the RFC 7519 OAuth JSON Web Token (JWT)
154
112
  standard.
155
113
  email: timrudat@gmail.com
@@ -157,46 +115,57 @@ executables: []
157
115
  extensions: []
158
116
  extra_rdoc_files: []
159
117
  files:
160
- - ".codeclimate.yml"
161
- - ".ebert.yml"
162
- - ".gitignore"
163
- - ".rspec"
164
- - ".rubocop.yml"
165
- - ".travis.yml"
166
118
  - AUTHORS
167
- - Appraisals
168
119
  - CHANGELOG.md
169
- - Gemfile
120
+ - CODE_OF_CONDUCT.md
121
+ - CONTRIBUTING.md
170
122
  - LICENSE
171
123
  - README.md
172
- - Rakefile
173
124
  - lib/jwt.rb
174
- - lib/jwt/algos/ecdsa.rb
175
- - lib/jwt/algos/eddsa.rb
176
- - lib/jwt/algos/hmac.rb
177
- - lib/jwt/algos/ps.rb
178
- - lib/jwt/algos/rsa.rb
179
- - lib/jwt/algos/unsupported.rb
180
125
  - lib/jwt/base64.rb
181
126
  - lib/jwt/claims_validator.rb
127
+ - lib/jwt/configuration.rb
128
+ - lib/jwt/configuration/container.rb
129
+ - lib/jwt/configuration/decode_configuration.rb
130
+ - lib/jwt/configuration/jwk_configuration.rb
182
131
  - lib/jwt/decode.rb
183
- - lib/jwt/default_options.rb
132
+ - lib/jwt/deprecations.rb
184
133
  - lib/jwt/encode.rb
185
134
  - lib/jwt/error.rb
186
135
  - lib/jwt/json.rb
136
+ - lib/jwt/jwa.rb
137
+ - lib/jwt/jwa/ecdsa.rb
138
+ - lib/jwt/jwa/eddsa.rb
139
+ - lib/jwt/jwa/hmac.rb
140
+ - lib/jwt/jwa/hmac_rbnacl.rb
141
+ - lib/jwt/jwa/hmac_rbnacl_fixed.rb
142
+ - lib/jwt/jwa/none.rb
143
+ - lib/jwt/jwa/ps.rb
144
+ - lib/jwt/jwa/rsa.rb
145
+ - lib/jwt/jwa/unsupported.rb
146
+ - lib/jwt/jwa/wrapper.rb
187
147
  - lib/jwt/jwk.rb
148
+ - lib/jwt/jwk/ec.rb
149
+ - lib/jwt/jwk/hmac.rb
150
+ - lib/jwt/jwk/key_base.rb
188
151
  - lib/jwt/jwk/key_finder.rb
152
+ - lib/jwt/jwk/kid_as_key_digest.rb
153
+ - lib/jwt/jwk/okp_rbnacl.rb
189
154
  - lib/jwt/jwk/rsa.rb
190
- - lib/jwt/security_utils.rb
191
- - lib/jwt/signature.rb
155
+ - lib/jwt/jwk/set.rb
156
+ - lib/jwt/jwk/thumbprint.rb
192
157
  - lib/jwt/verify.rb
193
158
  - lib/jwt/version.rb
159
+ - lib/jwt/x5c_key_finder.rb
194
160
  - ruby-jwt.gemspec
195
161
  homepage: https://github.com/jwt/ruby-jwt
196
162
  licenses:
197
163
  - MIT
198
- metadata: {}
199
- post_install_message:
164
+ metadata:
165
+ bug_tracker_uri: https://github.com/jwt/ruby-jwt/issues
166
+ changelog_uri: https://github.com/jwt/ruby-jwt/blob/v2.8.1/CHANGELOG.md
167
+ rubygems_mfa_required: 'true'
168
+ post_install_message:
200
169
  rdoc_options: []
201
170
  require_paths:
202
171
  - lib
@@ -204,15 +173,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
173
  requirements:
205
174
  - - ">="
206
175
  - !ruby/object:Gem::Version
207
- version: '2.1'
176
+ version: '2.5'
208
177
  required_rubygems_version: !ruby/object:Gem::Requirement
209
178
  requirements:
210
179
  - - ">="
211
180
  - !ruby/object:Gem::Version
212
181
  version: '0'
213
182
  requirements: []
214
- rubygems_version: 3.0.3
215
- signing_key:
183
+ rubygems_version: 3.3.7
184
+ signing_key:
216
185
  specification_version: 4
217
186
  summary: JSON Web Token implementation in Ruby
218
187
  test_files: []
data/.codeclimate.yml DELETED
@@ -1,20 +0,0 @@
1
- engines:
2
- rubocop:
3
- enabled: true
4
- golint:
5
- enabled: false
6
- gofmt:
7
- enabled: false
8
- eslint:
9
- enabled: false
10
- csslint:
11
- enabled: false
12
-
13
- ratings:
14
- paths:
15
- - lib/**
16
- - "**.rb"
17
-
18
- exclude_paths:
19
- - spec/**/*
20
- - vendor/**/*
data/.ebert.yml DELETED
@@ -1,18 +0,0 @@
1
- styleguide: excpt/linters
2
- engines:
3
- reek:
4
- enabled: true
5
- fixme:
6
- enabled: true
7
- rubocop:
8
- enabled: true
9
- channel: rubocop-0-49
10
- duplication:
11
- config:
12
- languages:
13
- - ruby
14
- enabled: true
15
- remark-lint:
16
- enabled: true
17
- exclude_paths:
18
- - spec
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- .idea/
2
- jwt.gemspec
3
- pkg
4
- Gemfile.lock
5
- coverage/
6
- .DS_Store
7
- .rbenv-gemsets
8
- .ruby-version
9
- .vscode/
10
- .bundle
11
- *gemfile.lock
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/.rubocop.yml DELETED
@@ -1,98 +0,0 @@
1
- AllCops:
2
- Exclude:
3
- - 'bin/**/*'
4
- - 'db/**/*'
5
- - 'config/**/*'
6
- - 'script/**/*'
7
-
8
- Rails:
9
- Enabled: true
10
-
11
- Style/AlignParameters:
12
- EnforcedStyle: with_fixed_indentation
13
-
14
- Style/CaseIndentation:
15
- EnforcedStyle: end
16
-
17
- Style/AsciiComments:
18
- Enabled: false
19
-
20
- Style/IndentHash:
21
- Enabled: false
22
-
23
- Style/CollectionMethods:
24
- Enabled: true
25
- PreferredMethods:
26
- inject: 'inject'
27
-
28
- Style/Documentation:
29
- Enabled: false
30
-
31
- Style/BlockDelimiters:
32
- Exclude:
33
- - spec/**/*_spec.rb
34
-
35
- Style/BracesAroundHashParameters:
36
- Exclude:
37
- - spec/**/*_spec.rb
38
-
39
- Style/GuardClause:
40
- Enabled: false
41
-
42
- Style/IfUnlessModifier:
43
- Enabled: false
44
-
45
- Style/SpaceInsideHashLiteralBraces:
46
- Enabled: false
47
-
48
- Style/Lambda:
49
- Enabled: false
50
-
51
- Style/RaiseArgs:
52
- Enabled: false
53
-
54
- Style/SignalException:
55
- Enabled: false
56
-
57
- Metrics/AbcSize:
58
- Max: 20
59
-
60
- Metrics/ClassLength:
61
- Max: 100
62
-
63
- Metrics/ModuleLength:
64
- Max: 100
65
-
66
- Metrics/LineLength:
67
- Enabled: false
68
-
69
- Metrics/MethodLength:
70
- Max: 15
71
-
72
- Style/SingleLineBlockParams:
73
- Enabled: false
74
-
75
- Lint/EndAlignment:
76
- EnforcedStyleAlignWith: variable
77
-
78
- Style/FormatString:
79
- Enabled: false
80
-
81
- Style/MultilineMethodCallIndentation:
82
- EnforcedStyle: indented
83
-
84
- Style/MultilineOperationIndentation:
85
- EnforcedStyle: indented
86
-
87
- Style/WordArray:
88
- Enabled: false
89
-
90
- Style/RedundantSelf:
91
- Enabled: false
92
-
93
- Style/AlignHash:
94
- Enabled: true
95
- EnforcedLastArgumentHashStyle: always_ignore
96
-
97
- Style/TrivialAccessors:
98
- AllowPredicates: true
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- sudo: required
2
- cache: bundler
3
- dist: trusty
4
- language: ruby
5
- rvm:
6
- - 2.3
7
- - 2.4
8
- - 2.5
9
- - 2.6
10
- gemfiles:
11
- - gemfiles/standalone.gemfile
12
- - gemfiles/rails_5.0.gemfile
13
- - gemfiles/rails_5.1.gemfile
14
- - gemfiles/rails_5.2.gemfile
15
- script: "bundle exec rspec && bundle exec codeclimate-test-reporter"
16
- before_install:
17
- - sudo add-apt-repository ppa:chris-lea/libsodium -y
18
- - sudo apt-get update -q
19
- - sudo apt-get install libsodium-dev -y
20
- - gem install bundler
data/Appraisals DELETED
@@ -1,14 +0,0 @@
1
- appraise 'standalone' do
2
- end
3
-
4
- appraise 'rails-5.0' do
5
- gem 'rails', '~> 5.0.0'
6
- end
7
-
8
- appraise 'rails-5.1' do
9
- gem 'rails', '~> 5.1.0'
10
- end
11
-
12
- appraise 'rails-5.2' do
13
- gem 'rails', '~> 5.2.0'
14
- end
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'bundler/gem_tasks'
2
-
3
- begin
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:test)
7
-
8
- task default: :test
9
- rescue LoadError
10
- puts 'RSpec rake tasks not available. Please run "bundle install" to install missing dependencies.'
11
- end
@@ -1,35 +0,0 @@
1
- module JWT
2
- module Algos
3
- module Ecdsa
4
- module_function
5
-
6
- SUPPORTED = %w[ES256 ES384 ES512].freeze
7
- NAMED_CURVES = {
8
- 'prime256v1' => 'ES256',
9
- 'secp384r1' => 'ES384',
10
- 'secp521r1' => 'ES512'
11
- }.freeze
12
-
13
- def sign(to_sign)
14
- algorithm, msg, key = to_sign.values
15
- key_algorithm = NAMED_CURVES[key.group.curve_name]
16
- if algorithm != key_algorithm
17
- raise IncorrectAlgorithm, "payload algorithm is #{algorithm} but #{key_algorithm} signing key was provided"
18
- end
19
-
20
- digest = OpenSSL::Digest.new(algorithm.sub('ES', 'sha'))
21
- SecurityUtils.asn1_to_raw(key.dsa_sign_asn1(digest.digest(msg)), key)
22
- end
23
-
24
- def verify(to_verify)
25
- algorithm, public_key, signing_input, signature = to_verify.values
26
- key_algorithm = NAMED_CURVES[public_key.group.curve_name]
27
- if algorithm != key_algorithm
28
- raise IncorrectAlgorithm, "payload algorithm is #{algorithm} but #{key_algorithm} verification key was provided"
29
- end
30
- digest = OpenSSL::Digest.new(algorithm.sub('ES', 'sha'))
31
- public_key.dsa_verify_asn1(digest.digest(signing_input), SecurityUtils.raw_to_asn1(signature, public_key))
32
- end
33
- end
34
- end
35
- end
@@ -1,23 +0,0 @@
1
- module JWT
2
- module Algos
3
- module Eddsa
4
- module_function
5
-
6
- SUPPORTED = %w[ED25519].freeze
7
-
8
- def sign(to_sign)
9
- algorithm, msg, key = to_sign.values
10
- raise EncodeError, "Key given is a #{key.class} but has to be an RbNaCl::Signatures::Ed25519::SigningKey" if key.class != RbNaCl::Signatures::Ed25519::SigningKey
11
- raise IncorrectAlgorithm, "payload algorithm is #{algorithm} but #{key.primitive} signing key was provided" if algorithm.downcase.to_sym != key.primitive
12
- key.sign(msg)
13
- end
14
-
15
- def verify(to_verify)
16
- algorithm, public_key, signing_input, signature = to_verify.values
17
- raise IncorrectAlgorithm, "payload algorithm is #{algorithm} but #{public_key.primitive} verification key was provided" if algorithm.downcase.to_sym != public_key.primitive
18
- raise DecodeError, "key given is a #{public_key.class} but has to be a RbNaCl::Signatures::Ed25519::VerifyKey" if public_key.class != RbNaCl::Signatures::Ed25519::VerifyKey
19
- public_key.verify(signature, signing_input)
20
- end
21
- end
22
- end
23
- end