62 size_t rem_size = buf_size;
69 if (id_context != NULL && id_context->
length > 0) {
80 (
const char *)type->
s,
95 if (memcmp(a_ptr, b_ptr, a_len) == 0) {
104 if (c_context->p_osc_ctx) {
112 prev->
next = osc_ctx;
114 c_context->p_osc_ctx = osc_ctx;
150 while (c_context->p_osc_ctx) {
153 c_context->p_osc_ctx = osc_ctx->
next;
164 if (next == osc_ctx) {
168 c_context->p_osc_ctx = next->
next;
192 *recipient_ctx = NULL;
193 assert(rcpkey_id.
length == 0 || rcpkey_id.
s != NULL);
201 if (rcpkey_id.
length != 0)
205 ok = ok + (memcmp(pt->
id_context->
s, oscore_r2, 8) != 0);
209 }
else if (ctxkey_id) {
217 }
else if (ctxkey_id->
length > 0)
222 *recipient_ctx = rpt;
233#define OSCORE_LOG_SIZE 16
245 coap_log(level,
" %-16s <>\n", name);
257 coap_log(level,
" %-16s %s\n", i == 0 ? name :
"", number);
264 coap_log(level,
" %-16s %2d\n", name, value);
269 coap_log(level,
" %-16s %s\n", name, value);
281 size_t space = (dst_len - 4) / 3;
284 for (qq = 0; qq < src_len && qq < space; qq++) {
285 char tmp = src[qq] >> 4;
287 tmp = tmp + 0x61 - 10;
293 tmp = tmp + 0x61 - 10;
296 dest[qq * 3 + 1] = tmp;
297 dest[qq * 3 + 2] = 0x20;
301 dest[qq * 3 + 1] =
'.';
302 dest[qq * 3 + 2] =
'.';
313 uint8_t info_buffer[80];
326 if (info_len == 0 || info_len >
sizeof(info_buffer))
342#if COAP_MAX_LOGGING_LEVEL < _COAP_LOG_OSCORE
371 snprintf(buffer,
sizeof(buffer),
"Recipient ID[%zu]", count);
375 snprintf(buffer,
sizeof(buffer),
"Recipient Key[%zu]", count);
444 if (sender_ctx == NULL)
497 if (copy_rid == NULL)
524 if (sender_ctx == NULL)
601 uint32_t break_key) {
606 coap_log_warn(
"oscore_add_recipient: Maximum size of recipient_id is 7 bytes\n");
621 if (recipient_ctx == NULL)
645 recipient_ctx->
osc_ctx = osc_ctx;
650 return recipient_ctx;
698 if (association == NULL)
710 token->
length, token->
s, NULL);
718 if (association->
token == NULL)
723 if (association->
aad == NULL)
729 if (association->
nonce == NULL)
777 session->associations = NULL;
Library specific build wrapper for coap_internal.h.
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
#define COAP_OSCORE_DEFAULT_REPLAY_WINDOW
coap_log_t coap_get_log_level(void)
Get the current logging level.
#define coap_log_oscore(...)
#define coap_log_warn(...)
#define coap_log(level,...)
Logging function.
size_t oscore_cbor_put_text(uint8_t **buffer, size_t *buf_size, const char *text, size_t text_len)
size_t oscore_cbor_put_nil(uint8_t **buffer, size_t *buf_size)
size_t oscore_cbor_put_unsigned(uint8_t **buffer, size_t *buf_size, uint64_t value)
size_t oscore_cbor_put_bytes(uint8_t **buffer, size_t *buf_size, const uint8_t *bytes, size_t bytes_len)
size_t oscore_cbor_put_array(uint8_t **buffer, size_t *buf_size, size_t elements)
const char * cose_get_hkdf_alg_name(cose_hkdf_alg_t id, char *buffer, size_t buflen)
const char * cose_get_alg_name(cose_alg_t id, char *buffer, size_t buflen)
#define OSCORE_ASSOCIATIONS_ITER_SAFE(e, el, rtmp)
void oscore_convert_to_hex(const uint8_t *src, size_t src_len, char *dest, size_t dst_len)
int oscore_delete_association(coap_session_t *session, oscore_association_t *association)
oscore_recipient_ctx_t * oscore_add_recipient(oscore_ctx_t *osc_ctx, coap_bin_const_t *rid, uint32_t break_key)
oscore_add_recipient - add in recipient information
int oscore_delete_recipient(oscore_ctx_t *osc_ctx, coap_bin_const_t *rid)
#define OSCORE_ASSOCIATIONS_DELETE(r, obj)
void oscore_update_ctx(oscore_ctx_t *osc_ctx, coap_bin_const_t *id_context)
oscore_update_ctx - update a osc_ctx with a new id_context
void oscore_free_context(oscore_ctx_t *osc_ctx)
#define OSCORE_ASSOCIATIONS_ADD(r, obj)
oscore_ctx_t * oscore_derive_ctx(coap_context_t *c_context, coap_oscore_conf_t *oscore_conf)
oscore_derive_ctx - derive a osc_ctx from oscore_conf information
void oscore_free_association(oscore_association_t *association)
int oscore_hkdf(cose_hkdf_alg_t hkdf_alg, coap_bin_const_t *salt, coap_bin_const_t *ikm, uint8_t *info, size_t info_len, uint8_t *okm, size_t okm_len)
Derive the key using HKDF() function.
int oscore_new_association(coap_session_t *session, coap_pdu_t *sent_pdu, coap_bin_const_t *token, oscore_recipient_ctx_t *recipient_ctx, coap_bin_const_t *aad, coap_bin_const_t *nonce, coap_bin_const_t *partial_iv, int is_observe)
void oscore_delete_server_associations(coap_session_t *session)
void oscore_log_char_value(coap_log_t level, const char *name, const char *value)
void oscore_free_contexts(coap_context_t *c_context)
void oscore_log_hex_value(coap_log_t level, const char *name, coap_bin_const_t *value)
void oscore_log_int_value(coap_log_t level, const char *name, int value)
oscore_ctx_t * oscore_duplicate_ctx(coap_context_t *c_context, oscore_ctx_t *o_osc_ctx, coap_bin_const_t *sender_id, coap_bin_const_t *recipient_id, coap_bin_const_t *id_context)
oscore_duplicate_ctx - duplicate a osc_ctx
int oscore_remove_context(coap_context_t *c_context, oscore_ctx_t *osc_ctx)
oscore_association_t * oscore_find_association(coap_session_t *session, coap_bin_const_t *token)
oscore_ctx_t * oscore_find_context(const coap_context_t *c_context, const coap_bin_const_t rcpkey_id, const coap_bin_const_t *ctxkey_id, uint8_t *oscore_r2, oscore_recipient_ctx_t **recipient_ctx)
oscore_find_context - Locate recipient context (and hence OSCORE context)
#define OSCORE_ASSOCIATIONS_FIND(r, k, res)
#define CONTEXT_INIT_VECT_LEN
uint8_t oscore_bytes_equal(uint8_t *a_ptr, uint8_t a_len, uint8_t *b_ptr, uint8_t b_len)
coap_pdu_t * coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options)
Duplicate an existing PDU.
void coap_delete_pdu(coap_pdu_t *pdu)
Dispose of an CoAP PDU and frees associated storage.
int coap_get_data(const coap_pdu_t *pdu, size_t *len, const uint8_t **data)
Retrieves the length and data pointer of specified PDU.
int coap_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
coap_str_const_t * coap_make_str_const(const char *string)
Take the specified byte array (text) and create a coap_str_const_t *.
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
static void oscore_log_context(oscore_ctx_t *osc_ctx, const char *heading)
static void oscore_free_recipient(oscore_recipient_ctx_t *recipient)
static coap_bin_const_t * oscore_build_key(oscore_ctx_t *osc_ctx, coap_bin_const_t *id, coap_str_const_t *type, size_t out_len)
static void oscore_enter_context(coap_context_t *c_context, oscore_ctx_t *osc_ctx)
static size_t compose_info(uint8_t *buffer, size_t buf_size, uint8_t alg, coap_bin_const_t *id, coap_bin_const_t *id_context, coap_str_const_t *type, size_t out_len)
CoAP binary data definition with const data.
size_t length
length of binary data
const uint8_t * s
read-only binary data
The CoAP stack's global state is stored in a coap_context_t object.
The structure used to hold the OSCORE configuration information.
void * save_seq_num_func_param
Passed to save_seq_num_func()
uint32_t rfc8613_b_2
1 if rfc8613 B.2 protocol else 0
cose_hkdf_alg_t hkdf_alg
Set to one of COSE_HKDF_ALG_*.
uint32_t break_sender_key
1 if sender key to be broken, else 0
uint32_t ssn_freq
Sender Seq Num update frequency.
coap_oscore_save_seq_num_t save_seq_num_func
Called every seq num change.
uint32_t rfc8613_b_1_2
1 if rfc8613 B.1.2 enabled else 0
uint64_t start_seq_num
Used for ssn_freq updating.
coap_bin_const_t * sender_id
Sender ID (i.e.
coap_bin_const_t ** recipient_id
Recipient ID (i.e.
uint32_t break_recipient_key
1 if recipient key to be broken, else 0
coap_bin_const_t * master_secret
Common Master Secret.
cose_alg_t aead_alg
Set to one of COSE_ALGORITHM_AES*.
coap_bin_const_t * master_salt
Common Master Salt.
uint32_t replay_window
Replay window size Use COAP_OSCORE_DEFAULT_REPLAY_WINDOW.
coap_bin_const_t * id_context
Common ID context.
uint32_t recipient_id_count
Number of recipient_id entries.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
CoAP string data definition with const data.
const uint8_t * s
read-only string data
size_t length
length of string
coap_bin_const_t * obs_partial_iv
coap_bin_const_t * partial_iv
oscore_recipient_ctx_t * recipient_ctx
coap_bin_const_t * master_secret
uint32_t replay_window_size
coap_bin_const_t * common_iv
Derived from Master Secret, Master Salt, and ID Context.
struct oscore_ctx_t * next
uint8_t rfc8613_b_1_2
1 if rfc8613 B.1.2 enabled else 0
void * save_seq_num_func_param
Passed to save_seq_num_func()
oscore_sender_ctx_t * sender_context
uint8_t rfc8613_b_2
1 if rfc8613 B.2 protocol else 0
coap_bin_const_t * master_salt
coap_oscore_save_seq_num_t save_seq_num_func
Called every seq num change.
oscore_recipient_ctx_t * recipient_chain
coap_bin_const_t * id_context
contains GID in case of group
uint32_t ssn_freq
Sender Seq Num update frequency.
oscore_recipient_ctx_t * next_recipient
coap_bin_const_t * recipient_key
coap_bin_const_t * recipient_id
coap_bin_const_t * sender_id
coap_bin_const_t * sender_key
uint64_t next_seq
Used for ssn_freq updating.