Repository navigation
LibJWT 3.8.0 is a feature release. A jwt_checker_t now has a maximum token size, 1 MiB by default. After a successful verify, an application can read the token it accepted. jwt_builder_setkey() now has a signer of its own, separate from jwt_builder_add_signature() signers, so the order of the two calls no longer matters. ECDH-ES Direct Key Agreement now works with A192CBC-HS384 and A256CBC-HS512. Keyring verification is faster and leaner. The json-c backend now treats a JSON null member as Jansson does, and both backends reject a non-array "keys". Read the behavior changes below before upgrading.
This release adds API and is ABI-compatible with 3.7.0. An nm diff shows 158 exported symbols, up from 155, with three added and none removed or changed. Per the libtool rules, the SONAME goes 18:5:4 → 19:0:5. The SONAME stays libjwt.so.14 and existing binaries keep working.
⚠️ Behavior changes
- Tokens over 1 MiB are rejected by default (#378).
jwt_checker_verify()andjwt_checker_verify_detached()reject a token longer than 1048576 bytes withToken too large, before they parse it. Before, only tokens ofINT_MAXbytes or more were rejected. To accept larger tokens, raise the limit on the checker:jwt_checker_setmaxsize(checker, 4 * 1024 * 1024);
- For
jwt_checker_verify_detached()the payload counts: the token rebuilt with the payload attached must fit, and a payload whose own length exceeds the limit is refused before it is encoded. Base64url encoding makes a payload about 4/3 of its size, so with the default limit a detached payload over roughly 768 KiB now fails. An unencoded ("b64":false) payload counts at its own length. - JWE tokens (
jwe_checker_t) and JWK/JWKS input are not subject to this limit.
- For
jwt_builder_setkey()no longer re-keys anadd_signature()signer (#361).- Called after
jwt_builder_add_signature(),setkey()now adds a second signer and switches the builder to the General JSON serialization, as any second signer does.jwt_builder_generate()then returns a JSON document where it used to return a Compact token. Before,setkey()re-keyed theadd_signature()signer: that signer kept its headers (such as its"kid") but signed with thesetkey()key, and its own key was dropped without an error. To keep a single Compact signer, drop theadd_signature()call. To change anadd_signature()signer's key, pass that key toadd_signature(). - If the application then selects
JWT_FORMAT_COMPACT, generation fails rather than leave anadd_signature()signer out of the token.setkey()alone in Compact signs as before. jwt_builder_setkey(builder, JWT_ALG_NONE, NULL)removes only thesetkey()signer. It never turns anadd_signature()signer into an unsigned one. With a JSON format and no other signer, generation now fails withNo key set for JSON serialization(it wasA JSON-serialized JWS cannot use "none").- A builder callback's
config->key/config->algnow apply to thesetkey()signer in the JSON serializations too; before, they applied only to Compact. - Without
setkey(), a key set by the callback adds one more signature, placed before theadd_signature()ones. - In a JSON form, generation fails if the callback clears
config->keyfor asetkey()signer. - A builder callback that sets a key but leaves
config->algasJWT_ALG_NONEnow gets a Compact token signed with the key's own"alg". It used to get an unsigned ("alg":"none") token, unless the builder had refused a key that was in error. This now matches the JSON forms andjwt_builder_setkey(builder, JWT_ALG_NONE, key). If you meant an unsigned token, leaveconfig->keyNULL in the callback.
- Called after
- JSON
nullmembers, non-array"keys"and non-string private members (#357). Most of these apply to both JSON backends:- A JWKS whose
"keys"member is not an array (includingnull) now setsjwks_error()on the set (Invalid JWKS: "keys" is not an array) and adds no key. Before, Jansson loaded it as an empty set without an error, and json-c read anullone as a single JWK. Every CLI tool that loads a key file now stops with this error. "alg":nulland"x5c":nullput a key in error. Since 3.6.3 both backends had read them as absent.- On every JSON and crypto backend, a private member (RSA
d/p/q/dp/dq/qi, EC and OKPd, AKPpriv) that is present but not a string puts the key in error withInvalid JWK: "<name>" is not a string. Before, GnuTLS and MbedTLS loaded such an EC or OKP key as a public key, which could verify, and OpenSSL failed it with a message of its own. Fix the JWK. Such a key still keeps itskid,alg,useandkey_ops, as any key that fails to load does, sojwks_find_bykid()and messages that name the key still work. - Getting a member that is not an object or array as
JWT_VALUE_JSONnow returnsJWT_VALUE_ERR_TYPE. Jansson returnedJWT_VALUE_ERR_INVALIDand json-c returned the scalar's JSON text. - json-c only: a
nullmember is now present. Getters returnJWT_VALUE_ERR_TYPE(wasJWT_VALUE_ERR_NOEXIST), so code that treatsJWT_VALUE_ERR_NOEXISTas "absent" now sees an error. Setters without replace returnJWT_VALUE_ERR_EXIST. Anullexpornbffails the claims check, anullclaim satisfiesjwt_checker_require(), and a JWE token with anullcrit,zip,protected,unprotected,recipients,header,aadorencrypted_keynow fails. The full list is under Library below.
- A JWKS whose
- Error text on the Jansson keyring path (#355). A Compact token that is not valid UTF-8 in its header, signature or base64url-encoded payload is still rejected against a keyring. The error now comes from the check it fails, such as
JWS protected header is not valid JSONorError decoding signature, instead ofToken is not valid UTF-8. An unencoded"b64":falsepayload is covered under Library. - CLI message text (#365). Scripts that match the
jwt-verifyunknown-algorithm message need updating. Details are under CLI tools below.
✨ New API
jwt_checker_setmaxsize()(#378) sets the checker's maximum token size. It accepts 1 toINT_MAX - 1. Any other value returns non-zero, setsInvalid maximum token sizeon the checker and keeps the previous limit. A new checker starts at 1 MiB.jwt_checker_verified_jwt()(#362) returns thejwt_tthat the lastjwt_checker_verify()orjwt_checker_verify_detached()accepted. Use it to read the claims and protected header.jwt_get_alg()on it gives the algorithm that verified it, even when the key has no"alg".- The checker owns the returned
jwt_t; do not free it. It stays valid until the next verify call (even one that fails immediately) orjwt_checker_free(). A checker therefore now keeps the last token it accepted in memory until then. - After a failed verify, and from inside a verify or jti callback, it returns
NULL. - For a General JWS JSON token, the
jwt_thas an empty header andjwt_get_alg()returnsJWT_ALG_INVAL, since each signature has a header of its own; usejwt_checker_sig_header_get()instead.
- The checker owns the returned
jwt_checker_sig_header_get()(#362) reads a protected-header member of one signature, by index, asjwt_header_get()does. It returns a value only for a signature that verified in an accepted token; otherwise it returnsJWT_VALUE_ERR_INVALID. It never reads the unprotected"header", which is not integrity protected.
🔐 Library
- ECDH-ES with A192CBC-HS384 and A256CBC-HS512 (#369). In Direct Key Agreement mode (
"alg":"ECDH-ES"), the derived key is the content key, so these twoencvalues need 48 or 64 octets. Before, every backend ran a single round of the Concat KDF and refused anything longer than 32 octets.jwe_builder_generate()returnedNULLandjwe_checker_decrypt()failed withECDH-ES key agreement failed, even for valid tokens from other implementations.- The three backend copies of the KDF are now one shared implementation of RFC 7518 §4.6.2 in full.
- ECDH-ES now encrypts and decrypts with every
encon OpenSSL, GnuTLS and MbedTLS. X25519 and X448 on GnuTLS still need GnuTLS 3.8.13 or later, as before. - Keys of 32 octets or less (A128CBC-HS256, the AES-GCM
encvalues and theECDH-ES+A*KWKEKs) derive byte for byte as before.ECDH-ES+A*KWwas not affected.
- Compact tokens against a keyring (#355). A checker with a keyring no longer converts a Compact token into a Flattened JWS JSON document, serializes it and parses it again. It checks the token's own bytes, with the same per-signature checks a JSON signature gets.
- On a 350 KB token under Jansson, a one-key ring now allocates about 0.85× what
jwt_checker_setkey()does, down from about 2.5×. Each further candidate key costs only its own signature check. - With Jansson, a Compact token whose unencoded (
"b64":false) payload is not valid UTF-8, attached or detached, now verifies against a keyring. It already did with json-c and withjwt_checker_setkey(). - Verdicts and the
jwt_checker_sig_*()results are otherwise unchanged.
- On a 350 KB token under Jansson, a one-key ring now allocates about 0.85× what
- Keyring scan in one pass (#356). A signature without
"kid"is tried against every compatible key in the ring. That scan walked the key list from its head for each key, which is quadratic in the ring size. It is now linear: on a 10,000-key ring with no matching key, a signature takes a few milliseconds instead of about 0.4 s. Key order, the first key that verifies, the tried count and the error messages are unchanged. Thejwt_checker_setkeyring()docs now describe the scan. - JSON
nullmembers on json-c (#357). json-c's lookup returns nothing both for a missing member and for one whose value isnull. libjwt used that lookup to test whether a member was present, so the two JSON backends gave different answers for the same token, key or call. It now checks presence explicitly, and json-c gives Jansson's results:- Getters (
jwt_claim_get(),jwt_header_get()and the builder's): anullmember isJWT_VALUE_ERR_TYPE, notJWT_VALUE_ERR_NOEXIST. - Setters: setting over a
nullmember without replace givesJWT_VALUE_ERR_EXIST. - Checker: a
nullexpornbffails the claims check, anullclaim is present forjwt_checker_require(), and anullprotected JWS parameter overlaps the same name in the unprotected header. - Builder:
jwt_builder_setcrit()may name anullheader parameter, an application'snulltypis kept, and anullprotected parameter overlaps a signature's unprotected one. - JWE:
- A
nullprotectedcritorzip, and anullprotected,unprotected,recipients,header,aadorencrypted_keymember, are rejected as the wrong type. - A
nullheader parameter counts for the disjointness rule. - A token with a
nullparameter in the shared or per-recipient unprotected header now decrypts; it used to fail withError allocating memory.
- A
- Getters (
🧰 CLI tools
jwt-verifyjwt-generate: for an unknown-a/--algorithmvalue, one blank line now separates the error from the usage text (it was two), as for every other error (#365).- All tools: a key file whose
"keys"is not an array (or isnull) now fails to load withInvalid JWKS: "keys" is not an array(#357).
🏗️ Tests & docs
- New test programs
jwt_verifiedandjwt_maxsize, a large-keyring scan test, ECDH-ES round trips with everyencon every curve and backend, and the Wycheproofjwe_ecvectors for A192CBC-HS384 and A256CBC-HS512 (#362, #378, #356, #369). - The README and the Doxygen main page describe the
setkey()signer and ECDH-ES with everyenc. Thejwt.hAPI docs cover the keyring scan, the size limit and the new getters. Thejwt_taccessor docs no longer refer to ajwt_create()that does not exist.
Full Changelog: v3.7.0...v3.8.0