Zaubrik / djwt

Create and verify JSON Web Tokens (JWT) with Deno or the browser.
MIT License
228 stars 23 forks source link

Add RS512, PS256, and PS512 support #41

Closed invisal closed 3 years ago

invisal commented 3 years ago

With new release of god_crypto v1.4.7, you can now add support for the following algorithms: RS512, PS256, and PS512.

RS512

await rsa.sign(message, { algorithm: "rsassa-pkcs1-v1_5", hash: "sha512" })
await rsa.verify(signature, message,  { algorithm: "rsassa-pkcs1-v1_5", hash: "sha512" });

PS256

await rsa.sign(message, { algorithm: "rsassa-pss", hash: "sha256" });
await rsa.verify(signature, message, { algorithm: "rsassa-pss", hash: "sha256" });

PS512

await rsa.sign(message, { algorithm: "rsassa-pss", hash: "sha512" });
await rsa.verify(signature, message, { algorithm: "rsassa-pss", hash: "sha512" });
timonson commented 3 years ago

Hi @invisal thank you for this update!

Unfortunately, the tests for the new algorithms fail. If you don't mind please take a look at this new branch https://github.com/timonson/djwt/tree/alg-patch1 and run deno test -A.

I got the JWTs for comparison from https://jwt.io/.

An additional test for PS512 is missing but the tests for RS512 and PS256 fail because the signatures don't match.

invisal commented 3 years ago

Thank. I have checked the problems and I found the problem in my implementation:

The test method for testing PS256 in your code is also wrong. PS256 and PS512 include random salt. That's mean that it always produce different signature for same message.

I will patch the fix this week and I will update back to you on this issue.

itohatweb commented 3 years ago

Maybe add support for ed25519 too?

invisal commented 3 years ago

I have updated the fix in 1.4.8. However, it still fail the PS256 test case because PS256 is random algorithm. It always reproduce different signature every time you sign same message.

@itohatweb elliptic curve algorithm is also in my roadmap. But I need to do more reading to implement it.

timonson commented 3 years ago

The tests pass now.

I would love to get a code review before I merge these changes: https://github.com/timonson/djwt/pull/44