mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2026-10-02 16:24:45 +08:00
Connection sharing demo reconnect and TLS (#305)
* Add reconnect logic and TLS options to demo * Update demo config text Co-authored-by: SarenaAWS <6563840+sarenameas@users.noreply.github.com> Co-authored-by: Oscar Michael Abrina <abrinao@amazon.com>
This commit is contained in:
co-authored by
SarenaAWS
Oscar Michael Abrina
parent
9857c0b502
commit
420c1e7838
+313
-34
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -89,7 +89,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
|
||||
* call to FreeRTOS_gethostbyname() will return immediately, without even creating
|
||||
* a socket. */
|
||||
#define ipconfigUSE_DNS_CACHE ( 1 )
|
||||
#define ipconfigDNS_CACHE_NAME_LENGTH ( 32 )
|
||||
#define ipconfigDNS_CACHE_NAME_LENGTH ( 64 )
|
||||
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
|
||||
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
|
||||
|
||||
|
||||
+171
-4
File diff suppressed because it is too large
Load Diff
+527
-5
File diff suppressed because it is too large
Load Diff
+74
-39
@@ -63,46 +63,17 @@
|
||||
|
||||
|
||||
/**
|
||||
* @brief MQTT broker end point to connect to.
|
||||
* @brief Endpoint of the MQTT broker to connect to.
|
||||
*
|
||||
* @note For running this demo an MQTT broker, which can be run locally on
|
||||
* the same host is recommended. Any MQTT broker, which can be run on a Windows
|
||||
* host can be used for this demo. However, the instructions below are for
|
||||
* setting up a local Mosquitto broker on a Windows host.
|
||||
* 1. Download Mosquitto from https://mosquitto.org/download/
|
||||
* 2. Install Mosquitto as a Windows service by running the installer.
|
||||
* More details about installing as a Windows service can be found at
|
||||
* https://github.com/eclipse/mosquitto/blob/master/readme-windows.txt and
|
||||
* https://github.com/eclipse/mosquitto/blob/master/readme.md
|
||||
* 3. Verify that Mosquitto server is running locally and listening on port
|
||||
* 1883 by following the steps below.
|
||||
* a. Open Power Shell.
|
||||
* b. Type in command `netstat -a -p TCP | grep 1883` to check if there
|
||||
* is an active connection listening on port 1883.
|
||||
* c. Verify that there is an output as shown below
|
||||
* `TCP 0.0.0.0:1883 <HOST-NAME>:0 LISTENING`
|
||||
* d. If there is no output on step c,go through the Mosquitto documentation
|
||||
* listed above to check if the installation was successful.
|
||||
* 4. Make sure the Mosquitto broker is allowed to communicate through
|
||||
* Windows Firewall. The instructions for allowing an application on Windows 10
|
||||
* Defender Firewall can be found at the link below.
|
||||
* https://support.microsoft.com/en-us/help/4558235/windows-10-allow-an-app-through-microsoft-defender-firewall
|
||||
* After running this MQTT example, consider disabling the Mosquitto broker to
|
||||
* communicate through Windows Firewall for avoiding unwanted network traffic
|
||||
* to your machine.
|
||||
* 5. After verifying that a Mosquitto broker is running successfully, update
|
||||
* the config democonfigMQTT_BROKER_ENDPOINT to the local IP address of the
|
||||
* Windows host machine. Please note that "localhost" or address "127.0.0.1"
|
||||
* will not work as this example is running on a Windows Simulator and not on
|
||||
* Windows host natively. Also note that, if the Windows host is using a
|
||||
* Virtual Private Network(VPN), connection to the Mosquitto broker may not
|
||||
* work.
|
||||
* This demo application can be run with any MQTT broker, although it is
|
||||
* recommended to use one that supports mutual authentication. If mutual
|
||||
* authentication is not used, then #democonfigUSE_TLS should be set to 0.
|
||||
*
|
||||
* As an alternative option, a publicly hosted Mosquitto broker can also be
|
||||
* used as an MQTT broker end point. This can be done by updating the config
|
||||
* democonfigMQTT_BROKER_ENDPOINT to "test.mosquitto.org". However, this is not
|
||||
* recommended due the possible downtimes of the broker as indicated by the
|
||||
* documentation in https://test.mosquitto.org/.
|
||||
* For AWS IoT MQTT broker, this is the Thing's REST API Endpoint.
|
||||
*
|
||||
* @note Your AWS IoT Core endpoint can be found in the AWS IoT console under
|
||||
* Settings/Custom Endpoint, or using the describe-endpoint REST API (with
|
||||
* AWS CLI command line tool).
|
||||
*
|
||||
* #define democonfigMQTT_BROKER_ENDPOINT "insert here."
|
||||
*/
|
||||
@@ -111,9 +82,73 @@
|
||||
/**
|
||||
* @brief The port to use for the demo.
|
||||
*
|
||||
* #define democonfigMQTT_BROKER_PORT ( insert here. )
|
||||
* In general, port 8883 is for secured MQTT connections, and port 1883 if not
|
||||
* using TLS.
|
||||
*
|
||||
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
|
||||
* name. When using port 8883, ALPN is not required.
|
||||
*
|
||||
* #define democonfigMQTT_BROKER_PORT ( insert here. )
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Server's root CA certificate.
|
||||
*
|
||||
* For AWS IoT MQTT broker, this certificate is used to identify the AWS IoT
|
||||
* server and is publicly available. Refer to the AWS documentation available
|
||||
* in the link below.
|
||||
* https://docs.aws.amazon.com/iot/latest/developerguide/server-authentication.html#server-authentication-certs
|
||||
*
|
||||
* @note This certificate should be PEM-encoded.
|
||||
*
|
||||
* Must include the PEM header and footer:
|
||||
* "-----BEGIN CERTIFICATE-----\n"\
|
||||
* "...base64 data...\n"\
|
||||
* "-----END CERTIFICATE-----\n"
|
||||
*
|
||||
* #define democonfigROOT_CA_PEM "...insert here..."
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Client certificate.
|
||||
*
|
||||
* For AWS IoT MQTT broker, refer to the AWS documentation below for details
|
||||
* regarding client authentication.
|
||||
* https://docs.aws.amazon.com/iot/latest/developerguide/client-authentication.html
|
||||
*
|
||||
* @note This certificate should be PEM-encoded.
|
||||
*
|
||||
* Must include the PEM header and footer:
|
||||
* "-----BEGIN CERTIFICATE-----\n"\
|
||||
* "...base64 data...\n"\
|
||||
* "-----END CERTIFICATE-----\n"
|
||||
*
|
||||
* #define democonfigCLIENT_CERTIFICATE_PEM "...insert here..."
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Client's private key.
|
||||
*
|
||||
* For AWS IoT MQTT broker, refer to the AWS documentation below for details
|
||||
* regarding clientauthentication.
|
||||
* https://docs.aws.amazon.com/iot/latest/developerguide/client-authentication.html
|
||||
*
|
||||
* @note This private key should be PEM-encoded.
|
||||
*
|
||||
* Must include the PEM header and footer:
|
||||
* "-----BEGIN RSA PRIVATE KEY-----\n"\
|
||||
* "...base64 data...\n"\
|
||||
* "-----END RSA PRIVATE KEY-----\n"
|
||||
*
|
||||
* #define democonfigCLIENT_PRIVATE_KEY_PEM "...insert here..."
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Whether to use mutual authentication. If this macro is not set to 1
|
||||
* or not defined, then plaintext TCP will be used instead of TLS over TCP.
|
||||
*/
|
||||
#define democonfigUSE_TLS 1
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the stack size of the main demo task.
|
||||
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (C) 2006-2018, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*
|
||||
* This file is provided under the Apache License 2.0, or the
|
||||
* GNU General Public License v2.0 or later.
|
||||
*
|
||||
* **********
|
||||
* Apache License 2.0:
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* **********
|
||||
*
|
||||
* **********
|
||||
* GNU General Public License v2.0 or later:
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* **********
|
||||
*
|
||||
* This repository uses Mbed TLS under Apache 2.0
|
||||
*/
|
||||
|
||||
/* This file configures mbed TLS for FreeRTOS. */
|
||||
|
||||
#ifndef MBEDTLS_CONFIG_H_
|
||||
#define MBEDTLS_CONFIG_H_
|
||||
|
||||
/* FreeRTOS include. */
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
/* Generate errors if deprecated functions are used. */
|
||||
#define MBEDTLS_DEPRECATED_REMOVED
|
||||
|
||||
/* Place AES tables in ROM. */
|
||||
#define MBEDTLS_AES_ROM_TABLES
|
||||
|
||||
/* Enable the following cipher modes. */
|
||||
#define MBEDTLS_CIPHER_MODE_CBC
|
||||
#define MBEDTLS_CIPHER_MODE_CFB
|
||||
#define MBEDTLS_CIPHER_MODE_CTR
|
||||
|
||||
/* Enable the following cipher padding modes. */
|
||||
#define MBEDTLS_CIPHER_PADDING_PKCS7
|
||||
#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
|
||||
#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN
|
||||
#define MBEDTLS_CIPHER_PADDING_ZEROS
|
||||
|
||||
/* Cipher suite configuration. */
|
||||
#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
|
||||
#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
#define MBEDTLS_ECP_NIST_OPTIM
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
|
||||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
|
||||
|
||||
/* Enable all SSL alert messages. */
|
||||
#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
|
||||
|
||||
/* Enable the following SSL features. */
|
||||
#define MBEDTLS_SSL_ENCRYPT_THEN_MAC
|
||||
#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
|
||||
#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
|
||||
#define MBEDTLS_SSL_PROTO_TLS1_2
|
||||
#define MBEDTLS_SSL_ALPN
|
||||
#define MBEDTLS_SSL_SERVER_NAME_INDICATION
|
||||
|
||||
/* Check certificate key usage. */
|
||||
#define MBEDTLS_X509_CHECK_KEY_USAGE
|
||||
#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
|
||||
|
||||
/* Disable platform entropy functions. */
|
||||
#define MBEDTLS_NO_PLATFORM_ENTROPY
|
||||
|
||||
/* Enable the following mbed TLS features. */
|
||||
#define MBEDTLS_AES_C
|
||||
#define MBEDTLS_ASN1_PARSE_C
|
||||
#define MBEDTLS_ASN1_WRITE_C
|
||||
#define MBEDTLS_BASE64_C
|
||||
#define MBEDTLS_BIGNUM_C
|
||||
#define MBEDTLS_CIPHER_C
|
||||
#define MBEDTLS_CTR_DRBG_C
|
||||
#define MBEDTLS_ECDH_C
|
||||
#define MBEDTLS_ECDSA_C
|
||||
#define MBEDTLS_ECP_C
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_GCM_C
|
||||
#define MBEDTLS_MD_C
|
||||
#define MBEDTLS_OID_C
|
||||
#define MBEDTLS_PEM_PARSE_C
|
||||
#define MBEDTLS_PK_C
|
||||
#define MBEDTLS_PK_PARSE_C
|
||||
#define MBEDTLS_PKCS1_V15
|
||||
#define MBEDTLS_PLATFORM_C
|
||||
#define MBEDTLS_RSA_C
|
||||
#define MBEDTLS_SHA1_C
|
||||
#define MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SSL_CLI_C
|
||||
#define MBEDTLS_SSL_TLS_C
|
||||
#define MBEDTLS_THREADING_ALT
|
||||
#define MBEDTLS_THREADING_C
|
||||
#define MBEDTLS_X509_USE_C
|
||||
#define MBEDTLS_X509_CRT_PARSE_C
|
||||
|
||||
/* Set the memory allocation functions on FreeRTOS. */
|
||||
void * mbedtls_platform_calloc( size_t nmemb,
|
||||
size_t size );
|
||||
void mbedtls_platform_free( void * ptr );
|
||||
#define MBEDTLS_PLATFORM_MEMORY
|
||||
#define MBEDTLS_PLATFORM_CALLOC_MACRO mbedtls_platform_calloc
|
||||
#define MBEDTLS_PLATFORM_FREE_MACRO mbedtls_platform_free
|
||||
|
||||
/* The network send and receive functions on FreeRTOS. */
|
||||
int mbedtls_platform_send( void * ctx,
|
||||
const unsigned char * buf,
|
||||
size_t len );
|
||||
int mbedtls_platform_recv( void * ctx,
|
||||
unsigned char * buf,
|
||||
size_t len );
|
||||
|
||||
/* The entropy poll function. */
|
||||
int mbedtls_platform_entropy_poll( void * data,
|
||||
unsigned char * output,
|
||||
size_t len,
|
||||
size_t * olen );
|
||||
|
||||
#include "mbedtls/check_config.h"
|
||||
|
||||
#endif /* ifndef MBEDTLS_CONFIG_H_ */
|
||||
Reference in New Issue
Block a user