From 4a89bff610b86f534f67d032a3e1549d8c4da95f Mon Sep 17 00:00:00 2001 From: fractal-def <56096827+fractal-def@users.noreply.github.com> Date: Tue, 10 Aug 2021 15:02:35 -0600 Subject: [PATCH 1/3] Check CONFIG_MBEDTLS_CERTIFICATE_BUNDLE is set Fixes a compilation error where `esp_transport_ssl_crt_bundle_attach` is undefined in this scenario. --- mqtt_client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mqtt_client.c b/mqtt_client.c index 6c5b32e..e9ad126 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -204,12 +204,14 @@ static esp_err_t esp_mqtt_set_ssl_transport_properties(esp_transport_list_handle if (cfg->use_global_ca_store == true) { esp_transport_ssl_enable_global_ca_store(ssl); +#ifdef CONFIG_MBEDTLS_CERTIFICATE_BUNDLE } else if (cfg->crt_bundle_attach != NULL) { -#ifdef MQTT_SUPPORTED_FEATURE_CERTIFICATE_BUNDLE + #ifdef MQTT_SUPPORTED_FEATURE_CERTIFICATE_BUNDLE esp_transport_ssl_crt_bundle_attach(ssl, cfg->crt_bundle_attach); -#else + #else ESP_LOGE(TAG, "Certificate bundle feature is not available in IDF version %s", IDF_VER); goto esp_mqtt_set_transport_failed; + #endif #endif } else { ESP_OK_CHECK(TAG, esp_mqtt_set_cert_key_data(ssl, MQTT_SSL_DATA_API_CA_CERT, cfg->cacert_buf, cfg->cacert_bytes), From 1b719805756f60140312f8e314f732c0a177f74f Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 7 Sep 2021 15:38:20 +0200 Subject: [PATCH 2/3] Config: Add error message if certbunde is not enabled Merges https://github.com/espressif/esp-mqtt/pull/198 --- mqtt_client.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mqtt_client.c b/mqtt_client.c index e9ad126..f47e61c 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -204,15 +204,18 @@ static esp_err_t esp_mqtt_set_ssl_transport_properties(esp_transport_list_handle if (cfg->use_global_ca_store == true) { esp_transport_ssl_enable_global_ca_store(ssl); -#ifdef CONFIG_MBEDTLS_CERTIFICATE_BUNDLE } else if (cfg->crt_bundle_attach != NULL) { - #ifdef MQTT_SUPPORTED_FEATURE_CERTIFICATE_BUNDLE +#ifdef MQTT_SUPPORTED_FEATURE_CERTIFICATE_BUNDLE +#ifdef CONFIG_MBEDTLS_CERTIFICATE_BUNDLE esp_transport_ssl_crt_bundle_attach(ssl, cfg->crt_bundle_attach); - #else +#else + ESP_LOGE(TAG, "Certificate bundle is not enabled for mbedTLS in menuconfig"); + goto esp_mqtt_set_transport_failed; +#endif /* CONFIG_MBEDTLS_CERTIFICATE_BUNDLE */ +#else ESP_LOGE(TAG, "Certificate bundle feature is not available in IDF version %s", IDF_VER); goto esp_mqtt_set_transport_failed; - #endif -#endif +#endif /* MQTT_SUPPORTED_FEATURE_CERTIFICATE_BUNDLE */ } else { ESP_OK_CHECK(TAG, esp_mqtt_set_cert_key_data(ssl, MQTT_SSL_DATA_API_CA_CERT, cfg->cacert_buf, cfg->cacert_bytes), goto esp_mqtt_set_transport_failed); From 5b3c81ee482c815e2602f5d16adb0e197b9e3695 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 10 Sep 2021 09:15:36 +0200 Subject: [PATCH 3/3] Config: Fix build issue if WS/WSS transport disabled Closes https://github.com/espressif/esp-idf/issues/7535 --- mqtt_client.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/mqtt_client.c b/mqtt_client.c index f47e61c..d7b8d86 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -519,19 +519,28 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl if (config->transport) { free(client->config->scheme); - if (config->transport == MQTT_TRANSPORT_OVER_WS) { - client->config->scheme = create_string("ws", 2); - ESP_MEM_CHECK(TAG, client->config->scheme, goto _mqtt_set_config_failed); - } else if (config->transport == MQTT_TRANSPORT_OVER_TCP) { + if (config->transport == MQTT_TRANSPORT_OVER_TCP) { client->config->scheme = create_string("mqtt", 4); ESP_MEM_CHECK(TAG, client->config->scheme, goto _mqtt_set_config_failed); - } else if (config->transport == MQTT_TRANSPORT_OVER_SSL) { + } +#if MQTT_ENABLE_WS + else if (config->transport == MQTT_TRANSPORT_OVER_WS) { + client->config->scheme = create_string("ws", 2); + ESP_MEM_CHECK(TAG, client->config->scheme, goto _mqtt_set_config_failed); + } +#endif +#if MQTT_ENABLE_SSL + else if (config->transport == MQTT_TRANSPORT_OVER_SSL) { client->config->scheme = create_string("mqtts", 5); ESP_MEM_CHECK(TAG, client->config->scheme, goto _mqtt_set_config_failed); - } else if (config->transport == MQTT_TRANSPORT_OVER_WSS) { + } +#endif +#if MQTT_ENABLE_WSS + else if (config->transport == MQTT_TRANSPORT_OVER_WSS) { client->config->scheme = create_string("wss", 3); ESP_MEM_CHECK(TAG, client->config->scheme, goto _mqtt_set_config_failed); } +#endif } // Set uri at the end of config to override separately configured uri elements @@ -868,14 +877,18 @@ esp_err_t esp_mqtt_client_set_uri(esp_mqtt_client_handle_t client, const char *u } if (client->config->path) { - esp_transport_handle_t trans = esp_transport_list_get_transport(client->transport_list, "ws"); - if (trans) { - esp_transport_ws_set_path(trans, client->config->path); +#if MQTT_ENABLE_WS + esp_transport_handle_t ws_trans = esp_transport_list_get_transport(client->transport_list, "ws"); + if (ws_trans) { + esp_transport_ws_set_path(ws_trans, client->config->path); } - trans = esp_transport_list_get_transport(client->transport_list, "wss"); - if (trans) { - esp_transport_ws_set_path(trans, client->config->path); +#endif +#if MQTT_ENABLE_WSS + esp_transport_handle_t wss_trans = esp_transport_list_get_transport(client->transport_list, "wss"); + if (wss_trans) { + esp_transport_ws_set_path(wss_trans, client->config->path); } +#endif } if (puri.field_data[UF_PORT].len) {