José
|
JSON Web Keys (RFC 7517) More...
Functions | |
bool | jose_jwk_gen (jose_cfg_t *cfg, json_t *jwk) |
Generates a new JWK. More... | |
bool | jose_jwk_pub (jose_cfg_t *cfg, json_t *jwk) |
Removes all private key material from a JWK. More... | |
bool | jose_jwk_prm (jose_cfg_t *cfg, const json_t *jwk, bool req, const char *op) |
Determines if an operation is permitted for a JWK. More... | |
json_t * | jose_jwk_thp (jose_cfg_t *cfg, const json_t *jwk, const char *alg) |
Calculates the thumbprint of a JWK as a URL-safe Base64 encoded JSON string. More... | |
size_t | jose_jwk_thp_buf (jose_cfg_t *cfg, const json_t *jwk, const char *alg, uint8_t *thp, size_t len) |
Calculates the thumbprint of a JWK. More... | |
json_t * | jose_jwk_exc (jose_cfg_t *cfg, const json_t *prv, const json_t *pub) |
Perform a key exchange. More... | |
JSON Web Keys (RFC 7517)
A JSON Web Key (JWS) is a standard data format for expresing cryptographic keys in JSON.
bool jose_jwk_gen | ( | jose_cfg_t * | cfg, |
json_t * | jwk | ||
) |
Generates a new JWK.
The JWK is generated using hints from the input in exactly the same format as you would find in the output. For example, the most common way to generate a key is to specify the algorithm you'd like to use the key with. For example (error handling omitted):
json_t *gen(void) { json_auto_t *jwk = json_pack("{s:s}", "alg", "ES256"); jose_jwk_gen(NULL, jwk); return json_incref(jwk); }
This method is preferred because other metadata can be inferred from the algorithm name, such as the key usage. Additionally, the algorithm metadata can be used to automatically generate correct headers when creating signatures (JWS) or encryptions (JWE). Thus, you should always default to creating keys by their algorithm usage.
However, should your requirements differ, you can also generate a key using raw parameters (again, error handling omitted):
json_t *gen(void) { json_auto_t *jwk = json_pack("{s:s,s:s}", "kty", "EC", "crv", "P-256"); jose_jwk_gen(NULL, jwk); return json_incref(jwk); } json_t *gen(void) { json_auto_t *jwk = json_pack("{s:s,s:i}", "kty", "RSA", "bits", 2048); jose_jwk_gen(NULL, jwk); return json_incref(jwk); } json_t *gen(void) { json_auto_t *jwk = json_pack("{s:s,s:i}", "kty", "oct", "bytes", 32); jose_jwk_gen(NULL, jwk); return json_incref(jwk); }
In this case, "bits" and "bytes" will be removed from the final output.
cfg | The configuration context (optional). |
jwk | The JWK to generate. |
bool jose_jwk_pub | ( | jose_cfg_t * | cfg, |
json_t * | jwk | ||
) |
Removes all private key material from a JWK.
In addition, this function will remove any key operations from the key_ops
JWK property (if present) that apply only to the private key.
This function should be used before exporting keys to third parties.
cfg | The configuration context (optional). |
jwk | The JWK to remove private keys from. |
bool jose_jwk_prm | ( | jose_cfg_t * | cfg, |
const json_t * | jwk, | ||
bool | req, | ||
const char * | op | ||
) |
Determines if an operation is permitted for a JWK.
The operation to be confirmed (op
) is always specified according to the syntax of the "key_ops" JWK property, even when the "use" property is defined on the JWK.
This function has two modes of operation. If req
is false, then JWKs which do not have any key use metadata will be approved for this operation. However, if req
is true then this metadata will be required for approval.
cfg | The configuration context (optional). |
jwk | The JWK from which to remove private keys. |
req | Whether JWK key use metadata is required or not. |
op | The opperation to seek approval for. |
json_t* jose_jwk_thp | ( | jose_cfg_t * | cfg, |
const json_t * | jwk, | ||
const char * | alg | ||
) |
Calculates the thumbprint of a JWK as a URL-safe Base64 encoded JSON string.
This function is a thin wrapper around jose_jwk_thp_buf().
cfg | The configuration context (optional). |
jwk | The JWK to calculate the thumbprint for. |
alg | The hash algorithm to use. |
size_t jose_jwk_thp_buf | ( | jose_cfg_t * | cfg, |
const json_t * | jwk, | ||
const char * | alg, | ||
uint8_t * | thp, | ||
size_t | len | ||
) |
Calculates the thumbprint of a JWK.
This function calculates the thumbprint of a JWK according to the method defined by RFC 7638.
If thp
is NULL, this function returns the size of the buffer required for the thumbprint output.
cfg | The configuration context (optional). |
jwk | The JWK to calculate the thumbprint for. |
alg | The hash algorithm to use. |
thp | The output hash buffer. |
len | The size of the output hash buffer. |
json_t* jose_jwk_exc | ( | jose_cfg_t * | cfg, |
const json_t * | prv, | ||
const json_t * | pub | ||
) |
Perform a key exchange.
The only currently implemented algorithm is ECDH.
cfg | The configuration context (optional). |
prv | The private JWK. |
pub | The public JWK. |