Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JWK does not decode. #332

Closed
rabajaj0509 opened this issue Sep 13, 2019 · 2 comments
Closed

JWK does not decode. #332

rabajaj0509 opened this issue Sep 13, 2019 · 2 comments
Assignees
Milestone

Comments

@rabajaj0509
Copy link
Contributor

rabajaj0509 commented Sep 13, 2019

while using the ruby version 2.3.5, I get this error:

2.3.5 :010 > JWT.decode(token, nil, true, { algorithms: ['RS512'], jwks: jwk_loader})
NoMethodError: undefined method `set_key' for #<OpenSSL::PKey::RSA:0x0000000001e2c9e8>
	from /home/vagrant/.rvm/gems/ruby-2.3.5/gems/jwt-2.2.1/lib/jwt/jwk/rsa.rb:40:in `import'
	from /home/vagrant/.rvm/gems/ruby-2.3.5/gems/jwt-2.2.1/lib/jwt/jwk.rb:19:in `import'
	from /home/vagrant/.rvm/gems/ruby-2.3.5/gems/jwt-2.2.1/lib/jwt/jwk/key_finder.rb:19:in `key_for'
	from /home/vagrant/.rvm/gems/ruby-2.3.5/gems/jwt-2.2.1/lib/jwt/decode.rb:37:in `verify_signature'
	from /home/vagrant/.rvm/gems/ruby-2.3.5/gems/jwt-2.2.1/lib/jwt/decode.rb:26:in `decode_segments'
	from /home/vagrant/.rvm/gems/ruby-2.3.5/gems/jwt-2.2.1/lib/jwt.rb:28:in `decode'
	from (irb):10
	from /home/vagrant/.rvm/rubies/ruby-2.3.5/bin/irb:11:in `<main>'

Can anyone please help me out with this? or can suggest me with a workaround?

@rabajaj0509
Copy link
Contributor Author

rabajaj0509 commented Sep 13, 2019

Can we add an implementation to our gem similar to this one? https://github.com/tootsuite/ostatus2/pull/3/files

@rabajaj0509
Copy link
Contributor Author

rabajaj0509 commented Sep 13, 2019

@excpt can we do something like this:

imported_key = OpenSSL::PKey::RSA.new  
if "#{RUBY_VERSION}".to_f < 2.4.0
  def set_key(key, modulus, exponent)
    key.n = OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:n]), BINARY)
    key.e = OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:e]), BINARY)
  end
else
  def set_key(key, modulus, exponent)
    imported_key.set_key(OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:n]), BINARY),
      OpenSSL::BN.new(::Base64.urlsafe_decode64(jwk_data[:e]), BINARY),
    nil)
  end
end

@excpt excpt self-assigned this Sep 16, 2019
@excpt excpt added the WIP label Sep 16, 2019
@excpt excpt closed this as completed Sep 18, 2019
@excpt excpt added this to the Version 2.2.2 milestone Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants