48#if COAP_OSCORE_SUPPORT
53#define OSC_MOVE_PTR(a,b) do { (a) = (b); (b) = NULL; } while(0)
56compose_info(uint8_t *buffer,
64 size_t rem_size = buf_size;
71 if (id_context !=
NULL && id_context->
length > 0) {
82 (
const char *)type->
s,
97 if (memcmp(a_ptr, b_ptr, a_len) == 0) {
106 if (c_context->p_osc_ctx) {
112 if (head == osc_ctx) {
115 while (next != head) {
116 if (next == osc_ctx) {
122 prev->
next = osc_ctx;
123 osc_ctx->
next = head;
125 c_context->p_osc_ctx = osc_ctx;
126 osc_ctx->
next = osc_ctx;
132 if (recipient ==
NULL)
188 while (c_context->p_osc_ctx) {
191 if (osc_ctx->
next == osc_ctx) {
192 c_context->p_osc_ctx =
NULL;
195 c_context->p_osc_ctx = osc_ctx->
next;
196 while (tail->
next != osc_ctx) {
199 tail->
next = c_context->p_osc_ctx;
219 if (next == osc_ctx) {
220 if (next->
next == next) {
221 c_context->p_osc_ctx =
NULL;
223 while (prev->
next != next) {
227 if (next == c_context->p_osc_ctx)
228 c_context->p_osc_ctx = next->
next;
235 }
while (next != head);
253 *recipient_ctx =
NULL;
254 assert(rcpkey_id.
length == 0 || rcpkey_id.
s !=
NULL);
264 if (rcpkey_id.
length != 0)
268 ok = ok + (memcmp(pt->
id_context->
s, oscore_r2, 8) != 0);
272 }
else if (ctxkey_id) {
280 }
else if (ctxkey_id->
length > 0)
285 *recipient_ctx = rpt;
292 }
while (pt != session->
context->p_osc_ctx);
296#define OSCORE_LOG_SIZE 16
308 coap_log(level,
" %-16s <>\n", name);
312 for (i = 0; i < value->
length; i += OSCORE_LOG_SIZE) {
313 char number[3 * OSCORE_LOG_SIZE + 4];
316 value->
length - i > OSCORE_LOG_SIZE ?
317 OSCORE_LOG_SIZE : value->length - i,
320 coap_log(level,
" %-16s %s\n", i == 0 ? name :
"", number);
327 coap_log(level,
" %-16s %2d\n", name, value);
332 coap_log(level,
" %-16s %s\n", name, value);
344 size_t space = (dst_len - 4) / 3;
347 for (qq = 0; qq < src_len && qq < space; qq++) {
348 char tmp = src[qq] >> 4;
350 tmp = tmp + 0x61 - 10;
356 tmp = tmp + 0x61 - 10;
359 dest[qq * 3 + 1] = tmp;
360 dest[qq * 3 + 2] = 0x20;
364 dest[qq * 3 + 1] =
'.';
365 dest[qq * 3 + 2] =
'.';
379 uint8_t info_buffer[80];
384 if (hkdf_tmp ==
NULL)
387 info_len = compose_info(info_buffer,
394 if (info_len == 0 || info_len >
sizeof(info_buffer)) {
412oscore_log_context(
oscore_ctx_t *osc_ctx,
const char *heading) {
413#if COAP_MAX_LOGGING_LEVEL < _COAP_LOG_OSCORE
442 snprintf(buffer,
sizeof(buffer),
"Recipient ID[%zu]", count);
446 snprintf(buffer,
sizeof(buffer),
"Recipient Key[%zu]", count);
505 oscore_log_context(osc_ctx,
"Updated Common context");
524 if (sender_ctx ==
NULL)
584 if (rcp_conf ==
NULL)
594 oscore_log_context(osc_ctx,
"New Common context");
595 oscore_enter_context(c_context, osc_ctx);
617 if (sender_ctx ==
NULL)
681 if (oscore_conf->
sender) {
704 oscore_log_context(osc_ctx,
"Common context");
706 oscore_enter_context(c_context, osc_ctx);
717 uint32_t break_key) {
722 coap_log_warn(
"oscore_add_recipient: Maximum size of recipient_id is 7 bytes\n");
736 if (rcp_ctx ==
NULL) {
793 oscore_free_recipient(next);
827 if (association ==
NULL)
907 session->associations =
NULL;
917#pragma GCC diagnostic ignored "-Wunused-function"
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)
size_t cose_nonce_len(cose_alg_t cose_alg)
size_t cose_key_len(cose_alg_t cose_alg)
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 *ctx, coap_oscore_rcp_conf_t *rcp_conf, uint32_t break_key)
oscore_add_recipient - add in recipient information
void oscore_free_sender(oscore_sender_ctx_t *snd_ctx)
coap_bin_const_t * oscore_build_key(oscore_ctx_t *osc_ctx, coap_bin_const_t *salt, coap_bin_const_t *ikm, cose_alg_t aead_alg, coap_bin_const_t *id, coap_str_const_t *type, size_t out_len)
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)
int coap_delete_oscore_rcp_conf(coap_oscore_rcp_conf_t *oscore_rcp_conf)
Release all the information associated with the OSCORE complex Recipient configuration.
#define OSCORE_ASSOCIATIONS_FIND(r, k, res)
oscore_ctx_t * oscore_find_context(const coap_session_t *session, 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)
uint8_t oscore_bytes_equal(uint8_t *a_ptr, uint8_t a_len, uint8_t *b_ptr, uint8_t b_len)
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
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.
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...
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
coap_oscore_snd_conf_t * sender
The sender - i.e.
coap_oscore_rcp_conf_t * recipient_chain
The recipients as a chain.
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.
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.
The structure used to hold the OSCORE Recipient configuration.
int silent_server
1 if server is likely to be silent else 0
coap_bin_const_t * recipient_id
Recipient ID (i.e.
struct coap_oscore_rcp_conf_t * next_recipient
Used to maintain the chain.
coap_bin_const_t * sender_id
Sender ID (i.e.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_context_t * context
session's context
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
cose_hkdf_alg_t hkdf_alg
Set to one of COSE_HKDF_ALG_*.
cose_alg_t aead_alg
Set to one of COSE_ALGORITHM_AES*.
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
uint64_t seq
Sender Sequence Number.
coap_bin_const_t * sender_key
uint64_t next_seq
Used for ssn_freq updating.