Skip to content

Commit

Permalink
fix merge mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanHri committed Nov 16, 2023
1 parent 2239652 commit 43182fe
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions inc/common/oscore_edhoc_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum err {
cbor_decoding_error = 120,
suites_i_list_to_long = 121,
xor_error = 122,
suites_i_list_empty = 123,

/*OSCORE specific errors*/
not_oscore_pkt = 200,
Expand Down
7 changes: 7 additions & 0 deletions inc/oscore/security_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,11 @@ enum err update_request_piv_request_kid(struct context *c,
struct byte_array *piv,
struct byte_array *kid);

/**
* @brief Check if given security context is still safe to be used, or a new one must be established.
* For more info, refer to RFC 8613 p. 7.2.1.
* @param c security context.
* @return enum err
*/
enum err check_context_freshness(struct context *c);
#endif
2 changes: 2 additions & 0 deletions makefile_config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ UNIT_TEST += -DUNIT_TEST
# currently only ZCBOR is supported
CBOR_ENGINE += -DZCBOR

# Uncomment to enable Non-volatile memory (NVM) support for storing security context between device reboots
OSCORE_NVM_SUPPORT += -DOSCORE_NVM_SUPPORT

################################################################################
# RAM optimization
Expand Down
44 changes: 44 additions & 0 deletions src/oscore/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,47 @@ enum err echo_val_is_fresh(struct byte_array *cache_val,

return no_echo_option;
}


enum err uri_path_create(struct o_coap_option *options, uint32_t options_size,
uint8_t *uri_path, uint32_t *uri_path_size)
{
if ((NULL == options) || (NULL == uri_path) ||
(NULL == uri_path_size)) {
return wrong_parameter;
}

uint32_t current_size = 0;
uint32_t max_size = *uri_path_size;
memset(uri_path, 0, max_size);

const uint8_t delimiter = '/';
const uint32_t delimiter_size = 1;

for (uint32_t index = 0; index < options_size; index++) {
struct o_coap_option *option = &options[index];
if (URI_PATH != option->option_number) {
continue;
}
if ((0 != option->len) && (NULL == option->value)) {
return oscore_wrong_uri_path;
}

TRY(buffer_append(uri_path, &current_size, max_size,
option->value, option->len));
TRY(buffer_append(uri_path, &current_size, max_size, &delimiter,
delimiter_size));
}

/* Remove last '/' character, or add a single one if the path is empty */
if (current_size > 0) {
uri_path[current_size] = 0;
current_size--;
} else {
uri_path[0] = delimiter;
current_size = delimiter_size;
}

*uri_path_size = current_size;
return ok;
}
15 changes: 8 additions & 7 deletions src/oscore/oscore_interactions.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void print_interaction_field(const char *name, uint8_t *buffer,
PRINTF("%02x ", buffer[index]);
}
}
PRINTF("\n");
PRINT_MSG("\n");
}

/**
Expand Down Expand Up @@ -286,7 +286,8 @@ enum err oscore_interactions_read_wrapper(
/* Server sends / Client receives any response (notification included) - read the record from interactions array and update request_piv and request_kid. */
struct oscore_interaction_t *record;
TRY(oscore_interactions_get_record(interactions, token->ptr,
token->len, &record));
(uint8_t)token->len,
&record));
request_piv->ptr = record->request_piv;
request_piv->len = record->request_piv_len;
request_kid->ptr = record->request_kid;
Expand Down Expand Up @@ -316,10 +317,10 @@ enum err oscore_interactions_update_wrapper(
/* Server receives / client sends any request (including registration and cancellation) - add the record to the interactions array.
Request_piv and request_kid not updated - current values of PIV and KID (Sender ID) are used. */
struct oscore_interaction_t record = {
.request_piv_len = request_piv->len,
.request_kid_len = request_kid->len,
.token_len = token->len,
.uri_paths_len = uri_paths->len,
.request_piv_len = (uint8_t)request_piv->len,
.request_kid_len = (uint8_t)request_kid->len,
.token_len = (uint8_t)token->len,
.uri_paths_len = (uint8_t)uri_paths->len,
.request_type = msg_type
};
TRY(_memcpy_s(record.request_piv, MAX_PIV_LEN, request_piv->ptr,
Expand All @@ -335,7 +336,7 @@ enum err oscore_interactions_update_wrapper(
/* Server sends / client receives a regular response - remove the record. */
//TODO removing records must be taken into account when No-Response support will be added.
TRY(oscore_interactions_remove_record(interactions, token->ptr,
token->len));
(uint8_t)token->len));
}

return ok;
Expand Down

0 comments on commit 43182fe

Please sign in to comment.