Skip to content

Commit

Permalink
Update for primary commit #9 (to be squashed later)
Browse files Browse the repository at this point in the history
Use new coap_log_debug() etc. in OSCORE specific code.
  • Loading branch information
mrdeep1 committed Dec 9, 2022
1 parent 2e05d29 commit e8ce092
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions examples/oscore-interop-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,14 @@ get_context(const char *node, const char *port) {

ep_udp = coap_new_endpoint(ctx, &addr, COAP_PROTO_UDP);
if (!ep_udp) {
coap_log(LOG_CRIT, "cannot create UDP endpoint\n");
coap_log_crit("cannot create UDP endpoint\n");
continue;
}
if (coap_tcp_is_supported()) {
coap_endpoint_t *ep_tcp;
ep_tcp = coap_new_endpoint(ctx, &addr, COAP_PROTO_TCP);
if (!ep_tcp) {
coap_log(LOG_CRIT, "cannot create TCP endpoint\n");
coap_log_crit("cannot create TCP endpoint\n");
}
}
if (ep_udp)
Expand Down Expand Up @@ -715,7 +715,7 @@ main(int argc, char **argv) {
result = select (nfds, &readfds, NULL, NULL, &tv);
if (result == -1) {
if (errno != EAGAIN) {
coap_log(LOG_DEBUG, "select: %s (%d)\n", coap_socket_strerror(),
coap_log_debug("select: %s (%d)\n", coap_socket_strerror(),
errno);
break;
}
Expand Down
56 changes: 28 additions & 28 deletions src/coap_oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ coap_oscore_initiate(coap_session_t *session, coap_oscore_conf_t *oscore_conf) {
oscore_ctx_t *osc_ctx;

if (oscore_conf->recipient_id_count == 0) {
coap_log(LOG_WARNING,
coap_log_warn(
"OSCORE: Recipient ID must be defined for a client\n");
return 0;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ coap_rebuild_pdu_for_proxy(coap_pdu_t *pdu) {
if (coap_split_proxy_uri(keep_proxy_uri,
coap_opt_length(option),
&uri) < 0 || uri.scheme >= COAP_URI_SCHEME_LAST) {
coap_log(LOG_WARNING,
coap_log_warn(
"Proxy URI '%.*s' not decodable\n",
coap_opt_length(option),
(const char *)coap_opt_value(option));
Expand Down Expand Up @@ -310,7 +310,7 @@ coap_oscore_new_pdu_encrypted(coap_session_t *session,
if (coap_check_option(pdu, COAP_OPTION_OBSERVE, &opt_iter))
doing_observe = 1;

coap_log(LOG_DEBUG, "PDU to encrypt\n");
coap_log_debug("PDU to encrypt\n");
coap_show_pdu(LOG_DEBUG, pdu);
osc_pdu = coap_pdu_init(pdu->type == COAP_MESSAGE_NON &&
session->b_2_step != COAP_OSCORE_B_2_NONE ?
Expand Down Expand Up @@ -797,7 +797,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
return NULL;

if (session->context->p_osc_ctx == NULL) {
coap_log(LOG_WARNING, "OSCORE: Not enabled\n");
coap_log_warn("OSCORE: Not enabled\n");
if (!coap_request)
coap_handle_event(session->context,
COAP_EVENT_OSCORE_NOT_ENABLED,
Expand All @@ -806,7 +806,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
}

if (pdu->data == NULL) {
coap_log(LOG_WARNING, "OSCORE: No protected payload\n");
coap_log_warn("OSCORE: No protected payload\n");
if (!coap_request)
coap_handle_event(session->context,
COAP_EVENT_OSCORE_NO_PROTECTED_PAYLOAD,
Expand Down Expand Up @@ -886,7 +886,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
* Get Recipient Context based on kid and optional kid_context
*/
if (oscore_decode_option_value(osc_value, osc_size, cose) == 0) {
coap_log(LOG_WARNING, "OSCORE: OSCORE Option cannot be decoded.\n");
coap_log_warn("OSCORE: OSCORE Option cannot be decoded.\n");
build_and_send_error_pdu(session,
pdu,
COAP_RESPONSE_CODE(402),
Expand Down Expand Up @@ -958,7 +958,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
coap_log_oscore("Appendix B.2 server finished\n");
}
if (!osc_ctx) {
coap_log(LOG_CRIT, "OSCORE: Security Context not found\n");
coap_log_crit("OSCORE: Security Context not found\n");
oscore_log_hex_value(COAP_LOG_OSCORE, "key_id", &cose->key_id);
oscore_log_hex_value(COAP_LOG_OSCORE, "kid_context", &cose->kid_context);
build_and_send_error_pdu(session,
Expand All @@ -983,7 +983,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
*/
if (rcp_ctx->initial_state == 0 &&
!oscore_validate_sender_seq(rcp_ctx, cose)) {
coap_log(LOG_WARNING, "OSCORE: Replayed or old message\n");
coap_log_warn("OSCORE: Replayed or old message\n");
build_and_send_error_pdu(session,
pdu,
COAP_RESPONSE_CODE(401),
Expand All @@ -1004,7 +1004,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
* Get Recipient Context based on token
*/
if (oscore_decode_option_value(osc_value, osc_size, cose) == 0) {
coap_log(LOG_WARNING, "OSCORE: OSCORE Option cannot be decoded.\n");
coap_log_warn("OSCORE: OSCORE Option cannot be decoded.\n");
coap_handle_event(session->context,
COAP_EVENT_OSCORE_DECODE_ERROR,
session);
Expand Down Expand Up @@ -1059,7 +1059,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
}
#endif /* COAP_CLIENT_SUPPORT */
} else {
coap_log(LOG_CRIT, "OSCORE: Security Context association not found\n");
coap_log_crit("OSCORE: Security Context association not found\n");
coap_handle_event(session->context,
COAP_EVENT_OSCORE_NO_SECURITY,
session);
Expand Down Expand Up @@ -1176,13 +1176,13 @@ coap_oscore_decrypt_pdu(coap_session_t *session,

if (rcp_ctx->initial_state == 0 &&
!oscore_validate_sender_seq(rcp_ctx, cose)) {
coap_log(LOG_WARNING, "OSCORE: Replayed or old message\n");
coap_log_warn("OSCORE: Replayed or old message\n");
goto error;
}
last_seq =
coap_decode_var_bytes8(cose->partial_iv.s, cose->partial_iv.length);
if (rcp_ctx->last_seq>= OSCORE_SEQ_MAX) {
coap_log(LOG_WARNING,
coap_log_warn(
"OSCORE Replay protection, SEQ larger than SEQ_MAX.\n");
goto error;
}
Expand Down Expand Up @@ -1270,7 +1270,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
st_encrypt = pdu->data;
encrypt_len = pdu->used_size - (pdu->data - pdu->token);
if (encrypt_len <= 0) {
coap_log(LOG_WARNING, "OSCORE: No protected payload\n");
coap_log_warn("OSCORE: No protected payload\n");
if (!coap_request)
coap_handle_event(session->context,
COAP_EVENT_OSCORE_NO_PROTECTED_PAYLOAD,
Expand Down Expand Up @@ -1309,7 +1309,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
pltxt_size =
cose_encrypt0_decrypt(cose, plain_pdu->token, encrypt_len - tag_len);
if (pltxt_size <= 0) {
coap_log(LOG_WARNING,
coap_log_warn(
"OSCORE: Decryption Failure, result code: %d \n",
(int)pltxt_size);
if (coap_request) {
Expand Down Expand Up @@ -1416,7 +1416,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
if (coap_opt_length(opt) == 8 &&
memcmp(coap_opt_value(opt), rcp_ctx->echo_value, 8) == 0) {
if (!oscore_validate_sender_seq(rcp_ctx, cose)) {
coap_log(LOG_WARNING, "OSCORE: Replayed or old message\n");
coap_log_warn("OSCORE: Replayed or old message\n");
build_and_send_error_pdu(session,
pdu,
COAP_RESPONSE_CODE(401),
Expand Down Expand Up @@ -1547,7 +1547,7 @@ coap_oscore_decrypt_pdu(coap_session_t *session,
session->con_active--;
if (sent_pdu) {
coap_send_ack(session, pdu);
coap_log(LOG_DEBUG, "PDU requesting re-transmit\n");
coap_log_debug("PDU requesting re-transmit\n");
coap_show_pdu(LOG_DEBUG, decrypt_pdu);
coap_log_oscore("RFC9175 retransmit pdu\n");
if (coap_retransmit_oscore_pdu(session, sent_pdu, opt) ==
Expand Down Expand Up @@ -1739,7 +1739,7 @@ get_split_entry(const char **start,
return 1;

bad_entry:
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: Unrecognized configuration entry '%.*s'\n",
(int)(end - begin),
begin);
Expand Down Expand Up @@ -1838,7 +1838,7 @@ coap_parse_oscore_conf_mem(coap_str_const_t conf_mem) {
value.encoding & oscore_config[i].encoding) {
if (memcmp(keyword.s, "recipient_id", keyword.length) == 0) {
if (value.u.value_bin->length > 7) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: Maximum size of recipient_id is 7 bytes\n");
goto error_free_value_bin;
}
Expand All @@ -1863,7 +1863,7 @@ coap_parse_oscore_conf_mem(coap_str_const_t conf_mem) {
&(((char *)oscore_conf)[oscore_config[i].offset]),
sizeof(unused_check));
if (unused_check != NULL) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: Keyword '%.*s' duplicated\n",
(int)keyword.length,
(const char *)keyword.s);
Expand Down Expand Up @@ -1891,7 +1891,7 @@ coap_parse_oscore_conf_mem(coap_str_const_t conf_mem) {
}
}
if (oscore_config[i].text_mapping[j].text == NULL) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: Keyword '%.*s': value '%.*s' unknown\n",
(int)keyword.length,
(const char *)keyword.s,
Expand All @@ -1910,7 +1910,7 @@ coap_parse_oscore_conf_mem(coap_str_const_t conf_mem) {
}
}
if (i == sizeof(oscore_config) / sizeof(oscore_config[0])) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: Keyword '%.*s', type '%s' unknown\n",
(int)keyword.length,
(const char *)keyword.s,
Expand All @@ -1921,22 +1921,22 @@ coap_parse_oscore_conf_mem(coap_str_const_t conf_mem) {
}
}
if (!oscore_conf->master_secret) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: master_secret not defined\n");
goto error;
}
if (!oscore_conf->sender_id) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: sender_id not defined\n");
goto error;
}
if (oscore_conf->sender_id->length > 7) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: Maximum size of sender_id is 7 bytes\n");
goto error;
}
if (oscore_conf->recipient_id && oscore_conf->recipient_id[0]->length > 7) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_conf: Maximum size of recipient_id is 7 bytes\n");
goto error;
}
Expand All @@ -1954,21 +1954,21 @@ coap_oscore_init(coap_context_t *c_context, coap_oscore_conf_t *oscore_conf) {
oscore_ctx_t *osc_ctx = NULL;

if (!coap_crypto_check_cipher_alg(oscore_conf->aead_alg)) {
coap_log(LOG_WARNING,
coap_log_warn(
"COSE: Cipher Algorithm %d not supported\n",
oscore_conf->aead_alg);
goto error;
}
if (!coap_crypto_check_hkdf_alg(oscore_conf->hkdf_alg)) {
coap_log(LOG_WARNING,
coap_log_warn(
"COSE: HKDF Algorithm %d not supported\n",
oscore_conf->hkdf_alg);
goto error;
}

osc_ctx = oscore_derive_ctx(c_context, oscore_conf);
if (!osc_ctx) {
coap_log(LOG_CRIT, "OSCORE: Could not create Security Context!\n");
coap_log_crit("OSCORE: Could not create Security Context!\n");
goto error;
}

Expand Down
6 changes: 3 additions & 3 deletions src/oscore/oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ oscore_validate_sender_seq(oscore_recipient_ctx_t *ctx, cose_encrypt0_t *cose) {
coap_decode_var_bytes8(cose->partial_iv.s, cose->partial_iv.length);

if (incoming_seq >= OSCORE_SEQ_MAX) {
coap_log(LOG_WARNING,
coap_log_warn(
"OSCORE Replay protection, SEQ larger than SEQ_MAX.\n");
return 0;
}
Expand All @@ -392,7 +392,7 @@ oscore_validate_sender_seq(oscore_recipient_ctx_t *ctx, cose_encrypt0_t *cose) {
ctx->sliding_window |= 1;
ctx->last_seq = incoming_seq;
} else if (incoming_seq == ctx->last_seq) {
coap_log(LOG_WARNING,
coap_log_warn(
"OSCORE: Replay protection, replayed SEQ (%lu)\n",
incoming_seq);
return 0;
Expand All @@ -411,7 +411,7 @@ oscore_validate_sender_seq(oscore_recipient_ctx_t *ctx, cose_encrypt0_t *cose) {
/* seq + replay_window_size > last_seq */
pattern = 1ULL << shift;
if (ctx->sliding_window & pattern) {
coap_log(LOG_WARNING,
coap_log_warn(
"OSCORE: Replay protection, replayed SEQ (%lu)\n",
incoming_seq);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/oscore/oscore_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ oscore_cbor_elem_contained(const uint8_t *data, uint8_t *end) {
const uint8_t *buf = data;
const uint8_t *last = data + oscore_cbor_get_element_size(&buf);
if (last > end) {
coap_log(LOG_ERR, "oscore_cbor_elem_contained returns 1 \n");
coap_log_err("oscore_cbor_elem_contained returns 1 \n");
return 1;
} else
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/oscore/oscore_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ oscore_derive_ctx(coap_context_t *c_context, coap_oscore_conf_t *oscore_conf) {
for (i = 0; i < oscore_conf->recipient_id_count; i++) {
if (oscore_add_recipient(osc_ctx, oscore_conf->recipient_id[i],
oscore_conf->break_recipient_key) == NULL) {
coap_log(LOG_WARNING, "OSCORE: Failed to add Client ID\n");
coap_log_warn("OSCORE: Failed to add Client ID\n");
goto error;
}
}
Expand All @@ -600,7 +600,7 @@ oscore_add_recipient(oscore_ctx_t *osc_ctx, coap_bin_const_t *rid,
oscore_recipient_ctx_t *recipient_ctx = NULL;

if (rid->length > 7) {
coap_log(LOG_WARNING,
coap_log_warn(
"oscore_add_recipient: Maximum size of recipient_id is 7 bytes\n");
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/oscore/oscore_cose.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ cose_get_hmac_alg_for_hkdf(cose_hkdf_alg_t hkdf_alg, cose_hmac_alg_t *hmac_alg)
return 1;
}
}
coap_log(LOG_DEBUG, "cose_get_hmac_alg_for_hkdf: COSE HKDF %d not supported\n",
coap_log_debug("cose_get_hmac_alg_for_hkdf: COSE HKDF %d not supported\n",
hkdf_alg);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/oscore/oscore_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ oscore_hmac_shaX(cose_hmac_alg_t hmac_alg,
coap_bin_const_t *data,
coap_bin_const_t **hmac) {
if (!coap_crypto_hmac(hmac_alg, key, data, hmac)) {
coap_log(LOG_WARNING, "oscore_hmac_shaX: Failed hmac\n");
coap_log_warn("oscore_hmac_shaX: Failed hmac\n");
return 1;
}
return 0;
Expand Down

0 comments on commit e8ce092

Please sign in to comment.