auth0 / docs

Auth0 documentation
MIT License
369 stars 1.61k forks source link

Incorrect description of signature validation in case of RSA256 encryption. #8731

Closed vit100 closed 4 years ago

vit100 commented 4 years ago

Description

Description of signature validation in case of RSA256 encryption is not correct - Validate JSON Web Tokens

Remember that the Signature is created using the Header and Payload segments, a signing algorithm, and a secret or public key (depending on the chosen signing algorithm).

Signature in RSA256 created from message hash by using private key.

To verify that the signature is correct, you need to generate a new Base64url-encoded signature using the public key (RS256) or secret (HS256) and verify that it matches the original Signature included with the JWT:

Take the original Base64url-encoded Header and original Base64url-encoded Payload segments (Base64url-encoded Header + "." + Base64url-encoded Payload), and hash them with SHA-256. Encrypt using either HMAC or RSA (depending on your selected signing algorithm) and the appropriate key.

In case of RSA following steps performed.

  1. Calculate current Hash Value. In the first step, a hash-value of the signed message is calculated. For this calculation, the same hashing algorithm is used as was used during the signing process. The obtained hash-value is called the current hash-value because it is calculated from the current state of the message.

  2. Calculate the Original Hash-Value. In the second step of the digital signature verification process, the digital signature is decrypted with the same encryption algorithm that was used during the signing process. The decryption is done by the public key that corresponds to the private key used during the signing of the message. As a result, we obtain the original hash-value that was calculated from the original message during the first step of the signing process (the original message digests).

  3. Compare the Current and the Original Hash-Values. In the third step, we compare the current hash-value obtained in the first step with the original hash-value obtained in the second step. If the two values are identical, the verification if successful and proves that the message has been signed with the private key that corresponds to the public key used in the verification process. If the two values differ from onr another, this means that the digital signature is invalid and the verification is unsuccessful.

tamigoodall commented 4 years ago

Updated - thanks for the great information.