From 186051992771b9defa1948b013c2801e6fe15a08 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:07:57 +0800 Subject: [PATCH] fix(mqtt): enable SNI only when configured host is not IP address --- src/connection/mqtt_client.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/connection/mqtt_client.c b/src/connection/mqtt_client.c index bd488506..56fb67f7 100644 --- a/src/connection/mqtt_client.c +++ b/src/connection/mqtt_client.c @@ -23,6 +23,8 @@ #include #include +#include + #define NNG_SUPP_TLS 1 #define NNG_SUPP_SQLITE 1 #include @@ -1045,7 +1047,10 @@ int neu_mqtt_client_set_tls(neu_mqtt_client_t *client, bool enabled, client->tls_cfg = cfg; } - if (0 != (rv = nng_tls_config_server_name(client->tls_cfg, client->host))) { + // validate server name and enable SNI only when host is not an IP address + struct sockaddr_in sa; + if (0 == inet_pton(AF_INET, client->host, &sa.sin_addr) && + 0 != (rv = nng_tls_config_server_name(client->tls_cfg, client->host))) { log(error, "nng_tls_config_server_name fail: %s", nng_strerror(rv)); rv = -1; goto end;