Skip to content

Commit 5e8950e

Browse files
committed
SSL: add config option for skipping common name check
Closes IDFGH-3408 Closes #158
1 parent 6bc94ad commit 5e8950e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

include/mqtt_client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ typedef struct {
182182
int clientkey_password_len; /*!< String length of the password pointed to by clientkey_password */
183183
esp_mqtt_protocol_ver_t protocol_ver; /*!< MQTT protocol version used for connection, defaults to value from menuconfig*/
184184
int out_buffer_size; /*!< size of MQTT output buffer. If not defined, both output and input buffers have the same size defined as ``buffer_size`` */
185+
bool skip_cert_common_name_check; /*!< Skip any validation of server certificate CN field, this reduces the security of TLS and makes the mqtt client susceptible to MITM attacks */
185186
} esp_mqtt_client_config_t;
186187

187188
/**

include/mqtt_supported_features.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(3, 3, 0)
3232
// Features supported from 3.3
3333
#define MQTT_SUPPORTED_FEATURE_EVENT_LOOP
34+
#define MQTT_SUPPORTED_FEATURE_SKIP_CRT_CMN_NAME_CHECK
3435
#endif
3536

3637
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
@@ -48,4 +49,4 @@
4849
#endif
4950
#endif
5051

51-
#endif // _MQTT_SUPPORTED_FEATURES_H_
52+
#endif // _MQTT_SUPPORTED_FEATURES_H_

mqtt_client.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef struct {
8080
const char *clientkey_buf;
8181
size_t clientkey_bytes;
8282
const struct psk_key_hint *psk_hint_key;
83+
bool skip_cert_common_name_check;
8384
} mqtt_config_storage_t;
8485

8586
typedef enum {
@@ -239,6 +240,16 @@ static esp_err_t esp_mqtt_set_ssl_transport_properties(esp_transport_list_handle
239240
#endif
240241
}
241242

243+
244+
if (cfg->skip_cert_common_name_check) {
245+
#if defined(MQTT_SUPPORTED_FEATURE_SKIP_CRT_CMN_NAME_CHECK) && MQTT_ENABLE_SSL
246+
esp_transport_ssl_skip_common_name_check(ssl);
247+
#else
248+
ESP_LOGE(TAG, "Skip certificate common name check is not available in IDF version %s", IDF_VER);
249+
goto esp_mqtt_set_transport_failed;
250+
#endif
251+
}
252+
242253
return ESP_OK;
243254

244255
esp_mqtt_set_transport_failed:
@@ -416,6 +427,7 @@ esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_mqtt_cl
416427
cfg->clientkey_buf = config->client_key_pem;
417428
cfg->clientkey_bytes = config->client_key_len;
418429
cfg->psk_hint_key = config->psk_hint_key;
430+
cfg->skip_cert_common_name_check = config->skip_cert_common_name_check;
419431

420432
if (config->clientkey_password && config->clientkey_password_len) {
421433
cfg->clientkey_password_len = config->clientkey_password_len;

0 commit comments

Comments
 (0)