From 0f21ce21d9325419dd4739af4e4845ffa62ceef6 Mon Sep 17 00:00:00 2001 From: Konstantin Tyurin Date: Fri, 4 Apr 2025 20:15:46 +0200 Subject: [PATCH] Support tls:// prefix Signed-off-by: Konstantin Tyurin --- src/MQTTAsync.c | 6 ++++++ src/MQTTAsyncUtils.c | 10 ++++++++++ src/MQTTClient.c | 17 +++++++++++++++++ src/SSLSocket.h | 9 +++++---- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/MQTTAsync.c b/src/MQTTAsync.c index c548ae31..6b6d96c6 100644 --- a/src/MQTTAsync.c +++ b/src/MQTTAsync.c @@ -335,6 +335,7 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const && strncmp(URI_WS, serverURI, strlen(URI_WS)) != 0 #if defined(OPENSSL) && strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0 + && strncmp(URI_TLS, serverURI, strlen(URI_TLS)) != 0 && strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) != 0 && strncmp(URI_WSS, serverURI, strlen(URI_WSS)) != 0 #endif @@ -405,6 +406,11 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const serverURI += strlen(URI_SSL); m->ssl = 1; } + else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0) + { + serverURI += strlen(URI_TLS); + m->ssl = 1; + } else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0) { serverURI += strlen(URI_MQTTS); diff --git a/src/MQTTAsyncUtils.c b/src/MQTTAsyncUtils.c index c084a11e..7c203d63 100644 --- a/src/MQTTAsyncUtils.c +++ b/src/MQTTAsyncUtils.c @@ -1348,6 +1348,11 @@ static int MQTTAsync_processCommand(void) serverURI += strlen(URI_SSL); command->client->ssl = 1; } + else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0) + { + serverURI += strlen(URI_TLS); + command->client->ssl = 1; + } else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0) { serverURI += strlen(URI_MQTTS); @@ -2888,6 +2893,11 @@ static int MQTTAsync_connecting(MQTTAsyncs* m) serverURI += strlen(URI_SSL); default_port = SECURE_MQTT_DEFAULT_PORT; } + else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0) + { + serverURI += strlen(URI_TLS); + default_port = SECURE_MQTT_DEFAULT_PORT; + } else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0) { serverURI += strlen(URI_MQTTS); diff --git a/src/MQTTClient.c b/src/MQTTClient.c index 32d59c3b..eb3ab5a2 100644 --- a/src/MQTTClient.c +++ b/src/MQTTClient.c @@ -71,6 +71,7 @@ #include #else #define URI_SSL "ssl://" +#define URI_TLS "tls://" #define URI_MQTTS "mqtts://" #endif @@ -403,6 +404,7 @@ int MQTTClient_createWithOptions(MQTTClient* handle, const char* serverURI, cons && strncmp(URI_WS, serverURI, strlen(URI_WS)) != 0 #if defined(OPENSSL) && strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0 + && strncmp(URI_TLS, serverURI, strlen(URI_TLS)) != 0 && strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) != 0 && strncmp(URI_WSS, serverURI, strlen(URI_WSS)) != 0 #endif @@ -465,6 +467,16 @@ int MQTTClient_createWithOptions(MQTTClient* handle, const char* serverURI, cons #else rc = MQTTCLIENT_SSL_NOT_SUPPORTED; goto exit; +#endif + } + else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0) + { +#if defined(OPENSSL) + serverURI += strlen(URI_TLS); + m->ssl = 1; +#else + rc = MQTTCLIENT_SSL_NOT_SUPPORTED; + goto exit; #endif } else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0) @@ -1898,6 +1910,11 @@ MQTTResponse MQTTClient_connectAll(MQTTClient handle, MQTTClient_connectOptions* serverURI += strlen(URI_SSL); m->ssl = 1; } + else if (strncmp(URI_TLS, serverURI, strlen(URI_TLS)) == 0) + { + serverURI += strlen(URI_TLS); + m->ssl = 1; + } else if (strncmp(URI_MQTTS, serverURI, strlen(URI_MQTTS)) == 0) { serverURI += strlen(URI_MQTTS); diff --git a/src/SSLSocket.h b/src/SSLSocket.h index 2e804cec..5a42be01 100644 --- a/src/SSLSocket.h +++ b/src/SSLSocket.h @@ -3,15 +3,15 @@ * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. + * and Eclipse Distribution License v1.0 which accompany this distribution. * - * The Eclipse Public License is available at + * The Eclipse Public License is available at * https://www.eclipse.org/legal/epl-2.0/ - * and the Eclipse Distribution License is available at + * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * * Contributors: - * Ian Craggs, Allan Stockdill-Mander - initial implementation + * Ian Craggs, Allan Stockdill-Mander - initial implementation * Ian Craggs - SNI support * Ian Craggs - post connect checks and CApath *******************************************************************************/ @@ -31,6 +31,7 @@ #include "Clients.h" #define URI_SSL "ssl://" +#define URI_TLS "tls://" #define URI_MQTTS "mqtts://" /** if we should handle openssl initialization (bool_value == 1) or depend on it to be initalized externally (bool_value == 0) */