diff --git a/HEAD/LibJWT-Icon-95x91.png b/HEAD/LibJWT-Icon-95x91.png new file mode 100644 index 00000000..1d8505df Binary files /dev/null and b/HEAD/LibJWT-Icon-95x91.png differ diff --git a/HEAD/annotated.html b/HEAD/annotated.html new file mode 100644 index 00000000..f5a8a1af --- /dev/null +++ b/HEAD/annotated.html @@ -0,0 +1,113 @@ + + + +
+ + + + ++ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
Cjwk_item_t | Structural representation of a JWK |
Cjwt_verify_t | Used to manage keys for verifying a JWT |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+Files | |
jwt.h | |
The C JSON Web Token Library +JWK + JWKS. | |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
This page explains how to interpret the graphs that are generated by doxygen.
+Consider the following example:
This will result in the following graph:
+The boxes in the above graph have the following meaning:
+The arrows have the following meaning:
++ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+Topics | |
Memory Handlers | |
These functions allow you to get or set memory allocation functions. | |
Cryptographic Operations | |
Functions used to set and get which crypto operations are used | |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
Functions to handle JSON that represents JWK and JWKS for use in validating JWT objects. +More...
++Data Structures | |
struct | jwk_item_t |
Structural representation of a JWK. More... | |
+Typedefs | |
typedef struct jwk_set | jwk_set_t |
Opaque JWKS object. | |
+Enumerations | |
enum | jwk_key_type_t { JWK_KEY_TYPE_NONE +, JWK_KEY_TYPE_EC +, JWK_KEY_TYPE_RSA +, JWK_KEY_TYPE_OKP + } |
JWK Key Types. More... | |
enum | jwk_pub_key_use_t { JWK_PUB_KEY_USE_NONE +, JWK_PUB_KEY_USE_SIG +, JWK_PUB_KEY_USE_ENC + } |
Usage types for JWK public keys. More... | |
enum | jwk_key_op_t { + JWK_KEY_OP_NONE +, JWK_KEY_OP_SIGN +, JWK_KEY_OP_VERIFY +, JWK_KEY_OP_ENCRYPT +, + JWK_KEY_OP_DECRYPT +, JWK_KEY_OP_WRAP +, JWK_KEY_OP_UNWRAP +, JWK_KEY_OP_DERIVE_KEY +, + JWK_KEY_OP_DERIVE_BITS +, JWK_KEY_OP_INVALID + + } |
Allowed key operations for JWK private keys. More... | |
+Functions | |
JWT_EX jwk_set_t * | jwks_create (const char *jwk_json_str) |
Create a new JWKS object for later use in validating JWTs. | |
JWT_EX int | jwks_item_add (jwk_set_t *jwk_set, jwk_item_t *item) |
Add a jwk_item_t to an existing jwk_set_t. | |
JWT_EX int | jwks_error (jwk_set_t *jwk_set) |
Check if there is an error within the jwk_set. | |
JWT_EX int | jwks_error_any (jwk_set_t *jwk_set) |
Check if there is an error within the jwk_set and any of the jwk_item_t in the set. | |
JWT_EX const char * | jwks_error_msg (jwk_set_t *jwk_set) |
Retrieve an error message from a jwk_set. | |
JWT_EX jwk_item_t * | jwks_item_get (jwk_set_t *jwk_set, size_t index) |
Return the index'th jwk_item in the jwk_set. | |
JWT_EX void | jwks_free (jwk_set_t *jwk_set) |
Free all memory associated with a jwt_set_t, including any jwk_item_t in the set. | |
JWT_EX int | jwks_item_free (jwk_set_t *jwk_set, size_t index) |
Free all memory associated with the nth jwt_item_t in a jwk_set. | |
JWT_EX int | jwks_item_free_all (jwk_set_t *jwk_set) |
Free all memory associated with alljwt_item_t in a jwk_set. | |
Functions to handle JSON that represents JWK and JWKS for use in validating JWT objects.
+typedef struct jwk_set jwk_set_t | +
Opaque JWKS object.
+Used for working with JSON Web Keys and JWK Sets (JWKS).
+enum jwk_key_op_t | +
Allowed key operations for JWK private keys.
+A JWK can support one or more of these bitwise flag operations. The names correspond with the RFC.
+enum jwk_key_type_t | +
enum jwk_pub_key_use_t | +
JWT_EX jwk_set_t * jwks_create | +( | +const char * | jwk_json_str | ) | ++ |
Create a new JWKS object for later use in validating JWTs.
+This function expects a JSON string either as a single object for one JWK or as an array of objects under a key of "keys" (as defined in JWKS specifications).
+If non-NULL is returned, you should then check to make sure there is no error with jwks_error(). There may be errors on individual JWK items in the set. You can check if there are any with jwks_error_any().
+jwk_json_str | JSON string representation of a single key or array of "keys". If NULL is passed, an empty jwk_set_t is created. |
JWT_EX int jwks_error | +( | +jwk_set_t * | jwk_set | ) | ++ |
Check if there is an error within the jwk_set.
+To get a string describing the error, use jwks_error_str.
+jwk_set | An existing jwk_set_t |
JWT_EX int jwks_error_any | +( | +jwk_set_t * | jwk_set | ) | ++ |
Check if there is an error within the jwk_set and any of the jwk_item_t in the set.
+jwk_set | An existing jwk_set_t |
JWT_EX const char * jwks_error_msg | +( | +jwk_set_t * | jwk_set | ) | ++ |
Retrieve an error message from a jwk_set.
+Note, a zero length string is valid if jwos_error() returns non-zero.
+jwk_set | An existing jwk_set_t |
JWT_EX void jwks_free | +( | +jwk_set_t * | jwk_set | ) | ++ |
Free all memory associated with a jwt_set_t, including any jwk_item_t in the set.
+jwk_set | An existing jwk_set_t |
JWT_EX int jwks_item_add | +( | +jwk_set_t * | jwk_set, | +
+ | + | jwk_item_t * | item ) | +
Add a jwk_item_t to an existing jwk_set_t.
+jwk_set | An existing jwk_set_t |
item | A JWK item to add to the set |
JWT_EX int jwks_item_free | +( | +jwk_set_t * | jwk_set, | +
+ | + | size_t | index ) | +
Free all memory associated with the nth jwt_item_t in a jwk_set.
+jwk_set | A JWKS object |
index | the position of the item in the index |
JWT_EX int jwks_item_free_all | +( | +jwk_set_t * | jwk_set | ) | ++ |
Free all memory associated with alljwt_item_t in a jwk_set.
+The jwk_set becomes an empty set.
+jwk_set | A JWKS object |
JWT_EX jwk_item_t * jwks_item_get | +( | +jwk_set_t * | jwk_set, | +
+ | + | size_t | index ) | +
Return the index'th jwk_item in the jwk_set.
+Allows you to obtain the raw jwk_item. NOTE, this is not a copy of the item, so any changes to it will be reflected to it in the jwk_set. This also means if the jwk_set is freed, then this data is freed and cannot be used.
+jwk_set | An existing jwk_set_t |
index | Index of the jwk_set |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
Set and check algorithms and algorithm specific values. +More...
++Functions | |
JWT_EX int | jwt_set_alg (jwt_t *jwt, jwt_alg_t alg, const unsigned char *key, int len) |
Set an algorithm for a jwt_t object. | |
JWT_EX jwt_alg_t | jwt_get_alg (const jwt_t *jwt) |
Get the jwt_alg_t set for this JWT object. | |
JWT_EX const char * | jwt_alg_str (jwt_alg_t alg) |
Convert alg type to it's string representation. | |
JWT_EX jwt_alg_t | jwt_str_alg (const char *alg) |
Convert alg string to type. | |
Set and check algorithms and algorithm specific values.
+When working with functions that require a key, the underlying library takes care to scrub memory when the key is no longer used (e.g. when calling jwt_free() or when changing the algorithm, the old key, if it exists, is scrubbed).
+JWT_EX const char * jwt_alg_str | +( | +jwt_alg_t | alg | ) | ++ |
Convert alg type to it's string representation.
+Returns a string that matches the alg type provided.
+alg | A valid jwt_alg_t specifier. |
Get the jwt_alg_t set for this JWT object.
+Returns the jwt_alg_t type for this JWT object.
+jwt | Pointer to a JWT object. |
JWT_EX int jwt_set_alg | +( | +jwt_t * | jwt, | +
+ | + | jwt_alg_t | alg, | +
+ | + | const unsigned char * | key, | +
+ | + | int | len ) | +
Set an algorithm for a jwt_t object.
+Specifies an algorithm for a jwt_t object. If JWT_ALG_NONE is used, then key must be NULL and len must be 0. All other algorithms must have a valid pointer to key data, which may be specific to the algorithm (e.g RS256 expects a PEM formatted RSA key).
+jwt | Pointer to a jwt_t object. |
alg | A valid jwt_alg_t specifier. |
key | The key data to use for the algorithm. |
len | The length of the key data. |
JWT_EX jwt_alg_t jwt_str_alg | +( | +const char * | alg | ) | ++ |
Convert alg string to type.
+Returns an alg type based on the string representation.
+ +alg | A valid string for algorithm type (e.g. "RS256"). |
Note, this only works for algorithms that LibJWT supports or knows about.
+ ++ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
Functions used to create and destroy JWT objects. +More...
++Typedefs | |
typedef struct jwt | jwt_t |
< | |
+Enumerations | |
enum | jwt_alg_t { + JWT_ALG_NONE +, JWT_ALG_HS256 +, JWT_ALG_HS384 +, JWT_ALG_HS512 +, + JWT_ALG_RS256 +, JWT_ALG_RS384 +, JWT_ALG_RS512 +, JWT_ALG_ES256 +, + JWT_ALG_ES384 +, JWT_ALG_ES512 +, JWT_ALG_PS256 +, JWT_ALG_PS384 +, + JWT_ALG_PS512 +, JWT_ALG_ES256K +, JWT_ALG_EDDSA +, JWT_ALG_INVAL + + } |
JWT algorithm types. More... | |
+Functions | |
JWT_EX int | jwt_new (jwt_t **jwt) |
Allocate a new, empty, JWT object. | |
JWT_EX void | jwt_free (jwt_t *jwt) |
Free a JWT object and any other resources it is using. | |
JWT_EX jwt_t * | jwt_dup (jwt_t *jwt) |
Duplicate an existing JWT object. | |
Functions used to create and destroy JWT objects.
+typedef struct jwt jwt_t | +
<
+Opaque JWT object
+This object is used throughout the JWT functions.
+enum jwt_alg_t | +
JWT algorithm types.
+These are the supported algorithm types for LibJWT.
+Duplicate an existing JWT object.
+Copies all grants and algorithm specific bits to a new JWT object.
+jwt | Pointer to a JWT object. |
JWT_EX void jwt_free | +( | +jwt_t * | jwt | ) | ++ |
Free a JWT object and any other resources it is using.
+After calling, the JWT object referenced will no longer be valid and its memory will be freed.
+jwt | Pointer to a JWT object previously created with jwt_new or jwt_decode. |
JWT_EX int jwt_new | +( | +jwt_t ** | jwt | ) | ++ |
Allocate a new, empty, JWT object.
+This is used to create a new object that would be passed to one of the Encoding and Output functions once setup.
+jwt | Pointer to a JWT object pointer. Will be allocated on success. |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
Functions used to set and get which crypto operations are used +More...
++Enumerations | |
enum | jwt_crypto_provider_t { JWT_CRYPTO_OPS_NONE +, JWT_CRYPTO_OPS_OPENSSL +, JWT_CRYPTO_OPS_GNUTLS +, JWT_CRYPTO_OPS_MBEDTLS + } |
Different providers for crypto operations. More... | |
+Functions | |
JWT_EX const char * | jwt_get_crypto_ops (void) |
Retrieve the name of the current crypto operations being used. | |
JWT_EX jwt_crypto_provider_t | jwt_get_crypto_ops_t (void) |
Retrieve the type of the current crypto operations being used. | |
JWT_EX int | jwt_set_crypto_ops (const char *opname) |
Set the crypto operations to the named set. | |
JWT_EX int | jwt_set_crypto_ops_t (jwt_crypto_provider_t opname) |
Set the crypto operations to a jwt_crypto_provider_t type. | |
JWT_EX int | jwt_crypto_ops_supports_jwk (void) |
Check if the current crypto operations support JWK usage. | |
Functions used to set and get which crypto operations are used
+LibJWT supports several crypto libaries, mainly "openssl" and "gnutls". By default, if enabled, "openssl" is used.
+enum jwt_crypto_provider_t | +
Different providers for crypto operations.
+Used to set or test the underlying cryptographic library provider.
+Enumerator | |
---|---|
JWT_CRYPTO_OPS_NONE | Used for error handling. + |
JWT_CRYPTO_OPS_OPENSSL | OpenSSL Library. + |
JWT_CRYPTO_OPS_GNUTLS | GnuTLS Library. + |
JWT_CRYPTO_OPS_MBEDTLS | MBedTLS embedded library. + |
JWT_EX int jwt_crypto_ops_supports_jwk | +( | +void | ) | ++ |
Check if the current crypto operations support JWK usage.
+JWT_EX const char * jwt_get_crypto_ops | +( | +void | ) | ++ |
Retrieve the name of the current crypto operations being used.
+JWT_EX jwt_crypto_provider_t jwt_get_crypto_ops_t | +( | +void | ) | ++ |
Retrieve the type of the current crypto operations being used.
+JWT_EX int jwt_set_crypto_ops | +( | +const char * | opname | ) | ++ |
Set the crypto operations to the named set.
+The opname is one of the available operators in the compiled version of LibJWT. Most times, this is either "openssl" or "gnutls".
+opname | the name of the crypto operation to set |
JWT_EX int jwt_set_crypto_ops_t | +( | +jwt_crypto_provider_t | opname | ) | ++ |
Set the crypto operations to a jwt_crypto_provider_t type.
+The same as jwt_set_crypto_ops(), but uses the type as opname
+opname | A valid jwt_crypto_provider_t type |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
Functions for encoding a valid JWT optionally (but preferably) using JWA operation such as sigining or encryption. +More...
++Functions | |
JWT_EX int | jwt_dump_fp (jwt_t *jwt, FILE *fp, int pretty) |
Output plain text representation to a FILE pointer. | |
JWT_EX char * | jwt_dump_str (jwt_t *jwt, int pretty) |
Return plain text representation as a string. | |
JWT_EX char * | jwt_dump_grants_str (jwt_t *jwt, int pretty) |
Return plain text representation of grants as a string. | |
JWT_EX int | jwt_encode_fp (jwt_t *jwt, FILE *fp) |
Fully encode a JWT object and write it to FILE. | |
JWT_EX char * | jwt_encode_str (jwt_t *jwt) |
Fully encode a JWT object and return as a string. | |
JWT_EX void | jwt_free_str (char *str) |
Free a string returned from the library. | |
Functions for encoding a valid JWT optionally (but preferably) using JWA operation such as sigining or encryption.
+JWT_EX int jwt_dump_fp | +( | +jwt_t * | jwt, | +
+ | + | FILE * | fp, | +
+ | + | int | pretty ) | +
Output plain text representation to a FILE pointer.
+This function will write a plain text representation of this JWT object without Base64 encoding. This only writes the header and body, and does not compute the signature or encryption (if such an algorithm were being used).
+jwt | Pointer to a JWT object. |
fp | Valid FILE pointer to write data to. |
pretty | Enables better visual formatting of output. Generally only used for debugging. |
JWT_EX char * jwt_dump_grants_str | +( | +jwt_t * | jwt, | +
+ | + | int | pretty ) | +
Return plain text representation of grants as a string.
+Similar to jwt_dump_str() except that only a string containing the grants string is returned. The string must be freed by the caller.
+jwt | Pointer to a JWT object. |
pretty | Enables better visual formatting of output. Generally only used for debugging. |
JWT_EX char * jwt_dump_str | +( | +jwt_t * | jwt, | +
+ | + | int | pretty ) | +
Return plain text representation as a string.
+Similar to jwt_dump_fp() except that a string is returned. The string must be freed by the caller.
+jwt | Pointer to a JWT object. |
pretty | Enables better visual formatting of output. Generally only used for debugging. |
JWT_EX int jwt_encode_fp | +( | +jwt_t * | jwt, | +
+ | + | FILE * | fp ) | +
Fully encode a JWT object and write it to FILE.
+This will create and write the complete JWT object to FILE. All parts will be Base64 encoded and signatures or encryption will be applied if the algorithm specified requires it.
+jwt | Pointer to a JWT object. |
fp | Valid FILE pointer to write data to. |
JWT_EX char * jwt_encode_str | +( | +jwt_t * | jwt | ) | ++ |
Fully encode a JWT object and return as a string.
+Similar to jwt_encode_fp() except that a string is returned. The string must be freed by the caller. If you changed the allocation method using jwt_set_alloc, then you must use jwt_free_str() to free the memory.
+jwt | Pointer to a JWT object. |
JWT_EX void jwt_free_str | +( | +char * | str | ) | ++ |
Free a string returned from the library.
+str | Pointer to a string previously created with jwt_encode_str(). |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
These functions allow you to add, remove and retrieve grants from a JWT object. +More...
++Functions | |
JWT_EX const char * | jwt_get_grant (jwt_t *jwt, const char *grant) |
Return the value of a string grant. | |
JWT_EX long | jwt_get_grant_int (jwt_t *jwt, const char *grant) |
Return the value of an integer grant. | |
JWT_EX int | jwt_get_grant_bool (jwt_t *jwt, const char *grant) |
Return the value of an boolean grant. | |
JWT_EX char * | jwt_get_grants_json (jwt_t *jwt, const char *grant) |
Return the value of a grant as JSON encoded object string. | |
JWT_EX int | jwt_add_grant (jwt_t *jwt, const char *grant, const char *val) |
Add a new string grant to this JWT object. | |
JWT_EX int | jwt_add_grant_int (jwt_t *jwt, const char *grant, long val) |
Add a new integer grant to this JWT object. | |
JWT_EX int | jwt_add_grant_bool (jwt_t *jwt, const char *grant, int val) |
Add a new boolean grant to this JWT object. | |
JWT_EX int | jwt_add_grants_json (jwt_t *jwt, const char *json) |
Add grants from a JSON encoded object string. | |
JWT_EX int | jwt_del_grants (jwt_t *jwt, const char *grant) |
Delete a grant from this JWT object. | |
These functions allow you to add, remove and retrieve grants from a JWT object.
+JWT_EX int jwt_add_grant | +( | +jwt_t * | jwt, | +
+ | + | const char * | grant, | +
+ | + | const char * | val ) | +
Add a new string grant to this JWT object.
+Creates a new grant for this object. The string for grant and val are copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a grant that already exists.
+jwt | Pointer to a JWT object. |
grant | String containing the name of the grant to add. |
val | String containing the value to be saved for grant. Can be an empty string, but cannot be NULL. |
JWT_EX int jwt_add_grant_bool | +( | +jwt_t * | jwt, | +
+ | + | const char * | grant, | +
+ | + | int | val ) | +
Add a new boolean grant to this JWT object.
+Creates a new grant for this object. The string for grant is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a grant that already exists.
+jwt | Pointer to a JWT object. |
grant | String containing the name of the grant to add. |
val | boolean containing the value to be saved for grant. |
JWT_EX int jwt_add_grant_int | +( | +jwt_t * | jwt, | +
+ | + | const char * | grant, | +
+ | + | long | val ) | +
Add a new integer grant to this JWT object.
+Creates a new grant for this object. The string for grant is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a grant that already exists.
+jwt | Pointer to a JWT object. |
grant | String containing the name of the grant to add. |
val | int containing the value to be saved for grant. |
JWT_EX int jwt_add_grants_json | +( | +jwt_t * | jwt, | +
+ | + | const char * | json ) | +
Add grants from a JSON encoded object string.
+Loads a grant from an existing JSON encoded object string. Overwrites existing grant. If grant is NULL, then the JSON encoded string is assumed to be a JSON hash of all grants being added and will be merged into the grant listing.
+jwt | Pointer to a JWT object. |
json | String containing a JSON encoded object of grants. |
JWT_EX int jwt_del_grants | +( | +jwt_t * | jwt, | +
+ | + | const char * | grant ) | +
Delete a grant from this JWT object.
+Deletes the named grant from this object. It is not an error if there is no grant matching the passed name. If grant is NULL, then all grants are deleted from this JWT.
+jwt | Pointer to a JWT object. |
grant | String containing the name of the grant to delete. If this is NULL, then all grants are deleted. |
JWT_EX const char * jwt_get_grant | +( | +jwt_t * | jwt, | +
+ | + | const char * | grant ) | +
Return the value of a string grant.
+Returns the string value for a grant (e.g. "iss"). If it does not exist, NULL will be returned.
+jwt | Pointer to a JWT object. |
grant | String containing the name of the grant to return a value for. |
JWT_EX int jwt_get_grant_bool | +( | +jwt_t * | jwt, | +
+ | + | const char * | grant ) | +
Return the value of an boolean grant.
+Returns the int value for a grant (e.g. "exp"). If it does not exist, 0 will be returned.
+jwt | Pointer to a JWT object. |
grant | String containing the name of the grant to return a value for. |
JWT_EX long jwt_get_grant_int | +( | +jwt_t * | jwt, | +
+ | + | const char * | grant ) | +
Return the value of an integer grant.
+Returns the int value for a grant (e.g. "exp"). If it does not exist, 0 will be returned.
+jwt | Pointer to a JWT object. |
grant | String containing the name of the grant to return a value for. |
JWT_EX char * jwt_get_grants_json | +( | +jwt_t * | jwt, | +
+ | + | const char * | grant ) | +
Return the value of a grant as JSON encoded object string.
+Returns the JSON encoded string value for a grant (e.g. "iss"). If it does not exist, NULL will be returned.
+jwt | Pointer to a JWT object. |
grant | String containing the name of the grant to return a value for. If this is NULL, all grants will be returned as a JSON encoded hash. |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
+Topics | |
Object Creation | |
Functions used to create and destroy JWT objects. | |
Token Verification | |
Functions used to decode and verify signatures for a JWT. | |
Grant Management | |
These functions allow you to add, remove and retrieve grants from a JWT object. | |
Header Hanagement | |
These functions allow you to add, remove and retrieve headers from a JWT object. | |
Encoding and Output | |
Functions for encoding a valid JWT optionally (but preferably) using JWA operation such as sigining or encryption. | |
Algorithm Management | |
Set and check algorithms and algorithm specific values. | |
Validation Functions | |
These functions allow you to define requirements for JWT validation. | |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
These functions allow you to add, remove and retrieve headers from a JWT object. +More...
++Functions | |
JWT_EX const char * | jwt_get_header (jwt_t *jwt, const char *header) |
Return the value of a string header. | |
JWT_EX long | jwt_get_header_int (jwt_t *jwt, const char *header) |
Return the value of an integer header. | |
JWT_EX int | jwt_get_header_bool (jwt_t *jwt, const char *header) |
Return the value of an boolean header. | |
JWT_EX char * | jwt_get_headers_json (jwt_t *jwt, const char *header) |
Return the value of a header as JSON encoded object string. | |
JWT_EX int | jwt_add_header (jwt_t *jwt, const char *header, const char *val) |
Add a new string header to this JWT object. | |
JWT_EX int | jwt_add_header_int (jwt_t *jwt, const char *header, long val) |
Add a new integer header to this JWT object. | |
JWT_EX int | jwt_add_header_bool (jwt_t *jwt, const char *header, int val) |
Add a new boolean header to this JWT object. | |
JWT_EX int | jwt_add_headers_json (jwt_t *jwt, const char *json) |
Add headers from a JSON encoded object string. | |
JWT_EX int | jwt_del_headers (jwt_t *jwt, const char *header) |
Delete a header from this JWT object. | |
These functions allow you to add, remove and retrieve headers from a JWT object.
+JWT_EX int jwt_add_header | +( | +jwt_t * | jwt, | +
+ | + | const char * | header, | +
+ | + | const char * | val ) | +
Add a new string header to this JWT object.
+Creates a new header for this object. The string for header and val are copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a header that already exists.
+jwt | Pointer to a JWT object. |
header | String containing the name of the header to add. |
val | String containing the value to be saved for header. Can be an empty string, but cannot be NULL. |
JWT_EX int jwt_add_header_bool | +( | +jwt_t * | jwt, | +
+ | + | const char * | header, | +
+ | + | int | val ) | +
Add a new boolean header to this JWT object.
+Creates a new header for this object. The string for header is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a header that already exists.
+jwt | Pointer to a JWT object. |
header | String containing the name of the header to add. |
val | boolean containing the value to be saved for header. |
JWT_EX int jwt_add_header_int | +( | +jwt_t * | jwt, | +
+ | + | const char * | header, | +
+ | + | long | val ) | +
Add a new integer header to this JWT object.
+Creates a new header for this object. The string for header is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a header that already exists.
+jwt | Pointer to a JWT object. |
header | String containing the name of the header to add. |
val | int containing the value to be saved for header. |
JWT_EX int jwt_add_headers_json | +( | +jwt_t * | jwt, | +
+ | + | const char * | json ) | +
Add headers from a JSON encoded object string.
+Loads a header from an existing JSON encoded object string. Overwrites existing header. If header is NULL, then the JSON encoded string is assumed to be a JSON hash of all headers being added and will be merged into the header listing.
+jwt | Pointer to a JWT object. |
json | String containing a JSON encoded object of headers. |
JWT_EX int jwt_del_headers | +( | +jwt_t * | jwt, | +
+ | + | const char * | header ) | +
Delete a header from this JWT object.
+Deletes the named header from this object. It is not an error if there is no header matching the passed name. If header is NULL, then all headers are deleted from this JWT.
+jwt | Pointer to a JWT object. |
header | String containing the name of the header to delete. If this is NULL, then all headers are deleted. |
JWT_EX const char * jwt_get_header | +( | +jwt_t * | jwt, | +
+ | + | const char * | header ) | +
Return the value of a string header.
+Returns the string value for a header (e.g. ""). If it does not exist, NULL will be returned.
+jwt | Pointer to a JWT object. |
header | String containing the name of the header to return a value for. |
JWT_EX int jwt_get_header_bool | +( | +jwt_t * | jwt, | +
+ | + | const char * | header ) | +
Return the value of an boolean header.
+Returns the int value for a header (e.g. ""). If it does not exist, 0 will be returned.
+jwt | Pointer to a JWT object. |
header | String containing the name of the header to return a value for. |
JWT_EX long jwt_get_header_int | +( | +jwt_t * | jwt, | +
+ | + | const char * | header ) | +
Return the value of an integer header.
+Returns the int value for a header (e.g. ""). If it does not exist, 0 will be returned.
+jwt | Pointer to a JWT object. |
header | String containing the name of the header to return a value for. |
JWT_EX char * jwt_get_headers_json | +( | +jwt_t * | jwt, | +
+ | + | const char * | header ) | +
Return the value of a header as JSON encoded object string.
+Returns the JSON encoded string value for a header (e.g. ""). If it does not exist, NULL will be returned.
+jwt | Pointer to a JWT object. |
header | String containing the name of the header to return a value for. If this is NULL, all headers will be returned as a JSON encoded hash. |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
These functions allow you to get or set memory allocation functions. +More...
++Typedefs | |
typedef void *(* | jwt_malloc_t) (size_t) |
Prototype for malloc(3) | |
typedef void *(* | jwt_realloc_t) (void *, size_t) |
Prototype for realloc(3) | |
typedef void(* | jwt_free_t) (void *) |
Prototype for free(3) | |
+Functions | |
JWT_EX int | jwt_set_alloc (jwt_malloc_t pmalloc, jwt_realloc_t prealloc, jwt_free_t pfree) |
Set functions to be used for allocating and freeing memory. | |
JWT_EX void | jwt_get_alloc (jwt_malloc_t *pmalloc, jwt_realloc_t *prealloc, jwt_free_t *pfree) |
Get functions used for allocating and freeing memory. | |
These functions allow you to get or set memory allocation functions.
+typedef void(* jwt_free_t) (void *) | +
typedef void *(* jwt_malloc_t) (size_t) | +
typedef void *(* jwt_realloc_t) (void *, size_t) | +
JWT_EX void jwt_get_alloc | +( | +jwt_malloc_t * | pmalloc, | +
+ | + | jwt_realloc_t * | prealloc, | +
+ | + | jwt_free_t * | pfree ) | +
Get functions used for allocating and freeing memory.
+pmalloc | Pointer to malloc function output variable, or NULL |
prealloc | Pointer to realloc function output variable, or NULL |
pfree | Pointer to free function output variable, or NULL |
JWT_EX int jwt_set_alloc | +( | +jwt_malloc_t | pmalloc, | +
+ | + | jwt_realloc_t | prealloc, | +
+ | + | jwt_free_t | pfree ) | +
Set functions to be used for allocating and freeing memory.
+By default, LibJWT uses malloc, realloc, and free for memory management. This function allows the user of the library to specify its own memory management functions. This is especially useful on Windows where mismatches in runtimes across DLLs can cause problems.
+The caller can specify either a valid function pointer for any of the parameters or NULL to use the corresponding default allocator function.
+Note that this function will also set the memory allocator for the Jansson library.
+pmalloc | The function to use for allocating memory or NULL to use malloc |
prealloc | The function to use for reallocating memory or NULL to use realloc |
pfree | The function to use for freeing memory or NULL to use free |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
These functions allow you to define requirements for JWT validation. +More...
++Typedefs | |
typedef struct jwt_valid | jwt_valid_t |
Opaque JWT Validation object. | |
+Enumerations | |
enum | jwt_valid_exception_t { + JWT_VALIDATION_SUCCESS +, JWT_VALIDATION_ERROR +, JWT_VALIDATION_ALG_MISMATCH +, JWT_VALIDATION_EXPIRED +, + JWT_VALIDATION_TOO_NEW +, JWT_VALIDATION_ISS_MISMATCH +, JWT_VALIDATION_SUB_MISMATCH +, JWT_VALIDATION_AUD_MISMATCH +, + JWT_VALIDATION_GRANT_MISSING +, JWT_VALIDATION_GRANT_MISMATCH + + } |
Validation exception types for jwt_t objects. More... | |
+Functions | |
JWT_EX jwt_valid_exception_t | jwt_validate (jwt_t *jwt, jwt_valid_t *jwt_valid) |
Validate a JWT object with a validation object. | |
JWT_EX int | jwt_valid_new (jwt_valid_t **jwt_valid, jwt_alg_t alg) |
Allocate a new, JWT validation object. | |
JWT_EX void | jwt_valid_free (jwt_valid_t *jwt_valid) |
Free a JWT validation object and any other resources it is using. | |
JWT_EX jwt_valid_exception_t | jwt_valid_get_status (jwt_valid_t *jwt_valid) |
Return the status string for the validation object. | |
JWT_EX time_t | jwt_valid_get_nbf_leeway (jwt_valid_t *jwt_valid) |
Return the nbf_leeway value set. | |
JWT_EX time_t | jwt_valid_get_exp_leeway (jwt_valid_t *jwt_valid) |
Return the exp_leeway value set. | |
JWT_EX int | jwt_valid_add_grant (jwt_valid_t *jwt_valid, const char *grant, const char *val) |
Add a new string grant requirement to this JWT validation object. | |
JWT_EX const char * | jwt_valid_get_grant (jwt_valid_t *jwt_valid, const char *grant) |
Return the value of a string required grant. | |
JWT_EX int | jwt_valid_add_grant_int (jwt_valid_t *jwt_valid, const char *grant, long val) |
Add a new integer grant requirement to this JWT validation object. | |
JWT_EX long | jwt_valid_get_grant_int (jwt_valid_t *jwt_valid, const char *grant) |
Return the value of an integer required grant. | |
JWT_EX int | jwt_valid_add_grant_bool (jwt_valid_t *jwt_valid, const char *grant, int val) |
Add a new boolean required grant to this JWT validation object. | |
JWT_EX int | jwt_valid_get_grant_bool (jwt_valid_t *jwt_valid, const char *grant) |
Return the value of an boolean required grant. | |
JWT_EX int | jwt_valid_add_grants_json (jwt_valid_t *jwt_valid, const char *json) |
Add required grants from a JSON encoded object string. | |
JWT_EX char * | jwt_valid_get_grants_json (jwt_valid_t *jwt_valid, const char *grant) |
Return the value of a grant as JSON encoded object string. | |
JWT_EX int | jwt_valid_del_grants (jwt_valid_t *jwt_valid, const char *grant) |
Delete a grant from this JWT object. | |
JWT_EX int | jwt_valid_set_now (jwt_valid_t *jwt_valid, const time_t now) |
Set the time for which expires and not-before claims should be evaluated. | |
JWT_EX int | jwt_valid_set_nbf_leeway (jwt_valid_t *jwt_valid, const time_t nbf_leeway) |
Set the nbf_leeway value as defined in: https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5. | |
JWT_EX int | jwt_valid_set_exp_leeway (jwt_valid_t *jwt_valid, const time_t exp_leeway) |
Set the exp_leeway value as defined in: https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4. | |
JWT_EX int | jwt_valid_set_headers (jwt_valid_t *jwt_valid, int hdr) |
Set validation for replicated claims in headers. | |
JWT_EX char * | jwt_exception_str (unsigned int exceptions) |
Parses exceptions and returns a comma delimited and human-readable string. | |
These functions allow you to define requirements for JWT validation.
+The most basic validation is that the JWT uses the expected algorithm.
+When replicating claims in header (usually for encrypted JWT), validation tests that they match claims in the body (iss, sub, aud).
+Time-based claims can also be validated (nbf, exp).
+Finally, validation can test that claims be present and have certain value.
+typedef struct jwt_valid jwt_valid_t | +
enum jwt_valid_exception_t | +
Validation exception types for jwt_t objects.
+These are bitwise values that allow you to check for exceptions when using the jwt_valid_t
+ RFC-7519 Sec 4.1.6 "iat"
Issued At
RFC-7519 Sec 4.1.7 "jti"
JWT ID
Enumerator | |
---|---|
JWT_VALIDATION_SUCCESS | Validation succeeded |
JWT_VALIDATION_ERROR | General failures |
JWT_VALIDATION_ALG_MISMATCH | RFC-7518 Sec 3.1 |
JWT_VALIDATION_EXPIRED | RFC-7519 Sec 4.1.4 |
JWT_VALIDATION_TOO_NEW | RFC-7519 Sec 4.1.5 |
JWT_VALIDATION_ISS_MISMATCH | RFC-7519 Sec 4.1.1 |
JWT_VALIDATION_SUB_MISMATCH | RFC-7519 Sec 4.1.2 |
JWT_VALIDATION_AUD_MISMATCH | RFC-7519 Sec 4.1.3 |
JWT_VALIDATION_GRANT_MISSING | User-defined Grant missing |
JWT_VALIDATION_GRANT_MISMATCH | User-defined Grant mismatch |
JWT_EX char * jwt_exception_str | +( | +unsigned int | exceptions | ) | ++ |
Parses exceptions and returns a comma delimited and human-readable string.
+The returned string must be freed by the caller. If you changed the allocation method using jwt_set_alloc, then you must use jwt_free_str() to free the memory.
+exceptions | Integer containing the exception flags. |
JWT_EX int jwt_valid_add_grant | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | grant, | +
+ | + | const char * | val ) | +
Add a new string grant requirement to this JWT validation object.
+jwt_valid | Pointer to a JWT validation object. |
grant | String containing the name of the grant to add. |
val | String containing the value to be saved for grant. Can be an empty string, but cannot be NULL. |
Note, this only allows for string based grants. If you wish to add integer grants, then use jwt_valid_add_grant_int(). If you wish to add more complex grants (e.g. an array), then use jwt_valid_add_grants_json().
+ +JWT_EX int jwt_valid_add_grant_bool | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | grant, | +
+ | + | int | val ) | +
Add a new boolean required grant to this JWT validation object.
+Creates a new grant for this object. The string for grant is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a grant that already exists.
+jwt_valid | Pointer to a JWT validation object. |
grant | String containing the name of the grant to add. |
val | boolean containing the value to be saved for grant. |
JWT_EX int jwt_valid_add_grant_int | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | grant, | +
+ | + | long | val ) | +
Add a new integer grant requirement to this JWT validation object.
+jwt_valid | Pointer to a JWT validation object. |
grant | String containing the name of the grant to add. |
val | int containing the value to be saved for grant. |
JWT_EX int jwt_valid_add_grants_json | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | json ) | +
Add required grants from a JSON encoded object string.
+Loads a grant from an existing JSON encoded object string. Overwrites existing grant.
+jwt_valid | Pointer to a JWT validation object. |
json | String containing a JSON encoded object of grants. |
JWT_EX int jwt_valid_del_grants | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | grant ) | +
Delete a grant from this JWT object.
+Deletes the named grant from this object. It is not an error if there is no grant matching the passed name. If grant is NULL, then all grants are deleted from this JWT.
+jwt_valid | Pointer to a JWT validation object. |
grant | String containing the name of the grant to delete. If this is NULL, then all grants are deleted. |
JWT_EX void jwt_valid_free | +( | +jwt_valid_t * | jwt_valid | ) | ++ |
Free a JWT validation object and any other resources it is using.
+After calling, the JWT validation object referenced will no longer be valid and its memory will be freed.
+jwt_valid | Pointer to a JWT validation object previously created with jwt_valid_new(). |
JWT_EX time_t jwt_valid_get_exp_leeway | +( | +jwt_valid_t * | jwt_valid | ) | ++ |
Return the exp_leeway value set.
+jwt_valid | Pointer to a JWT validation object. |
JWT_EX const char * jwt_valid_get_grant | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | grant ) | +
Return the value of a string required grant.
+Returns the string value for a grant (e.g. "iss"). If it does not exist, NULL will be returned.
+jwt_valid | Pointer to a JWT validation object. |
grant | String containing the name of the grant to return a value for. |
Note, this will only return grants with JSON string values. Use jwt_valid_get_grants_json() to get the JSON representation of more complex values (e.g. arrays) or use jwt_valid_get_grant_int() to get simple integer values.
+ +JWT_EX int jwt_valid_get_grant_bool | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | grant ) | +
Return the value of an boolean required grant.
+Returns the int value for a grant (e.g. "exp"). If it does not exist, 0 will be returned.
+jwt_valid | Pointer to a JWT validation object. |
grant | String containing the name of the grant to return a value for. |
JWT_EX long jwt_valid_get_grant_int | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | grant ) | +
Return the value of an integer required grant.
+Returns the int value for a grant (e.g. "exp"). If it does not exist, 0 will be returned.
+jwt_valid | Pointer to a JWT validation object. |
grant | String containing the name of the grant to return a value for. |
JWT_EX char * jwt_valid_get_grants_json | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const char * | grant ) | +
Return the value of a grant as JSON encoded object string.
+Returns the JSON encoded string value for a grant (e.g. "iss"). If it does not exist, NULL will be returned.
+jwt_valid | Pointer to a JWT validation object. |
grant | String containing the name of the grant to return a value for. |
JWT_EX time_t jwt_valid_get_nbf_leeway | +( | +jwt_valid_t * | jwt_valid | ) | ++ |
Return the nbf_leeway value set.
+jwt_valid | Pointer to a JWT validation object. |
JWT_EX jwt_valid_exception_t jwt_valid_get_status | +( | +jwt_valid_t * | jwt_valid | ) | ++ |
Return the status string for the validation object.
+The status of validation object is primarily for describing the reason jwt_validate() failed.
+jwt_valid | Pointer to a JWT validation object. |
JWT_EX int jwt_valid_new | +( | +jwt_valid_t ** | jwt_valid, | +
+ | + | jwt_alg_t | alg ) | +
Allocate a new, JWT validation object.
+This is used to create a new object for a JWT validation. After you have finished with the object, use jwt_valid_free() to clean up the memory used by it.
+jwt_valid | Pointer to a JWT validation object pointer. Will be allocated on success. |
alg | A valid jwt_alg_t specifier. |
JWT_EX int jwt_valid_set_exp_leeway | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const time_t | exp_leeway ) | +
Set the exp_leeway value as defined in: https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4.
+jwt_valid | Pointer to a JWT validation object. |
exp_leeway | leeway for exp value. |
JWT_EX int jwt_valid_set_headers | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | int | hdr ) | +
Set validation for replicated claims in headers.
+When set, validation tests for presence of iss, sub, aud in jwt headers and tests match for same claims in body.
+jwt_valid | Pointer to a JWT validation object. |
hdr | When true, test header claims |
JWT_EX int jwt_valid_set_nbf_leeway | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const time_t | nbf_leeway ) | +
Set the nbf_leeway value as defined in: https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5.
+jwt_valid | Pointer to a JWT validation object. |
nbf_leeway | leeway for nbf value. |
JWT_EX int jwt_valid_set_now | +( | +jwt_valid_t * | jwt_valid, | +
+ | + | const time_t | now ) | +
Set the time for which expires and not-before claims should be evaluated.
+jwt_valid | Pointer to a JWT validation object. |
now | Time to use when considering nbf and exp claims. |
JWT_EX jwt_valid_exception_t jwt_validate | +( | +jwt_t * | jwt, | +
+ | + | jwt_valid_t * | jwt_valid ) | +
Validate a JWT object with a validation object.
+jwt | Pointer to a JWT object. |
jwt_valid | Pointer to a JWT validation object. |
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
Functions used to decode and verify signatures for a JWT. +More...
++Data Structures | |
struct | jwt_verify_t |
Used to manage keys for verifying a JWT. More... | |
+Typedefs | |
typedef jwt_verify_t | jwt_key_t |
Backward compatibility for jwt_decode_2. | |
typedef int(* | jwt_verify_p_t) (const jwt_t *, jwt_verify_t *) |
Prototype of the key provider callback. | |
typedef jwt_verify_p_t | jwt_key_p_t |
Backward compatibility for jwt_decode_2. | |
+Functions | |
JWT_EX int | jwt_verify (jwt_t **jwt, const char *token, jwt_verify_t *key_v) |
JWT_EX int | jwt_verify_wcb (jwt_t **jwt, const char *token, jwt_verify_t *key_v, jwt_key_p_t key_provider) |
JWT_EX DEPRECATED int | jwt_decode (jwt_t **jwt, const char *token, const unsigned char *key, int key_len) |
JWT_EX DEPRECATED int | jwt_decode_2 (jwt_t **jwt, const char *token, jwt_key_p_t key_provider) |
Functions used to decode and verify signatures for a JWT.
+typedef jwt_verify_p_t jwt_key_p_t | +
Backward compatibility for jwt_decode_2.
+ + + +typedef jwt_verify_t jwt_key_t | +
Backward compatibility for jwt_decode_2.
+ + + +typedef int(* jwt_verify_p_t) (const jwt_t *, jwt_verify_t *) | +
Prototype of the key provider callback.
+This function is expected to return 0 on success, and errno otherwise. On success, the data in jwt_verify_t should be usable to to handle the operation needed to complete the verifification of the signature on the jwt_t.
+my_key
is on this function's stack and will be out of scope once it returns. JWT_EX DEPRECATED int jwt_decode | +( | +jwt_t ** | jwt, | +
+ | + | const char * | token, | +
+ | + | const unsigned char * | key, | +
+ | + | int | key_len ) | +
JWT_EX DEPRECATED int jwt_decode_2 | +( | +jwt_t ** | jwt, | +
+ | + | const char * | token, | +
+ | + | jwt_key_p_t | key_provider ) | +
JWT_EX int jwt_verify | +( | +jwt_t ** | jwt, | +
+ | + | const char * | token, | +
+ | + | jwt_verify_t * | key_v ) | +
JWT_EX int jwt_verify_wcb | +( | +jwt_t ** | jwt, | +
+ | + | const char * | token, | +
+ | + | jwt_verify_t * | key_v, | +
+ | + | jwt_key_p_t | key_provider ) | +
+ |
+ LibJWT v2.1.0
+
+ The C JSON Web Token Library +JWK +JWKS
+ |
+
Standard | RFC | Description |
---|---|---|
JWT | RFC-7519 | JSON Web Token |
JWA | RFC-7518 | JSON Web Algorithms |
JWS and JWE | RFC-7518 | Specific types of JWA |
JWK | RFC-7517 | JSON Web Key |
JWKS | RFC-7517 | A set of JWK as an array of "keys" |
LibJWT is available in most Linux distributions as well as through Homebrew.
+If you have libcheck installed, both targets will compile the test suite which you can run using the check
target.
Both build systems will auto detect OpenSSL and GnuTLS and use one or both. Each build system has a way to force-enable (error if not found) or force-disable either library. See the Cryptographic Operations section
+