โ— Shell
clean mode source โ†—

GitHub - benmcollins/libjwt: The C JSON Web Token Library +JWK +JWKS

LibJWT - The C JWT Library

codecov

maClara

๐Ÿ’ก Supported Standards

Standard RFC Description
JWS ๐Ÿ“„ RFC-7515 JSON Web Signature
JWE ๐Ÿ“„ RFC-7516 JSON Web Encryption
JWK ๐Ÿ“„ RFC-7517 JSON Web Keys and Sets
JWA ๐Ÿ“„ RFC-7518 JSON Web Algorithms
JWT ๐Ÿ“„ RFC-7519 JSON Web Token

Note

Throughout this documentation you will see links such as the ones above to RFC documents. These are relevant to that particular part of the library and are helpful to understand some of the specific standards that shaped the development of LibJWT.

๐Ÿšง Build Prerequisites

Required

  • A JSON library: either Jansson (>= 2.0, the default) or json-c (>= 0.16, selected with -DWITH_JSON_C=ON). The two are interchangeable.
  • CMake (>= 3.7)

Crypto support

  • OpenSSL (>= 3.0.0)
  • GnuTLS (>= 3.8.8)
  • MbedTLS (>= 3.6.0)

Note

At least one crypto backend is required, but any non-empty combination works. OpenSSL is enabled by default and can be disabled with -DWITH_OPENSSL=OFF. Each backend parses and converts JWK(S) natively.

Algorithm support matrix

JWS Algorithm alg OpenSSL GnuTLS MbedTLS
HS256 HS384 HS512 โœ… โœ… โœ…
ES256 ES384 ES512 โœ… โœ… โœ…
RS256 RS384 RS512 โœ… โœ… โœ…
EdDSA using ED25519 โœ… โœ… โŒ
EdDSA using ED448 โœ… โœ… โŒ
PS256 PS384 PS512 โœ… โœ… โœ…
ES256K โœ… โŒ โœ…

JWE

LibJWT supports JWE (RFC 7516) in both the Compact Serialization and the JSON Serialization (the Flattened form and the General form with one or more recipients). A JWE uses two algorithms: a key management algorithm (alg) and a content encryption algorithm (enc).

JWE serialization Recipients Supported
Compact (RFC 7516 ยง7.1) one โœ…
JSON Flattened (RFC 7516 ยง7.2.2) one โœ…
JSON General (RFC 7516 ยง7.2.1) one or more โœ…

With the JSON serializations the plaintext is encrypted once with a single CEK; each recipient wraps that CEK independently, so any recipient's key can decrypt the token. They also carry an optional shared unprotected header, per-recipient headers, and an application AAD member.

Legend: โœ… native implementation  ยท  โŒ not supported

JWE key management alg OpenSSL GnuTLS MbedTLS
dir (Direct Encryption) โœ… โœ… โœ…
A128KW A192KW A256KW โœ… โœ… โœ…
RSA-OAEP (SHA-1) โœ… โŒ โœ…
RSA-OAEP-256 โœ… โœ… โœ…
ECDH-ES (+ +A128KW/+A192KW/+A256KW) โœ… โœ… โœ…
JWE content encryption enc OpenSSL GnuTLS MbedTLS
A128GCM A192GCM A256GCM โœ… โœ… โœ…
A128CBC-HS256 A192CBC-HS384 A256CBC-HS512 โœ… โœ… โœ…

Note

ECDH-ES supports both Direct Key Agreement and the +A*KW key wrapping modes, on the EC curves P-256/384/521 and the OKP curves X25519/X448, with optional apu/apv PartyInfo. RSA1_5 and zip (compression) are intentionally not supported. Each backend implements JWE natively. GnuTLS/Nettle cannot perform RSA-OAEP with SHA-1, so the GnuTLS backend does not support plain RSA-OAEP (RSA-OAEP-256 is native).

Optional

๐Ÿ“š Docs and Source

๐Ÿ”— Current Docs

๐Ÿ”— Legacy Docs v2.1.1

๐Ÿ”— GitHub Repo

๐Ÿ“ฆ Pre-built Packages

LibJWT is available in most Linux distributions as well as through Homebrew for Linux, macOS, and Windows.

๐Ÿ”จ Build Instructions

With CMake:

$ mkdir build
$ cd build
$ cmake ..
$ make