Skip to content

Commit 77f657e

Browse files
dcgawsGordon Wang
authored andcommitted
Use AWS IoT Core support for MQTT over port 443 (#141)
* Use AWS IoT Core support for MQTT over port 443 in the five sample projects (this is done using ALPN during TLS negotiation). Also, fix a compiler warning in the three subscribe/publish projects. * Use AWS IoT Core support for MQTT over port 443 in the tests.
1 parent d3ea2e8 commit 77f657e

File tree

19 files changed

+28
-18
lines changed

19 files changed

+28
-18
lines changed

include/aws_iot_shadow_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern "C" {
5151
*/
5252
typedef struct {
5353
char *pHost; ///< This will be unique to a customer and can be retrieved from the console
54-
uint16_t port; ///< By default the port is 8883
54+
uint16_t port; ///< Network port for TCP/IP socket
5555
char *pRootCA; ///< Location with the Filename of the Root CA
5656
char *pClientCRT; ///< Location of Device certs signed by AWS IoT service
5757
char *pClientKey; ///< Location of Device private key

platform/linux/mbedtls/network_mbedtls_wrapper.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ IoT_Error_t iot_tls_connect(Network *pNetwork, TLSConnectParams *params) {
101101
TLSDataParams *tlsDataParams = NULL;
102102
char portBuffer[6];
103103
char vrfy_buf[512];
104+
const char *alpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
104105

105106
#ifdef ENABLE_IOT_DEBUG
106107
unsigned char buf[MBEDTLS_DEBUG_BUFFER_SIZE];
@@ -202,6 +203,15 @@ IoT_Error_t iot_tls_connect(Network *pNetwork, TLSConnectParams *params) {
202203

203204
mbedtls_ssl_conf_read_timeout(&(tlsDataParams->conf), pNetwork->tlsConnectParams.timeout_ms);
204205

206+
/* Use the AWS IoT ALPN extension for MQTT if port 443 is requested. */
207+
if(443 == pNetwork->tlsConnectParams.DestinationPort) {
208+
if((ret = mbedtls_ssl_conf_alpn_protocols(&(tlsDataParams->conf), alpnProtocols)) != 0) {
209+
IOT_ERROR(" failed\n ! mbedtls_ssl_conf_alpn_protocols returned -0x%x\n\n", -ret);
210+
return SSL_CONNECTION_ERROR;
211+
}
212+
}
213+
214+
/* Assign the resulting configuration to the SSL context. */
205215
if((ret = mbedtls_ssl_setup(&(tlsDataParams->ssl), &(tlsDataParams->conf))) != 0) {
206216
IOT_ERROR(" failed\n ! mbedtls_ssl_setup returned -0x%x\n\n", -ret);
207217
return SSL_CONNECTION_ERROR;

samples/linux/jobs_sample/aws_iot_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Get from console
2525
// =================================================
2626
#define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow
27-
#define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S
27+
#define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S
2828
#define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device
2929
#define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with
3030
#define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name

samples/linux/shadow_sample/aws_iot_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Get from console
2525
// =================================================
2626
#define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow
27-
#define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S
27+
#define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S
2828
#define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device
2929
#define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with
3030
#define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name

samples/linux/shadow_sample_console_echo/aws_iot_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Get from console
2525
// =================================================
2626
#define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow
27-
#define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S
27+
#define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S
2828
#define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device
2929
#define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with
3030
#define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name

samples/linux/subscribe_publish_cpp_sample/aws_iot_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Get from console
2525
// =================================================
2626
#define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow
27-
#define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S
27+
#define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S
2828
#define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device
2929
#define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with
3030
#define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name

samples/linux/subscribe_publish_cpp_sample/subscribe_publish_cpp_sample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void iot_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, ui
6262
IOT_UNUSED(pData);
6363
IOT_UNUSED(pClient);
6464
IOT_INFO("Subscribe callback");
65-
IOT_INFO("%.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, params->payload);
65+
IOT_INFO("%.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, (char *) params->payload);
6666
}
6767

6868
void disconnectCallbackHandler(AWS_IoT_Client *pClient, void *data) {

samples/linux/subscribe_publish_library_sample/aws_iot_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Get from console
2525
// =================================================
2626
#define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow
27-
#define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S
27+
#define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S
2828
#define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device
2929
#define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with
3030
#define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name

samples/linux/subscribe_publish_library_sample/subscribe_publish_library_sample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void iot_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, ui
6262
IOT_UNUSED(pData);
6363
IOT_UNUSED(pClient);
6464
IOT_INFO("Subscribe callback");
65-
IOT_INFO("%.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, params->payload);
65+
IOT_INFO("%.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, (char *) params->payload);
6666
}
6767

6868
void disconnectCallbackHandler(AWS_IoT_Client *pClient, void *data) {

samples/linux/subscribe_publish_sample/aws_iot_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Get from console
2525
// =================================================
2626
#define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow
27-
#define AWS_IOT_MQTT_PORT 8883 ///< default port for MQTT/S
27+
#define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S
2828
#define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device
2929
#define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with
3030
#define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name

0 commit comments

Comments
 (0)