Commit 9a465333 authored by Ian Craggs's avatar Ian Craggs

Merge branch 'develop' into mqttv5

parents bf7c2936 8276dcd2
/*******************************************************************************
* Copyright (c) 2009, 2017 IBM Corp.
* Copyright (c) 2009, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
......@@ -33,6 +33,7 @@
* Ian Craggs - SNI support
* Ian Craggs - auto reconnect timing fix #218
* Ian Craggs - fix for issue #190
* Ian Craggs - check for NULL SSL options #334
*******************************************************************************/
/**
......@@ -464,6 +465,20 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const
goto exit;
}
if (strstr(serverURI, "://") != NULL)
{
if (strncmp(URI_TCP, serverURI, strlen(URI_TCP)) != 0
#if defined(OPENSSL)
&& strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0
#endif
)
{
rc = MQTTASYNC_BAD_PROTOCOL;
goto exit;
}
}
if (options && (strncmp(options->struct_id, "MQCO", 4) != 0 || options->struct_version != 0))
{
rc = MQTTASYNC_BAD_STRUCTURE;
......@@ -2254,6 +2269,15 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
rc = MQTTASYNC_BAD_STRUCTURE;
goto exit;
}
#if defined(OPENSSL)
if (m->ssl && options->ssl == NULL)
{
rc = MQTTCLIENT_NULL_PARAMETER;
goto exit;
}
#endif
if (options->will) /* check validity of will options structure */
{
if (strncmp(options->will->struct_id, "MQTW", 4) != 0 || (options->will->struct_version != 0 && options->will->struct_version != 1))
......
......@@ -172,6 +172,11 @@
* Return code: Attempting SSL connection using non-SSL version of library
*/
#define MQTTASYNC_SSL_NOT_SUPPORTED -13
/**
* Return code: protocol prefix in serverURI should be tcp:// or ssl://
*/
#define MQTTASYNC_BAD_PROTOCOL -14
/**
* Default MQTT version to connect with. Use 3.1.1 then fall back to 3.1
......
/*******************************************************************************
* Copyright (c) 2009, 2017 IBM Corp.
* Copyright (c) 2009, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
......@@ -32,6 +32,7 @@
* Ian Craggs - SNI support, message queue unpersist bug
* Ian Craggs - binary will message support
* Ian Craggs - waitforCompletion fix #240
* Ian Craggs - check for NULL SSL options #334
*******************************************************************************/
/**
......@@ -319,6 +320,20 @@ int MQTTClient_create(MQTTClient* handle, const char* serverURI, const char* cli
goto exit;
}
if (strstr(serverURI, "://") != NULL)
{
if (strncmp(URI_TCP, serverURI, strlen(URI_TCP)) != 0
#if defined(OPENSSL)
&& strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0
#endif
)
{
rc = MQTTCLIENT_BAD_PROTOCOL;
goto exit;
}
}
if (!initialized)
{
#if defined(HEAP_H)
......@@ -1171,6 +1186,14 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
goto exit;
}
#if defined(OPENSSL)
if (m->ssl && options->ssl == NULL)
{
rc = MQTTCLIENT_NULL_PARAMETER;
goto exit;
}
#endif
if (options->will) /* check validity of will options structure */
{
if (strncmp(options->will->struct_id, "MQTW", 4) != 0 || (options->will->struct_version != 0 && options->will->struct_version != 1))
......@@ -1180,6 +1203,7 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
}
}
#if defined(OPENSSL)
if (options->struct_version != 0 && options->ssl) /* check validity of SSL options structure */
{
......
......@@ -179,6 +179,10 @@
* Return code: unrecognized MQTT version
*/
#define MQTTCLIENT_BAD_MQTT_VERSION -11
/**
* Return code: protocol prefix in serverURI should be tcp:// or ssl://
*/
#define MQTTCLIENT_BAD_PROTOCOL -14
/**
* Default MQTT version to connect with. Use 3.1.1 then fall back to 3.1
......
/*******************************************************************************
* Copyright (c) 2012, 2017 IBM Corp.
* Copyright (c) 2012, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
......@@ -12,6 +12,7 @@
*
* Contributors:
* Allan Stockdill-Mander - initial API and implementation and/or initial documentation
* Ian Craggs - add SSL options NULL test
*******************************************************************************/
/**
......@@ -570,6 +571,9 @@ int test1(struct Options options)
fprintf(xml, "<testcase classname=\"test3\" name=\"SSL connect fail to nonSSL MQTT server\"");
global_start_time = start_clock();
rc = MQTTClient_create(&c, "a b://wrong protocol", "test1", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
assert("bad rc from create", rc == MQTTCLIENT_BAD_PROTOCOL, "rc was %d \n", rc);
rc = MQTTClient_create(&c, options.connection, "test1", MQTTCLIENT_PERSISTENCE_DEFAULT, persistenceStore);
if (!(assert("good rc from create", rc == MQTTCLIENT_SUCCESS, "rc was %d \n", rc)))
goto exit;
......@@ -584,6 +588,10 @@ int test1(struct Options options)
opts.serverURIcount = options.hacount;
}
/* Try with ssl opts == NULL - should get error */
rc = MQTTClient_connect(c, &opts);
assert("Connect should fail", rc == MQTTCLIENT_NULL_PARAMETER, "rc was %d ", rc);
opts.ssl = &sslopts;
if (options.server_key_file != NULL)
opts.ssl->trustStore = options.server_key_file; /*file of certificates trusted by client*/
......
/*******************************************************************************
* Copyright (c) 2012, 2017 IBM Corp.
* Copyright (c) 2012, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
......@@ -613,6 +613,10 @@ int test1(struct Options options)
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
rc = MQTTAsync_create(&c, "rubbish://wrong", "test1", MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL);
assert("bad rc from create", rc == MQTTASYNC_BAD_PROTOCOL, "rc was %d \n", rc);
rc = MQTTAsync_create(&c, options.connection, "test1", MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d \n", rc);
......@@ -637,6 +641,9 @@ int test1(struct Options options)
opts.onFailure = test1OnFailure;
opts.context = c;
rc = MQTTAsync_connect(c, &opts);
assert("Bad rc from connect", rc == MQTTASYNC_NULL_PARAMETER, "rc was %d ", rc);
opts.ssl = &sslopts;
opts.ssl->enableServerCertAuth = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment