Skip to content

Support tls:// prefix #1593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/MQTTAsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/MQTTAsyncUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/MQTTClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include <openssl/ssl.h>
#else
#define URI_SSL "ssl://"
#define URI_TLS "tls://"
#define URI_MQTTS "mqtts://"
#endif

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/SSLSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*******************************************************************************/
Expand All @@ -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) */
Expand Down