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

HS512 signature verification fails for valid tokens #438

Closed
gh-spadwal opened this issue Aug 6, 2021 · 3 comments
Closed

HS512 signature verification fails for valid tokens #438

gh-spadwal opened this issue Aug 6, 2021 · 3 comments

Comments

@gh-spadwal
Copy link

gh-spadwal commented Aug 6, 2021

ruby-jwt fails with a Signature verification failed (JWT::VerificationError) error when decoding a valid JWT signed with HS512.


hmac_secret = '6Pw9eSE@8XTNX]1=_kEYU~KvGz9mB*A|M=%AgsfuUH}#ZItuJ#@U#8hq}@E%dy$ljEMVvEF5G$mEcOV^+vS]F]BUvy(1_2@VtwSvpkuc73idA[{XiUY}PjZdUUl4$)W2T2uAgS$#0RJi^zw{J6feK[kP*NrW|CdBqYwrcD#F%Em~hZmQF*720Y59_tOB[daSeN-23[zO_Bcb]{GY1nN%JE)fh3ZF4N|2(J]LuSVvo=Dovu}qvrs5{8GPl]C[DVjV]Vkr4mshGqdGtIxVjtHN2^#OazRF)Q2PyBKg)nWRwFWrMni[~ue}p42MzGTL0zeNjqdqZjPSJLKSV{U$h@czZ|urEgY3=3~b2iy+RGBe3i%Jhlj+3NLQXN+aL{xy(@pP02n9j1pOGxiSV=hHBPV@Xw#}(]zc}#3=U[Fd7GTuU[k3AA4+Tii-(uIYSQfAcwG70wM[cFDwZe{I7I[245GkXJMnC6v4rdjC}16SB7^y[I$zrLWJbLr8NnNevv%$vUk)kkLNrr{H4)Noxo|yG@Qra[KtfO7qmA+v0LG)pd64XtkC8WlNDPQ]IQY7*x2wn|%k)}XbfYN}11IJFL(I0lTc9p}iHc}-%Zmk7c@%yC{gIy%R_CnSx@bj(tDwwFVi%|WsyO{^$uGzq]NFk[a]b|S#t[ua(zx99iq[b}rb9n*kv12d^1LTGeX8K1NcE+0tpo}GEYp5*pIaB*(}n|wI]*#*ov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c291cmNlRW5kcG9pbnQiOiIvYXBpL3YxL3VzZXJyb2xlcyJ9LHsidXVpZCI6IjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAyYiIsInJlc291cmNlSHR0cE1ldGhvZCI6IlBPU1QiLCJyZXNvdXJjZUVuZHBvaW50IjoiL2FwaS92MS91c2Vycy97dXVpZH0vcm9sZXMifSx7InV1aWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMGUiLCJyZXNvdXJjZUh0dHBNZXRob2QiOiJHRVQiLCJyZXNvdXJjZUVuZHBvaW50IjoiL2FwaS92MS9vcmdhbml6YXRpb25zIn1dfV0sInRlbmFudFV1aWQiOm51bGwsInRlbmFudENvdW50cnkiOm51bGwsIm9yZ1V1aWQiOm51bGx9fQ.-1Bvmzg8xce_Poihu_IoZ_Isljrs0FVk_7vdVgGLBHH4bHkigVf1wj6HyEfaeXBTMKK3JG6prarwTN4IlE-l5A'

decoded_token = JWT.decode token, hmac_secret, true, { algorithm: 'HS512' }

Exception Stacktrace:

  /home/sarvesh/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jwt-2.2.1/lib/jwt/signature.rb:45:in `verify'
  /home/sarvesh/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jwt-2.2.1/lib/jwt/decode.rb:42:in `verify_signature'
  /home/sarvesh/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jwt-2.2.1/lib/jwt/decode.rb:26:in `decode_segments'
  /home/sarvesh/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/jwt-2.2.1/lib/jwt.rb:28:in `decode'

Provided token is valid token. This token can be also verified at https://jwt.io/

@anakinj
Copy link
Member

anakinj commented Aug 18, 2021

Hi,

Was trying to reproduce the problem and I am getting the same result using that snippet. But I wonder if the given secret actually is correct?

