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

ArgumentError in `verify': wrong number of arguments (given 3, expected 1) #435

Open
yazinsai opened this issue Jul 26, 2021 · 4 comments
Open

Comments

@yazinsai
Copy link

yazinsai commented Jul 26, 2021

I'm using the sample code shown in the README for RS256:

rsa_private = OpenSSL::PKey::RSA.generate 2048
rsa_public = rsa_private.public_key

token = JWT.encode payload, rsa_private, 'RS256'

decoded_token = JWT.decode token, rsa_public, true, { algorithm: 'RS256' }

Instead of getting a decoded_token hash, I get this error message:

Traceback (most recent call last):
    8: from main.rb:25:in `<main>'
    7: from main.rb:7:in `verify'
    6: from /home/runner/BasicAfraidSolidstatedrive/.bundle/ruby/2.5.0/gems/jwt-2.2.3/lib/jwt.rb:28:in `decode'
    5: from /home/runner/BasicAfraidSolidstatedrive/.bundle/ruby/2.5.0/gems/jwt-2.2.3/lib/jwt/decode.rb:26:in `decode_segments'
    4: from /home/runner/BasicAfraidSolidstatedrive/.bundle/ruby/2.5.0/gems/jwt-2.2.3/lib/jwt/decode.rb:42:in `verify_signature'
    3: from /home/runner/BasicAfraidSolidstatedrive/.bundle/ruby/2.5.0/gems/jwt-2.2.3/lib/jwt/signature.rb:31:in `verify'
    2: from /home/runner/BasicAfraidSolidstatedrive/.bundle/ruby/2.5.0/gems/jwt-2.2.3/lib/jwt/algos/rsa.rb:15:in `verify'
    1: from /home/runner/BasicAfraidSolidstatedrive/.bundle/ruby/2.5.0/gems/jwt-2.2.3/lib/jwt/security_utils.rb:20:in `verify_rsa'
/home/runner/BasicAfraidSolidstatedrive/.bundle/ruby/2.5.0/gems/jwt-2.2.3/lib/jwt/security_utils.rb:20:in `verify': wrong number of arguments (given 3, expected 1) (ArgumentError)
exit status 1

This seems to be because OpenSSL::X509::Certificate.verify expects a single argument but is receiving 3:

# jwt-2.2.3/lib/jwt/security_utils.rb:20
def verify_rsa(algorithm, public_key, signing_input, signature)
  public_key.verify(OpenSSL::Digest.new(algorithm.sub('RS', 'sha')), signature, signing_input) # 👈  3 arguments passed
end
@thomasdarde
Copy link

Any update on this ? Seeing the same issue (with ruby 3)

@yazinsai
Copy link
Author

yazinsai commented Aug 5, 2021

None, still waiting for feedback on this.

@thomasdarde
Copy link

Thanks for the feedback.
I did try this code and it seems to work with latest jwt version without issue 2.2.3. (FYI my payload was : payload= {a: "b"})

But I did get a very similar issue trying to decode an azure jwt token.

public_key was of type OpenSSL::X509::Certificate instead of OpenSSL::PKey::RSA on a OpenSSL::X509::Certificate instance you can call public_key and get a OpenSSL::PKey::RSA (but now I receive an invalid signature message from jwt...)

@anakinj
Copy link
Member

anakinj commented Aug 18, 2021

For sure if a OpenSSL::X509::Certificate object is given as the public_key there will be some errors. Apparently the OpenSSL::X509::Certificate#verify method is to verify the signature of the certificate.

Then why the verification is failing if the certificates public key is given is pretty hard to figure out without more info or some example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants