|
libwebsockets
Lightweight C library for HTML5 websockets
|
#include <lws-cose.h>
Go to the source code of this file.
Data Structures | |
| struct | lws_cose_key |
| struct | lws_cose_validate_res_t |
| struct | lws_cose_sig_ext_pay_t |
| struct | lws_cose_validate_create_info |
| struct | lws_cose_sign_create_info |
Macros | |
| #define | LCSC_FL_ADD_CBOR_TAG (1 << 0) |
| #define | LCSC_FL_ADD_CBOR_PREFER_MAC0 (1 << 1) |
Typedefs | |
| typedef int64_t | cose_param_t |
| typedef struct lws_cose_key | lws_cose_key_t |
| typedef int(* | lws_cose_key_import_callback) (struct lws_cose_key *s, void *user) |
| typedef int(* | lws_cose_sign_ext_pay_cb_t) (lws_cose_sig_ext_pay_t *x) |
| typedef int(* | lws_cose_validate_pay_cb_t) (struct lws_cose_validate_context *cps, void *opaque, const uint8_t *paychunk, size_t paychunk_len) |
| typedef struct lws_cose_validate_create_info | lws_cose_validate_create_info_t |
| typedef struct lws_cose_sign_create_info | lws_cose_sign_create_info_t |
| struct lws_cose_validate_res_t |
Definition at line 373 of file lws-cose.h.
| Data Fields | ||
|---|---|---|
| lws_dll2_t | list | |
| const lws_cose_key_t * | cose_key | |
| cose_param_t | cose_alg | |
| int | result | |
| struct lws_cose_sig_ext_pay_t |
Definition at line 389 of file lws-cose.h.
| Data Fields | ||
|---|---|---|
| struct lws_cose_validate_context * | cps | |
| const uint8_t * | ext | |
| size_t | xl | |
| struct lws_cose_validate_create_info |
Definition at line 400 of file lws-cose.h.
| Data Fields | ||
|---|---|---|
| struct lws_context * | cx |
REQUIRED: the lws context |
| lws_dll2_owner_t * | keyset |
REQUIRED: one or more cose_keys |
| enum lws_cose_sig_types | sigtype |
0 if a CBOR tag is in the sig, else one of SIGTYPE_MULTI, SIGTYPE_SINGLE, etc |
| lws_cose_validate_pay_cb_t | pay_cb |
optional: called back with unvalidated payload pieces |
| void * | pay_opaque |
optional: passed into pay_cb callback along with payload chunk |
| lws_cose_sign_ext_pay_cb_t | ext_cb |
optional extra application data provision callback |
| void * | ext_opaque |
optional extra application data provision callback opaque |
| size_t | ext_len |
if we have extra app data, this must be set to the length of it |
| struct lws_cose_sign_create_info |
Definition at line 475 of file lws-cose.h.
| Data Fields | ||
|---|---|---|
| struct lws_context * | cx |
REQUIRED: the lws context |
| lws_dll2_owner_t * | keyset |
REQUIRED: one or more cose_keys |
| lws_lec_pctx_t * | lec |
REQUIRED: the cbor output context to emit to, user must initialize with lws_lec_init() beforehand |
| lws_cose_sign_ext_pay_cb_t | ext_cb |
optional extra application data provision callback |
| void * | ext_opaque |
optional extra application data provision callback opaque |
| size_t | ext_len |
if we have extra app data, this must be set to the length of it |
| size_t | inline_payload_len |
REQUIRED: size of the inline payload we will provide |
| int | flags |
bitmap of LCSC_FL_* |
| enum lws_cose_sig_types | sigtype |
0, or sign type hint |
| #define LCSC_FL_ADD_CBOR_TAG (1 << 0) |
Definition at line 472 of file lws-cose.h.
| #define LCSC_FL_ADD_CBOR_PREFER_MAC0 (1 << 1) |
Definition at line 473 of file lws-cose.h.
| typedef int64_t cose_param_t |
Definition at line 259 of file lws-cose.h.
| typedef struct lws_cose_key lws_cose_key_t |
| typedef int(* lws_cose_key_import_callback) (struct lws_cose_key *s, void *user) |
Definition at line 284 of file lws-cose.h.
| typedef int(* lws_cose_sign_ext_pay_cb_t) (lws_cose_sig_ext_pay_t *x) |
Definition at line 395 of file lws-cose.h.
| typedef int(* lws_cose_validate_pay_cb_t) (struct lws_cose_validate_context *cps, void *opaque, const uint8_t *paychunk, size_t paychunk_len) |
Definition at line 396 of file lws-cose.h.
| typedef struct lws_cose_validate_create_info lws_cose_validate_create_info_t |
| typedef struct lws_cose_sign_create_info lws_cose_sign_create_info_t |
| anonymous enum |
Definition at line 33 of file lws-cose.h.
| Enumerator | |
|---|---|
| COSEKEY_META_KTY | |
| COSEKEY_META_KID | |
| COSEKEY_META_KEY_OPS | |
| COSEKEY_META_BASE_IV | |
| COSEKEY_META_ALG | |
| LWS_COUNT_COSE_KEY_ELEMENTS | |
Definition at line 249 of file lws-cose.h.
| enum lws_cose_sig_types |
| Enumerator | |
|---|---|
| SIGTYPE_UNKNOWN | |
| SIGTYPE_MULTI | |
| SIGTYPE_SINGLE | |
| SIGTYPE_COUNTERSIGNED | |
| SIGTYPE_MAC | |
| SIGTYPE_MAC0 | |
Definition at line 362 of file lws-cose.h.
| anonymous enum |
| Enumerator | |
|---|---|
| LCOSESIGEXTCB_RET_FINISHED | |
| LCOSESIGEXTCB_RET_AGAIN | |
| LCOSESIGEXTCB_RET_ERROR | |
Definition at line 383 of file lws-cose.h.
| LWS_VISIBLE LWS_EXTERN const char * lws_cose_alg_to_name | ( | cose_param_t | alg | ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN cose_param_t lws_cose_name_to_alg | ( | const char * | name | ) |
| LWS_VISIBLE LWS_EXTERN lws_cose_key_t * lws_cose_key_import | ( | lws_dll2_owner_t * | pkey_set, |
| lws_cose_key_import_callback | cb, | ||
| void * | user, | ||
| const uint8_t * | in, | ||
| size_t | len ) |
lws_cose_jwk_import() - Create an lws_cose_key_t object from cose_key CBOR
| pkey_set | NULL, or a pointer to an lws_dll2_owner_t for a cose_key set |
| cb | NULL, or a callback for each key of a key set as it is imported. It must not unlink or destroy the key; returning nonzero halts the import, which then fails as a whole. |
| user | pointer to be passed to the callback, otherwise ignored by lws. NULL if importing a single key with no parent "keys" JSON |
| in | a single cose_key |
| len | the length of the cose_key in bytes |
Creates a single lws_cose_key_t if pkey_set is NULL or if the incoming CBOR doesn't start with an array, otherwise expects a CBOR array containing zero or more cose_key CBOR, and adds each to the pkey_set lws_dll2_owner_t struct. Created lws_cose_key_t are filled with data from the COSE representation and can be used with other COSE crypto ops.
pkey_set may already hold keys, eg, from an earlier import: the imported keys are added after them, and a key whose kid is already in the set fails the import. The import is all or nothing... if it fails, or the set is empty, none of its keys are added and the keys already in pkey_set are left as they were.
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN enum lws_lec_pctx_ret lws_cose_key_export | ( | lws_cose_key_t * | ck, |
| lws_lec_pctx_t * | ctx, | ||
| int | flags ) |
lws_cose_key_export() - Create cose_key CBOR from an lws_cose_key_t
| ck | the lws_cose_key_t to export to CBOR |
| ctx | the CBOR writing context (same as for lws_lec_printf()) |
| flags | 0 to export only public elements, or LWSJWKF_EXPORT_PRIVATE |
Creates an lws_jwk struct filled with data from the COSE representation.
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN lws_cose_key_t * lws_cose_key_generate | ( | struct lws_context * | context, |
| cose_param_t | cose_kty, | ||
| int | use_mask, | ||
| int | bits, | ||
| const char * | curve, | ||
| const uint8_t * | kid, | ||
| size_t | kl ) |
lws_cose_key_generate() - generate a fresh key
| context | the lws_context used to get random |
| cose_kty | one of LWSCOSE_WKKTV_ indicating the well-known key type |
| use_mask | 0, or a bitfield where (1 << LWSCOSE_WKKO_...) set means valid for use |
| bits | key bits for RSA |
| curve | for EC keys, one of "P-256", "P-384" or "P-521" currently |
| kid | string describing the key, or NULL |
Create an lws_cose_key_t of the specified type and return it
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN lws_cose_key_t * lws_cose_key_from_set | ( | lws_dll2_owner_t * | set, |
| const uint8_t * | kid, | ||
| size_t | kl ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN void lws_cose_key_destroy | ( | lws_cose_key_t ** | ck | ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN void lws_cose_key_set_destroy | ( | lws_dll2_owner_t * | o | ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN void lws_cose_key_dump | ( | const lws_cose_key_t * | ck | ) |
| LWS_VISIBLE LWS_EXTERN struct lws_cose_validate_context * lws_cose_validate_create | ( | const lws_cose_validate_create_info_t * | info | ) |
lws_cose_validate_create() - create a signature validation context
| info | struct describing the validation context to create |
Creates a signature validation context set up as described in info.
You can then pass the signature cbor chunks to it using lws_cose_validate_chunk(), finialize and get the results list using lws_cose_validate_results() and destroy with lws_cose_validate_destroy().
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN int lws_cose_validate_chunk | ( | struct lws_cose_validate_context * | cps, |
| const uint8_t * | in, | ||
| size_t | in_len, | ||
| size_t * | used_in ) |
lws_cose_validate_chunk() - passes chunks of CBOR into the signature validator
| cps | the validation context |
| in | the chunk of CBOR (does not have to be logically complete) |
| in_len | number of bytes available at in |
| used_in | NULL, or set to how much of in was used |
Parses signature CBOR to produce a list of result objects.
Returns 0 when the COSE object is complete and produced at least one result object, which you then assess via lws_cose_validate_results().
Returns LECP_CONTINUE (-1) when the object is not complete yet: pass the next chunk. If your input ends while this is the last return, the object was truncated: the results list only holds whatever results were produced before the input ran out, which may already include passing ones, and the object must be treated as not validated.
Any other return (one of the LECP_REJECT_ codes) means the object could not be validated, including LECP_REJECT_CALLBACK for a complete object that did not produce a single result.
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN lws_dll2_owner_t * lws_cose_validate_results | ( | struct lws_cose_validate_context * | cps | ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN void lws_cose_validate_destroy | ( | struct lws_cose_validate_context ** | cps | ) |
| LWS_VISIBLE LWS_EXTERN struct lws_cose_sign_context * lws_cose_sign_create | ( | const lws_cose_sign_create_info_t * | info | ) |
lws_cose_sign_create() - Create a signing context
| info | a structure describing the signing context you want to create |
This allocates and returns a signing context created according to what is in the info parameter.
info must be prepared with the lws_context, a keyset to use, a CBOR output context, and the inline payload length.
Returns NULL on failure or the created signing context ready to add alg(s) to.
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN int lws_cose_sign_add | ( | struct lws_cose_sign_context * | csc, |
| cose_param_t | alg, | ||
| const lws_cose_key_t * | ck ) |
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN enum lws_lec_pctx_ret lws_cose_sign_payload_chunk | ( | struct lws_cose_sign_context * | csc, |
| const uint8_t * | in, | ||
| size_t | in_len ) |
lws_cose_sign_payload_chunk() - pass inline payload in, get the signed object out
| csc | the signing context |
| in | the current chunk of the inline payload |
| in_len | number of bytes available at in |
The payload may be passed in any number of chunks of any size, adding up to exactly the create info's inline_payload_len. The signed object is emitted into the create info's lec output context, which may be much smaller than the payload.
Returns LWS_LECPCTX_RET_AGAIN if the output filled: drain lec.used bytes from it, reset it with lws_lec_setbuf(), and call again with the same in and in_len, the signing context tracks how much of that chunk it already took. Returns LWS_LECPCTX_RET_FINISHED when all of in was used: drain the output, then either call again with the next payload chunk, or, if that was the last chunk, the object is complete. LWS_LECPCTX_RET_FAIL means the signing failed, or the chunks exceeded inline_payload_len, and the object must not be used.
References LWS_EXTERN, and LWS_VISIBLE.
| LWS_VISIBLE LWS_EXTERN void lws_cose_sign_destroy | ( | struct lws_cose_sign_context ** | csc | ) |