GitHub - benmcollins/libjwt: The C JSON Web Token Library +JWK +JWKS
๐ก 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
- Check Library (>= 0.9.10) for unit testing
- Doxygen (>= 1.13.0) for documentation
๐ 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
