From 0d5b5eed1fd50661fbabd913c45466a6f41ca818 Mon Sep 17 00:00:00 2001 From: Dane Walton Date: Thu, 3 Feb 2022 15:52:14 -0800 Subject: [PATCH 1/3] typos and topic lengths --- examples/Azure_IoT_Central_ESP32/AzureIoT.cpp | 8 ++++---- .../Azure_IoT_Central_ESP32/Azure_IoT_Central_ESP32.ino | 2 +- examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp b/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp index 782dd684..6e4299ef 100644 --- a/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp +++ b/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp @@ -316,7 +316,7 @@ void azure_iot_do_work(azure_iot_t* azure_iot) return; } - mqtt_message.topic = split_az_span(data_buffer, length, &data_buffer); + mqtt_message.topic = split_az_span(data_buffer, length + 1, &data_buffer); if (is_az_span_empty(mqtt_message.topic) || is_az_span_empty(data_buffer)) { @@ -395,7 +395,7 @@ void azure_iot_do_work(azure_iot_t* azure_iot) return; } - mqtt_message.topic = az_span_slice(azure_iot->data_buffer, 0, length); + mqtt_message.topic = az_span_slice(azure_iot->data_buffer, 0, length + 1); mqtt_message.payload = AZ_SPAN_EMPTY; mqtt_message.qos = mqtt_qos_at_most_once; @@ -1111,7 +1111,7 @@ static int generate_sas_token_for_dps( EXIT_IF_TRUE(result != 0, 0, "Failed decoding SAS key."); // Step 2.c. - sas_hmac256_signed_signature = split_az_span(data_buffer_span, SAS_HMAC256_ENCRIPTED_SIGNATURE_BUFFER_SIZE, &data_buffer_span); + sas_hmac256_signed_signature = split_az_span(data_buffer_span, SAS_HMAC256_ENCRYPTED_SIGNATURE_BUFFER_SIZE, &data_buffer_span); EXIT_IF_TRUE(is_az_span_empty(sas_hmac256_signed_signature), 0, "Failed reserving buffer for sas_hmac256_signed_signature."); result = data_manipulation_functions.hmac_sha256_encrypt( @@ -1202,7 +1202,7 @@ static int generate_sas_token_for_iot_hub( EXIT_IF_TRUE(result != 0, 0, "Failed decoding SAS key."); // Step 2.c. - sas_hmac256_signed_signature = split_az_span(data_buffer_span, SAS_HMAC256_ENCRIPTED_SIGNATURE_BUFFER_SIZE, &data_buffer_span); + sas_hmac256_signed_signature = split_az_span(data_buffer_span, SAS_HMAC256_ENCRYPTED_SIGNATURE_BUFFER_SIZE, &data_buffer_span); EXIT_IF_TRUE(is_az_span_empty(sas_hmac256_signed_signature), 0, "Failed reserving buffer for sas_hmac256_signed_signature."); result = data_manipulation_functions.hmac_sha256_encrypt( diff --git a/examples/Azure_IoT_Central_ESP32/Azure_IoT_Central_ESP32.ino b/examples/Azure_IoT_Central_ESP32/Azure_IoT_Central_ESP32.ino index becd292b..b31c2dad 100644 --- a/examples/Azure_IoT_Central_ESP32/Azure_IoT_Central_ESP32.ino +++ b/examples/Azure_IoT_Central_ESP32/Azure_IoT_Central_ESP32.ino @@ -96,7 +96,7 @@ static esp_mqtt_client_handle_t mqtt_client; static char mqtt_broker_uri[128]; -#define AZ_IOT_DATA_BUFFER_SIZE 1000 +#define AZ_IOT_DATA_BUFFER_SIZE 1000 static uint8_t az_iot_data_buffer[AZ_IOT_DATA_BUFFER_SIZE]; #define MQTT_PROTOCOL_PREFIX "mqtts://" diff --git a/examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp b/examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp index 782dd684..9c6a1da1 100644 --- a/examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp +++ b/examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp @@ -25,7 +25,7 @@ log_function_t default_logging_function = NULL; #define MQTT_USERNAME_BUFFER_SIZE 256 #define DECODED_SAS_KEY_BUFFER_SIZE 32 #define PLAIN_SAS_SIGNATURE_BUFFER_SIZE 256 -#define SAS_HMAC256_ENCRIPTED_SIGNATURE_BUFFER_SIZE 32 +#define SAS_HMAC256_ENCRYPTED_SIGNATURE_BUFFER_SIZE 32 #define SAS_SIGNATURE_BUFFER_SIZE 64 #define MQTT_PASSWORD_BUFFER_SIZE 256 @@ -1111,7 +1111,7 @@ static int generate_sas_token_for_dps( EXIT_IF_TRUE(result != 0, 0, "Failed decoding SAS key."); // Step 2.c. - sas_hmac256_signed_signature = split_az_span(data_buffer_span, SAS_HMAC256_ENCRIPTED_SIGNATURE_BUFFER_SIZE, &data_buffer_span); + sas_hmac256_signed_signature = split_az_span(data_buffer_span, SAS_HMAC256_ENCRYPTED_SIGNATURE_BUFFER_SIZE, &data_buffer_span); EXIT_IF_TRUE(is_az_span_empty(sas_hmac256_signed_signature), 0, "Failed reserving buffer for sas_hmac256_signed_signature."); result = data_manipulation_functions.hmac_sha256_encrypt( @@ -1202,7 +1202,7 @@ static int generate_sas_token_for_iot_hub( EXIT_IF_TRUE(result != 0, 0, "Failed decoding SAS key."); // Step 2.c. - sas_hmac256_signed_signature = split_az_span(data_buffer_span, SAS_HMAC256_ENCRIPTED_SIGNATURE_BUFFER_SIZE, &data_buffer_span); + sas_hmac256_signed_signature = split_az_span(data_buffer_span, SAS_HMAC256_ENCRYPTED_SIGNATURE_BUFFER_SIZE, &data_buffer_span); EXIT_IF_TRUE(is_az_span_empty(sas_hmac256_signed_signature), 0, "Failed reserving buffer for sas_hmac256_signed_signature."); result = data_manipulation_functions.hmac_sha256_encrypt( From b47e1fd48847b4aa87da2af583fdbdd4fad8a3ad Mon Sep 17 00:00:00 2001 From: Dane Walton Date: Thu, 3 Feb 2022 17:25:27 -0800 Subject: [PATCH 2/3] add to other places --- examples/Azure_IoT_Central_ESP32/AzureIoT.cpp | 4 ++-- examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp b/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp index 6e4299ef..3215fe04 100644 --- a/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp +++ b/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp @@ -547,7 +547,7 @@ int azure_iot_send_telemetry(azure_iot_t* azure_iot, az_span message) &azure_iot->iot_hub_client, NULL, (char*)az_span_ptr(azure_iot->data_buffer), az_span_size(azure_iot->data_buffer), &topic_length); EXIT_IF_AZ_FAILED(azr, RESULT_ERROR, "Failed to get the telemetry topic"); - mqtt_message.topic = az_span_slice(azure_iot->data_buffer, 0, topic_length); + mqtt_message.topic = az_span_slice(azure_iot->data_buffer, 0, topic_length + 1); mqtt_message.payload = message; mqtt_message.qos = mqtt_qos_at_most_once; @@ -887,7 +887,7 @@ int azure_iot_send_command_response(azure_iot_t* azure_iot, az_span request_id, (char*)az_span_ptr(mqtt_message.topic), az_span_size(mqtt_message.topic), &topic_length); EXIT_IF_AZ_FAILED(azrc, RESULT_ERROR, "Failed to get the commands response topic."); - mqtt_message.topic = az_span_slice(mqtt_message.topic, 0, topic_length); + mqtt_message.topic = az_span_slice(mqtt_message.topic, 0, topic_length + 1); mqtt_message.payload = payload; mqtt_message.qos = mqtt_qos_at_most_once; diff --git a/examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp b/examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp index 9c6a1da1..4a8412ff 100644 --- a/examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp +++ b/examples/Azure_IoT_Central_ESP32_AzureIoTKit/AzureIoT.cpp @@ -316,7 +316,7 @@ void azure_iot_do_work(azure_iot_t* azure_iot) return; } - mqtt_message.topic = split_az_span(data_buffer, length, &data_buffer); + mqtt_message.topic = split_az_span(data_buffer, length + 1, &data_buffer); if (is_az_span_empty(mqtt_message.topic) || is_az_span_empty(data_buffer)) { @@ -395,7 +395,7 @@ void azure_iot_do_work(azure_iot_t* azure_iot) return; } - mqtt_message.topic = az_span_slice(azure_iot->data_buffer, 0, length); + mqtt_message.topic = az_span_slice(azure_iot->data_buffer, 0, length + 1); mqtt_message.payload = AZ_SPAN_EMPTY; mqtt_message.qos = mqtt_qos_at_most_once; @@ -547,7 +547,7 @@ int azure_iot_send_telemetry(azure_iot_t* azure_iot, az_span message) &azure_iot->iot_hub_client, NULL, (char*)az_span_ptr(azure_iot->data_buffer), az_span_size(azure_iot->data_buffer), &topic_length); EXIT_IF_AZ_FAILED(azr, RESULT_ERROR, "Failed to get the telemetry topic"); - mqtt_message.topic = az_span_slice(azure_iot->data_buffer, 0, topic_length); + mqtt_message.topic = az_span_slice(azure_iot->data_buffer, 0, topic_length + 1); mqtt_message.payload = message; mqtt_message.qos = mqtt_qos_at_most_once; @@ -887,7 +887,7 @@ int azure_iot_send_command_response(azure_iot_t* azure_iot, az_span request_id, (char*)az_span_ptr(mqtt_message.topic), az_span_size(mqtt_message.topic), &topic_length); EXIT_IF_AZ_FAILED(azrc, RESULT_ERROR, "Failed to get the commands response topic."); - mqtt_message.topic = az_span_slice(mqtt_message.topic, 0, topic_length); + mqtt_message.topic = az_span_slice(mqtt_message.topic, 0, topic_length + 1); mqtt_message.payload = payload; mqtt_message.qos = mqtt_qos_at_most_once; From 66a5c897bbaebe8337458859f8690988cfc879f7 Mon Sep 17 00:00:00 2001 From: Dane Walton Date: Thu, 3 Feb 2022 17:33:25 -0800 Subject: [PATCH 3/3] patch up --- examples/Azure_IoT_Central_ESP32/AzureIoT.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp b/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp index 3215fe04..4a8412ff 100644 --- a/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp +++ b/examples/Azure_IoT_Central_ESP32/AzureIoT.cpp @@ -25,7 +25,7 @@ log_function_t default_logging_function = NULL; #define MQTT_USERNAME_BUFFER_SIZE 256 #define DECODED_SAS_KEY_BUFFER_SIZE 32 #define PLAIN_SAS_SIGNATURE_BUFFER_SIZE 256 -#define SAS_HMAC256_ENCRIPTED_SIGNATURE_BUFFER_SIZE 32 +#define SAS_HMAC256_ENCRYPTED_SIGNATURE_BUFFER_SIZE 32 #define SAS_SIGNATURE_BUFFER_SIZE 64 #define MQTT_PASSWORD_BUFFER_SIZE 256