#jwt #oidc #open-id #jws #connect #applications

compact_jwt

Minimal implementation of JWT for OIDC and other applications

26 releases

new 0.4.0-dev Apr 11, 2024
0.3.5 Mar 12, 2024
0.3.4 Feb 14, 2024
0.3.3 Nov 30, 2023
0.1.7 Nov 13, 2021

#123 in Authentication

Download history 2020/week @ 2023-12-23 5261/week @ 2023-12-30 6073/week @ 2024-01-06 5548/week @ 2024-01-13 10120/week @ 2024-01-20 7769/week @ 2024-01-27 9036/week @ 2024-02-03 11779/week @ 2024-02-10 4718/week @ 2024-02-17 12694/week @ 2024-02-24 6183/week @ 2024-03-02 9699/week @ 2024-03-09 8784/week @ 2024-03-16 12122/week @ 2024-03-23 16046/week @ 2024-03-30 4627/week @ 2024-04-06

43,697 downloads per month
Used in 7 crates (4 directly)

MPL-2.0 license

225KB
4.5K SLoC

Compact JWT / JWE

Json Web Tokens (JWT) are a popular method for creating signed transparent tokens that can be verified by clients and servers. They are enshrined in standards like OpenID Connect which causes them to be a widespread and required component of many modern web authentication system.

Json Web Encryption (JWE) is an occasionally used method for sending secrets to a recipient or to create opaque tokens for services.

JWE, JWT, and Json Web Signature (JWS) however have a long track record of handling issues, which have led to security issues. This library will not be a complete implementation of JWE/JWT/JWS, instead focusing on a minimal subset that can be secured and audited for correctness more closely within a limited set of use cases.

When should I use this library?

If you are:

  • creating ECDSA signed JWT tokens, or verify ECDSA signed JWT tokens
  • implementing OIDC as a relying party or authorisation server
  • wanting to use HMAC signatures for transparent json data
  • needing a minimal secure JWS implementation
  • using TPM bound keys for signing JWTs
  • creating opaque encrypted tokens protected with AES-128-GCM
  • receiving or sending encrypted data to an ECDSA key

Then this library is for you

If you need non-compact JWS, or other complex use cases, this library is not for you.

Why another JWT library?

There are already many other libraries for JWT on crates.io however they each have a limitation or design that conflicts with the project goals in Kanidm. Examples are:

  • Incorrect Implementations - There are a number of JWT libraries in Rust that are incorrect to the RFC or do not have RFC vector tests
  • Ring as the sole cryptographic provider - we need to use OpenSSL
  • Only supporting RSA/Weak cryptographic algos - We want to use ECDSA
  • Full JWS implementation - As mentioned, JWS has a number of sharp edges like alg=none
  • No library supports pkcs11 or TPMS - We aim to allow hardware security modules to store private keys

As a result, nothing "fit" what we wanted, so we are making another library.

Dependencies

~4.5–6MB
~151K SLoC