Skip to content

Commit

Permalink
credentials-check: Change to run-time check
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AhmedIsmail02 authored and urutva committed Oct 30, 2023
1 parent 615555d commit e27bc1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/.cSpellWords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ECJPAKE
ecdh
ECDH
ECKEY
endpointid
fsanitize
FVPs
havege
Expand Down
19 changes: 6 additions & 13 deletions Config/aws_configs/aws_clientcredential.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions Projects/aws-iot-example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>

#include "app_config.h"
#include "aws_clientcredential.h"
#include "dev_mode_key_provisioning.h"

#include "mqtt_agent_task.h"
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e27bc1b

Please sign in to comment.