From e27bc1b4c48c96df553665dcf78a26aacc97ce17 Mon Sep 17 00:00:00 2001 From: Ahmed Ismail Date: Thu, 26 Oct 2023 14:38:32 +0100 Subject: [PATCH] credentials-check: Change to run-time check Modify the AWS client credentials check to be part of the main application (run-time check) rather than being part of the compile-time checks. This change ease the development process because it is no longer needed to modify the aws_clientcredential.h file to build the application and then revert it back when pushing the changes remotely. Signed-off-by: Ahmed Ismail --- .github/.cSpellWords.txt | 1 + Config/aws_configs/aws_clientcredential.h | 19 ++++++------------- Projects/aws-iot-example/main.c | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index 3413c569..8aceccf8 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -37,6 +37,7 @@ ECJPAKE ecdh ECDH ECKEY +endpointid fsanitize FVPs havege diff --git a/Config/aws_configs/aws_clientcredential.h b/Config/aws_configs/aws_clientcredential.h index bd9a10e4..3857a849 100644 --- a/Config/aws_configs/aws_clientcredential.h +++ b/Config/aws_configs/aws_clientcredential.h @@ -14,31 +14,24 @@ * * 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 + * @note Replace the used dummy value "dummy.endpointid.amazonaws.com" by your + * AWS IoT Core endpoint which 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 clientcredentialMQTT_BROKER_ENDPOINT "" */ - -#ifndef clientcredentialMQTT_BROKER_ENDPOINT - #error "Uncomment the clientcredentialMQTT_BROKER_ENDPOINT macro above and insert AWS IoT Core endpoint" -#endif /* clientcredentialMQTT_BROKER_ENDPOINT */ +#define clientcredentialMQTT_BROKER_ENDPOINT "dummy.endpointid.amazonaws.com" /** * @brief The MQTT client identifier used in this example. Each client identifier - * must be unique; so edit as required to ensure that no two clients connecting to - * the same broker use the same client identifier. + * must be unique; so replace the used dummy value "dummy_thingname" as required to + * ensure that no two clients connecting to the same broker use the same client identifier. * * Value is defined in "aws_clientcredential.h". */ -/* #define clientcredentialIOT_THING_NAME "" */ - -#ifndef clientcredentialIOT_THING_NAME - #error "Uncomment the clientcredentialIOT_THING_NAME macro above and insert MQTT client identifier" -#endif /* clientcredentialIOT_THING_NAME */ +#define clientcredentialIOT_THING_NAME "dummy_thingname" /** * @brief The port to use for the demo. diff --git a/Projects/aws-iot-example/main.c b/Projects/aws-iot-example/main.c index 9dfa214f..8b4c7a64 100644 --- a/Projects/aws-iot-example/main.c +++ b/Projects/aws-iot-example/main.c @@ -8,6 +8,7 @@ #include #include "app_config.h" +#include "aws_clientcredential.h" #include "dev_mode_key_provisioning.h" #include "mqtt_agent_task.h" @@ -61,6 +62,19 @@ extern BaseType_t xStartPubSubTasks( uint32_t ulNumPubsubTasks, extern uint32_t tfm_ns_interface_init( void ); +static bool xAreAwsCredentialsValid( void ) +{ + if( ( strcmp( clientcredentialMQTT_BROKER_ENDPOINT, "dummy.endpointid.amazonaws.com" ) == 0 ) || + ( strcmp( clientcredentialIOT_THING_NAME, "dummy_thingname" ) == 0 ) ) + { + printf( "[ERR] INVALID BROKER ENDPOINT AND/OR THING NAME.\r\n" ); + printf( "[ERR] Set the right credentials in aws_clientcredential.h\r\n" ); + return false; + } + + return true; +} + void vAssertCalled( const char * pcFile, unsigned long ulLine ) { @@ -151,6 +165,11 @@ int main() bsp_serial_init(); + if( xAreAwsCredentialsValid() != true ) + { + return EXIT_FAILURE; + } + /* Create logging task */ xLoggingTaskInitialize( appCONFIG_LOGGING_TASK_STACK_SIZE, appCONFIG_LOGGING_TASK_PRIORITY,