190
190
*/
191
191
#define AWS_IOT_MQTT_ALPN "\x0ex-amzn-mqtt-ca"
192
192
193
- /**
194
- * @brief Length of ALPN protocol name.
195
- */
196
- #define AWS_IOT_MQTT_ALPN_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_MQTT_ALPN ) - 1 ) )
197
-
198
193
/**
199
194
* @brief This is the ALPN (Application-Layer Protocol Negotiation) string
200
195
* required by AWS IoT for password-based authentication using TCP port 443.
201
196
*/
202
197
#define AWS_IOT_CUSTOM_AUTH_ALPN "\x04mqtt"
203
198
204
- /**
205
- * @brief Length of password ALPN.
206
- */
207
- #define AWS_IOT_CUSTOM_AUTH_ALPN_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_CUSTOM_AUTH_ALPN ) - 1 ) )
208
-
209
199
/**
210
200
* Provide default values for undefined configuration settings.
211
201
*/
@@ -567,6 +557,11 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
567
557
RetryUtilsStatus_t xRetryUtilsStatus = RetryUtilsSuccess ;
568
558
RetryUtilsParams_t xReconnectParams ;
569
559
560
+ /* ALPN protocols must be a NULL-terminated list of strings. Therefore,
561
+ * the first entry will contain the actual ALPN protocol string while the
562
+ * second entry must remain NULL. */
563
+ char * pcAlpnProtocols [] = { NULL , NULL };
564
+
570
565
/* Set the credentials for establishing a TLS connection. */
571
566
pxNetworkCredentials -> pRootCa = ( const unsigned char * ) democonfigROOT_CA_PEM ;
572
567
pxNetworkCredentials -> rootCaSize = sizeof ( democonfigROOT_CA_PEM );
@@ -580,11 +575,12 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
580
575
pxNetworkCredentials -> disableSni = pdFALSE ;
581
576
/* The ALPN string changes depending on whether username/password authentication is used. */
582
577
#ifdef democonfigCLIENT_USERNAME
583
- pxNetworkCredentials -> pAlpnProtos = AWS_IOT_CUSTOM_AUTH_ALPN ;
578
+ pcAlpnProtocols [ 0 ] = AWS_IOT_CUSTOM_AUTH_ALPN ;
584
579
#else
585
- pxNetworkCredentials -> pAlpnProtos = AWS_IOT_MQTT_ALPN ;
580
+ pcAlpnProtocols [ 0 ] = AWS_IOT_MQTT_ALPN ;
586
581
#endif
587
- #else
582
+ pxNetworkCredentials -> pAlpnProtos = pcAlpnProtocols ;
583
+ #else /* ifdef democonfigUSE_AWS_IOT_CORE_BROKER */
588
584
589
585
/* When using a local Mosquitto server setup, SNI needs to be disabled for
590
586
* an MQTT broker that only has an IP address but no hostname. However,
@@ -686,7 +682,7 @@ static void prvCreateMQTTConnectionWithBroker( MQTTContext_t * pxMQTTContext,
686
682
/* Password for authentication is not used. */
687
683
xConnectInfo .pPassword = NULL ;
688
684
xConnectInfo .passwordLength = 0U ;
689
- #endif /* ifdef democonfigCLIENT_USERNAME */
685
+ #endif
690
686
#else /* ifdef democonfigUSE_AWS_IOT_CORE_BROKER */
691
687
#ifdef democonfigCLIENT_USERNAME
692
688
xConnectInfo .pUserName = democonfigCLIENT_USERNAME ;
0 commit comments