From c7cda6309218d27b4fbcf457ca9e3cf249d738c8 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Fri, 3 Feb 2023 09:49:20 +0000 Subject: [PATCH] oscore: Handle encrypt error return Check return from cose_encrypt0_encrypt() and correct spelling error. --- examples/coap-client.c | 4 ++-- examples/coap-server.c | 4 ++-- examples/oscore-interop-server.c | 4 ++-- src/coap_oscore.c | 6 ++++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/coap-client.c b/examples/coap-client.c index 47297ece..54f95476 100644 --- a/examples/coap-client.c +++ b/examples/coap-client.c @@ -734,7 +734,7 @@ get_oscore_conf(void) { /* Need a rw var to free off later and file_mem.s is a const */ buf = read_file_mem(oscore_conf_file, &length); if (buf == NULL) { - fprintf(stderr, "OSCORE configuraton file error: %s\n", oscore_conf_file); + fprintf(stderr, "OSCORE configuration file error: %s\n", oscore_conf_file); return NULL; } file_mem.s = buf; @@ -760,7 +760,7 @@ get_oscore_conf(void) { NULL, start_seq_num); coap_free(buf); if (oscore_conf == NULL) { - fprintf(stderr, "OSCORE configuraton file error: %s\n", oscore_conf_file); + fprintf(stderr, "OSCORE configuration file error: %s\n", oscore_conf_file); return NULL; } return oscore_conf; diff --git a/examples/coap-server.c b/examples/coap-server.c index 33ac1c5e..a4802767 100644 --- a/examples/coap-server.c +++ b/examples/coap-server.c @@ -2406,7 +2406,7 @@ get_oscore_conf(coap_context_t *context) { /* Need a rw var to free off later and file_mem.s is a const */ buf = read_file_mem(oscore_conf_file, &length); if (buf == NULL) { - fprintf(stderr, "OSCORE configuraton file error: %s\n", oscore_conf_file); + fprintf(stderr, "OSCORE configuration file error: %s\n", oscore_conf_file); return NULL; } file_mem.s = buf; @@ -2432,7 +2432,7 @@ get_oscore_conf(coap_context_t *context) { NULL, start_seq_num); coap_free(buf); if (oscore_conf == NULL) { - fprintf(stderr, "OSCORE configuraton file error: %s\n", oscore_conf_file); + fprintf(stderr, "OSCORE configuration file error: %s\n", oscore_conf_file); return NULL; } coap_context_oscore_server(context, oscore_conf); diff --git a/examples/oscore-interop-server.c b/examples/oscore-interop-server.c index 87824153..4091e524 100644 --- a/examples/oscore-interop-server.c +++ b/examples/oscore-interop-server.c @@ -512,7 +512,7 @@ get_oscore_conf(coap_context_t *context) { buf = read_file_mem(oscore_conf_file, &length); if (buf == NULL) { - fprintf(stderr, "OSCORE configuraton file error: %s\n", oscore_conf_file); + fprintf(stderr, "OSCORE configuration file error: %s\n", oscore_conf_file); return NULL; } file_mem.s = buf; @@ -538,7 +538,7 @@ get_oscore_conf(coap_context_t *context) { NULL, start_seq_num); coap_free(buf); if (oscore_conf == NULL) { - fprintf(stderr, "OSCORE configuraton file error: %s\n", oscore_conf_file); + fprintf(stderr, "OSCORE configuration file error: %s\n", oscore_conf_file); return NULL; } coap_context_oscore_server(context, oscore_conf); diff --git a/src/coap_oscore.c b/src/coap_oscore.c index c8528061..95bec197 100644 --- a/src/coap_oscore.c +++ b/src/coap_oscore.c @@ -591,6 +591,12 @@ coap_oscore_new_pdu_encrypted(coap_session_t *session, ciphertext_len = cose_encrypt0_encrypt(cose, ciphertext_buffer, plain_pdu->used_size + AES_CCM_TAG); + if ((int)ciphertext_len <= 0) { + coap_log_warn( + "OSCORE: Encryption Failure, result code: %d \n", + (int)ciphertext_len); + goto error; + } assert(ciphertext_len < OSCORE_CRYPTO_BUFFER_SIZE); /* Add in OSCORE option (previously computed) */