According to https://jwt.io the signature when using that secret is
suWFqcqo-BpYJpX9vbkcptvc_yPBF5Q8Aztp0V5ag4tjZtq6OgzsFLFxjfOC7UVoiACZOJdczQO7AWkwGgSLUQ

This does not match with the provided token in the example:
-1Bvmzg8xce_Poihu_IoZ_Isljrs0FVk_7vdVgGLBHH4bHkigVf1wj6HyEfaeXBTMKK3JG6prarwTN4IlE-l5A

@lilisako
Copy link

lilisako commented Dec 27, 2021

As anakinj said the secret does not match to the result from https://jwt.io/. Here is the copy-pastable example.

require 'jwt'

hmac_secret = '6Pw9eSE@8XTNX]1=_kEYU~KvGz9mB*A|M=%AgsfuUH}#ZItuJ#@U#8hq}@E%dy$ljEMVvEF5G$mEcOV^+vS]F]BUvy(1_2@VtwSvpkuc73idA[{XiUY}PjZdUUl4$)W2T2uAgS$#0RJi^zw{J6feK[kP*NrW|CdBqYwrcD#F%Em~hZmQF*720Y59_tOB[daSeN-23[zO_Bcb]{GY1nN%JE)fh3ZF4N|2(J]LuSVvo=Dovu}qvrs5{8GPl]C[DVjV]Vkr4mshGqdGtIxVjtHN2^#OazRF)Q2PyBKg)nWRwFWrMni[~ue}p42MzGTL0zeNjqdqZjPSJLKSV{U$h@czZ|urEgY3=3~b2iy+RGBe3i%Jhlj+3NLQXN+aL{xy(@pP02n9j1pOGxiSV=hHBPV@Xw#}(]zc}#3=U[Fd7GTuU[k3AA4+Tii-(uIYSQfAcwG70wM[cFDwZe{I7I[245GkXJMnC6v4rdjC}16SB7^y[I$zrLWJbLr8NnNevv%$vUk)kkLNrr{H4)Noxo|yG@Qra[KtfO7qmA+v0LG)pd64XtkC8WlNDPQ]IQY7*x2wn|%k)}XbfYN}11IJFL(I0lTc9p}iHc}-%Zmk7c@%yC{gIy%R_CnSx@bj(tDwwFVi%|WsyO{^$uGzq]NFk[a]b|S#t[ua(zx99iq[b}rb9n*kv12d^1LTGeX8K1NcE+0tpo}GEYp5*pIaB*(}n|wI]*#*ovKRiR6]#ggaqlYPNo+p=4MLv^%^rFXF*]4JNF*negapf_pb_D3LD9Eo}*sY~)lRQWkjEP()0b3cHR44jlmzDgqlz8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0wMDAwLTAwMDAwMDAwMDAyYiIsInJlc291cmNlSHR0cE1ldGhvZCI6IlBPU1QiLCJyZXNvdXJjZUVuZHBvaW50IjoiL2FwaS92MS91c2Vycy97dXVpZH0vcm9sZXMifSx7InV1aWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMGUiLCJyZXNvdXJjZUh0dHBNZXRob2QiOiJHRVQiLCJyZXNvdXJjZUVuZHBvaW50IjoiL2FwaS92MS9vcmdhbml6YXRpb25zIn1dfV0sInRlbmFudFV1aWQiOm51bGwsInRlbmFudENvdW50cnkiOm51bGwsIm9yZ1V1aWQiOm51bGx9fQ.suWFqcqo-BpYJpX9vbkcptvc_yPBF5Q8Aztp0V5ag4tjZtq6OgzsFLFxjfOC7UVoiACZOJdczQO7AWkwGgSLUQ'

decoded_token = JWT.decode token, hmac_secret, true, { algorithm: 'HS512' }
puts decoded_token
#=> Signature has expired (JWT::ExpiredSignature) 
# This is expected because the expiration is Aug 07 2021

@anakinj
Copy link
Member

anakinj commented Dec 27, 2021

Im going to close this issue. Don't hesitate to comment and we'll re-open if this still needs some attention.

@anakinj anakinj closed this as completed Dec 27, 2021
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