|
75 | 75 | /* Clock for timer. */ |
76 | 76 | #include "clock.h" |
77 | 77 |
|
| 78 | +/* AWS IoT Core TLS ALPN definitions for MQTT authentication */ |
| 79 | +#include "aws_iot_alpn_defs.h" |
| 80 | + |
78 | 81 | /** |
79 | 82 | * These configuration settings are required to run the mutual auth demo. |
80 | 83 | * Throw compilation error if the below configs are not defined. |
|
139 | 142 | /** |
140 | 143 | * @brief Length of MQTT server host name. |
141 | 144 | */ |
142 | | -#define AWS_IOT_ENDPOINT_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_ENDPOINT ) - 1 ) ) |
| 145 | +#define AWS_IOT_ENDPOINT_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_ENDPOINT ) - 1 ) ) |
143 | 146 |
|
144 | 147 | /** |
145 | 148 | * @brief Length of client identifier. |
146 | 149 | */ |
147 | | -#define CLIENT_IDENTIFIER_LENGTH ( ( uint16_t ) ( sizeof( CLIENT_IDENTIFIER ) - 1 ) ) |
148 | | - |
149 | | -/** |
150 | | - * @brief ALPN (Application-Layer Protocol Negotiation) protocol name for AWS IoT MQTT. |
151 | | - * |
152 | | - * This will be used if the AWS_MQTT_PORT is configured as 443 for AWS IoT MQTT broker. |
153 | | - * Please see more details about the ALPN protocol for AWS IoT MQTT endpoint |
154 | | - * in the link below. |
155 | | - * https://aws.amazon.com/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/ |
156 | | - * |
157 | | - * @note OpenSSL requires that the protocol string passed to it for configuration be encoded |
158 | | - * with the prefix of 8-bit length information of the string. Thus, the 14 byte (0x0e) length |
159 | | - * information is prefixed to the string. |
160 | | - */ |
161 | | -#define AWS_IOT_MQTT_ALPN "\x0ex-amzn-mqtt-ca" |
162 | | - |
163 | | -/** |
164 | | - * @brief Length of ALPN protocol name. |
165 | | - */ |
166 | | -#define AWS_IOT_MQTT_ALPN_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_MQTT_ALPN ) - 1 ) ) |
167 | | - |
168 | | -/** |
169 | | - * @brief This is the ALPN (Application-Layer Protocol Negotiation) string |
170 | | - * required by AWS IoT for password-based authentication using TCP port 443. |
171 | | - * |
172 | | - * @note OpenSSL requires that the protocol string passed to it for configuration |
173 | | - * be encoded with the prefix of 8-bit length information of the string. Thus, the |
174 | | - * 4 byte (0x04) length information is prefixed to the string. |
175 | | - */ |
176 | | -#define AWS_IOT_PASSWORD_ALPN "\x04mqtt" |
177 | | - |
178 | | -/** |
179 | | - * @brief Length of password ALPN. |
180 | | - */ |
181 | | -#define AWS_IOT_PASSWORD_ALPN_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_PASSWORD_ALPN ) - 1 ) ) |
182 | | - |
| 150 | +#define CLIENT_IDENTIFIER_LENGTH ( ( uint16_t ) ( sizeof( CLIENT_IDENTIFIER ) - 1 ) ) |
183 | 151 |
|
184 | 152 | /** |
185 | 153 | * @brief The maximum number of retries for connecting to server. |
|
201 | 169 | */ |
202 | 170 | #define CONNACK_RECV_TIMEOUT_MS ( 1000U ) |
203 | 171 |
|
204 | | - |
205 | 172 | /** |
206 | 173 | * @brief The topic to subscribe and publish to in the example. |
207 | 174 | * |
208 | 175 | * The topic name starts with the client identifier to ensure that each demo |
209 | 176 | * interacts with a unique topic name. |
210 | 177 | */ |
211 | | -#define MQTT_EXAMPLE_TOPIC CLIENT_IDENTIFIER "/example/topic" |
| 178 | +#define MQTT_EXAMPLE_TOPIC CLIENT_IDENTIFIER "/example/topic" |
212 | 179 |
|
213 | 180 | /** |
214 | 181 | * @brief Length of client MQTT topic. |
215 | 182 | */ |
216 | | -#define MQTT_EXAMPLE_TOPIC_LENGTH ( ( uint16_t ) ( sizeof( MQTT_EXAMPLE_TOPIC ) - 1 ) ) |
| 183 | +#define MQTT_EXAMPLE_TOPIC_LENGTH ( ( uint16_t ) ( sizeof( MQTT_EXAMPLE_TOPIC ) - 1 ) ) |
217 | 184 |
|
218 | 185 | /** |
219 | 186 | * @brief The MQTT message published in this example. |
220 | 187 | */ |
221 | | -#define MQTT_EXAMPLE_MESSAGE "Hello World!" |
| 188 | +#define MQTT_EXAMPLE_MESSAGE "Hello World!" |
222 | 189 |
|
223 | 190 | /** |
224 | 191 | * @brief The length of the MQTT message published in this example. |
225 | 192 | */ |
226 | | -#define MQTT_EXAMPLE_MESSAGE_LENGTH ( ( uint16_t ) ( sizeof( MQTT_EXAMPLE_MESSAGE ) - 1 ) ) |
| 193 | +#define MQTT_EXAMPLE_MESSAGE_LENGTH ( ( uint16_t ) ( sizeof( MQTT_EXAMPLE_MESSAGE ) - 1 ) ) |
227 | 194 |
|
228 | 195 | /** |
229 | 196 | * @brief Maximum number of outgoing publishes maintained in the application |
230 | 197 | * until an ack is received from the broker. |
231 | 198 | */ |
232 | | -#define MAX_OUTGOING_PUBLISHES ( 5U ) |
| 199 | +#define MAX_OUTGOING_PUBLISHES ( 5U ) |
233 | 200 |
|
234 | 201 | /** |
235 | 202 | * @brief Invalid packet identifier for the MQTT packets. Zero is always an |
236 | 203 | * invalid packet identifier as per MQTT 3.1.1 spec. |
237 | 204 | */ |
238 | | -#define MQTT_PACKET_ID_INVALID ( ( uint16_t ) 0U ) |
| 205 | +#define MQTT_PACKET_ID_INVALID ( ( uint16_t ) 0U ) |
239 | 206 |
|
240 | 207 | /** |
241 | 208 | * @brief Timeout for MQTT_ProcessLoop function in milliseconds. |
242 | 209 | */ |
243 | | -#define MQTT_PROCESS_LOOP_TIMEOUT_MS ( 500U ) |
| 210 | +#define MQTT_PROCESS_LOOP_TIMEOUT_MS ( 500U ) |
244 | 211 |
|
245 | 212 | /** |
246 | 213 | * @brief The maximum time interval in seconds which is allowed to elapse |
|
251 | 218 | * absence of sending any other Control Packets, the Client MUST send a |
252 | 219 | * PINGREQ Packet. |
253 | 220 | */ |
254 | | -#define MQTT_KEEP_ALIVE_INTERVAL_SECONDS ( 60U ) |
| 221 | +#define MQTT_KEEP_ALIVE_INTERVAL_SECONDS ( 60U ) |
255 | 222 |
|
256 | 223 | /** |
257 | 224 | * @brief Delay between MQTT publishes in seconds. |
258 | 225 | */ |
259 | | -#define DELAY_BETWEEN_PUBLISHES_SECONDS ( 1U ) |
| 226 | +#define DELAY_BETWEEN_PUBLISHES_SECONDS ( 1U ) |
260 | 227 |
|
261 | 228 | /** |
262 | 229 | * @brief Number of PUBLISH messages sent per iteration. |
263 | 230 | */ |
264 | | -#define MQTT_PUBLISH_COUNT_PER_LOOP ( 5U ) |
| 231 | +#define MQTT_PUBLISH_COUNT_PER_LOOP ( 5U ) |
265 | 232 |
|
266 | 233 | /** |
267 | 234 | * @brief Delay in seconds between two iterations of subscribePublishLoop(). |
268 | 235 | */ |
269 | | -#define MQTT_SUBPUB_LOOP_DELAY_SECONDS ( 5U ) |
| 236 | +#define MQTT_SUBPUB_LOOP_DELAY_SECONDS ( 5U ) |
270 | 237 |
|
271 | 238 | /** |
272 | 239 | * @brief Transport timeout in milliseconds for transport send and receive. |
273 | 240 | */ |
274 | | -#define TRANSPORT_SEND_RECV_TIMEOUT_MS ( 500 ) |
| 241 | +#define TRANSPORT_SEND_RECV_TIMEOUT_MS ( 500 ) |
275 | 242 |
|
276 | 243 | /** |
277 | 244 | * @brief The MQTT metrics string expected by AWS IoT. |
278 | 245 | */ |
279 | | -#define METRICS_STRING "?SDK=" OS_NAME "&Version=" OS_VERSION "&Platform=" HARDWARE_PLATFORM_NAME "&MQTTLib=" MQTT_LIB |
| 246 | +#define METRICS_STRING "?SDK=" OS_NAME "&Version=" OS_VERSION "&Platform=" HARDWARE_PLATFORM_NAME "&MQTTLib=" MQTT_LIB |
280 | 247 |
|
281 | 248 | /** |
282 | 249 | * @brief The length of the MQTT metrics string expected by AWS IoT. |
283 | 250 | */ |
284 | | -#define METRICS_STRING_LENGTH ( ( uint16_t ) ( sizeof( METRICS_STRING ) - 1 ) ) |
| 251 | +#define METRICS_STRING_LENGTH ( ( uint16_t ) ( sizeof( METRICS_STRING ) - 1 ) ) |
285 | 252 |
|
286 | 253 |
|
287 | 254 | #ifdef CLIENT_USERNAME |
@@ -673,22 +640,22 @@ static int connectToServerWithBackoffRetries( NetworkContext_t * pNetworkContext |
673 | 640 |
|
674 | 641 | if( AWS_MQTT_PORT == 443 ) |
675 | 642 | { |
676 | | - /* Pass the ALPN protocol name depending on the port being used. |
| 643 | + /* Pass the ALPN protocol name depending on the port and auth type being used. |
677 | 644 | * Please see more details about the ALPN protocol for the AWS IoT MQTT |
678 | 645 | * endpoint in the link below. |
679 | 646 | * https://aws.amazon.com/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/ |
680 | 647 | * |
681 | 648 | * For username and password based authentication in AWS IoT, |
682 | | - * #AWS_IOT_PASSWORD_ALPN is used. More details can be found in the |
| 649 | + * #AWS_IOT_ALPN_MQTT_CUSTOM_AUTH is used. More details can be found in the |
683 | 650 | * link below. |
684 | 651 | * https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html |
685 | 652 | */ |
686 | 653 | #ifdef CLIENT_USERNAME |
687 | | - opensslCredentials.pAlpnProtos = AWS_IOT_PASSWORD_ALPN; |
688 | | - opensslCredentials.alpnProtosLen = AWS_IOT_PASSWORD_ALPN_LENGTH; |
| 654 | + opensslCredentials.pAlpnProtos = AWS_IOT_ALPN_MQTT_CUSTOM_AUTH_OPENSSL; |
| 655 | + opensslCredentials.alpnProtosLen = AWS_IOT_ALPN_MQTT_CUSTOM_AUTH_OPENSSL_LEN; |
689 | 656 | #else |
690 | | - opensslCredentials.pAlpnProtos = AWS_IOT_MQTT_ALPN; |
691 | | - opensslCredentials.alpnProtosLen = AWS_IOT_MQTT_ALPN_LENGTH; |
| 657 | + opensslCredentials.pAlpnProtos = AWS_IOT_ALPN_MQTT_CA_AUTH_OPENSSL; |
| 658 | + opensslCredentials.alpnProtosLen = AWS_IOT_ALPN_MQTT_CA_AUTH_OPENSSL_LEN; |
692 | 659 | #endif |
693 | 660 | } |
694 | 661 |
|
|
0 commit comments