|
LibJWT 3.5.0
The C JSON Web Token Library +JWK +JWKS
|
Inspect and use individual JWK items from a keyring. More...
Typedefs | |
| typedef struct jwk_item | jwk_item_t |
| Object representation of a JWK. | |
Enumerations | |
| enum | jwk_key_type_t { JWK_KEY_TYPE_NONE = 0 , JWK_KEY_TYPE_EC , JWK_KEY_TYPE_RSA , JWK_KEY_TYPE_OKP , JWK_KEY_TYPE_OCT , JWK_KEY_TYPE_AKP } |
| JWK Key Types. More... | |
| enum | jwk_pub_key_use_t { JWK_PUB_KEY_USE_NONE = 0 , 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 = 0x0000 , JWK_KEY_OP_SIGN = 0x0001 , JWK_KEY_OP_VERIFY = 0x0002 , JWK_KEY_OP_ENCRYPT = 0x0004 , JWK_KEY_OP_DECRYPT = 0x0008 , JWK_KEY_OP_WRAP = 0x0010 , JWK_KEY_OP_UNWRAP = 0x0020 , JWK_KEY_OP_DERIVE_KEY = 0x0040 , JWK_KEY_OP_DERIVE_BITS = 0x0080 , JWK_KEY_OP_INVALID = 0xffff } |
| Allowed key operations for JWK private keys. More... | |
Functions | |
| const jwk_item_t * | jwks_item_get (const jwk_set_t *jwk_set, size_t index) |
| Return the index'th jwk_item in the jwk_set. | |
| jwk_item_t * | jwks_find_bykid (jwk_set_t *jwk_set, const char *kid) |
| Find a jwk_item_t with a specific kid (Key ID). | |
| int | jwks_item_is_private (const jwk_item_t *item) |
| Whether this key is private (or public). | |
| int | jwks_item_error (const jwk_item_t *item) |
| Check the error condition for this JWK. | |
| const char * | jwks_item_error_msg (const jwk_item_t *item) |
| Check the error message for a JWK Item. | |
| const char * | jwks_item_curve (const jwk_item_t *item) |
| A curve name, if applicable, for this key. | |
| const char * | jwks_item_kid (const jwk_item_t *item) |
| A kid (Key ID) for this JWK. | |
| jwt_alg_t | jwks_item_alg (const jwk_item_t *item) |
| The algorithm for this JWK. | |
| jwk_key_type_t | jwks_item_kty (const jwk_item_t *item) |
| The Key Type of this JWK. | |
| jwk_pub_key_use_t | jwks_item_use (const jwk_item_t *item) |
| The "use" field for this JWK. | |
| jwk_key_op_t | jwks_item_key_ops (const jwk_item_t *item) |
| The "key_ops" field for this JWK. | |
| const char * | jwks_item_pem (const jwk_item_t *item) |
| The PEM generated for the JWK. | |
| size_t | jwks_item_x5c_count (const jwk_item_t *item) |
| Number of certificates in the JWK x5c chain. | |
| const unsigned char * | jwks_item_x5c (const jwk_item_t *item, size_t index, size_t *len) |
| Get a certificate from the JWK x5c chain (DER). | |
| const char * | jwks_item_x5t (const jwk_item_t *item) |
| The JWK x5t (SHA-1 certificate thumbprint). | |
| const char * | jwks_item_x5t_s256 (const jwk_item_t *item) |
| The JWK x5t#S256 (SHA-256 certificate thumbprint). | |
| char * | jwks_item_export (const jwk_item_t *item, int priv) |
| Serialize a single JWK item to a JWK JSON string. | |
| char * | jwks_export (const jwk_set_t *jwk_set, int priv) |
| Serialize a whole keyring to a JWKS JSON string. | |
| char * | jwks_item_thumbprint (const jwk_item_t *item, jwk_thumbprint_alg_t alg) |
| Compute the JWK Thumbprint of a key. | |
| char * | jwks_item_thumbprint_uri (const jwk_item_t *item, jwk_thumbprint_alg_t alg) |
| Compute the JWK Thumbprint URI of a key. | |
| jwk_item_t * | jwks_find_bythumbprint (jwk_set_t *jwk_set, jwk_thumbprint_alg_t alg, const char *thumbprint) |
| Find a key in a set by its JWK Thumbprint. | |
| jwk_item_t * | jwks_find_bythumbprint_uri (jwk_set_t *jwk_set, const char *uri) |
| Find a key in a set by its JWK Thumbprint URI. | |
| int | jwks_item_key_oct (const jwk_item_t *item, const unsigned char **buf, size_t *len) |
| Retrieve binary octet data of a key. | |
| int | jwks_item_key_bits (const jwk_item_t *item) |
| The number of bits in this JWK. | |
| int | jwks_item_free (jwk_set_t *jwk_set, size_t index) |
| Free remove and free the nth jwk_item_t in a jwk_set. | |
| int | jwks_item_free_all (jwk_set_t *jwk_set) |
| Remove and free all jwk_item_t in a jwk_set_t. | |
| int | jwks_item_free_bad (jwk_set_t *jwk_set) |
| Free all keys marked with an error in a jwk_set_t. | |
| size_t | jwks_item_count (const jwk_set_t *jwk_set) |
| Return the number of keys in a jwk_set_t. | |
Inspect and use individual JWK items from a keyring.
Functionality for using a JWK (represented as a jwk_item_t) to sign and validate JWT objects.
| typedef struct jwk_item jwk_item_t |
Object representation of a JWK.
This object is produced by importing a JWK or JWKS into a jwk_set_t object. It represents single key and is used when generating or verifying JWT.
| enum jwk_key_op_t |
Allowed key operations for JWK private keys.
Corresponds to the "key_ops" attribute in a JWK that represents a private key. These can be bitwise compares to the key_ops attribute of a jwk_item_t. These flags are used internally to decide if a JWK can be used for certain operations.
| enum jwk_key_type_t |
JWK Key Types.
Corresponds to the "kty" attribute of the JWK.
RFC-7517 Sec 4.1 RFC-7518 Sec 6.1
| Enumerator | |
|---|---|
| JWK_KEY_TYPE_NONE | Unused on valid keys |
| JWK_KEY_TYPE_EC | Elliptic Curve keys |
| JWK_KEY_TYPE_RSA | RSA keys (RSA and RSA-PSS) |
| JWK_KEY_TYPE_OKP | Octet Key Pair (e.g. EdDSA) |
| JWK_KEY_TYPE_OCT | Octet sequence (e.g. HS256) |
| JWK_KEY_TYPE_AKP | Algorithm Key Pair (e.g. ML-DSA) RFC-9964 Sec 3
|
| enum jwk_pub_key_use_t |
| char * jwks_export | ( | const jwk_set_t * | jwk_set, |
| int | priv ) |
Serialize a whole keyring to a JWKS JSON string.
Produces a JWK Set (an object with a "keys" array) containing every item in the set.
| jwk_set | An existing jwk_set_t |
| priv | If non-zero, include private key parameters for private keys. If zero, only public parameters are emitted. |
| jwk_item_t * jwks_find_bykid | ( | jwk_set_t * | jwk_set, |
| const char * | kid ) |
Find a jwk_item_t with a specific kid (Key ID).
LibJWT does not ensure that kid's are unique in a given keyring, so care must be taken. This will return the first match.
| jwk_set | An existing jwk_set_t |
| kid | String representing a kid to find |
| jwk_item_t * jwks_find_bythumbprint | ( | jwk_set_t * | jwk_set, |
| jwk_thumbprint_alg_t | alg, | ||
| const char * | thumbprint ) |
Find a key in a set by its JWK Thumbprint.
📄 RFC-7638
Returns the first item in jwk_set whose thumbprint (for the given hash) equals thumbprint. Unlike jwks_find_bykid(), this matches on the key's canonical, deterministic identity rather than the advisory "kid", so it works even when keys carry no (or an inconsistent) "kid" — e.g. matching a proof-of-possession "cnf"/ against a set of known keys."jkt" value
| jwk_set | An existing jwk_set_t |
| alg | The hash used to produce thumbprint (see jwk_thumbprint_alg_t) |
| thumbprint | A base64url JWK thumbprint, as from jwks_item_thumbprint() |
| jwk_item_t * jwks_find_bythumbprint_uri | ( | jwk_set_t * | jwk_set, |
| const char * | uri ) |
Find a key in a set by its JWK Thumbprint URI.
📄 RFC-9278
As jwks_find_bythumbprint(), but takes the RFC 9278 URI form ("urn:ietf:params:oauth:jwk-thumbprint:sha-256:<thumbprint>"); the hash is taken from the URI's sha-NNN label.
| jwk_set | An existing jwk_set_t |
| uri | A JWK Thumbprint URI, as from jwks_item_thumbprint_uri() |
| jwt_alg_t jwks_item_alg | ( | const jwk_item_t * | item | ) |
The algorithm for this JWK.
It is perfectly valid for this to be JWT_ALG_NONE.
| item | A JWK Item |
| size_t jwks_item_count | ( | const jwk_set_t * | jwk_set | ) |
Return the number of keys in a jwk_set_t.
| jwk_set | Pointer to a JWKS object |
| const char * jwks_item_curve | ( | const jwk_item_t * | item | ) |
A curve name, if applicable, for this key.
Mainly applies to EC and OKP (EdDSA) type keys.
| item | A JWK Item |
| int jwks_item_error | ( | const jwk_item_t * | item | ) |
Check the error condition for this JWK.
| item | A JWK Item |
| const char * jwks_item_error_msg | ( | const jwk_item_t * | item | ) |
Check the error message for a JWK Item.
| item | A JWK Item |
| char * jwks_item_export | ( | const jwk_item_t * | item, |
| int | priv ) |
Serialize a single JWK item to a JWK JSON string.
Produces the JSON Web Key representation of this item. This is the serialization counterpart to the jwks_load_fromkey() import path.
| item | A JWK Item |
| priv | If non-zero, include private key parameters when the item is a private key. If zero, only public parameters are emitted. |
| int jwks_item_free | ( | jwk_set_t * | jwk_set, |
| size_t | index ) |
Free remove and free the nth jwk_item_t in a jwk_set.
| jwk_set | Pointer to a JWKS object |
| index | the position of the item in the index |
| int jwks_item_free_all | ( | jwk_set_t * | jwk_set | ) |
Remove and free all jwk_item_t in a jwk_set_t.
The jwk_set_t becomes an empty set.
| jwk_set | Pointer to a JWKS object |
| int jwks_item_free_bad | ( | jwk_set_t * | jwk_set | ) |
| const jwk_item_t * jwks_item_get | ( | const 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, which 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 |
| int jwks_item_is_private | ( | const jwk_item_t * | item | ) |
Whether this key is private (or public).
| item | A JWK Item |
| int jwks_item_key_bits | ( | const jwk_item_t * | item | ) |
The number of bits in this JWK.
This is relevant to the key type (kty). E.g. an RSA key would have at least 2048 bits, and an EC key would be 256, 384, or 521 bits, etc.
| item | A JWK Item |
| int jwks_item_key_oct | ( | const jwk_item_t * | item, |
| const unsigned char ** | buf, | ||
| size_t * | len ) |
Retrieve binary octet data of a key.
Only valid for JWT_KEY_TYPE_OCT.
| item | A JWK Item |
| buf | Pointer to a pointer buffer |
| len | Pointer to a length |
buf will point to data of len length. Non-zero on error. | jwk_key_op_t jwks_item_key_ops | ( | const jwk_item_t * | item | ) |
The "key_ops" field for this JWK.
| item | A JWK Item |
| const char * jwks_item_kid | ( | const jwk_item_t * | item | ) |
A kid (Key ID) for this JWK.
| item | A JWK Item |
| jwk_key_type_t jwks_item_kty | ( | const jwk_item_t * | item | ) |
The Key Type of this JWK.
| item | A JWK Item |
| const char * jwks_item_pem | ( | const jwk_item_t * | item | ) |
The PEM generated for the JWK.
This is an optional field that may or may not be supported depending on which crypto backend is in use. It is provided as a courtesy.
| item | A JWK Item |
| char * jwks_item_thumbprint | ( | const jwk_item_t * | item, |
| jwk_thumbprint_alg_t | alg ) |
Compute the JWK Thumbprint of a key.
Produces the base64url-encoded SHA-2 digest of the key's canonical JWK form: a JSON object containing only the members required for the key type, with no whitespace and the member names in lexicographic order. The result is a stable, deterministic fingerprint of the (public) key parameters, commonly used as a key id ("kid") or as the "jkt" confirmation value.
The thumbprint is computed over public parameters and is identical whether the item was loaded from a JWK or from a PEM/DER key.
| item | A JWK Item |
| alg | The thumbprint hash algorithm (see jwk_thumbprint_alg_t); JWK_THUMBPRINT_SHA256 is the default. |
alg). | char * jwks_item_thumbprint_uri | ( | const jwk_item_t * | item, |
| jwk_thumbprint_alg_t | alg ) |
Compute the JWK Thumbprint URI of a key.
📄 RFC-9278
As jwks_item_thumbprint(), but returns the RFC 9278 URI form: "urn:ietf:params:oauth:jwk-thumbprint:sha-256:<thumbprint>" (or sha-384 / sha-512 to match alg).
| item | A JWK Item |
| alg | The thumbprint hash algorithm (see jwk_thumbprint_alg_t); JWK_THUMBPRINT_SHA256 is the default. |
| jwk_pub_key_use_t jwks_item_use | ( | const jwk_item_t * | item | ) |
The "use" field for this JWK.
| item | A JWK Item |
| const unsigned char * jwks_item_x5c | ( | const jwk_item_t * | item, |
| size_t | index, | ||
| size_t * | len ) |
Get a certificate from the JWK x5c chain (DER).
Returns the raw DER bytes of the certificate at index in the x5c chain (index 0 is the leaf, which holds the public key matching the JWK). The bytes are owned by the JWK item and remain valid until it is freed; the caller must not free them. Certificate-chain validation is the caller's responsibility (libjwt does not build or verify the trust chain).
| item | A JWK Item |
| index | The certificate index (0 is the leaf) |
| len | If not NULL, set to the length of the DER in bytes |
index is out of range | size_t jwks_item_x5c_count | ( | const jwk_item_t * | item | ) |
Number of certificates in the JWK x5c chain.
| item | A JWK Item |
| const char * jwks_item_x5t | ( | const jwk_item_t * | item | ) |
The JWK x5t (SHA-1 certificate thumbprint).
| item | A JWK Item |
| const char * jwks_item_x5t_s256 | ( | const jwk_item_t * | item | ) |
The JWK x5t#S256 (SHA-256 certificate thumbprint).
If the JWK also carries an x5c chain, this value was verified at parse time to equal base64url(SHA-256(DER(leaf))) (RFC 7517 §4.9); a JWK whose x5t#S256 disagrees with its x5c leaf is rejected (the item carries an error).
| item | A JWK Item |