diff options
| author | Bo Chen <[email protected]> | 2021-06-02 06:45:26 +0000 |
|---|---|---|
| committer | Bo Chen <[email protected]> | 2021-06-02 06:45:26 +0000 |
| commit | c187d60014b149ee7c5e79b4d84c416caddbdef7 (patch) | |
| tree | 72a504278f1d766a1014ad8ee237813e0644c72a | |
| parent | 678fb5b540e93d85f8ddf4cb83c059d38fb04587 (diff) | |
Release 6.1.7v6.1.7_rel
94 files changed, 1608 insertions, 412 deletions
diff --git a/addons/BSD/nxd_bsd.h b/addons/BSD/nxd_bsd.h index e4a19075..3cdfe38d 100644 --- a/addons/BSD/nxd_bsd.h +++ b/addons/BSD/nxd_bsd.h @@ -62,7 +62,9 @@ extern "C" { #endif +#ifndef __CCRX__ #include "time.h" +#endif /* __CCRX__ */ /* Bring in the necessary NetX include file. */ #include "nx_api.h" @@ -499,7 +501,10 @@ extern "C" { /* Define data types used in structure timeval. */ -typedef LONG suseconds_t; +#ifdef __CCRX__ +typedef LONG time_t; +#endif /* __CCRX__ */ +typedef LONG suseconds_t; #ifndef __SES_ARM struct timeval diff --git a/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE.dist b/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE.dist index 5d85d570..15ec5b7c 100644 --- a/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE.dist +++ b/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE.dist @@ -1,4 +1,11 @@ -# DIST: groups configuration for specific distribution +# set default configuration from specific parent dist +CONF_DEFINE_BASE(${g_core_config_path} base_dist.cmake) + +# DIST: overwrite configuration for specific distribution +set(SECURITY_MODULE_VERSION_MAJOR 3) +set(SECURITY_MODULE_VERSION_MINOR 5) +set(SECURITY_MODULE_VERSION_PATCH 1) + set(ASC_COMPONENT_CONFIGURATION OFF) set(ASC_COLLECTOR_HEARTBEAT_ENABLED ON) @@ -7,16 +14,9 @@ set(ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED ON) set(ASC_COMPONENT_SECURITY_MODULE ON) -# set default configuration from specific parent dist -CONF_DEFINE_BASE(${g_core_config_path} base_dist.cmake) - -# DIST: overwrite configuration for specific distribution -set(SECURITY_MODULE_VERSION_MAJOR 3) -set(SECURITY_MODULE_VERSION_MINOR 3) -set(SECURITY_MODULE_VERSION_PATCH 1) - set(ASC_COMPONENT_CORE_SUPPORTS_RESTART OFF) set(ASC_NOTIFIERS_OBJECT_POOL_ENTRIES 2) +set(ASC_LOG_TIMESTAMP_DEFAULT OFF) set(ASC_BEST_EFFORT_EVENT_LOOP ON) set(ASC_SECURITY_MODULE_SEND_MESSAGE_RETRY_TIME 3) @@ -30,4 +30,6 @@ if(ASC_COMPONENT_CORE_SUPPORTS_RESTART) set(ASC_BE_TIMERS_OBJECT_POOL_ENTRIES 3) else() set(ASC_BE_TIMERS_OBJECT_POOL_ENTRIES 2) -endif()
\ No newline at end of file +endif() +set(FLATCC_NO_ASSERT OFF) +set(FLATCC_ASSERT NX_ASSERT)
\ No newline at end of file diff --git a/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE_UT.dist b/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE_UT.dist index 1b7ce843..caedf490 100644 --- a/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE_UT.dist +++ b/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE_UT.dist @@ -6,11 +6,11 @@ set(ASC_FIRST_FORCE_COLLECTION_INTERVAL 2) set(ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES 1) set(ASC_SECURITY_MODULE_MAX_HUB_DEVICES 128) set(ASC_FLATCC_JSON_PRINTER_OVERWRITE ON) -set(FLATCC_NO_ASSERT OFF) if (NOT DEFINED log_level_cmdline) set(ASC_LOG_LEVEL 0) endif() set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 4) set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 4) set(run_unittests ON CACHE BOOL "set run_unittests to ON to run unittests (default is OFF)") -set(run_coverage ON CACHE BOOL "set run_unittests to ON to run unittests (default is OFF)")
\ No newline at end of file +set(run_coverage ON CACHE BOOL "set run_unittests to ON to run unittests (default is OFF)") +set(FLATCC_ASSERT 0)
\ No newline at end of file diff --git a/addons/azure_iot/azure_iot_security_module/configs/asc_config.h.in b/addons/azure_iot/azure_iot_security_module/configs/asc_config.h.in index 55844f53..97ae5790 100644 --- a/addons/azure_iot/azure_iot_security_module/configs/asc_config.h.in +++ b/addons/azure_iot/azure_iot_security_module/configs/asc_config.h.in @@ -2,9 +2,18 @@ /************************ * Platform configuration *************************/ +#ifdef FLATCC_ASSERT +#undef FLATCC_ASSERT +#endif + #ifndef __ASC_CONFIG_EXCLUDE_PORT__H__ #include "tx_port.h" #include "nx_port.h" +#include "nx_api.h" + +/* Flat buffer serializer platform */ +#cmakedefine FLATCC_ASSERT @FLATCC_ASSERT@ + #endif /* __ASC_CONFIG_EXCLUDE_PORT__H__ */ /* Security Module pending time, in seconds */ diff --git a/addons/azure_iot/azure_iot_security_module/inc/configs/L4_BASE/asc_config.h b/addons/azure_iot/azure_iot_security_module/inc/configs/L4_BASE/asc_config.h index 6d53e447..daa4f106 100644 --- a/addons/azure_iot/azure_iot_security_module/inc/configs/L4_BASE/asc_config.h +++ b/addons/azure_iot/azure_iot_security_module/inc/configs/L4_BASE/asc_config.h @@ -21,23 +21,28 @@ extern "C" { /******************** * Core configuration *********************/ +/* Based on 2021.05.12-3.5.0 core tag */ /* ID and version */ #define ASC_SECURITY_MODULE_ID "defender-iot-micro-agent" #define SECURITY_MODULE_VERSION_MAJOR 3 -#define SECURITY_MODULE_VERSION_MINOR 3 +#define SECURITY_MODULE_VERSION_MINOR 5 #define SECURITY_MODULE_VERSION_PATCH 1 #ifndef SECURITY_MODULE_VERSION_MAJOR -#define SECURITY_MODULE_VERSION_MAJOR 3 +#define SECURITY_MODULE_VERSION_MAJOR 0 #endif #ifndef SECURITY_MODULE_VERSION_MINOR -#define SECURITY_MODULE_VERSION_MINOR 3 +#define SECURITY_MODULE_VERSION_MINOR 0 #endif #ifndef SECURITY_MODULE_VERSION_PATCH #define SECURITY_MODULE_VERSION_PATCH 0 #endif /* Collectors definitions */ +/* #undef ASC_DYNAMIC_COLLECTORS_MAX */ +#ifndef ASC_DYNAMIC_COLLECTORS_MAX +#define ASC_DYNAMIC_COLLECTORS_MAX 0 +#endif #define ASC_COLLECTOR_HEARTBEAT_ENABLED /* #undef ASC_COLLECTOR_BASELINE_ENABLED */ @@ -59,7 +64,6 @@ extern "C" { /* #undef ASC_COLLECTOR_PROCESS_ENABLED */ /* #undef ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS */ -/* #undef ASC_COLLECTOR_PROCESS_MODE_AGGREGATED_DISABLE */ /* #undef ASC_COLLECTOR_PROCESS_IN_CACHE */ #ifndef ASC_COLLECTOR_PROCESS_IN_CACHE #define ASC_COLLECTOR_PROCESS_IN_CACHE 0 @@ -70,6 +74,14 @@ extern "C" { /* #undef ASC_COLLECTOR_LISTENING_PORTS_ENABLED */ /* Components definitions */ +/* #undef ASC_DYNAMIC_FACTORY_ENABLED */ +/* #undef ASC_DYNAMIC_FACTORY_PATH */ +/* #undef ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET */ +/* #undef ASC_DYNAMIC_COMPONENTS_MAX */ +#ifndef ASC_DYNAMIC_COMPONENTS_MAX +#define ASC_DYNAMIC_COMPONENTS_MAX 0 +#endif + /* #undef ASC_COMPONENT_COMMAND_EXECUTOR */ /* #undef ASC_OPERATIONS_POOL_ENTRIES */ @@ -92,6 +104,12 @@ extern "C" { /* #undef ASC_COLLECTORS_INFO_SUPPORT */ /* #undef ASC_LINKED_LIST_NODE_SUPPORT */ +/* Log */ +// Highest compiled log level +/* #undef ASC_LOG_LEVEL */ +/* #undef ASC_TIME_H_SUPPORT */ +/* #undef ASC_LOG_TIMESTAMP_DEFAULT */ + /* Notifier definitions */ #define ASC_NOTIFIERS_OBJECT_POOL_ENTRIES 2 @@ -103,26 +121,44 @@ extern "C" { #define ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR /* #undef ASC_FLATCC_JSON_PRINTER_OVERWRITE */ #define ASC_EMITTER_PAGE_CACHE_SIZE 1 -#define FLATCC_NO_ASSERT +/* #undef FLATCC_NO_ASSERT */ +/* FLATCC_ASSERT might be redefined in platform area */ +#define FLATCC_ASSERT NX_ASSERT #define FLATCC_USE_GENERIC_ALIGNED_ALLOC /* #undef FLATCC_EMITTER_PAGE_SIZE */ /* Tests definitions */ -// Highest compiled log level -/* #undef ASC_LOG_LEVEL */ // Set ASC_FIRST_FORCE_COLLECTION_INTERVAL to '-1' to force immediatly collecting /* #undef ASC_FIRST_FORCE_COLLECTION_INTERVAL */ /* #undef ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES */ /* #undef ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES */ /* #undef ASC_EXTRA_COMPONENTS_COUNT */ +#ifndef ASC_EXTRA_COMPONENTS_COUNT +#define ASC_EXTRA_COMPONENTS_COUNT 0 +#endif /* #undef ASC_EXTRA_COLLECTORS_COUNT */ +#ifndef ASC_EXTRA_COLLECTORS_COUNT +#define ASC_EXTRA_COLLECTORS_COUNT 0 +#endif + +#define LOOP_ASSERT_FAIL for (;;) { } +#define LOOP_ASSERT(s) if (!(s)) {LOOP_ASSERT_FAIL} /************************ * Platform configuration *************************/ +#ifdef FLATCC_ASSERT +#undef FLATCC_ASSERT +#endif + #ifndef __ASC_CONFIG_EXCLUDE_PORT__H__ #include "tx_port.h" #include "nx_port.h" +#include "nx_api.h" + +/* Flat buffer serializer platform */ +#define FLATCC_ASSERT NX_ASSERT + #endif /* __ASC_CONFIG_EXCLUDE_PORT__H__ */ /* Security Module pending time, in seconds */ diff --git a/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE/asc_config.h b/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE/asc_config.h index aaef1e16..7fe1d9b2 100644 --- a/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE/asc_config.h +++ b/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE/asc_config.h @@ -21,23 +21,28 @@ extern "C" { /******************** * Core configuration *********************/ +/* Based on 2021.05.12-3.5.0 core tag */ /* ID and version */ #define ASC_SECURITY_MODULE_ID "defender-iot-micro-agent" #define SECURITY_MODULE_VERSION_MAJOR 3 -#define SECURITY_MODULE_VERSION_MINOR 3 +#define SECURITY_MODULE_VERSION_MINOR 5 #define SECURITY_MODULE_VERSION_PATCH 1 #ifndef SECURITY_MODULE_VERSION_MAJOR -#define SECURITY_MODULE_VERSION_MAJOR 3 +#define SECURITY_MODULE_VERSION_MAJOR 0 #endif #ifndef SECURITY_MODULE_VERSION_MINOR -#define SECURITY_MODULE_VERSION_MINOR 3 +#define SECURITY_MODULE_VERSION_MINOR 0 #endif #ifndef SECURITY_MODULE_VERSION_PATCH #define SECURITY_MODULE_VERSION_PATCH 0 #endif /* Collectors definitions */ +/* #undef ASC_DYNAMIC_COLLECTORS_MAX */ +#ifndef ASC_DYNAMIC_COLLECTORS_MAX +#define ASC_DYNAMIC_COLLECTORS_MAX 0 +#endif #define ASC_COLLECTOR_HEARTBEAT_ENABLED /* #undef ASC_COLLECTOR_BASELINE_ENABLED */ @@ -59,7 +64,6 @@ extern "C" { /* #undef ASC_COLLECTOR_PROCESS_ENABLED */ /* #undef ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS */ -/* #undef ASC_COLLECTOR_PROCESS_MODE_AGGREGATED_DISABLE */ /* #undef ASC_COLLECTOR_PROCESS_IN_CACHE */ #ifndef ASC_COLLECTOR_PROCESS_IN_CACHE #define ASC_COLLECTOR_PROCESS_IN_CACHE 0 @@ -70,6 +74,14 @@ extern "C" { /* #undef ASC_COLLECTOR_LISTENING_PORTS_ENABLED */ /* Components definitions */ +/* #undef ASC_DYNAMIC_FACTORY_ENABLED */ +/* #undef ASC_DYNAMIC_FACTORY_PATH */ +/* #undef ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET */ +/* #undef ASC_DYNAMIC_COMPONENTS_MAX */ +#ifndef ASC_DYNAMIC_COMPONENTS_MAX +#define ASC_DYNAMIC_COMPONENTS_MAX 0 +#endif + /* #undef ASC_COMPONENT_COMMAND_EXECUTOR */ /* #undef ASC_OPERATIONS_POOL_ENTRIES */ @@ -92,6 +104,12 @@ extern "C" { /* #undef ASC_COLLECTORS_INFO_SUPPORT */ /* #undef ASC_LINKED_LIST_NODE_SUPPORT */ +/* Log */ +// Highest compiled log level +/* #undef ASC_LOG_LEVEL */ +/* #undef ASC_TIME_H_SUPPORT */ +/* #undef ASC_LOG_TIMESTAMP_DEFAULT */ + /* Notifier definitions */ #define ASC_NOTIFIERS_OBJECT_POOL_ENTRIES 2 @@ -103,26 +121,44 @@ extern "C" { #define ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR /* #undef ASC_FLATCC_JSON_PRINTER_OVERWRITE */ #define ASC_EMITTER_PAGE_CACHE_SIZE 1 -#define FLATCC_NO_ASSERT +/* #undef FLATCC_NO_ASSERT */ +/* FLATCC_ASSERT might be redefined in platform area */ +#define FLATCC_ASSERT NX_ASSERT #define FLATCC_USE_GENERIC_ALIGNED_ALLOC /* #undef FLATCC_EMITTER_PAGE_SIZE */ /* Tests definitions */ -// Highest compiled log level -/* #undef ASC_LOG_LEVEL */ // Set ASC_FIRST_FORCE_COLLECTION_INTERVAL to '-1' to force immediatly collecting /* #undef ASC_FIRST_FORCE_COLLECTION_INTERVAL */ /* #undef ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES */ /* #undef ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES */ /* #undef ASC_EXTRA_COMPONENTS_COUNT */ +#ifndef ASC_EXTRA_COMPONENTS_COUNT +#define ASC_EXTRA_COMPONENTS_COUNT 0 +#endif /* #undef ASC_EXTRA_COLLECTORS_COUNT */ +#ifndef ASC_EXTRA_COLLECTORS_COUNT +#define ASC_EXTRA_COLLECTORS_COUNT 0 +#endif + +#define LOOP_ASSERT_FAIL for (;;) { } +#define LOOP_ASSERT(s) if (!(s)) {LOOP_ASSERT_FAIL} /************************ * Platform configuration *************************/ +#ifdef FLATCC_ASSERT +#undef FLATCC_ASSERT +#endif + #ifndef __ASC_CONFIG_EXCLUDE_PORT__H__ #include "tx_port.h" #include "nx_port.h" +#include "nx_api.h" + +/* Flat buffer serializer platform */ +#define FLATCC_ASSERT NX_ASSERT + #endif /* __ASC_CONFIG_EXCLUDE_PORT__H__ */ /* Security Module pending time, in seconds */ diff --git a/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE_UT/asc_config.h b/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE_UT/asc_config.h index 015979de..664816c6 100644 --- a/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE_UT/asc_config.h +++ b/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE_UT/asc_config.h @@ -21,23 +21,28 @@ extern "C" { /******************** * Core configuration *********************/ +/* Based on 2021.05.12-3.5.0 core tag */ /* ID and version */ #define ASC_SECURITY_MODULE_ID "defender-iot-micro-agent" #define SECURITY_MODULE_VERSION_MAJOR 3 -#define SECURITY_MODULE_VERSION_MINOR 3 +#define SECURITY_MODULE_VERSION_MINOR 5 #define SECURITY_MODULE_VERSION_PATCH 1 #ifndef SECURITY_MODULE_VERSION_MAJOR -#define SECURITY_MODULE_VERSION_MAJOR 3 +#define SECURITY_MODULE_VERSION_MAJOR 0 #endif #ifndef SECURITY_MODULE_VERSION_MINOR -#define SECURITY_MODULE_VERSION_MINOR 3 +#define SECURITY_MODULE_VERSION_MINOR 0 #endif #ifndef SECURITY_MODULE_VERSION_PATCH #define SECURITY_MODULE_VERSION_PATCH 0 #endif /* Collectors definitions */ +/* #undef ASC_DYNAMIC_COLLECTORS_MAX */ +#ifndef ASC_DYNAMIC_COLLECTORS_MAX +#define ASC_DYNAMIC_COLLECTORS_MAX 0 +#endif #define ASC_COLLECTOR_HEARTBEAT_ENABLED /* #undef ASC_COLLECTOR_BASELINE_ENABLED */ @@ -59,7 +64,6 @@ extern "C" { /* #undef ASC_COLLECTOR_PROCESS_ENABLED */ /* #undef ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS */ -/* #undef ASC_COLLECTOR_PROCESS_MODE_AGGREGATED_DISABLE */ /* #undef ASC_COLLECTOR_PROCESS_IN_CACHE */ #ifndef ASC_COLLECTOR_PROCESS_IN_CACHE #define ASC_COLLECTOR_PROCESS_IN_CACHE 0 @@ -70,6 +74,14 @@ extern "C" { /* #undef ASC_COLLECTOR_LISTENING_PORTS_ENABLED */ /* Components definitions */ +/* #undef ASC_DYNAMIC_FACTORY_ENABLED */ +/* #undef ASC_DYNAMIC_FACTORY_PATH */ +/* #undef ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET */ +/* #undef ASC_DYNAMIC_COMPONENTS_MAX */ +#ifndef ASC_DYNAMIC_COMPONENTS_MAX +#define ASC_DYNAMIC_COMPONENTS_MAX 0 +#endif + /* #undef ASC_COMPONENT_COMMAND_EXECUTOR */ /* #undef ASC_OPERATIONS_POOL_ENTRIES */ @@ -92,6 +104,12 @@ extern "C" { /* #undef ASC_COLLECTORS_INFO_SUPPORT */ /* #undef ASC_LINKED_LIST_NODE_SUPPORT */ +/* Log */ +// Highest compiled log level +/* #undef ASC_LOG_LEVEL */ +/* #undef ASC_TIME_H_SUPPORT */ +/* #undef ASC_LOG_TIMESTAMP_DEFAULT */ + /* Notifier definitions */ #define ASC_NOTIFIERS_OBJECT_POOL_ENTRIES 2 @@ -104,25 +122,43 @@ extern "C" { #define ASC_FLATCC_JSON_PRINTER_OVERWRITE #define ASC_EMITTER_PAGE_CACHE_SIZE 1 /* #undef FLATCC_NO_ASSERT */ +/* FLATCC_ASSERT might be redefined in platform area */ +/* #undef FLATCC_ASSERT */ #define FLATCC_USE_GENERIC_ALIGNED_ALLOC /* #undef FLATCC_EMITTER_PAGE_SIZE */ /* Tests definitions */ -// Highest compiled log level -/* #undef ASC_LOG_LEVEL */ // Set ASC_FIRST_FORCE_COLLECTION_INTERVAL to '-1' to force immediatly collecting #define ASC_FIRST_FORCE_COLLECTION_INTERVAL 2 /* #undef ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES */ #define ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES 1 /* #undef ASC_EXTRA_COMPONENTS_COUNT */ +#ifndef ASC_EXTRA_COMPONENTS_COUNT +#define ASC_EXTRA_COMPONENTS_COUNT 0 +#endif /* #undef ASC_EXTRA_COLLECTORS_COUNT */ +#ifndef ASC_EXTRA_COLLECTORS_COUNT +#define ASC_EXTRA_COLLECTORS_COUNT 0 +#endif + +#define LOOP_ASSERT_FAIL for (;;) { } +#define LOOP_ASSERT(s) if (!(s)) {LOOP_ASSERT_FAIL} /************************ * Platform configuration *************************/ +#ifdef FLATCC_ASSERT +#undef FLATCC_ASSERT +#endif + #ifndef __ASC_CONFIG_EXCLUDE_PORT__H__ #include "tx_port.h" #include "nx_port.h" +#include "nx_api.h" + +/* Flat buffer serializer platform */ +/* #undef FLATCC_ASSERT */ + #endif /* __ASC_CONFIG_EXCLUDE_PORT__H__ */ /* Security Module pending time, in seconds */ diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_coreBuild.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_coreBuild.cmake index 218e1a8b..0d79a56c 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_coreBuild.cmake +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_coreBuild.cmake @@ -51,6 +51,7 @@ function(setTargetCompileOptions target) "-Wfloat-equal" "-Wmissing-declarations" "-Wno-unused-parameter" + "-Wjump-misses-init" ) if(${build_pedantic}) diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/asc_config.h.in b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/asc_config.h.in index 89995762..9b1c9735 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/asc_config.h.in +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/asc_config.h.in @@ -1,6 +1,7 @@ /******************** * Core configuration *********************/ +/* Based on 2021.05.12-3.5.0 core tag */ /* ID and version */ #cmakedefine ASC_SECURITY_MODULE_ID "@ASC_SECURITY_MODULE_ID@" @@ -8,16 +9,20 @@ #cmakedefine SECURITY_MODULE_VERSION_MINOR @SECURITY_MODULE_VERSION_MINOR@ #cmakedefine SECURITY_MODULE_VERSION_PATCH @SECURITY_MODULE_VERSION_PATCH@ #ifndef SECURITY_MODULE_VERSION_MAJOR -#define SECURITY_MODULE_VERSION_MAJOR 3 +#define SECURITY_MODULE_VERSION_MAJOR 0 #endif #ifndef SECURITY_MODULE_VERSION_MINOR -#define SECURITY_MODULE_VERSION_MINOR 3 +#define SECURITY_MODULE_VERSION_MINOR 0 #endif #ifndef SECURITY_MODULE_VERSION_PATCH #define SECURITY_MODULE_VERSION_PATCH 0 #endif /* Collectors definitions */ +#cmakedefine ASC_DYNAMIC_COLLECTORS_MAX @ASC_DYNAMIC_COLLECTORS_MAX@ +#ifndef ASC_DYNAMIC_COLLECTORS_MAX +#define ASC_DYNAMIC_COLLECTORS_MAX 0 +#endif #cmakedefine ASC_COLLECTOR_HEARTBEAT_ENABLED #cmakedefine ASC_COLLECTOR_BASELINE_ENABLED @@ -39,7 +44,6 @@ #cmakedefine ASC_COLLECTOR_PROCESS_ENABLED #cmakedefine ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS -#cmakedefine ASC_COLLECTOR_PROCESS_MODE_AGGREGATED_DISABLE #cmakedefine ASC_COLLECTOR_PROCESS_IN_CACHE @ASC_COLLECTOR_PROCESS_IN_CACHE@ #ifndef ASC_COLLECTOR_PROCESS_IN_CACHE #define ASC_COLLECTOR_PROCESS_IN_CACHE 0 @@ -50,6 +54,14 @@ #cmakedefine ASC_COLLECTOR_LISTENING_PORTS_ENABLED /* Components definitions */ +#cmakedefine ASC_DYNAMIC_FACTORY_ENABLED +#cmakedefine ASC_DYNAMIC_FACTORY_PATH "@ASC_DYNAMIC_FACTORY_PATH@" +#cmakedefine ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET +#cmakedefine ASC_DYNAMIC_COMPONENTS_MAX @ASC_DYNAMIC_COMPONENTS_MAX@ +#ifndef ASC_DYNAMIC_COMPONENTS_MAX +#define ASC_DYNAMIC_COMPONENTS_MAX 0 +#endif + #cmakedefine ASC_COMPONENT_COMMAND_EXECUTOR #cmakedefine ASC_OPERATIONS_POOL_ENTRIES @ASC_OPERATIONS_POOL_ENTRIES@ @@ -72,6 +84,12 @@ #cmakedefine ASC_COLLECTORS_INFO_SUPPORT #cmakedefine ASC_LINKED_LIST_NODE_SUPPORT +/* Log */ +// Highest compiled log level +#cmakedefine ASC_LOG_LEVEL @ASC_LOG_LEVEL@ +#cmakedefine ASC_TIME_H_SUPPORT +#cmakedefine ASC_LOG_TIMESTAMP_DEFAULT + /* Notifier definitions */ #cmakedefine ASC_NOTIFIERS_OBJECT_POOL_ENTRIES @ASC_NOTIFIERS_OBJECT_POOL_ENTRIES@ @@ -84,15 +102,24 @@ #cmakedefine ASC_FLATCC_JSON_PRINTER_OVERWRITE #cmakedefine ASC_EMITTER_PAGE_CACHE_SIZE @ASC_EMITTER_PAGE_CACHE_SIZE@ #cmakedefine FLATCC_NO_ASSERT +/* FLATCC_ASSERT might be redefined in platform area */ +#cmakedefine FLATCC_ASSERT @FLATCC_ASSERT@ #cmakedefine FLATCC_USE_GENERIC_ALIGNED_ALLOC #cmakedefine FLATCC_EMITTER_PAGE_SIZE @FLATCC_EMITTER_PAGE_SIZE@ /* Tests definitions */ -// Highest compiled log level -#cmakedefine ASC_LOG_LEVEL @ASC_LOG_LEVEL@ // Set ASC_FIRST_FORCE_COLLECTION_INTERVAL to '-1' to force immediatly collecting #cmakedefine ASC_FIRST_FORCE_COLLECTION_INTERVAL @ASC_FIRST_FORCE_COLLECTION_INTERVAL@ #cmakedefine ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES @ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES@ #cmakedefine ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES @ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES@ #cmakedefine ASC_EXTRA_COMPONENTS_COUNT @ASC_EXTRA_COMPONENTS_COUNT@ +#ifndef ASC_EXTRA_COMPONENTS_COUNT +#define ASC_EXTRA_COMPONENTS_COUNT 0 +#endif #cmakedefine ASC_EXTRA_COLLECTORS_COUNT @ASC_EXTRA_COLLECTORS_COUNT@ +#ifndef ASC_EXTRA_COLLECTORS_COUNT +#define ASC_EXTRA_COLLECTORS_COUNT 0 +#endif + +#define LOOP_ASSERT_FAIL for (\;\;) { } +#define LOOP_ASSERT(s) if (!(s)) {LOOP_ASSERT_FAIL} diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/base_dist.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/base_dist.cmake index b4ba647e..9a6a3a72 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/base_dist.cmake +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/base_dist.cmake @@ -1,41 +1,37 @@ +set(ASC_SECURITY_MODULE_ID "defender-iot-micro-agent") +set(ASC_FIRST_COLLECTION_INTERVAL 30) +set(ASC_HIGH_PRIORITY_INTERVAL 10) +set(ASC_MEDIUM_PRIORITY_INTERVAL 30) +set(ASC_LOW_PRIORITY_INTERVAL 60) -if(ASC_COLLECTOR_BASELINE_ENABLED) - set(ASC_BASELINE_REPORT_POOL_ENTRIES 100) -endif() - -if(ASC_COLLECTOR_LOG_ENABLED) - set(ASC_LOG_REPORT_POOL_ENTRIES 100) -endif() +set(ASC_COLLECTOR_HEARTBEAT_ENABLED ON) +set(ASC_COLLECTOR_BASELINE_ENABLED OFF) +set(ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED OFF) +set(ASC_COLLECTOR_PROCESS_ENABLED OFF) +set(ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED OFF) +set(ASC_COLLECTOR_LISTENING_PORTS_ENABLED OFF) -if(ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED) - set(ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS OFF) - set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 64) - set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 64) -endif() +set(ASC_COMPONENT_COMMAND_EXECUTOR OFF) +set(ASC_COMPONENT_CONFIGURATION OFF) +set(ASC_COMPONENT_SECURITY_MODULE OFF) -if(ASC_COLLECTOR_PROCESS_ENABLED) - set(ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS OFF) - set(ASC_COLLECTOR_PROCESS_IN_CACHE 32) -endif() +set(ASC_OPERATIONS_POOL_ENTRIES 50) +set(ASC_BASELINE_REPORT_POOL_ENTRIES 100) +set(ASC_LOG_REPORT_POOL_ENTRIES 100) +set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 64) +set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 64) +set(ASC_COLLECTOR_PROCESS_IN_CACHE 32) -if(ASC_COMPONENT_COMMAND_EXECUTOR) - set(ASC_OPERATIONS_POOL_ENTRIES 50) -endif() +set(ASC_DYNAMIC_MEMORY_ENABLED OFF) -set(ASC_COMPONENT_CONFIGURATION_PLAT OFF) -set(ASC_FIRST_COLLECTION_INTERVAL 30) -set(ASC_HIGH_PRIORITY_INTERVAL 10) -set(ASC_MEDIUM_PRIORITY_INTERVAL 30) -set(ASC_LOW_PRIORITY_INTERVAL 60) +set(ASC_BEST_EFFORT_EVENT_LOOP OFF) -if(NOT ASC_DYNAMIC_MEMORY_ENABLED) - set(ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR ON) - set(ASC_EMITTER_PAGE_CACHE_SIZE 1) -else() - set(FLATCC_EMITTER_PAGE_SIZE 14016) -endif() +set(ASC_LOG_TIMESTAMP_DEFAULT ON) -set(FLATCC_NO_ASSERT ON) +set(run_core_unittests OFF) +set(run_core_coverage OFF) +set(build_json_printer OFF) +set(FLATCC_NO_ASSERT OFF) set(FLATCC_USE_GENERIC_ALIGNED_ALLOC ON) set(ASC_FLATCC_JSON_PRINTER_OVERWRITE OFF) set(ASC_COMPONENT_CORE_SUPPORTS_RESTART ON)
\ No newline at end of file diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/depends_configuration.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/depends_configuration.cmake new file mode 100644 index 00000000..a4b67b4a --- /dev/null +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/depends_configuration.cmake @@ -0,0 +1,47 @@ +if(NOT ASC_COMPONENT_CONFIGURATION) + set(ASC_COMPONENT_CONFIGURATION_PLAT OFF) +endif() + +if(NOT ASC_COMPONENT_COMMAND_EXECUTOR) + set(ASC_OPERATIONS_POOL_ENTRIES 0) + set(ASC_COMPONENT_CONFIGURATION_PLAT OFF) +endif() + +if(NOT ASC_COLLECTOR_BASELINE_ENABLED) + set(ASC_BASELINE_REPORT_POOL_ENTRIES 0) + set(ASC_COMPONENT_BASELINE_PLAT OFF) +endif() + +if(NOT ASC_COLLECTOR_LOG_ENABLED) + set(ASC_LOG_REPORT_POOL_ENTRIES 0) +endif() + +if(NOT ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED) + set(ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS OFF) + set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 0) + set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0) +endif() + +if(NOT ASC_COLLECTOR_PROCESS_ENABLED) + set(ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS OFF) + set(ASC_COLLECTOR_PROCESS_IN_CACHE 0) + set(ASC_COLLECTOR_PROCESS_MODE_AGGREGATED_DISABLE OFF) +endif() + +if(NOT ASC_DYNAMIC_FACTORY_ENABLED) + set(ASC_DYNAMIC_COMPONENTS_MAX 0) + set(ASC_DYNAMIC_COLLECTORS_MAX 0) + set(ASC_DYNAMIC_FACTORY_PATH OFF) + set(ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET OFF) +endif() + +if(FLATCC_NO_ASSERT) + set(FLATCC_ASSERT OFF) +endif() + +if(NOT ASC_DYNAMIC_MEMORY_ENABLED) + set(ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR ON) + set(ASC_EMITTER_PAGE_CACHE_SIZE 1) +else() + set(FLATCC_EMITTER_PAGE_SIZE 14016) +endif() diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/functions.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/functions.cmake index 1275ffb3..904d82de 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/functions.cmake +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/functions.cmake @@ -1,6 +1,6 @@ -macro(CONF_GROUPS_OPTIONS __core_config_dir) - # include default groups configuration - include(${__core_config_dir}groups_configuration.cmake) +macro(CONF_DEPENDS_OPTIONS __core_config_dir) + # include default depends configuration + include(${__core_config_dir}depends_configuration.cmake) endmacro() macro(CONF_DEFINE_BASE __config_path __base) @@ -67,12 +67,12 @@ macro(CONF_CREATE_DIST __dist __core_config_dir __plat_config_dir __output __ifd set(g_core_config_path ${__core_config_dir}) set(g_plat_config_path ${__plat_config_dir}) - # set default options from ${__core_config_dir}groups_configuration.cmake - CONF_GROUPS_OPTIONS(${__core_config_dir}) - # configure target dist include(${__plat_config_dir}${__dist}.dist) + # set depends from ${__core_config_dir}depends_configuration.cmake + CONF_DEPENDS_OPTIONS(${__core_config_dir}) + # create asc_config.h.in.tmp for target dist CONF_IN_CREATE(${__core_config_dir} ${__plat_config_dir} ${__dist} ${CMAKE_BINARY_DIR}/asc_config.h.in.tmp ${__ifdef} ${__cpp}) configure_file(${CMAKE_BINARY_DIR}/asc_config.h.in.tmp ${__output} @ONLY) diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/groups_configuration.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/groups_configuration.cmake deleted file mode 100644 index 6fdf8fae..00000000 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/groups_configuration.cmake +++ /dev/null @@ -1,20 +0,0 @@ -set(ASC_SECURITY_MODULE_ID "defender-iot-micro-agent") - -set(ASC_COLLECTOR_HEARTBEAT_ENABLED ON) -set(ASC_COLLECTOR_BASELINE_ENABLED OFF) -set(ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED OFF) -set(ASC_COLLECTOR_PROCESS_ENABLED OFF) -set(ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED OFF) -set(ASC_COLLECTOR_LISTENING_PORTS_ENABLED OFF) - -set(ASC_COMPONENT_COMMAND_EXECUTOR OFF) -set(ASC_COMPONENT_CONFIGURATION OFF) -set(ASC_COMPONENT_SECURITY_MODULE OFF) - -set(ASC_DYNAMIC_MEMORY_ENABLED OFF) - -set(ASC_BEST_EFFORT_EVENT_LOOP OFF) - -set(run_core_unittests OFF) -set(run_core_coverage OFF) -set(build_json_printer OFF) diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_assert.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_assert.h index 225d7337..7e9ccd3b 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_assert.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_assert.h @@ -32,6 +32,13 @@ extern "C" { #define FLATCC_ASSERT(x) ((void)0) /* Grisu3 is used for floating point conversion in JSON processing. */ #define GRISU3_NO_ASSERT +#define __SET_ASSERT__ +#define __ASSERT_VAL__ +#define __ASSERT_REASON__ +#else +extern int __SET_ASSERT__; +extern int __ASSERT_VAL__; +extern const char *__ASSERT_REASON__; #endif #ifndef FLATCC_ASSERT diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/builder.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/builder.c index 130fe8e4..7ea58f19 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/builder.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/builder.c @@ -18,7 +18,13 @@ #include "flatcc/flatcc_builder.h" #include "flatcc/flatcc_emitter.h" +#include "flatcc/flatcc_assert.h" +#ifndef FLATCC_NO_ASSERT +int __SET_ASSERT__ = 0; +int __ASSERT_VAL__ = 0; +const char *__ASSERT_REASON__ = ""; +#endif /* * `check` is designed to handle incorrect use errors that can be * ignored in production of a tested product. @@ -314,7 +320,7 @@ static inline void *reserve_buffer(flatcc_builder_t *B, int alloc_type, size_t u if (used + need > buf->iov_len) { if (B->alloc(B->alloc_context, buf, used + need, zero_init, alloc_type)) { - check(0, "memory allocation failed"); + check(__SET_ASSERT__, "memory allocation failed"); return 0; } } @@ -664,11 +670,11 @@ static inline flatcc_builder_ref_t emit_front(flatcc_builder_t *B, iov_state_t * (iov->len > 16 && iov->len - 16 > FLATBUFFERS_UOFFSET_MAX) || #endif ref >= B->emit_start) { - check(0, "buffer too large to represent"); + check(__SET_ASSERT__, "buffer too large to represent"); return 0; } if (B->emit(B->emit_context, iov->iov, iov->count, ref, iov->len)) { - check(0, "emitter rejected buffer content"); + check(__SET_ASSERT__, "emitter rejected buffer content"); return 0; } return B->emit_start = ref; @@ -690,11 +696,11 @@ static inline flatcc_builder_ref_t emit_back(flatcc_builder_t *B, iov_state_t *i * separately. */ if (B->emit_end < ref) { - check(0, "buffer too large to represent"); + check(__SET_ASSERT__, "buffer too large to represent"); return 0; } if (B->emit(B->emit_context, iov->iov, iov->count, ref, iov->len)) { - check(0, "emitter rejected buffer content"); + check(__SET_ASSERT__, "emitter rejected buffer content"); return 0; } /* @@ -719,7 +725,7 @@ static int align_to_block(flatcc_builder_t *B, uint16_t *align, uint16_t block_a init_iov(); push_iov(_pad, end_pad); if (0 == emit_back(B, &iov)) { - check(0, "emitter rejected buffer content"); + check(__SET_ASSERT__, "emitter rejected buffer content"); return -1; } } @@ -789,7 +795,7 @@ flatcc_builder_ref_t flatcc_builder_create_buffer(flatcc_builder_t *B, } write_uoffset(&object_offset, (uoffset_t)object_ref - buffer_base); if (0 == (buffer_ref = emit_front(B, &iov))) { - check(0, "emitter rejected buffer content"); + check(__SET_ASSERT__, "emitter rejected buffer content"); return 0; } return buffer_ref; @@ -1482,7 +1488,7 @@ static flatcc_builder_ref_t _create_offset_vector_direct(flatcc_builder_t *B, if (types) { check(types[i] == 0, "union vector cannot have null element without type NONE"); } else { - check(0, "offset vector cannot have null element"); + check(__SET_ASSERT__, "offset vector cannot have null element"); } } } @@ -1811,7 +1817,7 @@ void *flatcc_builder_table_add(flatcc_builder_t *B, int id, size_t size, uint16_ } #else if (B->vs[id] != 0) { - check(0, "table field already set"); + check(__SET_ASSERT__, "table field already set"); return 0; } #endif @@ -1846,7 +1852,7 @@ flatcc_builder_ref_t *flatcc_builder_table_add_offset(flatcc_builder_t *B, int i } #else if (B->vs[id] != 0) { - check(0, "table field already set"); + check(__SET_ASSERT__, "table field already set"); return 0; } #endif @@ -1971,11 +1977,11 @@ void *flatcc_builder_finalize_buffer(flatcc_builder_t *B, size_t *size_out) buffer = FLATCC_BUILDER_ALLOC(size); if (!buffer) { - check(0, "failed to allocated memory for finalized buffer"); + check(__SET_ASSERT__, "failed to allocated memory for finalized buffer"); goto done; } if (!flatcc_builder_copy_buffer(B, buffer, size)) { - check(0, "default emitter declined to copy buffer"); + check(__SET_ASSERT__, "default emitter declined to copy buffer"); FLATCC_BUILDER_FREE(buffer); buffer = 0; } diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/refmap.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/refmap.c index a2497f02..e346dad5 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/refmap.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/refmap.c @@ -102,7 +102,7 @@ int flatcc_refmap_resize(flatcc_refmap_t *refmap, size_t count) refmap->table = _flatcc_refmap_calloc(buckets, sizeof(refmap->table[0])); if (refmap->table == 0) { refmap->table = T_old; - FLATCC_ASSERT(0); /* out of memory */ + FLATCC_ASSERT(__SET_ASSERT__); /* out of memory */ return -1; } } diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector.h index 750d4087..c3c55125 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector.h @@ -197,8 +197,8 @@ asc_result_t collector_default_start(component_id_t id); */ asc_result_t collector_default_stop(component_id_t id); -#define COLLECTOR_OPS_DEFINITIONS(__init, __deinit, __subscribe, __unsubscribe, __start, __stop) \ -static component_ops_t _ops = { \ +#define COLLECTOR_OPS_DEFINITIONS(__ops, __init, __deinit, __subscribe, __unsubscribe, __start, __stop) \ +static component_ops_t _ops##__ops = { \ .init = __init, \ .deinit = __deinit, \ .subscribe = __subscribe, \ diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_info.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_info.h index 163a4aa2..164e73a9 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_info.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_info.h @@ -61,7 +61,7 @@ typedef struct { component_id_t id; /* The component's name */ - char *name; + const char *name; /* The component's enumerator */ int enumerator; @@ -80,6 +80,7 @@ typedef struct { /* The log level */ unsigned int log_level; + } component_info_t; /** diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory.h index 2b88e9a8..cfdbccf8 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory.h @@ -34,21 +34,12 @@ extern component_load_function_t components_factory_##_component##_load_ptr; #define COMPONENTS_FACTORY_DEFINITION(_component, _ops) \ asc_result_t components_factory_##_component##_load(void);\ asc_result_t components_factory_##_component##_load(void) { \ - if ((char *)#_component == NULL || str_str(#_component, "_")){ log_fatal("Component name is NULL or has '_'"); return ASC_RESULT_BAD_ARGUMENT; } \ - g_component_factory[_component].component.info.state = COMPONENT_LOADED; \ - g_component_factory[_component].component.info.last_result = ASC_RESULT_OK; \ - g_component_factory[_component].component.info.log_level = ASC_LOG_LEVEL; \ - g_component_factory[_component].component.ops = _ops; \ - g_component_factory[_component].component.info.id = (component_id_t)(&g_component_factory[_component].component); \ - g_component_factory[_component].component.info.name = #_component; \ - g_component_factory[_component].component.info.enumerator = _component; \ - bit_vector_clean(component_owners_t, &g_component_factory[_component].component.info.owners); \ + asc_result_t result = components_factory_set(#_component, _component, _ops, false); \ __auto_generated_self_id = g_component_factory[_component].component.info.id; \ - return ASC_RESULT_OK; \ + return result; \ } \ component_load_function_t components_factory_##_component##_load_ptr = components_factory_##_component##_load; - /* Add this macro in src/components_factory.c */ #define COMPONENTS_FACTORY_LOAD(_component) &components_factory_##_component##_load_ptr diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_enum.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_enum.h index fe022a09..04976b26 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_enum.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_enum.h @@ -13,9 +13,6 @@ #define __COMPONENTS_FACTORY_ENUM_H__ #include <asc_config.h> -/** - * @brief Factory enumerator of collectors. This enumerator comes first in component enum. - */ typedef enum { #ifdef ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED SystemInformation, @@ -38,15 +35,20 @@ typedef enum { __COLLECTOR_COUNT // Must be last } collector_enum_t; -#ifndef ASC_EXTRA_COLLECTORS_COUNT -#define COLLECTORS_COUNT __COLLECTOR_COUNT -#else -#define COLLECTORS_COUNT (__COLLECTOR_COUNT + ASC_EXTRA_COLLECTORS_COUNT) -#endif +#define COLLECTORS_COUNT (__COLLECTOR_COUNT + ASC_EXTRA_COLLECTORS_COUNT + ASC_DYNAMIC_COLLECTORS_MAX) /** * @brief Factory enumerator of all built-in component. * Components factory has following struct: + * FACTORY_ARRAY[__COLLECTOR_COUNT, ASC_EXTRA_COLLECTORS_COUNT, ASC_DYNAMIC_COLLECTORS_MAX, __COMPONENT_COUNT, ASC_EXTRA_COMPONENTS_COUNT, ASC_DYNAMIC_COMPONENTS_MAX] + * COLLECTORS_COUNT + * |________________________________________________________________________| + * COMPONENTS_COUNT + * |___________________________________________________________________________________________________________________________________________________| + */ +/** + * @brief Factory enumerator of collectors. This enumerator comes first in component enum. + * * <Product collectors>: * <starts>: 0 * CollectorN1 @@ -56,7 +58,12 @@ typedef enum { * <starts>: __COLLECTOR_COUNT * CollectorExtraN1 * CollectorExtraNx - * <ends>: COLLECTORS_COUNT + * <ends>: __COLLECTOR_COUNT + ASC_EXTRA_COLLECTORS_COUNT + * <Dynamic collectors>: + * <starts>: __COLLECTOR_COUNT + ASC_DYNAMIC_COLLECTORS_MAX + * CollectorDynamicN1 + * CollectorDynamicNx + * <ends>: COLLECTORS_COUNT = __COLLECTOR_COUNT + ASC_DYNAMIC_COLLECTORS_MAX + ASC_DYNAMIC_COLLECTORS_MAX * <Product components>: * <starts>: COLLECTORS_COUNT * ComponentN1 @@ -66,7 +73,11 @@ typedef enum { * <starts>: __COMPONENT_COUNT * ComponentExtraN1 * ComponentExtraNx - * <ends>: COMPONENTS_COUNT + * <Dynamic components>: + * <starts>: __COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT + * ComponentDynamicN1 + * ComponentDynamicNx + * <ends>: COMPONENTS_COUNT = __COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT + ASC_DYNAMIC_COMPONENTS_MAX * * Each component should be defined in 5 places: * in @c component_enum_t or @c collector_enum_t enum: ComponentName or CollectorName @@ -109,10 +120,6 @@ typedef enum { __COMPONENT_COUNT // Must be last } component_enum_t; -#ifndef ASC_EXTRA_COMPONENTS_COUNT -#define COMPONENTS_COUNT __COMPONENT_COUNT -#else -#define COMPONENTS_COUNT (__COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT) -#endif +#define COMPONENTS_COUNT (__COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT + ASC_DYNAMIC_COMPONENTS_MAX) #endif // __COMPONENTS_FACTORY_ENUM_H__ diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_type.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_type.h index 47f1e03f..79a7c50f 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_type.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_type.h @@ -13,11 +13,13 @@ #define __COMPONENTS_FACTORY__TYPE_H__ #include <asc_config.h> +#include <stdbool.h> + #include "asc_security_core/asc_result.h" #include "asc_security_core/component_info.h" /** - * @brief Factory load the component function prototype + * @brief Factory load the component function prototype. */ typedef asc_result_t (*component_load_function_t)(void); @@ -34,7 +36,7 @@ typedef struct { extern components_factory_t g_component_factory[]; /** - * @brief Get array of component load functions + * @brief Get array of component load functions. * * @return An @c component_load_function_t array of component load functions. */ @@ -42,7 +44,96 @@ component_load_function_t **components_factory_get_load_array(void); /** * @brief Factory unload - clean built-in components data from @c g_component_factory . + * + * @return none. */ void components_factory_unload(void); +/** + * @brief Factory unload - clean built-in component with specified index from @c g_component_factory . + * + * @param index A component's index. + * + * @return none. + */ +void component_factory_unload(int index); + +/** + * @brief Generate ID for component with specified index. + * + * @param index A component's index. + * + * @return A component's ID. + */ +component_id_t components_factory_create_id(int index); + +/** + * @brief Insert component with specified index to @c g_component_factory . + * + * @param name A component's name. + * @param index A component's index. + * @param ops A component's LCM ops. + * @param auto_disable Is componet auto disable to run. + * + * @return ASC_RESULT_OK on success, corresponding error code otherwise. + */ +asc_result_t components_factory_set(const char *name, int index, component_ops_t *ops, bool auto_disable); + +/** + * @brief Dynamic loading API . + */ +#ifdef ASC_DYNAMIC_FACTORY_ENABLED +/** + * @brief Insert dynamic loaded collector with specified index to @c g_component_factory . + * + * @param name A collector's name. + * @param index A collector's index. + * @param ops A collector's LCM ops. + * @param auto_disable Is collector auto disable to run. + * + * @return ASC_RESULT_OK on success, corresponding error code otherwise. + */ +asc_result_t components_factory_set_dynamic_collector(const char *name, int index, component_ops_t *ops, bool auto_disable); + +/** + * @brief Insert dynamic loaded component with specified index to @c g_component_factory . + * + * @param name A component's name. + * @param index A component's index. + * @param ops A component's LCM ops. + * @param auto_disable Is componet auto disable to run. + * + * @return ASC_RESULT_OK on success, corresponding error code otherwise. + */ +asc_result_t components_factory_set_dynamic_component(const char *name, int index, component_ops_t *ops, bool auto_disable); + +/** + * @brief Dynamic loading of all existing collectors and componets to @c g_component_factory . + * + * @param __path A directory of dynamic stuff - if NULL taken from components_factory_dynamic_path_set() and ASC_DYNAMIC_FACTORY_PATH. + * + * @return ASC_RESULT_OK on success, corresponding error code otherwise. + */ +asc_result_t components_factory_load_dynamic(const char *__path); + +/** + * @brief Unload all dynamic loaded entries from @c g_component_factory . + * + * @return none. + */ +void components_factory_unload_dynamic(void); + + +#ifdef ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET +/** + * @brief Overwrite default path to dynamic stuff. + * + * @param __path A directory of dynamic stuff. + * + * @return none. + */ +void components_factory_dynamic_path_set(const char *__path); #endif +#endif // ASC_DYNAMIC_FACTORY_ENABLED + +#endif // __COMPONENTS_FACTORY__TYPE_H__ diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/logger.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/logger.h index 2e04058f..8adde4bc 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/logger.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/logger.h @@ -31,6 +31,8 @@ #define log_error(...) #define log_fatal(...) #define logger_set_system_log_level(_l) + #define logger_set_timestamp(_s) + #define logger_get_system_log_level() (LOG_LEVEL_NOTSET) #else #include <stdio.h> #include <string.h> @@ -41,7 +43,6 @@ #include "asc_security_core/component_id.h" #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) - #define MDC_FORMAT "%s [%s/%s:%d] " bool logger_log(component_id_t id, unsigned int level, const char *filename, const char *func, int line, const char *fmt, ...) ATTRIBUTE_FORMAT(6, 7); /** @@ -52,6 +53,8 @@ * @return true on seccess, otherwise false. */ bool logger_set_system_log_level(int set); + void logger_set_timestamp(bool set); + int logger_get_system_log_level(void); // define log by severity according to ASC_LOG_LEVEL #if ASC_LOG_LEVEL < LOG_LEVEL_DEBUG diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/flatbuffers_common_reader.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/flatbuffers_common_reader.h index 3571c0ed..5f6f64df 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/flatbuffers_common_reader.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/flatbuffers_common_reader.h @@ -14,7 +14,7 @@ #define __flatbuffers_read_vt(ID, offset, t)\ flatbuffers_voffset_t offset = 0;\ { flatbuffers_voffset_t id__tmp, *vt__tmp;\ - FLATCC_ASSERT(t != 0 && "null pointer table access");\ + FLATCC_ASSERT((0 != (__ASSERT_VAL__ = (t != 0))) && (NULL != (__ASSERT_REASON__ = "null pointer table access")));\ id__tmp = ID;\ vt__tmp = (flatbuffers_voffset_t *)((uint8_t *)(t) -\ __flatbuffers_soffset_read_from_pe(t));\ @@ -51,7 +51,7 @@ __flatbuffers_define_scan_by_scalar_field(N, NK, T) if (offset__tmp) {\ return (T)((uint8_t *)(t) + offset__tmp);\ }\ - FLATCC_ASSERT(!(r) && "required field missing");\ + FLATCC_ASSERT((0 != (__ASSERT_VAL__ = !(r))) && (NULL != (__ASSERT_REASON__ = "required field missing")));\ return 0;\ } #define __flatbuffers_offset_field(T, ID, t, r, adjust)\ @@ -64,7 +64,7 @@ __flatbuffers_define_scan_by_scalar_field(N, NK, T) return (T)((uint8_t *)(elem__tmp) + adjust +\ __flatbuffers_uoffset_read_from_pe(elem__tmp));\ }\ - FLATCC_ASSERT(!(r) && "required field missing");\ + FLATCC_ASSERT((0 != (__ASSERT_VAL__ = !(r))) && (NULL != (__ASSERT_REASON__ = "required field missing")));\ return 0;\ } #define __flatbuffers_vector_field(T, ID, t, r) __flatbuffers_offset_field(T, ID, t, r, sizeof(flatbuffers_uoffset_t)) @@ -104,14 +104,14 @@ __flatbuffers_define_scan_by_string_field(N, NK) static inline size_t flatbuffers_vec_len(const void *vec) __flatbuffers_vec_len(vec) #define __flatbuffers_scalar_vec_at(N, vec, i)\ -{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range");\ +{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && (NULL != (__ASSERT_REASON__ = "index out of range")));\ return __flatbuffers_read_scalar(N, &(vec)[i]); } #define __flatbuffers_struct_vec_at(vec, i)\ -{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range"); return (vec) + (i); } +{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && (NULL != (__ASSERT_REASON__ = "index out of range"))); return (vec) + (i); } /* `adjust` skips past the header for string vectors. */ #define __flatbuffers_offset_vec_at(T, vec, i, adjust)\ { const flatbuffers_uoffset_t *elem__tmp = (vec) + (i);\ - FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range");\ + FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && (NULL != (__ASSERT_REASON__ = "index out of range")));\ return (T)((uint8_t *)(elem__tmp) + (size_t)__flatbuffers_uoffset_read_from_pe(elem__tmp) + (adjust)); } #define __flatbuffers_define_scalar_vec_len(N)\ static inline size_t N ## _vec_len(N ##_vec_t vec__tmp)\ @@ -191,7 +191,7 @@ static inline size_t T ## _union_vec_len(T ## _union_vec_t uv__tmp)\ { return NS ## vec_len(uv__tmp.type); }\ static inline T ## _union_t T ## _union_vec_at(T ## _union_vec_t uv__tmp, size_t i__tmp)\ { T ## _union_t u__tmp = { 0, 0 }; size_t n__tmp = NS ## vec_len(uv__tmp.type);\ - FLATCC_ASSERT(n__tmp > (i__tmp) && "index out of range"); u__tmp.type = uv__tmp.type[i__tmp];\ + FLATCC_ASSERT(n__tmp > (i__tmp) && (NULL != (__ASSERT_REASON__ = "index out of range"))); u__tmp.type = uv__tmp.type[i__tmp];\ /* Unknown type is treated as NONE for schema evolution. */\ if (u__tmp.type == 0) return u__tmp;\ u__tmp.value = NS ## generic_vec_at(uv__tmp.value, i__tmp); return u__tmp; }\ @@ -217,7 +217,7 @@ static inline T ## _union_vec_t N ## _ ## NK ## _union(N ## _table_t t__tmp)\ { T ## _union_vec_t uv__tmp; uv__tmp.type = N ## _ ## NK ## _type_get(t__tmp);\ uv__tmp.value = N ## _ ## NK(t__tmp);\ FLATCC_ASSERT(NS ## vec_len(uv__tmp.type) == NS ## vec_len(uv__tmp.value)\ - && "union vector type length mismatch"); return uv__tmp; } + && (NULL != (__ASSERT_REASON__ = "union vector type length mismatch"))); return uv__tmp; } #include <string.h> static const size_t flatbuffers_not_found = (size_t)-1; static const size_t flatbuffers_end = (size_t)-1; diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashtable.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashtable.h index f9486618..f7374915 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashtable.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashtable.h @@ -21,6 +21,8 @@ /* Pay your attention, that this implementation is not thread safe. */ +#define HASH_KEY(_key) ((const void *)((uintptr_t)(_key))) + /** * @brief Typedef of hash function * diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/itime.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/itime.h index 4371cb83..26b91fed 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/itime.h +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/itime.h @@ -19,6 +19,8 @@ #define SEC_HOUR (SEC_MIN * 60) #define SEC_DAY (SEC_HOUR * 24) +#define ITIME_FAILED ((unsigned long)(-1)) + typedef unsigned long (*unix_time_callback_t)(unsigned long *unix_time); void itime_init(unix_time_callback_t time_callback); diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors/collector_heartbeat.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors/collector_heartbeat.c index f42056ea..f41e966e 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors/collector_heartbeat.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors/collector_heartbeat.c @@ -22,7 +22,7 @@ static asc_result_t _collector_heartbeat_get_events(collector_internal_t *collec static asc_result_t _collector_heartbeat_init(component_id_t id); -COLLECTOR_OPS_DEFINITIONS(_collector_heartbeat_init, collector_default_deinit, +COLLECTOR_OPS_DEFINITIONS(, _collector_heartbeat_init, collector_default_deinit, collector_default_subscribe, collector_default_unsubscribe, collector_default_start, collector_default_stop); COMPONENTS_FACTORY_DEFINITION(Heartbeat, &_ops) diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_factory.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_factory.c index e371a61b..cfb4dc8f 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_factory.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_factory.c @@ -13,16 +13,7 @@ #include <stdlib.h> #include "asc_security_core/components_factory_declarations.h" - -#define COMPONENTS_FACTORY_UNLOAD(_component) do { \ - g_component_factory[_component].component.ops = NULL; \ - g_component_factory[_component].component.info.state = COMPONENT_UNLOADED; \ - g_component_factory[_component].component.info.id = 0; \ - g_component_factory[_component].component.info.name = NULL; \ - g_component_factory[_component].component.info.enumerator = COMPONENTS_COUNT; \ - g_component_factory[_component].component.info.log_level = ASC_LOG_LEVEL; \ - bit_vector_clean(component_owners_t, &g_component_factory[_component].component.info.owners); \ -} while (0) +#include "asc_security_core/components_manager.h" components_factory_t g_component_factory[COMPONENTS_COUNT]; @@ -80,11 +71,70 @@ component_load_function_t **components_factory_get_load_array(void) return component_load_function_array; } +component_id_t components_factory_create_id(int index) +{ + return (component_id_t)(&g_component_factory[index].component); +} + +asc_result_t components_factory_set(const char *name, int index, component_ops_t *ops, bool auto_disable) +{ + if (name == NULL || str_str(name, "_")) { + log_fatal("Component name=[%s] is wrong (NULL or has '_')", name ? name : "NULL"); + return ASC_RESULT_BAD_ARGUMENT; + } + if (components_manager_get_id_by_name(name, str_len(name))) { + log_fatal("Component name=[%s] already exists", name); + return ASC_RESULT_BAD_ARGUMENT; + } + g_component_factory[index].component.info.state = COMPONENT_LOADED; + g_component_factory[index].component.info.last_result = ASC_RESULT_OK; + g_component_factory[index].component.info.log_level = ASC_LOG_LEVEL; + g_component_factory[index].component.ops = ops; + g_component_factory[index].component.info.id = components_factory_create_id(index); + g_component_factory[index].component.info.name = name; + g_component_factory[index].component.info.enumerator = index; + g_component_factory[index].component.info.auto_start_disable = auto_disable; + bit_vector_clean(component_owners_t, &g_component_factory[index].component.info.owners); + //__auto_generated_self_id = g_component_factory[_component].component.info.id; + return ASC_RESULT_OK; +} + +#ifdef ASC_DYNAMIC_FACTORY_ENABLED +asc_result_t components_factory_set_dynamic_collector(const char *name, int index, component_ops_t *ops, bool auto_disable) +{ + if (index < (__COLLECTOR_COUNT + ASC_EXTRA_COLLECTORS_COUNT) || index >= COLLECTORS_COUNT) { + log_fatal("Index=[%d] is out of dynamic collectors area", index); + return ASC_RESULT_MEMORY_EXCEPTION; + } + return components_factory_set(name, index, ops, auto_disable); +} + +asc_result_t components_factory_set_dynamic_component(const char *name, int index, component_ops_t *ops, bool auto_disable) +{ + if (index < (__COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT) || index >= COMPONENTS_COUNT) { + log_fatal("Index=[%d] is out of dynamic components area", index); + return ASC_RESULT_MEMORY_EXCEPTION; + } + return components_factory_set(name, index, ops, auto_disable); +} +#endif + +void component_factory_unload(int index) +{ + g_component_factory[index].component.ops = NULL; + g_component_factory[index].component.info.state = COMPONENT_UNLOADED; + g_component_factory[index].component.info.id = 0; + g_component_factory[index].component.info.name = NULL; + g_component_factory[index].component.info.enumerator = COMPONENTS_COUNT; + g_component_factory[index].component.info.log_level = ASC_LOG_LEVEL; + bit_vector_clean(component_owners_t, &g_component_factory[index].component.info.owners); +} + void components_factory_unload(void) { int index; for (index = 0; index < COMPONENTS_COUNT; index++) { - COMPONENTS_FACTORY_UNLOAD(index); + component_factory_unload(index); } } diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_manager.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_manager.c index da7df3d7..839e269d 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_manager.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_manager.c @@ -58,6 +58,13 @@ asc_result_t components_manager_init(void) } } +#ifdef ASC_DYNAMIC_FACTORY_ENABLED + asc_result_t result_dyn = components_factory_load_dynamic(NULL); + if (result_dyn != ASC_RESULT_OK && result_dyn != ASC_RESULT_EMPTY) { + result = result_dyn; + } +#endif + components_manager_do_lcm_action(COMPONENT_INITIALIZED, COMPONENT_LOADED); components_manager_do_lcm_action(COMPONENT_SUBSCRIBED, COMPONENT_INITIALIZED); components_manager_do_lcm_action(COMPONENT_RUNNING, COMPONENT_SUBSCRIBED); @@ -77,6 +84,9 @@ asc_result_t components_manager_deinit(void) components_manager_do_lcm_action(COMPONENT_UNSUBSCRIBED, COMPONENT_UNDEFINED); components_manager_do_lcm_action(COMPONENT_LOADED, COMPONENT_UNDEFINED); +#ifdef ASC_DYNAMIC_FACTORY_ENABLED + components_factory_unload_dynamic(); // must be before components_factory_unload(); +#endif components_factory_unload(); _components_manager_global_context = 0; return ASC_RESULT_OK; @@ -120,7 +130,12 @@ unsigned int components_manager_get_log_level(component_id_t id) } component_info_t *info = components_manager_get_info(id); - return info ? info->log_level : LOG_LEVEL_DEBUG; // return highest on fail + // return debug if no info or not initialized yet to not lost the log print + if (!info || info->state == COMPONENT_UNLOADED) { + return LOG_LEVEL_DEBUG; + } + + return info->log_level; } bool components_manager_set_log_level_all(int set) @@ -142,7 +157,7 @@ component_t *components_manager_get_component(component_id_t id) { for (int index = 0; index < COMPONENTS_COUNT; index++) { if (g_component_factory[index].component.info.id == id) { - return (component_t*)id; + return &g_component_factory[index].component; } } return NULL; @@ -381,7 +396,9 @@ static void _perform_lcm_action(lcm_func_t func, int index, component_state_enum break; default: if (func == NULL) { - g_component_factory[index].component.info.state = to_state; + if (g_component_factory[index].component.info.state != COMPONENT_FAIL) { + g_component_factory[index].component.info.state = to_state; + } log_debug("%d function function in component=[%s] is not armed", to_state, g_component_factory[index].component.info.name); return; } @@ -418,8 +435,8 @@ static void components_manager_do_lcm_action(component_state_enum_t to_state, co is_stop_start_same_state = true; } - if (!is_stop_start_same_state && from_state != COMPONENT_UNDEFINED && g_component_factory[index].component.info.state != from_state) { - log_error("Expected=[%d] state is not match current=[%d]", from_state, g_component_factory[index].component.info.state); + if (func && !is_stop_start_same_state && from_state != COMPONENT_UNDEFINED && g_component_factory[index].component.info.state != from_state) { + log_error("Expected=[%d] state is not match current=[%d] component=[%s]", from_state, g_component_factory[index].component.info.state, g_component_factory[index].component.info.name); g_component_factory[index].component.info.last_result = ASC_RESULT_PARSE_EXCEPTION; continue; } diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/core.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/core.c index d02c0b81..4c580147 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/core.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/core.c @@ -82,7 +82,7 @@ static void _security_module_state_cb(notifier_t *notifier, int message_num, voi static void _init_random_collect_offset(core_t *core_ptr) { unsigned long now = itime_time(NULL); - if (now == (unsigned long)(-1)) { + if (now == ITIME_FAILED) { log_error("Error get current time"); now = 0; } @@ -104,7 +104,7 @@ static unsigned long _calculate_collector_time_offset(core_t *core_ptr, collecto // TODO it breaks sequence of collections and cause to increasing of security messages - need to sync on init_random_collect_offset if (state == COMPONENT_RUNNING) { unsigned long now = itime_time(NULL); - if (now == (unsigned long)(-1)) { + if (now == ITIME_FAILED) { log_error("Error get current time"); now = 0; } @@ -317,7 +317,7 @@ static asc_result_t core_collect(core_t *core_ptr, unsigned long now) bool at_least_one_success = false; bool time_passed = false; - if (now == (unsigned long)(-1)) { + if (now == ITIME_FAILED) { log_error("Error get current time"); return ASC_RESULT_IMPOSSIBLE; } @@ -441,7 +441,7 @@ static asc_result_t _set_next_collect_timer(core_t *core_ptr, unsigned long now, // stop existing timer el->timer_delete(core_ptr->h_collect); - if (now == (unsigned long)(-1)) { + if (now == ITIME_FAILED) { log_error("Error get current time"); core_ptr->h_collect = el->timer_create(cb_collect, core_ptr, ASC_HIGH_PRIORITY_INTERVAL, 0, &core_ptr->h_collect); core_ptr->nearest_collect_time = ASC_HIGH_PRIORITY_INTERVAL; diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/logger.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/logger.c index 5f3abff2..448f1d2a 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/logger.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/logger.c @@ -9,14 +9,21 @@ /* */ /*******************************************************************************/ #include <asc_config.h> +#include "asc_security_core/components_manager.h" +// #define ASC_TIME_H_SUPPORT +#if ASC_LOG_LEVEL != LOG_LEVEL_NOTSET #include <stdio.h> #include <stdarg.h> #include <stdbool.h> +#ifdef ASC_TIME_H_SUPPORT +#include <time.h> +#endif + #include "asc_security_core/logger.h" +#include "asc_security_core/utils/itime.h" #include "asc_security_core/utils/string_utils.h" -#include "asc_security_core/components_manager.h" #ifdef ASC_COMPONENT_CONFIGURATION #include "asc_security_core/configuration.h" #endif @@ -24,9 +31,12 @@ #include "asc_security_core/utils/string_utils.h" #include "asc_security_core/logger.h" -#if ASC_LOG_LEVEL != LOG_LEVEL_NOTSET - static unsigned int _system_level = ASC_LOG_LEVEL; +#ifdef ASC_LOG_TIMESTAMP_DEFAULT +static bool _timestamp = true; +#else +static bool _timestamp = false; +#endif static code2string_t _log_levels[] = { {LOG_LEVEL_NOTSET, "NOSET"}, @@ -196,8 +206,23 @@ bool logger_set_system_log_level(int set) return true; } +int logger_get_system_log_level(void) +{ + return (int)_system_level; +} + +void logger_set_timestamp(bool set) +{ + _timestamp = set; +} + bool logger_log(component_id_t id, unsigned int level, const char *filename, const char *func, int line, const char *fmt, ...) { +#define MDC_FORMAT "%s [%s/%s:%d] " +#define MDC_TS_FORMAT "%s %lu - [%s/%s:%d] " +#ifdef ASC_TIME_H_SUPPORT + #define MDC_TS_TIME_H_FORMAT "%s %02d:%02d:%02d [%s/%s:%d] " +#endif const char *level_str = NULL; if (_system_level < level @@ -214,7 +239,21 @@ bool logger_log(component_id_t id, unsigned int level, const char *filename, con level_str = "UNDEF"; } - printf(MDC_FORMAT , level_str, filename, func, line); + if (_timestamp) { + unsigned long rawtime = itime_time(NULL); +#ifdef ASC_TIME_H_SUPPORT + struct tm *ptm = localtime((time_t *)&rawtime); + if (ptm == NULL) { + printf(MDC_TS_FORMAT, level_str, rawtime, filename, func, line); + } else { + printf(MDC_TS_TIME_H_FORMAT, level_str, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, filename, func, line); + } +#else + printf(MDC_TS_FORMAT, level_str, rawtime, filename, func, line); +#endif + } else { + printf(MDC_FORMAT, level_str, filename, func, line); + } va_list args; va_start(args, fmt); diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/collector.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/collector.c index 7f961186..e30ad63b 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/collector.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/collector.c @@ -169,7 +169,7 @@ asc_result_t collector_serialize_events(collector_t *collector_ptr, serializer_t return ASC_RESULT_BAD_ARGUMENT; } unsigned long now = itime_time(NULL); - if (now == (unsigned long)(-1)) { + if (now == ITIME_FAILED) { log_error("Error get current time"); now = 0; } diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/event_loop_be.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/event_loop_be.c index a7e6b0fa..aa534a2a 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/event_loop_be.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/event_loop_be.c @@ -129,7 +129,7 @@ static event_timer_t *_timer_add(event_timer_t *t, event_loop_timer_cb_t cb, voi event_timer_t *curr = NULL, *new; bool is_periodic = !!t; unsigned long now = itime_time(NULL); - if (now == (unsigned long)(-1)) { + if (now == ITIME_FAILED) { log_error("Error get current time"); now = 0; } @@ -195,7 +195,7 @@ static bool _run_once(void) { event_timer_t *t; unsigned long now = itime_time(NULL); - if (now == (unsigned long)(-1)) { + if (now == ITIME_FAILED) { log_error("Error get current time"); now = 0; } diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/notifier.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/notifier.c index 8a8cc81a..aee98b82 100644 --- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/notifier.c +++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/notifier.c @@ -40,13 +40,15 @@ static bool _linked_list_find_condition(void *item, void *condition_input) int32_t notifier_notify(notify_topic_t topic, int msg_num, void *payload) { + linked_list_t *linked_list_handle = NULL; + notifier_item_t *curr = NULL; + if (topic >= NOTIFY_TOPICS_NUMBER) { log_error("Failed to remove notifier due to bad argument"); goto error; } - linked_list_t *linked_list_handle = &_notify_arr[topic]; - notifier_item_t *curr = NULL; + linked_list_handle = &_notify_arr[topic]; linked_list_foreach(linked_list_handle, curr) { if (curr->notifier->notify) { curr->notifier->notify(curr->notifier, msg_num, payload); diff --git a/addons/azure_iot/azure_iot_security_module/nx_azure_iot_security_module.c b/addons/azure_iot/azure_iot_security_module/nx_azure_iot_security_module.c index 834fe9d4..e87446d3 100644 --- a/addons/azure_iot/azure_iot_security_module/nx_azure_iot_security_module.c +++ b/addons/azure_iot/azure_iot_security_module/nx_azure_iot_security_module.c @@ -196,7 +196,7 @@ UINT nx_azure_iot_security_module_enable(NX_AZURE_IOT *nx_azure_iot_ptr) goto cleanup; } - if (nx_azure_iot_ptr->nx_azure_iot_unix_time_get(&t) != NX_SUCCESS) + if (nx_azure_iot_ptr->nx_azure_iot_unix_time_get(&t) != NX_AZURE_IOT_SUCCESS) { status = NX_AZURE_IOT_FAILURE; LogError(LogLiteralArgs("Failed to retrieve UNIX time")); @@ -322,10 +322,10 @@ static unsigned long _security_module_unix_time_get(unsigned long *unix_time) if (security_module_ptr == NULL || security_module_ptr->nx_azure_iot_ptr == NULL) { - return (unsigned long)-1; + return ITIME_FAILED; } - if (security_module_ptr->nx_azure_iot_ptr->nx_azure_iot_unix_time_get(&t) == NX_SUCCESS) + if (security_module_ptr->nx_azure_iot_ptr->nx_azure_iot_unix_time_get(&t) == NX_AZURE_IOT_SUCCESS) { if (unix_time != NULL) { @@ -335,7 +335,7 @@ static unsigned long _security_module_unix_time_get(unsigned long *unix_time) return (unsigned long)t; } - return (unsigned long)-1; + return ITIME_FAILED; } static UINT _security_module_get_nx_status(UINT current) @@ -509,13 +509,13 @@ static void _security_module_event_process_state_pending(NX_AZURE_IOT_SECURITY_M } /* Get current timestamp. */ - if (itime_time(&now_timestamp) == (unsigned long)-1) + if (itime_time(&now_timestamp) == ITIME_FAILED) { LogError(LogLiteralArgs("Failed to retrieve timestamp")); } - if (security_module_ptr->state_timestamp != (unsigned long)-1 && - now_timestamp != (unsigned long)-1 && + if (security_module_ptr->state_timestamp != ITIME_FAILED && + now_timestamp != ITIME_FAILED && now_timestamp - security_module_ptr->state_timestamp > ASC_SECURITY_MODULE_PENDING_TIME) { /* Security Module pending state time expired. */ @@ -721,7 +721,7 @@ static void _security_module_update_state(NX_AZURE_IOT_SECURITY_MODULE *security } /* Set security module state timestamp. */ - if (itime_time(&now_timestamp) == (unsigned long)-1) + if (itime_time(&now_timestamp) == ITIME_FAILED) { LogError(LogLiteralArgs("Failed to retrive time")); } diff --git a/addons/azure_iot/azure_iot_security_module/src/collectors/collector_network_activity.c b/addons/azure_iot/azure_iot_security_module/src/collectors/collector_network_activity.c index 742c6204..bfd602f2 100644 --- a/addons/azure_iot/azure_iot_security_module/src/collectors/collector_network_activity.c +++ b/addons/azure_iot/azure_iot_security_module/src/collectors/collector_network_activity.c @@ -181,7 +181,7 @@ static asc_result_t _init(component_id_t id); static asc_result_t _start(component_id_t id); static asc_result_t _stop(component_id_t id); -COLLECTOR_OPS_DEFINITIONS(_init, collector_default_deinit, collector_default_subscribe, collector_default_unsubscribe, _start, _stop); +COLLECTOR_OPS_DEFINITIONS(, _init, collector_default_deinit, collector_default_subscribe, collector_default_unsubscribe, _start, _stop); COMPONENTS_FACTORY_DEFINITION(NetworkActivity, &_ops) diff --git a/addons/azure_iot/azure_iot_security_module/src/collectors/collector_system_information.c b/addons/azure_iot/azure_iot_security_module/src/collectors/collector_system_information.c index 09782179..b4446495 100644 --- a/addons/azure_iot/azure_iot_security_module/src/collectors/collector_system_information.c +++ b/addons/azure_iot/azure_iot_security_module/src/collectors/collector_system_information.c @@ -31,7 +31,7 @@ static asc_result_t _collect_operation_system_information(collector_internal_t * static asc_result_t _init(component_id_t id); -COLLECTOR_OPS_DEFINITIONS(_init, collector_default_deinit, +COLLECTOR_OPS_DEFINITIONS(, _init, collector_default_deinit, collector_default_subscribe, collector_default_unsubscribe, collector_default_start, collector_default_stop); COMPONENTS_FACTORY_DEFINITION(SystemInformation, &_ops) diff --git a/addons/azure_iot/azure_iot_security_module/src/utils/itime.c b/addons/azure_iot/azure_iot_security_module/src/utils/itime.c index 76257424..2a30d7cf 100644 --- a/addons/azure_iot/azure_iot_security_module/src/utils/itime.c +++ b/addons/azure_iot/azure_iot_security_module/src/utils/itime.c @@ -26,7 +26,7 @@ unsigned long itime_time(unsigned long *timer) { if (_time_callback == NULL) { - return (unsigned long)-1; + return ITIME_FAILED; } return _time_callback(timer); diff --git a/addons/azure_iot/docs/azure_rtos_iot_hub_client.md b/addons/azure_iot/docs/azure_rtos_iot_hub_client.md index 2fcdba02..dd12ab9e 100644 --- a/addons/azure_iot/docs/azure_rtos_iot_hub_client.md +++ b/addons/azure_iot/docs/azure_rtos_iot_hub_client.md @@ -87,6 +87,41 @@ Threads <div style="page-break-after: always;"></div> +**nx_azure_iot_hub_client_trusted_cert_add** +*** +<div style="text-align: right"> Add trusted certificate </div> + +**Prototype** +```c +UINT nx_azure_iot_hub_client_trusted_cert_add(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr, + NX_SECURE_X509_CERT *trusted_certificate); +``` +**Description** + +<p>This routine adds the trusted certificate. It can be called multiple times to set multiple trusted certificates.</p> + +**Parameters** + +| Name | Description | +| - |:-| +| hub_client_ptr [in] | A pointer to a `NX_AZURE_IOT_HUB_CLIENT` | +| trusted_certificate [in] | A pointer to a `NX_SECURE_X509_CERT` | + +**Return Values** +* NX_AZURE_IOT_SUCCESS Successfully add trusted certificate to Azure IoT Hub Instance. +* NX_AZURE_IOT_INVALID_PARAMETER Fail to add trusted certificate to Azure IoT Hub Instance due to invalid parameter. +* NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE Fail to add trusted certificate due to `NX_AZURE_IOT_MAX_NUM_OF_TRUSTED_CERTS` is too small. + +**Allowed From** + +Threads + +**Example** + +**See Also** + +<div style="page-break-after: always;"></div> + **nx_azure_iot_hub_client_device_cert_set** *** <div style="text-align: right"> Set client certificate </div> @@ -98,7 +133,7 @@ UINT nx_azure_iot_hub_client_device_cert_set(NX_AZURE_IOT_HUB_CLIENT *hub_client ``` **Description** -<p>This routine sets the device certificate.</p> +<p>This routine sets the device certificate. It can be called multiple times to set certificate chain.</p> **Parameters** @@ -108,8 +143,9 @@ UINT nx_azure_iot_hub_client_device_cert_set(NX_AZURE_IOT_HUB_CLIENT *hub_client | device_certificate [in] | A pointer to a `NX_SECURE_X509_CERT` | **Return Values** -* NX_AZURE_IOT_SUCCESS Successfully set device certificate to AZ IoT Hub Instance. -* NX_AZURE_IOT_INVALID_PARAMETER Fail to set device certificate to AZ IoT Hub Instance due to invalid parameter. +* NX_AZURE_IOT_SUCCESS Successfully set device certificate to Azure IoT Hub Instance. +* NX_AZURE_IOT_INVALID_PARAMETER Fail to set device certificate to Azure IoT Hub Instance due to invalid parameter. +* NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE Fail to set device certificate due to `NX_AZURE_IOT_MAX_NUM_OF_DEVICE_CERTS` is too small. **Allowed From** diff --git a/addons/azure_iot/docs/azure_rtos_iot_provisioning_client.md b/addons/azure_iot/docs/azure_rtos_iot_provisioning_client.md index 99f3e067..90560d25 100644 --- a/addons/azure_iot/docs/azure_rtos_iot_provisioning_client.md +++ b/addons/azure_iot/docs/azure_rtos_iot_provisioning_client.md @@ -89,6 +89,40 @@ Threads <div style="page-break-after: always;"></div> +**nx_azure_iot_provisioning_client_trusted_cert_add** +*** +<div style="text-align: right"> Add trusted certificate </div> + +**Prototype** +```c +UINT nx_azure_iot_provisioning_client_trusted_cert_add(NX_AZURE_IOT_PROVISIONING_CLIENT *prov_client_ptr, + NX_SECURE_X509_CERT *trusted_certificate); +``` +**Description** + +<p>This routine adds trusted certificate. It can be called multiple times to set certificate chain.</p> + +**Parameters** +| Name | Description | +| - |:-| +| prov_client_ptr [in] | A pointer to a `NX_AZURE_IOT_PROVISIONING_CLIENT` | +| trusted_certificate [in] | A pointer to a `NX_SECURE_X509_CERT` | + +**Return Values** +* NX_AZURE_IOT_SUCCESS Successfully add trusted certs to AZ IoT Provisioning Client Instance. +* NX_AZURE_IOT_INVALID_PARAMETER Fail to add trusted certs to AZ IoT Provisioning Client Instance due to invalid parameter. +* NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE Fail to add trusted certificate due to `NX_AZURE_IOT_MAX_NUM_OF_TRUSTED_CERTS` is too small. + +**Allowed From** + +Threads + +**Example** + +**See Also** + +<div style="page-break-after: always;"></div> + **nx_azure_iot_provisioning_client_device_cert_set** *** <div style="text-align: right"> Set client certificate </div> @@ -100,7 +134,7 @@ UINT nx_azure_iot_provisioning_client_device_cert_set(NX_AZURE_IOT_PROVISIONING_ ``` **Description** -<p>This routine sets device certificate.</p> +<p>This routine sets device certificate. It can be called multiple times to set certificate chain.</p> **Parameters** | Name | Description | @@ -111,6 +145,7 @@ UINT nx_azure_iot_provisioning_client_device_cert_set(NX_AZURE_IOT_PROVISIONING_ **Return Values** * NX_AZURE_IOT_SUCCESS Successfully set device certs to AZ IoT Provisioning Client Instance. * NX_AZURE_IOT_INVALID_PARAMETER Fail to set device certs to AZ IoT Provisioning Client Instance due to invalid parameter. +* NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE Fail to set device certificate due to `NX_AZURE_IOT_MAX_NUM_OF_DEVICE_CERTS` is too small. **Allowed From** diff --git a/addons/azure_iot/nx_azure_iot.c b/addons/azure_iot/nx_azure_iot.c index 7acc7172..632c7e71 100644 --- a/addons/azure_iot/nx_azure_iot.c +++ b/addons/azure_iot/nx_azure_iot.c @@ -619,6 +619,7 @@ UINT nx_azure_iot_mqtt_tls_setup(NXD_MQTT_CLIENT *client_ptr, NX_SECURE_TLS_SESS NX_SECURE_X509_CERT *trusted_certificate) { UINT status; +UINT i; NX_AZURE_IOT_RESOURCE *resource_ptr; NX_PARAMETER_NOT_USED(certificate); @@ -651,21 +652,30 @@ NX_AZURE_IOT_RESOURCE *resource_ptr; LogError(LogLiteralArgs("Failed to create TLS session status: %d"), status); return(status); } - - status = nx_secure_tls_trusted_certificate_add(tls_session, resource_ptr -> resource_trusted_certificate); - if (status) + + for (i = 0; i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_trusted_certificates); i++) { - LogError(LogLiteralArgs("Failed to add trusted CA certificate to session status: %d"), status); - return(status); + if (resource_ptr -> resource_trusted_certificates[i]) + { + status = nx_secure_tls_trusted_certificate_add(tls_session, resource_ptr -> resource_trusted_certificates[i]); + if (status) + { + LogError(LogLiteralArgs("Failed to add trusted CA certificate to session status: %d"), status); + return(status); + } + } } - if (resource_ptr -> resource_device_certificate) + for (i = 0; i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_device_certificates); i++) { - status = nx_secure_tls_local_certificate_add(tls_session, resource_ptr -> resource_device_certificate); - if (status) + if (resource_ptr -> resource_device_certificates[i]) { - LogError(LogLiteralArgs("Failed to add device certificate to session status: %d"), status); - return(status); + status = nx_secure_tls_local_certificate_add(tls_session, resource_ptr -> resource_device_certificates[i]); + if (status) + { + LogError(LogLiteralArgs("Failed to add device certificate to session status: %d"), status); + return(status); + } } } diff --git a/addons/azure_iot/nx_azure_iot.h b/addons/azure_iot/nx_azure_iot.h index d4229d2f..2d07aac4 100644 --- a/addons/azure_iot/nx_azure_iot.h +++ b/addons/azure_iot/nx_azure_iot.h @@ -48,6 +48,18 @@ extern "C" { #define NX_AZURE_IOT_LOG_LEVEL 2 #endif /* NX_AZURE_IOT_LOG_LEVEL */ +/* Define maximum trusted certificates count. */ +#ifndef NX_AZURE_IOT_MAX_NUM_OF_TRUSTED_CERTS +#define NX_AZURE_IOT_MAX_NUM_OF_TRUSTED_CERTS 3 +#endif /* NX_AZURE_IOT_MAX_NUM_OF_TRUSTED_CERTS */ + +/* Define maximum device certificates count. */ +#ifndef NX_AZURE_IOT_MAX_NUM_OF_DEVICE_CERTS +#define NX_AZURE_IOT_MAX_NUM_OF_DEVICE_CERTS 2 +#endif /* NX_AZURE_IOT_MAX_NUM_OF_DEVICE_CERTS */ + +#define NX_AZURE_IOT_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + /* Define the az iot log function. */ #define LogError(...) #define LogInfo(...) @@ -170,8 +182,8 @@ typedef struct NX_AZURE_IOT_RESOURCE_STRUCT UINT resource_cipher_map_size; UCHAR *resource_metadata_ptr; UINT resource_metadata_size; - NX_SECURE_X509_CERT *resource_trusted_certificate; - NX_SECURE_X509_CERT *resource_device_certificate; + NX_SECURE_X509_CERT *resource_trusted_certificates[NX_AZURE_IOT_MAX_NUM_OF_TRUSTED_CERTS]; + NX_SECURE_X509_CERT *resource_device_certificates[NX_AZURE_IOT_MAX_NUM_OF_DEVICE_CERTS]; const UCHAR *resource_hostname; UINT resource_hostname_length; struct NX_AZURE_IOT_RESOURCE_STRUCT *resource_next; diff --git a/addons/azure_iot/nx_azure_iot_hub_client.c b/addons/azure_iot/nx_azure_iot_hub_client.c index 0b15d58e..13842882 100644 --- a/addons/azure_iot/nx_azure_iot_hub_client.c +++ b/addons/azure_iot/nx_azure_iot_hub_client.c @@ -22,14 +22,16 @@ #ifndef NX_AZURE_IOT_HUB_CLIENT_USER_AGENT -/* Useragent e.g: DeviceClientType=c%2F1.0.0-preview.1%20%28nx%206.0%3Bazrtos%206.0%29 */ +/* Useragent e.g: DeviceClientType=c%2F1.0.0%20%28nx%206.0.0%3Bazrtos%206.0.0%29 */ #define NX_AZURE_IOT_HUB_CLIENT_STR(C) #C #define NX_AZURE_IOT_HUB_CLIENT_TO_STR(x) NX_AZURE_IOT_HUB_CLIENT_STR(x) #define NX_AZURE_IOT_HUB_CLIENT_USER_AGENT "DeviceClientType=c%2F" AZ_SDK_VERSION_STRING "%20%28nx%20" \ NX_AZURE_IOT_HUB_CLIENT_TO_STR(NETXDUO_MAJOR_VERSION) "." \ - NX_AZURE_IOT_HUB_CLIENT_TO_STR(NETXDUO_MINOR_VERSION) "%3Bazrtos%20"\ + NX_AZURE_IOT_HUB_CLIENT_TO_STR(NETXDUO_MINOR_VERSION) "." \ + NX_AZURE_IOT_HUB_CLIENT_TO_STR(NETXDUO_PATCH_VERSION) "%3Bazrtos%20"\ NX_AZURE_IOT_HUB_CLIENT_TO_STR(THREADX_MAJOR_VERSION) "." \ - NX_AZURE_IOT_HUB_CLIENT_TO_STR(THREADX_MINOR_VERSION) "%29" + NX_AZURE_IOT_HUB_CLIENT_TO_STR(THREADX_MINOR_VERSION) "." \ + NX_AZURE_IOT_HUB_CLIENT_TO_STR(THREADX_PATCH_VERSION) "%29" #endif /* NX_AZURE_IOT_HUB_CLIENT_USER_AGENT */ static VOID nx_azure_iot_hub_client_received_message_cleanup(NX_AZURE_IOT_HUB_CLIENT_RECEIVE_MESSAGE *message); @@ -155,7 +157,7 @@ az_result core_result; hub_client_ptr -> nx_azure_iot_hub_client_resource.resource_cipher_map_size = cipher_map_size; hub_client_ptr -> nx_azure_iot_hub_client_resource.resource_metadata_ptr = metadata_memory; hub_client_ptr -> nx_azure_iot_hub_client_resource.resource_metadata_size = memory_size; - hub_client_ptr -> nx_azure_iot_hub_client_resource.resource_trusted_certificate = trusted_certificate; + hub_client_ptr -> nx_azure_iot_hub_client_resource.resource_trusted_certificates[0] = trusted_certificate; hub_client_ptr -> nx_azure_iot_hub_client_resource.resource_hostname = host_name; hub_client_ptr -> nx_azure_iot_hub_client_resource.resource_hostname_length = host_name_length; options.module_id = az_span_create((UCHAR *)module_id, (INT)module_id_length); @@ -688,9 +690,53 @@ UINT status; return(NX_AZURE_IOT_SUCCESS); } +UINT nx_azure_iot_hub_client_trusted_cert_add(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr, + NX_SECURE_X509_CERT *trusted_certificate) +{ +UINT i; +NX_AZURE_IOT_RESOURCE *resource_ptr; + + if ((hub_client_ptr == NX_NULL) || + (hub_client_ptr -> nx_azure_iot_ptr == NX_NULL) || + (trusted_certificate == NX_NULL)) + { + LogError(LogLiteralArgs("IoTHub device certificate set fail: INVALID POINTER")); + return(NX_AZURE_IOT_INVALID_PARAMETER); + } + + /* Obtain the mutex. */ + tx_mutex_get(hub_client_ptr -> nx_azure_iot_ptr -> nx_azure_iot_mutex_ptr, TX_WAIT_FOREVER); + + resource_ptr = &(hub_client_ptr -> nx_azure_iot_hub_client_resource); + for (i = 0; i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_trusted_certificates); i++) + { + if (resource_ptr -> resource_trusted_certificates[i] == NX_NULL) + { + resource_ptr -> resource_trusted_certificates[i] = trusted_certificate; + break; + } + } + + /* Release the mutex. */ + tx_mutex_put(hub_client_ptr -> nx_azure_iot_ptr -> nx_azure_iot_mutex_ptr); + + if (i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_trusted_certificates)) + { + return(NX_AZURE_IOT_SUCCESS); + } + else + { + + /* No more space to store trusted certificate. */ + return(NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE); + } +} + UINT nx_azure_iot_hub_client_device_cert_set(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr, NX_SECURE_X509_CERT *device_certificate) { +UINT i; +NX_AZURE_IOT_RESOURCE *resource_ptr; if ((hub_client_ptr == NX_NULL) || (hub_client_ptr -> nx_azure_iot_ptr == NX_NULL) || @@ -703,12 +749,29 @@ UINT nx_azure_iot_hub_client_device_cert_set(NX_AZURE_IOT_HUB_CLIENT *hub_client /* Obtain the mutex. */ tx_mutex_get(hub_client_ptr -> nx_azure_iot_ptr -> nx_azure_iot_mutex_ptr, TX_WAIT_FOREVER); - hub_client_ptr -> nx_azure_iot_hub_client_resource.resource_device_certificate = device_certificate; + resource_ptr = &(hub_client_ptr -> nx_azure_iot_hub_client_resource); + for (i = 0; i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_device_certificates); i++) + { + if (resource_ptr -> resource_device_certificates[i] == NX_NULL) + { + resource_ptr -> resource_device_certificates[i] = device_certificate; + break; + } + } /* Release the mutex. */ tx_mutex_put(hub_client_ptr -> nx_azure_iot_ptr -> nx_azure_iot_mutex_ptr); - return(NX_AZURE_IOT_SUCCESS); + if (i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_device_certificates)) + { + return(NX_AZURE_IOT_SUCCESS); + } + else + { + + /* No more space to store device certificate. */ + return(NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE); + } } UINT nx_azure_iot_hub_client_symmetric_key_set(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr, @@ -1248,7 +1311,7 @@ ULONG bytes_copied; NX_PARAMETER_NOT_USED(packet_id); NX_PARAMETER_NOT_USED(context); - /* Mointor subscribe ack. */ + /* Monitor subscribe ack. */ if (type == MQTT_CONTROL_PACKET_TYPE_SUBACK) { diff --git a/addons/azure_iot/nx_azure_iot_hub_client.h b/addons/azure_iot/nx_azure_iot_hub_client.h index 69a5348a..273d2d6f 100644 --- a/addons/azure_iot/nx_azure_iot_hub_client.h +++ b/addons/azure_iot/nx_azure_iot_hub_client.h @@ -77,7 +77,7 @@ extern "C" { #define NX_AZURE_IOT_HUB_CLIENT_MAX_BACKOFF_JITTER_PERCENT (60) #endif /* NX_AZURE_IOT_HUB_CLIENT_MAX_BACKOFF_JITTER_PERCENT */ -/* Define AZ IoT Hub Client state. */ +/* Define Azure IoT Hub Client state. */ /**< The client is not connected */ #define NX_AZURE_IOT_HUB_CLIENT_STATUS_NOT_CONNECTED 0 @@ -200,13 +200,27 @@ UINT nx_azure_iot_hub_client_initialize(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr, UINT nx_azure_iot_hub_client_deinitialize(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr); /** - * @brief Set the client certificate in the IoT Hub client. + * @brief Add more trusted certificate in the IoT Hub client if needed. It can be called multiple times to set multiple trusted certificates. + * + * @param[in] hub_client_ptr A pointer to a #NX_AZURE_IOT_HUB_CLIENT. + * @param[in] trusted_certificate A pointer to a `NX_SECURE_X509_CERT`, which is the trusted certificate. + * @return A `UINT` with the result of the API. + * @retval #NX_AZURE_IOT_SUCCESS Successfully add trusted certificate to Azure IoT Hub Instance. + * @retval #NX_AZURE_IOT_INVALID_PARAMETER Fail to add trusted certificate to Azure IoT Hub Instance due to invalid parameter. + * @retval #NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE Fail to add trusted certificate due to NX_AZURE_IOT_MAX_NUM_OF_TRUSTED_CERTS is too small. + */ +UINT nx_azure_iot_hub_client_trusted_cert_add(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr, + NX_SECURE_X509_CERT *trusted_certificate); + +/** + * @brief Set the client certificate in the IoT Hub client. It can be called multiple times to set certificate chain. * * @param[in] hub_client_ptr A pointer to a #NX_AZURE_IOT_HUB_CLIENT. * @param[in] device_certificate A pointer to a `NX_SECURE_X509_CERT`, which is the device certificate. * @return A `UINT` with the result of the API. - * @retval #NX_AZURE_IOT_SUCCESS Successfully set device certificate to AZ IoT Hub Instance. - * @retval #NX_AZURE_IOT_INVALID_PARAMETER Fail to set device certificate to AZ IoT Hub Instance due to invalid parameter. + * @retval #NX_AZURE_IOT_SUCCESS Successfully set device certificate to Azure IoT Hub Instance. + * @retval #NX_AZURE_IOT_INVALID_PARAMETER Fail to set device certificate to Azure IoT Hub Instance due to invalid parameter. + * @retval #NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE Fail to set device certificate due to NX_AZURE_IOT_MAX_NUM_OF_DEVICE_CERTS is too small. */ UINT nx_azure_iot_hub_client_device_cert_set(NX_AZURE_IOT_HUB_CLIENT *hub_client_ptr, NX_SECURE_X509_CERT *device_certificate); diff --git a/addons/azure_iot/nx_azure_iot_provisioning_client.c b/addons/azure_iot/nx_azure_iot_provisioning_client.c index 3ab6fb2f..b3e87619 100644 --- a/addons/azure_iot/nx_azure_iot_provisioning_client.c +++ b/addons/azure_iot/nx_azure_iot_provisioning_client.c @@ -839,7 +839,7 @@ az_span registration_id_span = az_span_create((UCHAR *)registration_id, (INT)reg prov_client_ptr -> nx_azure_iot_provisioning_client_resource.resource_cipher_map_size = cipher_map_size; prov_client_ptr -> nx_azure_iot_provisioning_client_resource.resource_metadata_ptr = metadata_memory; prov_client_ptr -> nx_azure_iot_provisioning_client_resource.resource_metadata_size = memory_size; - prov_client_ptr -> nx_azure_iot_provisioning_client_resource.resource_trusted_certificate = trusted_certificate; + prov_client_ptr -> nx_azure_iot_provisioning_client_resource.resource_trusted_certificates[0] = trusted_certificate; prov_client_ptr -> nx_azure_iot_provisioning_client_resource.resource_hostname = endpoint; prov_client_ptr -> nx_azure_iot_provisioning_client_resource.resource_hostname_length = endpoint_length; resource_ptr -> resource_mqtt_client_id_length = prov_client_ptr -> nx_azure_iot_provisioning_client_registration_id_length; @@ -1012,9 +1012,54 @@ UINT status; return(NX_AZURE_IOT_SUCCESS); } +UINT nx_azure_iot_provisioning_client_trusted_cert_add(NX_AZURE_IOT_PROVISIONING_CLIENT *prov_client_ptr, + NX_SECURE_X509_CERT *trusted_certificate) +{ +UINT i; +NX_AZURE_IOT_RESOURCE *resource_ptr; + + if ((prov_client_ptr == NX_NULL) || + (prov_client_ptr -> nx_azure_iot_ptr == NX_NULL) || + (trusted_certificate == NX_NULL)) + { + LogError(LogLiteralArgs("IoTHub device certificate set fail: INVALID POINTER")); + return(NX_AZURE_IOT_INVALID_PARAMETER); + } + + /* Obtain the mutex. */ + tx_mutex_get(prov_client_ptr -> nx_azure_iot_ptr -> nx_azure_iot_mutex_ptr, TX_WAIT_FOREVER); + + resource_ptr = &(prov_client_ptr -> nx_azure_iot_provisioning_client_resource); + for (i = 0; i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_trusted_certificates); i++) + { + if (resource_ptr -> resource_trusted_certificates[i] == NX_NULL) + { + resource_ptr -> resource_trusted_certificates[i] = trusted_certificate; + break; + } + } + + /* Release the mutex. */ + tx_mutex_put(prov_client_ptr -> nx_azure_iot_ptr -> nx_azure_iot_mutex_ptr); + + if (i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_trusted_certificates)) + { + return(NX_AZURE_IOT_SUCCESS); + } + else + { + + /* No more space to store trusted certificate. */ + return(NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE); + } +} + UINT nx_azure_iot_provisioning_client_device_cert_set(NX_AZURE_IOT_PROVISIONING_CLIENT *prov_client_ptr, NX_SECURE_X509_CERT *x509_cert) { +UINT i; +NX_AZURE_IOT_RESOURCE *resource_ptr; + if ((prov_client_ptr == NX_NULL) || (prov_client_ptr -> nx_azure_iot_ptr == NX_NULL) || (x509_cert == NX_NULL)) { LogError(LogLiteralArgs("IoTProvisioning device cert set fail: INVALID POINTER")); @@ -1024,12 +1069,29 @@ UINT nx_azure_iot_provisioning_client_device_cert_set(NX_AZURE_IOT_PROVISIONING_ /* Obtain the mutex. */ tx_mutex_get(prov_client_ptr -> nx_azure_iot_ptr -> nx_azure_iot_mutex_ptr, NX_WAIT_FOREVER); - prov_client_ptr -> nx_azure_iot_provisioning_client_resource.resource_device_certificate = x509_cert; + resource_ptr = &(prov_client_ptr -> nx_azure_iot_provisioning_client_resource); + for (i = 0; i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_device_certificates); i++) + { + if (resource_ptr -> resource_device_certificates[i] == NX_NULL) + { + resource_ptr -> resource_device_certificates[i] = x509_cert; + break; + } + } /* Release the mutex. */ tx_mutex_put(prov_client_ptr -> nx_azure_iot_ptr -> nx_azure_iot_mutex_ptr); - return(NX_AZURE_IOT_SUCCESS); + if (i < NX_AZURE_IOT_ARRAY_SIZE(resource_ptr -> resource_device_certificates)) + { + return(NX_AZURE_IOT_SUCCESS); + } + else + { + + /* No more space to store device certificate. */ + return(NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE); + } } diff --git a/addons/azure_iot/nx_azure_iot_provisioning_client.h b/addons/azure_iot/nx_azure_iot_provisioning_client.h index cba71332..65630bfe 100644 --- a/addons/azure_iot/nx_azure_iot_provisioning_client.h +++ b/addons/azure_iot/nx_azure_iot_provisioning_client.h @@ -160,14 +160,28 @@ UINT nx_azure_iot_provisioning_client_initialize(NX_AZURE_IOT_PROVISIONING_CLIEN UINT nx_azure_iot_provisioning_client_deinitialize(NX_AZURE_IOT_PROVISIONING_CLIENT *prov_client_ptr); /** + * @brief Add more trusted certificate in the IoT Provisioning client if needed. It can be called multiple times to set certificate chain. + * + * @param[in] prov_client_ptr A pointer to a #NX_AZURE_IOT_PROVISIONING_CLIENT. + * @param[in] trusted_certificate A pointer to a `NX_SECURE_X509_CERT`, which is the trusted certificate. + * @return A `UINT` with the result of the API. + * @retval #NX_AZURE_IOT_SUCCESS Successfully add trusted certificate to AZ IoT Provisioning Client Instance. + * @retval #NX_AZURE_IOT_INVALID_PARAMETER Fail to add trusted certificate to AZ IoT Provisioning Client Instance due to invalid parameter. + * @retval #NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE Fail to add trusted certificate due to NX_AZURE_IOT_MAX_NUM_OF_TRUSTED_CERTS is too small. + */ +UINT nx_azure_iot_provisioning_client_trusted_cert_add(NX_AZURE_IOT_PROVISIONING_CLIENT *prov_client_ptr, + NX_SECURE_X509_CERT *trusted_certificate); + +/** * @brief Set client certificate. - * @details This routine sets the device certificate. + * @details This routine sets the device certificate. It can be called multiple times to set certificate chain. * * @param[in] prov_client_ptr A pointer to a #NX_AZURE_IOT_PROVISIONING_CLIENT. * @param[in] x509_cert A pointer to a `NX_SECURE_X509_CERT` client cert. * @return A `UINT` with the result of the API. * @retval #NX_AZURE_IOT_SUCCESS Successfully set device certs to AZ IoT Provisioning Client Instance. * @retval #NX_AZURE_IOT_INVALID_PARAMETER Fail to set device certs to AZ IoT Provisioning Client Instance due to invalid parameter. + * @retval #NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE Fail to set device certificate due to NX_AZURE_IOT_MAX_NUM_OF_DEVICE_CERTS is too small. */ UINT nx_azure_iot_provisioning_client_device_cert_set(NX_AZURE_IOT_PROVISIONING_CLIENT *prov_client_ptr, NX_SECURE_X509_CERT *x509_cert); diff --git a/addons/azure_iot/samples/cert/nx_azure_iot_cert.c b/addons/azure_iot/samples/cert/nx_azure_iot_cert.c index 30341b4a..cde72833 100644 --- a/addons/azure_iot/samples/cert/nx_azure_iot_cert.c +++ b/addons/azure_iot/samples/cert/nx_azure_iot_cert.c @@ -72,5 +72,169 @@ const unsigned char _nx_azure_iot_root_cert[] = { 0x47, 0xd2, 0x38, 0x2e, 0xd0, 0xfe, 0x81, 0xdc, 0x32, 0x6a, 0x1e, 0xb5, 0xee, 0x3c, 0xd5, 0xfc, 0xe7, 0x81, 0x1d, 0x19, 0xc3, 0x24, 0x42, 0xea, 0x63, 0x39, 0xa9 }; - const unsigned int _nx_azure_iot_root_cert_size = sizeof(_nx_azure_iot_root_cert); + +/* Azure IoT Hub and DPS will migrate to the Digicert Global Root G2. + To continue without disruption due to this changes, Microsoft recommends that + client applications or devices trust the Digicert Global Root G2. */ + +/* Digicert Global Root G2 */ +const unsigned char _nx_azure_iot_root_cert_2[] = { + 0x30, 0x82, 0x03, 0x8e, 0x30, 0x82, 0x02, 0x76, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x03, + 0x3a, 0xf1, 0xe6, 0xa7, 0x11, 0xa9, 0xa0, 0xbb, 0x28, 0x64, 0xb1, 0x1d, 0x09, 0xfa, 0xe5, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x61, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x15, 0x30, + 0x13, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0c, 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, 0x72, 0x74, + 0x20, 0x49, 0x6e, 0x63, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x10, 0x77, + 0x77, 0x77, 0x2e, 0x64, 0x69, 0x67, 0x69, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x31, + 0x20, 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x17, 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, + 0x72, 0x74, 0x20, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x47, + 0x32, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x33, 0x30, 0x38, 0x30, 0x31, 0x31, 0x32, 0x30, 0x30, 0x30, + 0x30, 0x5a, 0x17, 0x0d, 0x33, 0x38, 0x30, 0x31, 0x31, 0x35, 0x31, 0x32, 0x30, 0x30, 0x30, 0x30, + 0x5a, 0x30, 0x61, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, + 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0c, 0x44, 0x69, 0x67, 0x69, 0x43, + 0x65, 0x72, 0x74, 0x20, 0x49, 0x6e, 0x63, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0b, + 0x13, 0x10, 0x77, 0x77, 0x77, 0x2e, 0x64, 0x69, 0x67, 0x69, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x63, + 0x6f, 0x6d, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x17, 0x44, 0x69, 0x67, + 0x69, 0x43, 0x65, 0x72, 0x74, 0x20, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x52, 0x6f, 0x6f, + 0x74, 0x20, 0x47, 0x32, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, + 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, + 0x02, 0x82, 0x01, 0x01, 0x00, 0xbb, 0x37, 0xcd, 0x34, 0xdc, 0x7b, 0x6b, 0xc9, 0xb2, 0x68, 0x90, + 0xad, 0x4a, 0x75, 0xff, 0x46, 0xba, 0x21, 0x0a, 0x08, 0x8d, 0xf5, 0x19, 0x54, 0xc9, 0xfb, 0x88, + 0xdb, 0xf3, 0xae, 0xf2, 0x3a, 0x89, 0x91, 0x3c, 0x7a, 0xe6, 0xab, 0x06, 0x1a, 0x6b, 0xcf, 0xac, + 0x2d, 0xe8, 0x5e, 0x09, 0x24, 0x44, 0xba, 0x62, 0x9a, 0x7e, 0xd6, 0xa3, 0xa8, 0x7e, 0xe0, 0x54, + 0x75, 0x20, 0x05, 0xac, 0x50, 0xb7, 0x9c, 0x63, 0x1a, 0x6c, 0x30, 0xdc, 0xda, 0x1f, 0x19, 0xb1, + 0xd7, 0x1e, 0xde, 0xfd, 0xd7, 0xe0, 0xcb, 0x94, 0x83, 0x37, 0xae, 0xec, 0x1f, 0x43, 0x4e, 0xdd, + 0x7b, 0x2c, 0xd2, 0xbd, 0x2e, 0xa5, 0x2f, 0xe4, 0xa9, 0xb8, 0xad, 0x3a, 0xd4, 0x99, 0xa4, 0xb6, + 0x25, 0xe9, 0x9b, 0x6b, 0x00, 0x60, 0x92, 0x60, 0xff, 0x4f, 0x21, 0x49, 0x18, 0xf7, 0x67, 0x90, + 0xab, 0x61, 0x06, 0x9c, 0x8f, 0xf2, 0xba, 0xe9, 0xb4, 0xe9, 0x92, 0x32, 0x6b, 0xb5, 0xf3, 0x57, + 0xe8, 0x5d, 0x1b, 0xcd, 0x8c, 0x1d, 0xab, 0x95, 0x04, 0x95, 0x49, 0xf3, 0x35, 0x2d, 0x96, 0xe3, + 0x49, 0x6d, 0xdd, 0x77, 0xe3, 0xfb, 0x49, 0x4b, 0xb4, 0xac, 0x55, 0x07, 0xa9, 0x8f, 0x95, 0xb3, + 0xb4, 0x23, 0xbb, 0x4c, 0x6d, 0x45, 0xf0, 0xf6, 0xa9, 0xb2, 0x95, 0x30, 0xb4, 0xfd, 0x4c, 0x55, + 0x8c, 0x27, 0x4a, 0x57, 0x14, 0x7c, 0x82, 0x9d, 0xcd, 0x73, 0x92, 0xd3, 0x16, 0x4a, 0x06, 0x0c, + 0x8c, 0x50, 0xd1, 0x8f, 0x1e, 0x09, 0xbe, 0x17, 0xa1, 0xe6, 0x21, 0xca, 0xfd, 0x83, 0xe5, 0x10, + 0xbc, 0x83, 0xa5, 0x0a, 0xc4, 0x67, 0x28, 0xf6, 0x73, 0x14, 0x14, 0x3d, 0x46, 0x76, 0xc3, 0x87, + 0x14, 0x89, 0x21, 0x34, 0x4d, 0xaf, 0x0f, 0x45, 0x0c, 0xa6, 0x49, 0xa1, 0xba, 0xbb, 0x9c, 0xc5, + 0xb1, 0x33, 0x83, 0x29, 0x85, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42, 0x30, 0x40, 0x30, 0x0f, + 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, + 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, + 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x4e, 0x22, 0x54, 0x20, 0x18, 0x95, + 0xe6, 0xe3, 0x6e, 0xe6, 0x0f, 0xfa, 0xfa, 0xb9, 0x12, 0xed, 0x06, 0x17, 0x8f, 0x39, 0x30, 0x0d, + 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, + 0x01, 0x00, 0x60, 0x67, 0x28, 0x94, 0x6f, 0x0e, 0x48, 0x63, 0xeb, 0x31, 0xdd, 0xea, 0x67, 0x18, + 0xd5, 0x89, 0x7d, 0x3c, 0xc5, 0x8b, 0x4a, 0x7f, 0xe9, 0xbe, 0xdb, 0x2b, 0x17, 0xdf, 0xb0, 0x5f, + 0x73, 0x77, 0x2a, 0x32, 0x13, 0x39, 0x81, 0x67, 0x42, 0x84, 0x23, 0xf2, 0x45, 0x67, 0x35, 0xec, + 0x88, 0xbf, 0xf8, 0x8f, 0xb0, 0x61, 0x0c, 0x34, 0xa4, 0xae, 0x20, 0x4c, 0x84, 0xc6, 0xdb, 0xf8, + 0x35, 0xe1, 0x76, 0xd9, 0xdf, 0xa6, 0x42, 0xbb, 0xc7, 0x44, 0x08, 0x86, 0x7f, 0x36, 0x74, 0x24, + 0x5a, 0xda, 0x6c, 0x0d, 0x14, 0x59, 0x35, 0xbd, 0xf2, 0x49, 0xdd, 0xb6, 0x1f, 0xc9, 0xb3, 0x0d, + 0x47, 0x2a, 0x3d, 0x99, 0x2f, 0xbb, 0x5c, 0xbb, 0xb5, 0xd4, 0x20, 0xe1, 0x99, 0x5f, 0x53, 0x46, + 0x15, 0xdb, 0x68, 0x9b, 0xf0, 0xf3, 0x30, 0xd5, 0x3e, 0x31, 0xe2, 0x8d, 0x84, 0x9e, 0xe3, 0x8a, + 0xda, 0xda, 0x96, 0x3e, 0x35, 0x13, 0xa5, 0x5f, 0xf0, 0xf9, 0x70, 0x50, 0x70, 0x47, 0x41, 0x11, + 0x57, 0x19, 0x4e, 0xc0, 0x8f, 0xae, 0x06, 0xc4, 0x95, 0x13, 0x17, 0x2f, 0x1b, 0x25, 0x9f, 0x75, + 0xf2, 0xb1, 0x8e, 0x99, 0xa1, 0x6f, 0x13, 0xb1, 0x41, 0x71, 0xfe, 0x88, 0x2a, 0xc8, 0x4f, 0x10, + 0x20, 0x55, 0xd7, 0xf3, 0x14, 0x45, 0xe5, 0xe0, 0x44, 0xf4, 0xea, 0x87, 0x95, 0x32, 0x93, 0x0e, + 0xfe, 0x53, 0x46, 0xfa, 0x2c, 0x9d, 0xff, 0x8b, 0x22, 0xb9, 0x4b, 0xd9, 0x09, 0x45, 0xa4, 0xde, + 0xa4, 0xb8, 0x9a, 0x58, 0xdd, 0x1b, 0x7d, 0x52, 0x9f, 0x8e, 0x59, 0x43, 0x88, 0x81, 0xa4, 0x9e, + 0x26, 0xd5, 0x6f, 0xad, 0xdd, 0x0d, 0xc6, 0x37, 0x7d, 0xed, 0x03, 0x92, 0x1b, 0xe5, 0x77, 0x5f, + 0x76, 0xee, 0x3c, 0x8d, 0xc4, 0x5d, 0x56, 0x5b, 0xa2, 0xd9, 0x66, 0x6e, 0xb3, 0x35, 0x37, 0xe5, + 0x32, 0xb6 +}; +const unsigned int _nx_azure_iot_root_cert_size_2 = sizeof(_nx_azure_iot_root_cert_2); + +/* To prevent future disruption, client applications or devices should also add the following root. */ + +/* Microsoft RSA Root Certificate Authority 2017 */ +const unsigned char _nx_azure_iot_root_cert_3[] = { + 0x30, 0x82, 0x05, 0xa8, 0x30, 0x82, 0x03, 0x90, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x1e, + 0xd3, 0x97, 0x09, 0x5f, 0xd8, 0xb4, 0xb3, 0x47, 0x70, 0x1e, 0xaa, 0xbe, 0x7f, 0x45, 0xb3, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0c, 0x05, 0x00, 0x30, 0x65, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x1e, 0x30, + 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x15, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, + 0x74, 0x20, 0x43, 0x6f, 0x72, 0x70, 0x6f, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x31, 0x36, 0x30, + 0x34, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x2d, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, + 0x74, 0x20, 0x52, 0x53, 0x41, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, + 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, + 0x20, 0x32, 0x30, 0x31, 0x37, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x31, 0x32, 0x31, 0x38, 0x32, + 0x32, 0x35, 0x31, 0x32, 0x32, 0x5a, 0x17, 0x0d, 0x34, 0x32, 0x30, 0x37, 0x31, 0x38, 0x32, 0x33, + 0x30, 0x30, 0x32, 0x33, 0x5a, 0x30, 0x65, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, + 0x13, 0x02, 0x55, 0x53, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x15, 0x4d, + 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x43, 0x6f, 0x72, 0x70, 0x6f, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x31, 0x36, 0x30, 0x34, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x2d, 0x4d, + 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x52, 0x53, 0x41, 0x20, 0x52, 0x6f, 0x6f, + 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, + 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x20, 0x32, 0x30, 0x31, 0x37, 0x30, 0x82, 0x02, 0x22, + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 0x82, 0x02, 0x01, 0x00, 0xca, 0x5b, 0xbe, + 0x94, 0x33, 0x8c, 0x29, 0x95, 0x91, 0x16, 0x0a, 0x95, 0xbd, 0x47, 0x62, 0xc1, 0x89, 0xf3, 0x99, + 0x36, 0xdf, 0x46, 0x90, 0xc9, 0xa5, 0xed, 0x78, 0x6a, 0x6f, 0x47, 0x91, 0x68, 0xf8, 0x27, 0x67, + 0x50, 0x33, 0x1d, 0xa1, 0xa6, 0xfb, 0xe0, 0xe5, 0x43, 0xa3, 0x84, 0x02, 0x57, 0x01, 0x5d, 0x9c, + 0x48, 0x40, 0x82, 0x53, 0x10, 0xbc, 0xbf, 0xc7, 0x3b, 0x68, 0x90, 0xb6, 0x82, 0x2d, 0xe5, 0xf4, + 0x65, 0xd0, 0xcc, 0x6d, 0x19, 0xcc, 0x95, 0xf9, 0x7b, 0xac, 0x4a, 0x94, 0xad, 0x0e, 0xde, 0x4b, + 0x43, 0x1d, 0x87, 0x07, 0x92, 0x13, 0x90, 0x80, 0x83, 0x64, 0x35, 0x39, 0x04, 0xfc, 0xe5, 0xe9, + 0x6c, 0xb3, 0xb6, 0x1f, 0x50, 0x94, 0x38, 0x65, 0x50, 0x5c, 0x17, 0x46, 0xb9, 0xb6, 0x85, 0xb5, + 0x1c, 0xb5, 0x17, 0xe8, 0xd6, 0x45, 0x9d, 0xd8, 0xb2, 0x26, 0xb0, 0xca, 0xc4, 0x70, 0x4a, 0xae, + 0x60, 0xa4, 0xdd, 0xb3, 0xd9, 0xec, 0xfc, 0x3b, 0xd5, 0x57, 0x72, 0xbc, 0x3f, 0xc8, 0xc9, 0xb2, + 0xde, 0x4b, 0x6b, 0xf8, 0x23, 0x6c, 0x03, 0xc0, 0x05, 0xbd, 0x95, 0xc7, 0xcd, 0x73, 0x3b, 0x66, + 0x80, 0x64, 0xe3, 0x1a, 0xac, 0x2e, 0xf9, 0x47, 0x05, 0xf2, 0x06, 0xb6, 0x9b, 0x73, 0xf5, 0x78, + 0x33, 0x5b, 0xc7, 0xa1, 0xfb, 0x27, 0x2a, 0xa1, 0xb4, 0x9a, 0x91, 0x8c, 0x91, 0xd3, 0x3a, 0x82, + 0x3e, 0x76, 0x40, 0xb4, 0xcd, 0x52, 0x61, 0x51, 0x70, 0x28, 0x3f, 0xc5, 0xc5, 0x5a, 0xf2, 0xc9, + 0x8c, 0x49, 0xbb, 0x14, 0x5b, 0x4d, 0xc8, 0xff, 0x67, 0x4d, 0x4c, 0x12, 0x96, 0xad, 0xf5, 0xfe, + 0x78, 0xa8, 0x97, 0x87, 0xd7, 0xfd, 0x5e, 0x20, 0x80, 0xdc, 0xa1, 0x4b, 0x22, 0xfb, 0xd4, 0x89, + 0xad, 0xba, 0xce, 0x47, 0x97, 0x47, 0x55, 0x7b, 0x8f, 0x45, 0xc8, 0x67, 0x28, 0x84, 0x95, 0x1c, + 0x68, 0x30, 0xef, 0xef, 0x49, 0xe0, 0x35, 0x7b, 0x64, 0xe7, 0x98, 0xb0, 0x94, 0xda, 0x4d, 0x85, + 0x3b, 0x3e, 0x55, 0xc4, 0x28, 0xaf, 0x57, 0xf3, 0x9e, 0x13, 0xdb, 0x46, 0x27, 0x9f, 0x1e, 0xa2, + 0x5e, 0x44, 0x83, 0xa4, 0xa5, 0xca, 0xd5, 0x13, 0xb3, 0x4b, 0x3f, 0xc4, 0xe3, 0xc2, 0xe6, 0x86, + 0x61, 0xa4, 0x52, 0x30, 0xb9, 0x7a, 0x20, 0x4f, 0x6f, 0x0f, 0x38, 0x53, 0xcb, 0x33, 0x0c, 0x13, + 0x2b, 0x8f, 0xd6, 0x9a, 0xbd, 0x2a, 0xc8, 0x2d, 0xb1, 0x1c, 0x7d, 0x4b, 0x51, 0xca, 0x47, 0xd1, + 0x48, 0x27, 0x72, 0x5d, 0x87, 0xeb, 0xd5, 0x45, 0xe6, 0x48, 0x65, 0x9d, 0xaf, 0x52, 0x90, 0xba, + 0x5b, 0xa2, 0x18, 0x65, 0x57, 0x12, 0x9f, 0x68, 0xb9, 0xd4, 0x15, 0x6b, 0x94, 0xc4, 0x69, 0x22, + 0x98, 0xf4, 0x33, 0xe0, 0xed, 0xf9, 0x51, 0x8e, 0x41, 0x50, 0xc9, 0x34, 0x4f, 0x76, 0x90, 0xac, + 0xfc, 0x38, 0xc1, 0xd8, 0xe1, 0x7b, 0xb9, 0xe3, 0xe3, 0x94, 0xe1, 0x46, 0x69, 0xcb, 0x0e, 0x0a, + 0x50, 0x6b, 0x13, 0xba, 0xac, 0x0f, 0x37, 0x5a, 0xb7, 0x12, 0xb5, 0x90, 0x81, 0x1e, 0x56, 0xae, + 0x57, 0x22, 0x86, 0xd9, 0xc9, 0xd2, 0xd1, 0xd7, 0x51, 0xe3, 0xab, 0x3b, 0xc6, 0x55, 0xfd, 0x1e, + 0x0e, 0xd3, 0x74, 0x0a, 0xd1, 0xda, 0xaa, 0xea, 0x69, 0xb8, 0x97, 0x28, 0x8f, 0x48, 0xc4, 0x07, + 0xf8, 0x52, 0x43, 0x3a, 0xf4, 0xca, 0x55, 0x35, 0x2c, 0xb0, 0xa6, 0x6a, 0xc0, 0x9c, 0xf9, 0xf2, + 0x81, 0xe1, 0x12, 0x6a, 0xc0, 0x45, 0xd9, 0x67, 0xb3, 0xce, 0xff, 0x23, 0xa2, 0x89, 0x0a, 0x54, + 0xd4, 0x14, 0xb9, 0x2a, 0xa8, 0xd7, 0xec, 0xf9, 0xab, 0xcd, 0x25, 0x58, 0x32, 0x79, 0x8f, 0x90, + 0x5b, 0x98, 0x39, 0xc4, 0x08, 0x06, 0xc1, 0xac, 0x7f, 0x0e, 0x3d, 0x00, 0xa5, 0x02, 0x03, 0x01, + 0x00, 0x01, 0xa3, 0x54, 0x30, 0x52, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, + 0x04, 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, + 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, + 0x04, 0x14, 0x09, 0xcb, 0x59, 0x7f, 0x86, 0xb2, 0x70, 0x8f, 0x1a, 0xc3, 0x39, 0xe3, 0xc0, 0xd9, + 0xe9, 0xbf, 0xbb, 0x4d, 0xb2, 0x23, 0x30, 0x10, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, + 0x37, 0x15, 0x01, 0x04, 0x03, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, + 0xf7, 0x0d, 0x01, 0x01, 0x0c, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0xac, 0xaf, 0x3e, 0x5d, + 0xc2, 0x11, 0x96, 0x89, 0x8e, 0xa3, 0xe7, 0x92, 0xd6, 0x97, 0x15, 0xb8, 0x13, 0xa2, 0xa6, 0x42, + 0x2e, 0x02, 0xcd, 0x16, 0x05, 0x59, 0x27, 0xca, 0x20, 0xe8, 0xba, 0xb8, 0xe8, 0x1a, 0xec, 0x4d, + 0xa8, 0x97, 0x56, 0xae, 0x65, 0x43, 0xb1, 0x8f, 0x00, 0x9b, 0x52, 0xcd, 0x55, 0xcd, 0x53, 0x39, + 0x6d, 0x62, 0x4c, 0x8b, 0x0d, 0x5b, 0x7c, 0x2e, 0x44, 0xbf, 0x83, 0x10, 0x8f, 0xf3, 0x53, 0x82, + 0x80, 0xc3, 0x4f, 0x3a, 0xc7, 0x6e, 0x11, 0x3f, 0xe6, 0xe3, 0x16, 0x91, 0x84, 0xfb, 0x6d, 0x84, + 0x7f, 0x34, 0x74, 0xad, 0x89, 0xa7, 0xce, 0xb9, 0xd7, 0xd7, 0x9f, 0x84, 0x64, 0x92, 0xbe, 0x95, + 0xa1, 0xad, 0x09, 0x53, 0x33, 0xdd, 0xee, 0x0a, 0xea, 0x4a, 0x51, 0x8e, 0x6f, 0x55, 0xab, 0xba, + 0xb5, 0x94, 0x46, 0xae, 0x8c, 0x7f, 0xd8, 0xa2, 0x50, 0x25, 0x65, 0x60, 0x80, 0x46, 0xdb, 0x33, + 0x04, 0xae, 0x6c, 0xb5, 0x98, 0x74, 0x54, 0x25, 0xdc, 0x93, 0xe4, 0xf8, 0xe3, 0x55, 0x15, 0x3d, + 0xb8, 0x6d, 0xc3, 0x0a, 0xa4, 0x12, 0xc1, 0x69, 0x85, 0x6e, 0xdf, 0x64, 0xf1, 0x53, 0x99, 0xe1, + 0x4a, 0x75, 0x20, 0x9d, 0x95, 0x0f, 0xe4, 0xd6, 0xdc, 0x03, 0xf1, 0x59, 0x18, 0xe8, 0x47, 0x89, + 0xb2, 0x57, 0x5a, 0x94, 0xb6, 0xa9, 0xd8, 0x17, 0x2b, 0x17, 0x49, 0xe5, 0x76, 0xcb, 0xc1, 0x56, + 0x99, 0x3a, 0x37, 0xb1, 0xff, 0x69, 0x2c, 0x91, 0x91, 0x93, 0xe1, 0xdf, 0x4c, 0xa3, 0x37, 0x76, + 0x4d, 0xa1, 0x9f, 0xf8, 0x6d, 0x1e, 0x1d, 0xd3, 0xfa, 0xec, 0xfb, 0xf4, 0x45, 0x1d, 0x13, 0x6d, + 0xcf, 0xf7, 0x59, 0xe5, 0x22, 0x27, 0x72, 0x2b, 0x86, 0xf3, 0x57, 0xbb, 0x30, 0xed, 0x24, 0x4d, + 0xdc, 0x7d, 0x56, 0xbb, 0xa3, 0xb3, 0xf8, 0x34, 0x79, 0x89, 0xc1, 0xe0, 0xf2, 0x02, 0x61, 0xf7, + 0xa6, 0xfc, 0x0f, 0xbb, 0x1c, 0x17, 0x0b, 0xae, 0x41, 0xd9, 0x7c, 0xbd, 0x27, 0xa3, 0xfd, 0x2e, + 0x3a, 0xd1, 0x93, 0x94, 0xb1, 0x73, 0x1d, 0x24, 0x8b, 0xaf, 0x5b, 0x20, 0x89, 0xad, 0xb7, 0x67, + 0x66, 0x79, 0xf5, 0x3a, 0xc6, 0xa6, 0x96, 0x33, 0xfe, 0x53, 0x92, 0xc8, 0x46, 0xb1, 0x11, 0x91, + 0xc6, 0x99, 0x7f, 0x8f, 0xc9, 0xd6, 0x66, 0x31, 0x20, 0x41, 0x10, 0x87, 0x2d, 0x0c, 0xd6, 0xc1, + 0xaf, 0x34, 0x98, 0xca, 0x64, 0x83, 0xfb, 0x13, 0x57, 0xd1, 0xc1, 0xf0, 0x3c, 0x7a, 0x8c, 0xa5, + 0xc1, 0xfd, 0x95, 0x21, 0xa0, 0x71, 0xc1, 0x93, 0x67, 0x71, 0x12, 0xea, 0x8f, 0x88, 0x0a, 0x69, + 0x19, 0x64, 0x99, 0x23, 0x56, 0xfb, 0xac, 0x2a, 0x2e, 0x70, 0xbe, 0x66, 0xc4, 0x0c, 0x84, 0xef, + 0xe5, 0x8b, 0xf3, 0x93, 0x01, 0xf8, 0x6a, 0x90, 0x93, 0x67, 0x4b, 0xb2, 0x68, 0xa3, 0xb5, 0x62, + 0x8f, 0xe9, 0x3f, 0x8c, 0x7a, 0x3b, 0x5e, 0x0f, 0xe7, 0x8c, 0xb8, 0xc6, 0x7c, 0xef, 0x37, 0xfd, + 0x74, 0xe2, 0xc8, 0x4f, 0x33, 0x72, 0xe1, 0x94, 0x39, 0x6d, 0xbd, 0x12, 0xaf, 0xbe, 0x0c, 0x4e, + 0x70, 0x7c, 0x1b, 0x6f, 0x8d, 0xb3, 0x32, 0x93, 0x73, 0x44, 0x16, 0x6d, 0xe8, 0xf4, 0xf7, 0xe0, + 0x95, 0x80, 0x8f, 0x96, 0x5d, 0x38, 0xa4, 0xf4, 0xab, 0xde, 0x0a, 0x30, 0x87, 0x93, 0xd8, 0x4d, + 0x00, 0x71, 0x62, 0x45, 0x27, 0x4b, 0x3a, 0x42, 0x84, 0x5b, 0x7f, 0x65, 0xb7, 0x67, 0x34, 0x52, + 0x2d, 0x9c, 0x16, 0x6b, 0xaa, 0xa8, 0xd8, 0x7b, 0xa3, 0x42, 0x4c, 0x71, 0xc7, 0x0c, 0xca, 0x3e, + 0x83, 0xe4, 0xa6, 0xef, 0xb7, 0x01, 0x30, 0x5e, 0x51, 0xa3, 0x79, 0xf5, 0x70, 0x69, 0xa6, 0x41, + 0x44, 0x0f, 0x86, 0xb0, 0x2c, 0x91, 0xc6, 0x3d, 0xea, 0xae, 0x0f, 0x84 +}; +const unsigned int _nx_azure_iot_root_cert_size_3 = sizeof(_nx_azure_iot_root_cert_3); diff --git a/addons/azure_iot/samples/cert/nx_azure_iot_cert.h b/addons/azure_iot/samples/cert/nx_azure_iot_cert.h index 196ff93b..90f60ff4 100644 --- a/addons/azure_iot/samples/cert/nx_azure_iot_cert.h +++ b/addons/azure_iot/samples/cert/nx_azure_iot_cert.h @@ -26,6 +26,10 @@ extern "C" { /* Users can use this root certificate as sample, and also can build the root certificate by themself. */ extern const unsigned char _nx_azure_iot_root_cert[]; extern const unsigned int _nx_azure_iot_root_cert_size; +extern const unsigned char _nx_azure_iot_root_cert_2[]; +extern const unsigned int _nx_azure_iot_root_cert_size_2; +extern const unsigned char _nx_azure_iot_root_cert_3[]; +extern const unsigned int _nx_azure_iot_root_cert_size_3; /* Determine if a C++ compiler is being used. If so, ensure that standard diff --git a/addons/azure_iot/samples/cert/nx_azure_iot_ciphersuites.c b/addons/azure_iot/samples/cert/nx_azure_iot_ciphersuites.c index a40dd3f6..7ed5f9fa 100644 --- a/addons/azure_iot/samples/cert/nx_azure_iot_ciphersuites.c +++ b/addons/azure_iot/samples/cert/nx_azure_iot_ciphersuites.c @@ -24,6 +24,7 @@ extern NX_CRYPTO_METHOD crypto_method_hmac; extern NX_CRYPTO_METHOD crypto_method_hmac_sha256; extern NX_CRYPTO_METHOD crypto_method_tls_prf_sha256; extern NX_CRYPTO_METHOD crypto_method_sha256; +extern NX_CRYPTO_METHOD crypto_method_sha384; extern NX_CRYPTO_METHOD crypto_method_aes_cbc_128; extern NX_CRYPTO_METHOD crypto_method_rsa; #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE @@ -38,6 +39,7 @@ const NX_CRYPTO_METHOD *_nx_azure_iot_tls_supported_crypto[] = &crypto_method_hmac_sha256, &crypto_method_tls_prf_sha256, &crypto_method_sha256, + &crypto_method_sha384, &crypto_method_aes_cbc_128, &crypto_method_rsa, #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE @@ -59,6 +61,7 @@ extern const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_rsa_with_aes_128_cbc_sha256; /* Define supported X.509 ciphersuites. */ extern const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_rsa_sha_256; +extern const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_rsa_sha_384; #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE extern const NX_CRYPTO_CIPHERSUITE nx_crypto_x509_ecdsa_sha_256; #endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */ @@ -75,6 +78,7 @@ const NX_CRYPTO_CIPHERSUITE *_nx_azure_iot_tls_ciphersuite_map[] = /* X.509 ciphersuites. */ &nx_crypto_x509_rsa_sha_256, + &nx_crypto_x509_rsa_sha_384, #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE &nx_crypto_x509_ecdsa_sha_256, #endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */ diff --git a/addons/azure_iot/samples/cert/nx_azure_iot_ciphersuites.h b/addons/azure_iot/samples/cert/nx_azure_iot_ciphersuites.h index 8b71fc59..270c02f9 100644 --- a/addons/azure_iot/samples/cert/nx_azure_iot_ciphersuites.h +++ b/addons/azure_iot/samples/cert/nx_azure_iot_ciphersuites.h @@ -23,7 +23,7 @@ extern const UINT _nx_azure_iot_tls_ciphersuite_map_size; /* Define the metadata size for _nx_azure_iot_tls_ciphers. */ #ifndef NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE -#define NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE (9 * 1024) +#define NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE (10 * 1024) #endif /* NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE */ #endif /* NX_AZURE_IOT_CIPHERSUITES_H */ diff --git a/addons/azure_iot/samples/sample_azure_iot_embedded_sdk.c b/addons/azure_iot/samples/sample_azure_iot_embedded_sdk.c index ac21c657..d62e4031 100644 --- a/addons/azure_iot/samples/sample_azure_iot_embedded_sdk.c +++ b/addons/azure_iot/samples/sample_azure_iot_embedded_sdk.c @@ -22,6 +22,8 @@ /* Define Azure RTOS TLS info. */ static NX_SECURE_X509_CERT root_ca_cert; +static NX_SECURE_X509_CERT root_ca_cert_2; +static NX_SECURE_X509_CERT root_ca_cert_3; static UCHAR nx_azure_iot_tls_metadata_buffer[NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE]; static ULONG nx_azure_iot_thread_stack[NX_AZURE_IOT_STACK_SIZE / sizeof(ULONG)]; @@ -184,14 +186,24 @@ UINT iothub_device_id_length = sizeof(DEVICE_ID) - 1; return(status); } + /* Add more CA certificates. */ + if ((status = nx_azure_iot_hub_client_trusted_cert_add(iothub_client_ptr, &root_ca_cert_2))) + { + printf("Failed on nx_azure_iot_hub_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + else if ((status = nx_azure_iot_hub_client_trusted_cert_add(iothub_client_ptr, &root_ca_cert_3))) + { + printf("Failed on nx_azure_iot_hub_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + #if (USE_DEVICE_CERTIFICATE == 1) /* Initialize the device certificate. */ - if ((status = nx_secure_x509_certificate_initialize(&device_certificate, - (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, - NX_NULL, 0, - (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, - DEVICE_KEY_TYPE))) + else if ((status = nx_secure_x509_certificate_initialize(&device_certificate, + (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, + NX_NULL, 0, + (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, + DEVICE_KEY_TYPE))) { printf("Failed on nx_secure_x509_certificate_initialize!: error code = 0x%08x\r\n", status); } @@ -204,9 +216,9 @@ UINT iothub_device_id_length = sizeof(DEVICE_ID) - 1; #else /* Set symmetric key. */ - if ((status = nx_azure_iot_hub_client_symmetric_key_set(iothub_client_ptr, - (UCHAR *)DEVICE_SYMMETRIC_KEY, - sizeof(DEVICE_SYMMETRIC_KEY) - 1))) + else if ((status = nx_azure_iot_hub_client_symmetric_key_set(iothub_client_ptr, + (UCHAR *)DEVICE_SYMMETRIC_KEY, + sizeof(DEVICE_SYMMETRIC_KEY) - 1))) { printf("Failed on nx_azure_iot_hub_client_symmetric_key_set!\r\n"); } @@ -269,7 +281,7 @@ UINT loop = NX_TRUE; return; } - /* Initialize CA certificate. */ + /* Initialize CA certificates. */ if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert, (UCHAR *)_nx_azure_iot_root_cert, (USHORT)_nx_azure_iot_root_cert_size, NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) @@ -278,6 +290,24 @@ UINT loop = NX_TRUE; nx_azure_iot_delete(&nx_azure_iot); return; } + + if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert_2, (UCHAR *)_nx_azure_iot_root_cert_2, + (USHORT)_nx_azure_iot_root_cert_size_2, + NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) + { + printf("Failed to initialize ROOT CA certificate!: error code = 0x%08x\r\n", status); + nx_azure_iot_delete(&nx_azure_iot); + return; + } + + if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert_3, (UCHAR *)_nx_azure_iot_root_cert_3, + (USHORT)_nx_azure_iot_root_cert_size_3, + NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) + { + printf("Failed to initialize ROOT CA certificate!: error code = 0x%08x\r\n", status); + nx_azure_iot_delete(&nx_azure_iot); + return; + } if ((status = sample_initialize_iothub(&iothub_client))) { @@ -382,11 +412,21 @@ UINT status; *iothub_hostname_length = sizeof(sample_iothub_hostname); *iothub_device_id_length = sizeof(sample_iothub_device_id); + /* Add more CA certificates. */ + if ((status = nx_azure_iot_provisioning_client_trusted_cert_add(&prov_client, &root_ca_cert_2))) + { + printf("Failed on nx_azure_iot_provisioning_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + else if ((status = nx_azure_iot_provisioning_client_trusted_cert_add(&prov_client, &root_ca_cert_3))) + { + printf("Failed on nx_azure_iot_provisioning_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + #if (USE_DEVICE_CERTIFICATE == 1) /* Initialize the device certificate. */ - if ((status = nx_secure_x509_certificate_initialize(&device_certificate, (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, NX_NULL, 0, - (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, DEVICE_KEY_TYPE))) + else if ((status = nx_secure_x509_certificate_initialize(&device_certificate, (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, NX_NULL, 0, + (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, DEVICE_KEY_TYPE))) { printf("Failed on nx_secure_x509_certificate_initialize!: error code = 0x%08x\r\n", status); } @@ -399,8 +439,8 @@ UINT status; #else /* Set symmetric key. */ - if ((status = nx_azure_iot_provisioning_client_symmetric_key_set(&prov_client, (UCHAR *)DEVICE_SYMMETRIC_KEY, - sizeof(DEVICE_SYMMETRIC_KEY) - 1))) + else if ((status = nx_azure_iot_provisioning_client_symmetric_key_set(&prov_client, (UCHAR *)DEVICE_SYMMETRIC_KEY, + sizeof(DEVICE_SYMMETRIC_KEY) - 1))) { printf("Failed on nx_azure_iot_hub_client_symmetric_key_set!: error code = 0x%08x\r\n", status); } diff --git a/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_pnp.c b/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_pnp.c index 7b4faac4..226e134b 100644 --- a/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_pnp.c +++ b/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_pnp.c @@ -40,24 +40,26 @@ /* Sample events. */ #define SAMPLE_ALL_EVENTS ((ULONG)0xFFFFFFFF) -#define SAMPLE_CONNECT_EVENT ((ULONG)0x00000001) -#define SAMPLE_INITIALIZATION_EVENT ((ULONG)0x00000002) -#define SAMPLE_METHOD_MESSAGE_EVENT ((ULONG)0x00000004) -#define SAMPLE_DEVICE_TWIN_GET_EVENT ((ULONG)0x00000008) -#define SAMPLE_DEVICE_TWIN_DESIRED_PROPERTY_EVENT ((ULONG)0x00000010) -#define SAMPLE_TELEMETRY_SEND_EVENT ((ULONG)0x00000020) -#define SAMPLE_DEVICE_TWIN_REPORTED_PROPERTY_EVENT ((ULONG)0x00000040) -#define SAMPLE_DISCONNECT_EVENT ((ULONG)0x00000080) -#define SAMPLE_RECONNECT_EVENT ((ULONG)0x00000100) -#define SAMPLE_CONNECTED_EVENT ((ULONG)0x00000200) +#define SAMPLE_NETWORK_CHECK_EVENT ((ULONG)0x00000001) +#define SAMPLE_CONNECT_EVENT ((ULONG)0x00000002) +#define SAMPLE_INITIALIZATION_EVENT ((ULONG)0x00000004) +#define SAMPLE_METHOD_MESSAGE_EVENT ((ULONG)0x00000008) +#define SAMPLE_DEVICE_TWIN_GET_EVENT ((ULONG)0x00000010) +#define SAMPLE_DEVICE_TWIN_DESIRED_PROPERTY_EVENT ((ULONG)0x00000020) +#define SAMPLE_TELEMETRY_SEND_EVENT ((ULONG)0x00000040) +#define SAMPLE_DEVICE_TWIN_REPORTED_PROPERTY_EVENT ((ULONG)0x00000080) +#define SAMPLE_DISCONNECT_EVENT ((ULONG)0x00000100) +#define SAMPLE_RECONNECT_EVENT ((ULONG)0x00000200) +#define SAMPLE_CONNECTED_EVENT ((ULONG)0x00000400) /* Sample states. */ #define SAMPLE_STATE_NONE (0) #define SAMPLE_STATE_INIT (1) -#define SAMPLE_STATE_CONNECTING (2) -#define SAMPLE_STATE_CONNECT (3) -#define SAMPLE_STATE_CONNECTED (4) -#define SAMPLE_STATE_DISCONNECTED (5) +#define SAMPLE_STATE_NETWORK_CHECK (2) +#define SAMPLE_STATE_CONNECTING (3) +#define SAMPLE_STATE_CONNECT (4) +#define SAMPLE_STATE_CONNECTED (5) +#define SAMPLE_STATE_DISCONNECTED (6) #define SAMPLE_DEAFULT_START_TEMP_CELSIUS (22) #define DOUBLE_DECIMAL_PLACE_DIGITS (2) @@ -106,6 +108,8 @@ static UINT sample_dps_entry(NX_AZURE_IOT_PROVISIONING_CLIENT *prov_client_ptr, /* Define Azure RTOS TLS info. */ static NX_SECURE_X509_CERT root_ca_cert; +static NX_SECURE_X509_CERT root_ca_cert_2; +static NX_SECURE_X509_CERT root_ca_cert_3; static UCHAR nx_azure_iot_tls_metadata_buffer[NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE]; static ULONG nx_azure_iot_thread_stack[NX_AZURE_IOT_STACK_SIZE / sizeof(ULONG)]; @@ -132,6 +136,9 @@ static SAMPLE_CONTEXT sample_context; static volatile UINT sample_connection_status = NX_NOT_CONNECTED; static UINT exponential_retry_count; +/* Define IP pointer. */ +static NX_IP *nx_azure_iot_ip_ptr; + /* Telemetry. */ static const CHAR telemetry_name[] = "temperature"; @@ -493,8 +500,26 @@ SAMPLE_CONTEXT *sample_ctx = (SAMPLE_CONTEXT *)context; SAMPLE_DEVICE_TWIN_DESIRED_PROPERTY_EVENT, TX_OR); } +static VOID sample_network_check(SAMPLE_CONTEXT *context) +{ +ULONG gateway_address; + + if (context -> state != SAMPLE_STATE_NETWORK_CHECK) + { + return; + } + + while (nx_ip_gateway_address_get(nx_azure_iot_ip_ptr, &gateway_address)) + { + tx_thread_sleep(NX_IP_PERIODIC_RATE); + } + + context -> state = SAMPLE_STATE_CONNECT; +} + static VOID sample_connect_action(SAMPLE_CONTEXT *context) { + if (context -> state != SAMPLE_STATE_CONNECT) { return; @@ -599,14 +624,24 @@ NX_AZURE_IOT_HUB_CLIENT* iothub_client_ptr = &(context -> iothub_client); return; } + /* Add more CA certificates. */ + if ((status = nx_azure_iot_hub_client_trusted_cert_add(iothub_client_ptr, &root_ca_cert_2))) + { + printf("Failed on nx_azure_iot_hub_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + else if ((status = nx_azure_iot_hub_client_trusted_cert_add(iothub_client_ptr, &root_ca_cert_3))) + { + printf("Failed on nx_azure_iot_hub_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + #if (USE_DEVICE_CERTIFICATE == 1) /* Initialize the device certificate. */ - if ((status = nx_secure_x509_certificate_initialize(&device_certificate, - (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, - NX_NULL, 0, - (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, - DEVICE_KEY_TYPE))) + else if ((status = nx_secure_x509_certificate_initialize(&device_certificate, + (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, + NX_NULL, 0, + (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, + DEVICE_KEY_TYPE))) { printf("Failed on nx_secure_x509_certificate_initialize!: error code = 0x%08x\r\n", status); } @@ -619,9 +654,9 @@ NX_AZURE_IOT_HUB_CLIENT* iothub_client_ptr = &(context -> iothub_client); #else /* Set symmetric key. */ - if ((status = nx_azure_iot_hub_client_symmetric_key_set(iothub_client_ptr, - (UCHAR *)DEVICE_SYMMETRIC_KEY, - sizeof(DEVICE_SYMMETRIC_KEY) - 1))) + else if ((status = nx_azure_iot_hub_client_symmetric_key_set(iothub_client_ptr, + (UCHAR *)DEVICE_SYMMETRIC_KEY, + sizeof(DEVICE_SYMMETRIC_KEY) - 1))) { printf("Failed on nx_azure_iot_hub_client_symmetric_key_set!\r\n"); } @@ -676,7 +711,7 @@ NX_AZURE_IOT_HUB_CLIENT* iothub_client_ptr = &(context -> iothub_client); if (status == NX_AZURE_IOT_SUCCESS) { - context -> state = SAMPLE_STATE_CONNECT; + context -> state = SAMPLE_STATE_NETWORK_CHECK; } } @@ -713,7 +748,7 @@ static VOID sample_connection_error_recover(SAMPLE_CONTEXT *context) printf("reconnecting iothub, after backoff\r\n"); tx_thread_sleep(exponential_backoff_with_jitter()); - context -> state = SAMPLE_STATE_CONNECT; + context -> state = SAMPLE_STATE_NETWORK_CHECK; } break; } @@ -729,6 +764,12 @@ static VOID sample_trigger_action(SAMPLE_CONTEXT *context) } break; + case SAMPLE_STATE_NETWORK_CHECK: + { + tx_event_flags_set(&(context -> sample_events), SAMPLE_NETWORK_CHECK_EVENT, TX_OR); + } + break; + case SAMPLE_STATE_CONNECT: { tx_event_flags_set(&(context -> sample_events), SAMPLE_CONNECT_EVENT, TX_OR); @@ -1065,11 +1106,21 @@ UINT status; *iothub_hostname_length = sizeof(sample_iothub_hostname); *iothub_device_id_length = sizeof(sample_iothub_device_id); + /* Add more CA certificates. */ + if ((status = nx_azure_iot_provisioning_client_trusted_cert_add(prov_client_ptr, &root_ca_cert_2))) + { + printf("Failed on nx_azure_iot_provisioning_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + else if ((status = nx_azure_iot_provisioning_client_trusted_cert_add(prov_client_ptr, &root_ca_cert_3))) + { + printf("Failed on nx_azure_iot_provisioning_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + #if (USE_DEVICE_CERTIFICATE == 1) /* Initialize the device certificate. */ - if ((status = nx_secure_x509_certificate_initialize(&device_certificate, (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, NX_NULL, 0, - (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, DEVICE_KEY_TYPE))) + else if ((status = nx_secure_x509_certificate_initialize(&device_certificate, (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, NX_NULL, 0, + (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, DEVICE_KEY_TYPE))) { printf("Failed on nx_secure_x509_certificate_initialize!: error code = 0x%08x\r\n", status); } @@ -1082,8 +1133,8 @@ UINT status; #else /* Set symmetric key. */ - if ((status = nx_azure_iot_provisioning_client_symmetric_key_set(prov_client_ptr, (UCHAR *)DEVICE_SYMMETRIC_KEY, - sizeof(DEVICE_SYMMETRIC_KEY) - 1))) + else if ((status = nx_azure_iot_provisioning_client_symmetric_key_set(prov_client_ptr, (UCHAR *)DEVICE_SYMMETRIC_KEY, + sizeof(DEVICE_SYMMETRIC_KEY) - 1))) { printf("Failed on nx_azure_iot_hub_client_symmetric_key_set!: error code = 0x%08x\r\n", status); } @@ -1125,29 +1176,31 @@ UINT status; * Sample Event loop * * - * +--------------+ +--------------+ +--------------+ +--------------+ - * | | INIT | | | | | | - * | | SUCCESS | | | | | +--------+ - * | INIT | | CONNECT | | CONNECTING | | CONNECTED | | (TELEMETRY | - * | +-----------> +----->+ +-------> | | METHOD | - * | | | | | | | <--------+ DEVICETWIN) - * | | | | | | | | - * +-----+--------+ +----+---+-----+ +------+-------+ +--------+-----+ - * ^ ^ | | | - * | | | | | - * | | | | | - * | | | CONNECT | CONNECTING | - * | | | FAIL | FAIL | - * REINITIALIZE| RECONNECT| | | | - * | | | v | DISCONNECT - * | | | +----------+-+ | - * | | | | | | - * | | +------->+ | | - * | | | DISCONNECT | | - * | | | +<---------------------+ - * | +------------+ | - * +--------------------------------------+ | - * +------------+ + * +--------------+ +--------------+ +--------------+ +--------------+ + * | | INIT | | NETWORK | | | | + * | | SUCCESS | | GOOD | | | | + * | INIT | | NETWORK | | CONNECT | | CONNECTING | + * | +---------> CHECK +---------> +----> +--+ + * | | | | | | | | | + * | | | | | | | | | + * +------^-------+ +------^-------+ +------+-------+ +-----------+--+ | + * | | | | | + * | | CONNECT FAIL | | | + * | | +-------------+ | | + * | | | CONNECTING FAIL | | + * | RECONNECT | | +-------------------------------+ | + * | | | | | + * | | +--v------v----+ +--------------+ | + * | REINITIALIZE | | | | | | + * | +-------+ | DISCONNECT | | | + * | | DISCONNECTED | | CONNECTED | | + * | | <--------------+ <--+ + * +--------------------------------+ | | | + * | | | | + * +--------------+ +---^------+---+ + * | |(TELEMETRY | + * | | METHOD | + * +------+ DEVICE TWIN) * * * @@ -1171,6 +1224,11 @@ UINT loop = NX_TRUE; continue; } + if (app_events & SAMPLE_NETWORK_CHECK_EVENT) + { + sample_network_check(context); + } + if (app_events & SAMPLE_CONNECT_EVENT) { sample_connect_action(context); @@ -1243,6 +1301,8 @@ void sample_entry(NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, NX_DNS *dns_ptr, UINT { UINT status = 0; + nx_azure_iot_ip_ptr = ip_ptr; + nx_azure_iot_log_init(log_callback); /* Create Azure IoT handler. */ @@ -1254,7 +1314,7 @@ UINT status = 0; return; } - /* Initialize CA certificate. */ + /* Initialize CA certificates. */ if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert, (UCHAR *)_nx_azure_iot_root_cert, (USHORT)_nx_azure_iot_root_cert_size, NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) @@ -1264,6 +1324,24 @@ UINT status = 0; return; } + if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert_2, (UCHAR *)_nx_azure_iot_root_cert_2, + (USHORT)_nx_azure_iot_root_cert_size_2, + NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) + { + printf("Failed to initialize ROOT CA certificate!: error code = 0x%08x\r\n", status); + nx_azure_iot_delete(&nx_azure_iot); + return; + } + + if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert_3, (UCHAR *)_nx_azure_iot_root_cert_3, + (USHORT)_nx_azure_iot_root_cert_size_3, + NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) + { + printf("Failed to initialize ROOT CA certificate!: error code = 0x%08x\r\n", status); + nx_azure_iot_delete(&nx_azure_iot); + return; + } + sample_context_init(&sample_context); sample_context.state = SAMPLE_STATE_INIT; diff --git a/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_with_retry.c b/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_with_retry.c index a27d5660..2ecde8b7 100644 --- a/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_with_retry.c +++ b/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_with_retry.c @@ -34,6 +34,8 @@ /* Define Azure RTOS TLS info. */ static NX_SECURE_X509_CERT root_ca_cert; +static NX_SECURE_X509_CERT root_ca_cert_2; +static NX_SECURE_X509_CERT root_ca_cert_3; static UCHAR nx_azure_iot_tls_metadata_buffer[NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE]; static ULONG nx_azure_iot_thread_stack[NX_AZURE_IOT_STACK_SIZE / sizeof(ULONG)]; @@ -321,14 +323,24 @@ UINT iothub_device_id_length = sizeof(DEVICE_ID) - 1; return(status); } + /* Add more CA certificates. */ + if ((status = nx_azure_iot_hub_client_trusted_cert_add(iothub_client_ptr, &root_ca_cert_2))) + { + printf("Failed on nx_azure_iot_hub_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + else if ((status = nx_azure_iot_hub_client_trusted_cert_add(iothub_client_ptr, &root_ca_cert_3))) + { + printf("Failed on nx_azure_iot_hub_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + #if (USE_DEVICE_CERTIFICATE == 1) /* Initialize the device certificate. */ - if ((status = nx_secure_x509_certificate_initialize(&device_certificate, - (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, - NX_NULL, 0, - (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, - DEVICE_KEY_TYPE))) + else if ((status = nx_secure_x509_certificate_initialize(&device_certificate, + (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, + NX_NULL, 0, + (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, + DEVICE_KEY_TYPE))) { printf("Failed on nx_secure_x509_certificate_initialize!: error code = 0x%08x\r\n", status); } @@ -341,9 +353,9 @@ UINT iothub_device_id_length = sizeof(DEVICE_ID) - 1; #else /* Set symmetric key. */ - if ((status = nx_azure_iot_hub_client_symmetric_key_set(iothub_client_ptr, - (UCHAR *)DEVICE_SYMMETRIC_KEY, - sizeof(DEVICE_SYMMETRIC_KEY) - 1))) + else if ((status = nx_azure_iot_hub_client_symmetric_key_set(iothub_client_ptr, + (UCHAR *)DEVICE_SYMMETRIC_KEY, + sizeof(DEVICE_SYMMETRIC_KEY) - 1))) { printf("Failed on nx_azure_iot_hub_client_symmetric_key_set!\r\n"); } @@ -407,7 +419,7 @@ UINT status = 0; return; } - /* Initialize CA certificate. */ + /* Initialize CA certificates. */ if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert, (UCHAR *)_nx_azure_iot_root_cert, (USHORT)_nx_azure_iot_root_cert_size, NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) @@ -417,6 +429,24 @@ UINT status = 0; return; } + if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert_2, (UCHAR *)_nx_azure_iot_root_cert_2, + (USHORT)_nx_azure_iot_root_cert_size_2, + NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) + { + printf("Failed to initialize ROOT CA certificate!: error code = 0x%08x\r\n", status); + nx_azure_iot_delete(&nx_azure_iot); + return; + } + + if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert_3, (UCHAR *)_nx_azure_iot_root_cert_3, + (USHORT)_nx_azure_iot_root_cert_size_3, + NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) + { + printf("Failed to initialize ROOT CA certificate!: error code = 0x%08x\r\n", status); + nx_azure_iot_delete(&nx_azure_iot); + return; + } + if ((sample_iot_hub_init_status = sample_initialize_iothub(&iothub_client))) { printf("Failed to initialize iothub client: error code = 0x%08x\r\n", sample_iot_hub_init_status); @@ -514,10 +544,20 @@ UINT status; *iothub_hostname_length = sizeof(sample_iothub_hostname); *iothub_device_id_length = sizeof(sample_iothub_device_id); + /* Add more CA certificates. */ + if ((status = nx_azure_iot_provisioning_client_trusted_cert_add(&prov_client, &root_ca_cert_2))) + { + printf("Failed on nx_azure_iot_provisioning_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + else if ((status = nx_azure_iot_provisioning_client_trusted_cert_add(&prov_client, &root_ca_cert_3))) + { + printf("Failed on nx_azure_iot_provisioning_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + #if (USE_DEVICE_CERTIFICATE == 1) /* Initialize the device certificate. */ - if ((status = nx_secure_x509_certificate_initialize(&device_certificate, (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, NX_NULL, 0, + else if ((status = nx_secure_x509_certificate_initialize(&device_certificate, (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, NX_NULL, 0, (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, DEVICE_KEY_TYPE))) { printf("Failed on nx_secure_x509_certificate_initialize!: error code = 0x%08x\r\n", status); @@ -531,7 +571,7 @@ UINT status; #else /* Set symmetric key. */ - if ((status = nx_azure_iot_provisioning_client_symmetric_key_set(&prov_client, (UCHAR *)DEVICE_SYMMETRIC_KEY, + else if ((status = nx_azure_iot_provisioning_client_symmetric_key_set(&prov_client, (UCHAR *)DEVICE_SYMMETRIC_KEY, sizeof(DEVICE_SYMMETRIC_KEY) - 1))) { printf("Failed on nx_azure_iot_hub_client_symmetric_key_set!: error code = 0x%08x\r\n", status); diff --git a/addons/azure_iot/samples/sample_pnp_temperature_controller/sample_pnp_temperature_controller.c b/addons/azure_iot/samples/sample_pnp_temperature_controller/sample_pnp_temperature_controller.c index 54d245e8..8e52290c 100644 --- a/addons/azure_iot/samples/sample_pnp_temperature_controller/sample_pnp_temperature_controller.c +++ b/addons/azure_iot/samples/sample_pnp_temperature_controller/sample_pnp_temperature_controller.c @@ -107,6 +107,8 @@ static UINT sample_dps_entry(NX_AZURE_IOT_PROVISIONING_CLIENT *prov_client_ptr, /* Define Azure RTOS TLS info. */ static NX_SECURE_X509_CERT root_ca_cert; +static NX_SECURE_X509_CERT root_ca_cert_2; +static NX_SECURE_X509_CERT root_ca_cert_3; static UCHAR nx_azure_iot_tls_metadata_buffer[NX_AZURE_IOT_TLS_METADATA_BUFFER_SIZE]; static ULONG nx_azure_iot_thread_stack[NX_AZURE_IOT_STACK_SIZE / sizeof(ULONG)]; @@ -532,14 +534,24 @@ NX_AZURE_IOT_HUB_CLIENT *iothub_client_ptr = &(context -> iothub_client); return; } + /* Add more CA certificates. */ + if ((status = nx_azure_iot_hub_client_trusted_cert_add(iothub_client_ptr, &root_ca_cert_2))) + { + printf("Failed on nx_azure_iot_hub_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + else if ((status = nx_azure_iot_hub_client_trusted_cert_add(iothub_client_ptr, &root_ca_cert_3))) + { + printf("Failed on nx_azure_iot_hub_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + #if (USE_DEVICE_CERTIFICATE == 1) /* Initialize the device certificate. */ - if ((status = nx_secure_x509_certificate_initialize(&device_certificate, - (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, - NX_NULL, 0, - (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, - DEVICE_KEY_TYPE))) + else if ((status = nx_secure_x509_certificate_initialize(&device_certificate, + (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, + NX_NULL, 0, + (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, + DEVICE_KEY_TYPE))) { printf("Failed on nx_secure_x509_certificate_initialize!: error code = 0x%08x\r\n", status); } @@ -552,9 +564,9 @@ NX_AZURE_IOT_HUB_CLIENT *iothub_client_ptr = &(context -> iothub_client); #else /* Set symmetric key. */ - if ((status = nx_azure_iot_hub_client_symmetric_key_set(iothub_client_ptr, - (UCHAR *)DEVICE_SYMMETRIC_KEY, - sizeof(DEVICE_SYMMETRIC_KEY) - 1))) + else if ((status = nx_azure_iot_hub_client_symmetric_key_set(iothub_client_ptr, + (UCHAR *)DEVICE_SYMMETRIC_KEY, + sizeof(DEVICE_SYMMETRIC_KEY) - 1))) { printf("Failed on nx_azure_iot_hub_client_symmetric_key_set! error: 0x%08x\r\n", status); } @@ -1050,11 +1062,21 @@ UINT status; *iothub_hostname_length = sizeof(sample_iothub_hostname); *iothub_device_id_length = sizeof(sample_iothub_device_id); + /* Add more CA certificates. */ + if ((status = nx_azure_iot_provisioning_client_trusted_cert_add(prov_client_ptr, &root_ca_cert_2))) + { + printf("Failed on nx_azure_iot_provisioning_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + else if ((status = nx_azure_iot_provisioning_client_trusted_cert_add(prov_client_ptr, &root_ca_cert_3))) + { + printf("Failed on nx_azure_iot_provisioning_client_trusted_cert_add!: error code = 0x%08x\r\n", status); + } + #if (USE_DEVICE_CERTIFICATE == 1) /* Initialize the device certificate. */ - if ((status = nx_secure_x509_certificate_initialize(&device_certificate, (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, NX_NULL, 0, - (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, DEVICE_KEY_TYPE))) + else if ((status = nx_secure_x509_certificate_initialize(&device_certificate, (UCHAR *)sample_device_cert_ptr, (USHORT)sample_device_cert_len, NX_NULL, 0, + (UCHAR *)sample_device_private_key_ptr, (USHORT)sample_device_private_key_len, DEVICE_KEY_TYPE))) { printf("Failed on nx_secure_x509_certificate_initialize!: error code = 0x%08x\r\n", status); } @@ -1067,8 +1089,8 @@ UINT status; #else /* Set symmetric key. */ - if ((status = nx_azure_iot_provisioning_client_symmetric_key_set(prov_client_ptr, (UCHAR *)DEVICE_SYMMETRIC_KEY, - sizeof(DEVICE_SYMMETRIC_KEY) - 1))) + else if ((status = nx_azure_iot_provisioning_client_symmetric_key_set(prov_client_ptr, (UCHAR *)DEVICE_SYMMETRIC_KEY, + sizeof(DEVICE_SYMMETRIC_KEY) - 1))) { printf("Failed on nx_azure_iot_hub_client_symmetric_key_set!: error code = 0x%08x\r\n", status); } @@ -1275,7 +1297,7 @@ UINT status; return; } - /* Initialize CA certificate. */ + /* Initialize CA certificates. */ if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert, (UCHAR *)_nx_azure_iot_root_cert, (USHORT)_nx_azure_iot_root_cert_size, NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) @@ -1285,6 +1307,24 @@ UINT status; return; } + if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert_2, (UCHAR *)_nx_azure_iot_root_cert_2, + (USHORT)_nx_azure_iot_root_cert_size_2, + NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) + { + printf("Failed to initialize ROOT CA certificate!: error code = 0x%08x\r\n", status); + nx_azure_iot_delete(&nx_azure_iot); + return; + } + + if ((status = nx_secure_x509_certificate_initialize(&root_ca_cert_3, (UCHAR *)_nx_azure_iot_root_cert_3, + (USHORT)_nx_azure_iot_root_cert_size_3, + NX_NULL, 0, NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE))) + { + printf("Failed to initialize ROOT CA certificate!: error code = 0x%08x\r\n", status); + nx_azure_iot_delete(&nx_azure_iot); + return; + } + sample_context_init(&sample_context); sample_context.state = SAMPLE_STATE_INIT; diff --git a/addons/ftp/nxd_ftp_server.c b/addons/ftp/nxd_ftp_server.c index f7071a70..ad4d1d3d 100644 --- a/addons/ftp/nxd_ftp_server.c +++ b/addons/ftp/nxd_ftp_server.c @@ -6866,7 +6866,7 @@ NX_PACKET *last_packet; /* FUNCTION RELEASE */ /* */ /* _nx_ftp_server_number_to_ascii PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -6902,6 +6902,9 @@ NX_PACKET *last_packet; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Yuxin Zhou Modified comment(s), and */ +/* corrected the size check, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ static VOID _nx_ftp_server_number_to_ascii(UCHAR *buffer_ptr, UINT buffer_size, UINT number) @@ -6916,7 +6919,7 @@ UINT size; memset(buffer_ptr, ' ', buffer_size); /* Loop to convert the number to ASCII. */ - while (size < buffer_size) + while (size <= buffer_size) { /* Compute the next decimal digit. */ diff --git a/addons/web/nx_web_http_server.c b/addons/web/nx_web_http_server.c index 7d5e669f..f9db8487 100644 --- a/addons/web/nx_web_http_server.c +++ b/addons/web/nx_web_http_server.c @@ -271,7 +271,7 @@ UINT _nxe_web_http_server_packet_content_find(NX_WEB_HTTP_SERVER *server_ptr, N /* FUNCTION RELEASE */ /* */ /* _nx_web_http_server_packet_content_find PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -318,6 +318,9 @@ UINT _nxe_web_http_server_packet_content_find(NX_WEB_HTTP_SERVER *server_ptr, N /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Yuxin Zhou Modified comment(s), */ +/* fixed compiler warnings, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ UINT _nx_web_http_server_packet_content_find(NX_WEB_HTTP_SERVER *server_ptr, NX_PACKET **packet_ptr, ULONG *content_length) @@ -392,6 +395,12 @@ ULONG temp_offset; (*packet_ptr) = (*packet_ptr) -> nx_packet_next; } + /* Chack if packet is valid. */ + if ((*packet_ptr) == NX_NULL) + { + return(NX_WEB_HTTP_BAD_PACKET_LENGTH); + } + /* If this packet contain no content, set next packet as the first packet of the content. */ if (temp_offset == (ULONG)((*packet_ptr) -> nx_packet_append_ptr - (*packet_ptr) -> nx_packet_prepend_ptr)) { diff --git a/common/inc/nx_api.h b/common/inc/nx_api.h index f552009f..824d9655 100644 --- a/common/inc/nx_api.h +++ b/common/inc/nx_api.h @@ -26,7 +26,7 @@ /* APPLICATION INTERFACE DEFINITION RELEASE */ /* */ /* nx_api.h PORTABLE C */ -/* 6.1.6 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -67,6 +67,9 @@ /* 04-02-2021 Yuxin Zhou Modified comment(s), and */ /* added functions for base64, */ /* resulting in version 6.1.6 */ +/* 06-02-2021 Yuxin Zhou Modified comment(s), and */ +/* updated product constants, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ @@ -474,7 +477,7 @@ VOID _nx_trace_event_update(TX_TRACE_BUFFER_ENTRY *event, ULONG timestamp, ULONG #define AZURE_RTOS_NETXDUO #define NETXDUO_MAJOR_VERSION 6 #define NETXDUO_MINOR_VERSION 1 -#define NETXDUO_PATCH_VERSION 6 +#define NETXDUO_PATCH_VERSION 7 /* Define the following symbols for backward compatibility */ #define EL_PRODUCT_NETXDUO diff --git a/common/src/nx_tcp_socket_state_ack_check.c b/common/src/nx_tcp_socket_state_ack_check.c index eafc92d1..b20e4424 100644 --- a/common/src/nx_tcp_socket_state_ack_check.c +++ b/common/src/nx_tcp_socket_state_ack_check.c @@ -40,7 +40,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_tcp_socket_state_ack_check PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -81,6 +81,9 @@ /* corrected the calculation of*/ /* ending packet sequence, */ /* resulting in version 6.1 */ +/* 06-02-2021 Yuxin Zhou Modified comment(s), */ +/* fixed compiler warnings, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ UINT _nx_tcp_socket_state_ack_check(NX_TCP_SOCKET *socket_ptr, NX_TCP_HEADER *tcp_header_ptr) @@ -132,6 +135,7 @@ UINT wrapped_flag = NX_FALSE; search_header_ptr = (NX_TCP_HEADER *)(search_ptr -> nx_packet_ip_header + sizeof(NX_IPV4_HEADER)); } + else #endif /* NX_DISABLE_IPV4 */ #ifdef FEATURE_NX_IPV6 if (search_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) @@ -141,7 +145,11 @@ UINT wrapped_flag = NX_FALSE; search_header_ptr = (NX_TCP_HEADER *)(search_ptr -> nx_packet_ip_header + sizeof(NX_IPV6_HEADER)); } + else #endif /* FEATURE_NX_IPV6 */ + { + return(NX_FALSE); + } /* Determine the size of the TCP header. */ temp = search_header_ptr -> nx_tcp_header_word_3; diff --git a/crypto_libraries/inc/nx_crypto.h b/crypto_libraries/inc/nx_crypto.h index 5a71357d..56ab422f 100644 --- a/crypto_libraries/inc/nx_crypto.h +++ b/crypto_libraries/inc/nx_crypto.h @@ -26,7 +26,7 @@ /* COMPONENT DEFINITION RELEASE */ /* */ /* nx_crypto.h PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -45,6 +45,10 @@ /* by default, and added */ /* crypto standalone support, */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* Renamed FIPS symbol and */ +/* fips memory functions, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ @@ -76,21 +80,28 @@ extern "C" { #define NX_CRYPTO_LITTLE_ENDIAN 1 #endif +/* Deprecated definition, provided only for backward compatibility */ +#ifdef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST +#define NX_CRYPTO_SELF_TEST +#endif /* NX_CRYPTO_SELF_TEST */ +#endif /* NX_CRYPTO_FIPS */ + #include "nx_crypto_const.h" #include <stdlib.h> #include <string.h> -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST -VOID *_nx_crypto_fips_memcpy(void *dest, const void *src, size_t size); -VOID *_nx_crypto_fips_memmove(void *dest, const void *src, size_t size); -VOID *_nx_crypto_fips_memset(void *dest, int value, size_t size); -int _nx_crypto_fips_memcmp(const void *dest, const void *src, size_t size); +VOID *_nx_crypto_self_test_memcpy(void *dest, const void *src, size_t size); +VOID *_nx_crypto_self_test_memmove(void *dest, const void *src, size_t size); +VOID *_nx_crypto_self_test_memset(void *dest, int value, size_t size); +int _nx_crypto_self_test_memcmp(const void *dest, const void *src, size_t size); UINT _nx_crypto_drbg(UINT bits, UCHAR *result); #ifdef _NX_CRYPTO_INITIALIZE_ -VOID *(*volatile _nx_crypto_memset_ptr)(void *dest, int value, size_t size) = _nx_crypto_fips_memset; -VOID *(*volatile _nx_crypto_memcpy_ptr)(void *dest, const void *src, size_t size) = _nx_crypto_fips_memcpy; +VOID *(*volatile _nx_crypto_memset_ptr)(void *dest, int value, size_t size) = _nx_crypto_self_test_memset; +VOID *(*volatile _nx_crypto_memcpy_ptr)(void *dest, const void *src, size_t size) = _nx_crypto_self_test_memcpy; #else extern VOID *(*volatile _nx_crypto_memset_ptr)(void *dest, int value, size_t size); extern VOID *(*volatile _nx_crypto_memcpy_ptr)(void *dest, const void *src, size_t size); @@ -101,7 +112,7 @@ extern VOID *(*volatile _nx_crypto_memcpy_ptr)(void *dest, const void *src, size #endif #ifndef NX_CRYPTO_MEMMOVE -#define NX_CRYPTO_MEMMOVE _nx_crypto_fips_memmove +#define NX_CRYPTO_MEMMOVE _nx_crypto_self_test_memmove #endif #ifndef NX_CRYPTO_MEMSET @@ -109,7 +120,7 @@ extern VOID *(*volatile _nx_crypto_memcpy_ptr)(void *dest, const void *src, size #endif #ifndef NX_CRYPTO_MEMCMP -#define NX_CRYPTO_MEMCMP _nx_crypto_fips_memcmp +#define NX_CRYPTO_MEMCMP _nx_crypto_self_test_memcmp #endif #ifndef NX_CRYPTO_RBG @@ -118,7 +129,7 @@ extern VOID *(*volatile _nx_crypto_memcpy_ptr)(void *dest, const void *src, size #define NX_CRYPTO_CONST -#else /* NON FIPS build. */ +#else /* NON NX_CRYPTO_SELF_TEST build. */ #ifdef _NX_CRYPTO_INITIALIZE_ VOID *(*volatile _nx_crypto_memset_ptr)(void *dest, int value, size_t size) = memset; @@ -177,9 +188,9 @@ extern VOID *(*volatile _nx_crypto_memcpy_ptr)(void *dest, const void *src, size #endif #endif -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST -/* FIPS build forces NX_SECURE_KEY_CLEAR to be set */ +/* NX_CRYPTO_SELF_TEST build forces NX_SECURE_KEY_CLEAR to be set */ #ifndef NX_SECURE_KEY_CLEAR #define NX_SECURE_KEY_CLEAR #endif /* NX_SECURE_KEY_CLEAR */ @@ -197,7 +208,7 @@ extern unsigned int _nx_crypto_library_state; #else #define NX_CRYPTO_STATE_CHECK -#endif /* NX_CRYPTO_FIPS */ +#endif /* NX_CRYPTO_SELF_TEST */ /* Keep functions not used which is compiler specific. */ #ifndef NX_CRYPTO_KEEP @@ -374,7 +385,7 @@ typedef struct NX_CRYPTO_CIPHERSUITE_STRUCT UINT _nx_crypto_initialize(VOID); -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST #define nx_crypto_method_self_test _nx_crypto_method_self_test #define nx_crypto_module_state_get _nx_crypto_module_state_get /* int nx_crypto_rand(void); */ diff --git a/crypto_libraries/inc/nx_crypto_const.h b/crypto_libraries/inc/nx_crypto_const.h index b7fb2adf..7f77e92b 100644 --- a/crypto_libraries/inc/nx_crypto_const.h +++ b/crypto_libraries/inc/nx_crypto_const.h @@ -26,7 +26,7 @@ /* COMPONENT DEFINITION RELEASE */ /* */ /* nx_crypto_const.h PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -43,6 +43,10 @@ /* 09-30-2020 Timothy Stapko Modified comment(s), added */ /* new constants, */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ @@ -319,13 +323,13 @@ typedef UINT NX_CRYPTO_KEY_SIZE; /* The following symbols are mapped to the error code for backward compatibility. */ #define NX_CRYPTO_AES_UNSUPPORTED_KEY_SIZE NX_CRYPTO_UNSUPPORTED_KEY_SIZE -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST #define NX_CRYPTO_LIBRARY_STATE_UNINITIALIZED 0x00000001U #define NX_CRYPTO_LIBRARY_STATE_POST_IN_PROGRESS 0x00000002U #define NX_CRYPTO_LIBRARY_STATE_POST_FAILED 0x00000004U #define NX_CRYPTO_LIBRARY_STATE_OPERATIONAL 0x80000000U -#endif /* NX_CRYPTO_FIPS */ +#endif /* NX_CRYPTO_SELF_TEST */ #ifdef __cplusplus diff --git a/crypto_libraries/inc/nx_crypto_method_self_test.h b/crypto_libraries/inc/nx_crypto_method_self_test.h index 37d6446d..0bec9858 100644 --- a/crypto_libraries/inc/nx_crypto_method_self_test.h +++ b/crypto_libraries/inc/nx_crypto_method_self_test.h @@ -34,7 +34,7 @@ extern "C" { #include "nx_crypto.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST UINT _nx_crypto_method_self_test_aes(NX_CRYPTO_METHOD *crypto_method_aes, VOID *metadata, UINT metadata_size); diff --git a/crypto_libraries/ports/cortex_m3/kiel/inc/nx_crypto_port.h b/crypto_libraries/ports/cortex_m3/keil/inc/nx_crypto_port.h index f32d3c0d..f32d3c0d 100644 --- a/crypto_libraries/ports/cortex_m3/kiel/inc/nx_crypto_port.h +++ b/crypto_libraries/ports/cortex_m3/keil/inc/nx_crypto_port.h diff --git a/crypto_libraries/ports/cortex_m4/kiel/inc/nx_crypto_port.h b/crypto_libraries/ports/cortex_m4/keil/inc/nx_crypto_port.h index f95f0451..f95f0451 100644 --- a/crypto_libraries/ports/cortex_m4/kiel/inc/nx_crypto_port.h +++ b/crypto_libraries/ports/cortex_m4/keil/inc/nx_crypto_port.h diff --git a/crypto_libraries/ports/cortex-m7/ac5/inc/nx_crypto_port.h b/crypto_libraries/ports/cortex_m7/ac5/inc/nx_crypto_port.h index 28e969cd..28e969cd 100644 --- a/crypto_libraries/ports/cortex-m7/ac5/inc/nx_crypto_port.h +++ b/crypto_libraries/ports/cortex_m7/ac5/inc/nx_crypto_port.h diff --git a/crypto_libraries/ports/cortex-m7/gnu/CMakeLists.txt b/crypto_libraries/ports/cortex_m7/gnu/CMakeLists.txt index 75c79531..75c79531 100644 --- a/crypto_libraries/ports/cortex-m7/gnu/CMakeLists.txt +++ b/crypto_libraries/ports/cortex_m7/gnu/CMakeLists.txt diff --git a/crypto_libraries/ports/cortex-m7/gnu/inc/nx_crypto_port.h b/crypto_libraries/ports/cortex_m7/gnu/inc/nx_crypto_port.h index 12657bf8..12657bf8 100644 --- a/crypto_libraries/ports/cortex-m7/gnu/inc/nx_crypto_port.h +++ b/crypto_libraries/ports/cortex_m7/gnu/inc/nx_crypto_port.h diff --git a/crypto_libraries/ports/cortex-m7/iar/inc/nx_crypto_port.h b/crypto_libraries/ports/cortex_m7/iar/inc/nx_crypto_port.h index ea772c8a..ea772c8a 100644 --- a/crypto_libraries/ports/cortex-m7/iar/inc/nx_crypto_port.h +++ b/crypto_libraries/ports/cortex_m7/iar/inc/nx_crypto_port.h diff --git a/crypto_libraries/src/nx_crypto_aes.c b/crypto_libraries/src/nx_crypto_aes.c index fed6e737..83dc2462 100644 --- a/crypto_libraries/src/nx_crypto_aes.c +++ b/crypto_libraries/src/nx_crypto_aes.c @@ -396,9 +396,9 @@ static const UCHAR aes_rcon_array[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, #endif -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST extern UINT _nx_crypto_library_state; -#endif /* NX_CRYPTO_FIPS */ +#endif /* NX_CRYPTO_SELF_TEST */ /**************************************************************************/ /* Utility routines */ @@ -411,7 +411,7 @@ extern UINT _nx_crypto_library_state; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_aes_add_round_key PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -447,6 +447,10 @@ extern UINT _nx_crypto_library_state; /* 09-30-2020 Timothy Stapko Modified comment(s), updated */ /* constants and conditionals, */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP static VOID _nx_crypto_aes_add_round_key(NX_CRYPTO_AES *aes_ptr, UINT *round_key) diff --git a/crypto_libraries/src/nx_crypto_dh.c b/crypto_libraries/src/nx_crypto_dh.c index 27cef7ea..84d5bf48 100644 --- a/crypto_libraries/src/nx_crypto_dh.c +++ b/crypto_libraries/src/nx_crypto_dh.c @@ -26,7 +26,7 @@ /* Include necessary system files. */ #include "nx_crypto_dh.h" -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST /* The Diffie-Hellman group 2 modulus. */ /* Modulus, in byte stream, be */ @@ -57,7 +57,7 @@ static const HN_UBASE _nx_dh_group_2_modulus[] = /* FUNCTION RELEASE */ /* */ /* _nx_crypto_dh_setup PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -108,6 +108,10 @@ static const HN_UBASE _nx_dh_group_2_modulus[] = /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_dh_setup(NX_CRYPTO_DH *dh_ptr, diff --git a/crypto_libraries/src/nx_crypto_ec.c b/crypto_libraries/src/nx_crypto_ec.c index e033e125..ca05d7fb 100644 --- a/crypto_libraries/src/nx_crypto_ec.c +++ b/crypto_libraries/src/nx_crypto_ec.c @@ -685,7 +685,7 @@ NX_CRYPTO_CONST NX_CRYPTO_EC _nx_crypto_ec_secp521r1 = _nx_crypto_ec_fp_projective_multiple, _nx_crypto_ec_secp521r1_reduce }; -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST static NX_CRYPTO_CONST NX_CRYPTO_EC *_nx_crypto_ec_named_curves[] = { &_nx_crypto_ec_secp192r1, @@ -1907,9 +1907,13 @@ UINT compare_value; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST NX_CRYPTO_KEEP VOID _nx_crypto_ec_add_digit_reduce(NX_CRYPTO_EC *curve, NX_CRYPTO_HUGE_NUMBER *value, HN_UBASE digit, @@ -2028,9 +2032,13 @@ NX_CRYPTO_KEEP VOID _nx_crypto_ec_subtract_digit_reduce(NX_CRYPTO_EC *curve, /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST NX_CRYPTO_KEEP VOID _nx_crypto_ec_fp_reduce(NX_CRYPTO_EC *curve, NX_CRYPTO_HUGE_NUMBER *value, HN_UBASE *scratch) @@ -3330,9 +3338,13 @@ NX_CRYPTO_EC_POINT public_key; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST NX_CRYPTO_KEEP VOID _nx_crypto_ec_precomputation(NX_CRYPTO_EC *curve, UINT window_width, UINT bits, @@ -3510,9 +3522,13 @@ UINT i, j; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST NX_CRYPTO_KEEP VOID _nx_crypto_ec_fixed_output(NX_CRYPTO_EC *curve, INT (*output)(const CHAR *format, ...), const CHAR *tab, @@ -3755,9 +3771,13 @@ const CHAR *array_name[] = {"", "_2e"}; /* 09-30-2020 Timothy Stapko Modified comment(s), updated */ /* constants, resulting */ /* in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST NX_CRYPTO_KEEP UINT _nx_crypto_ec_get_named_curve(NX_CRYPTO_EC **curve, UINT curve_id) { UINT i; diff --git a/crypto_libraries/src/nx_crypto_ecjpake.c b/crypto_libraries/src/nx_crypto_ecjpake.c index 3263613d..26bcf767 100644 --- a/crypto_libraries/src/nx_crypto_ecjpake.c +++ b/crypto_libraries/src/nx_crypto_ecjpake.c @@ -28,7 +28,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_ecjpake_init PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -1525,9 +1525,13 @@ UINT status; /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST UINT _nx_crypto_ecjpake_key_encryption_key_generate(NX_CRYPTO_METHOD *hash_method, VOID *hash_metadata, UCHAR *key_expansion, diff --git a/crypto_libraries/src/nx_crypto_huge_number_extended.c b/crypto_libraries/src/nx_crypto_huge_number_extended.c index 498a186b..256f19d8 100644 --- a/crypto_libraries/src/nx_crypto_huge_number_extended.c +++ b/crypto_libraries/src/nx_crypto_huge_number_extended.c @@ -27,13 +27,13 @@ #include "stdio.h" #include "nx_crypto_huge_number.h" -#ifndef NX_CRYPTO_FIPS +#ifndef NX_CRYPTO_SELF_TEST /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_huge_number_add_digit PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -73,6 +73,10 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP VOID _nx_crypto_huge_number_add_digit(NX_CRYPTO_HUGE_NUMBER *value, HN_UBASE digit) diff --git a/crypto_libraries/src/nx_crypto_initialize.c b/crypto_libraries/src/nx_crypto_initialize.c index 73f36e9c..6ae0aeff 100644 --- a/crypto_libraries/src/nx_crypto_initialize.c +++ b/crypto_libraries/src/nx_crypto_initialize.c @@ -24,7 +24,7 @@ #include "nx_crypto.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* Include necessary system files. */ @@ -33,8 +33,8 @@ /* */ /* FUNCTION RELEASE */ /* */ -/* _nx_crypto_fips_memcpy PORTABLE C */ -/* 6.1 */ +/* _nx_crypto_self_test_memcpy PORTABLE C */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -71,9 +71,12 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed function, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -NX_CRYPTO_KEEP VOID *_nx_crypto_fips_memcpy(void *dest, const void *src, size_t size) +NX_CRYPTO_KEEP VOID *_nx_crypto_self_test_memcpy(void *dest, const void *src, size_t size) { char *from, *to; unsigned int i; @@ -93,8 +96,8 @@ NX_CRYPTO_KEEP VOID *_nx_crypto_fips_memcpy(void *dest, const void *src, size_t /* */ /* FUNCTION RELEASE */ /* */ -/* _nx_crypto_fips_memset PORTABLE C */ -/* 6.1 */ +/* _nx_crypto_self_test_memset PORTABLE C */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -131,9 +134,12 @@ NX_CRYPTO_KEEP VOID *_nx_crypto_fips_memcpy(void *dest, const void *src, size_t /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed function, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -NX_CRYPTO_KEEP VOID *_nx_crypto_fips_memset(void *dest, int value, size_t size) +NX_CRYPTO_KEEP VOID *_nx_crypto_self_test_memset(void *dest, int value, size_t size) { char *to; unsigned int i; @@ -153,8 +159,8 @@ NX_CRYPTO_KEEP VOID *_nx_crypto_fips_memset(void *dest, int value, size_t size) /* */ /* FUNCTION RELEASE */ /* */ -/* _nx_crypto_fips_memcmp PORTABLE C */ -/* 6.1 */ +/* _nx_crypto_self_test_memcmp PORTABLE C */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -193,9 +199,12 @@ NX_CRYPTO_KEEP VOID *_nx_crypto_fips_memset(void *dest, int value, size_t size) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed function, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -NX_CRYPTO_KEEP int _nx_crypto_fips_memcmp(const void *str1, const void *str2, size_t size) +NX_CRYPTO_KEEP int _nx_crypto_self_test_memcmp(const void *str1, const void *str2, size_t size) { char *string1; char *string2; @@ -216,8 +225,8 @@ NX_CRYPTO_KEEP int _nx_crypto_fips_memcmp(const void *str1, const void *str2, si /* */ /* FUNCTION RELEASE */ /* */ -/* _nx_crypto_fips_memmove PORTABLE C */ -/* 6.1 */ +/* _nx_crypto_self_test_memmove PORTABLE C */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -253,9 +262,12 @@ NX_CRYPTO_KEEP int _nx_crypto_fips_memcmp(const void *str1, const void *str2, si /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed function, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ -NX_CRYPTO_KEEP void* _nx_crypto_fips_memmove(void *dest, const void *src, size_t size) +NX_CRYPTO_KEEP void* _nx_crypto_self_test_memmove(void *dest, const void *src, size_t size) { char *from, *to; unsigned int i; diff --git a/crypto_libraries/src/nx_crypto_method_self_test.c b/crypto_libraries/src/nx_crypto_method_self_test.c index cc320eb7..51d218fa 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test.c +++ b/crypto_libraries/src/nx_crypto_method_self_test.c @@ -26,7 +26,7 @@ /* Include necessary system files. */ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST static UCHAR metadata[10240]; extern NX_CRYPTO_METHOD crypto_method_aes_cbc_128; @@ -76,7 +76,7 @@ const UINT nx_crypto_hash_key_size = sizeof(nx_crypto_hash_key) << 3; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -109,6 +109,10 @@ const UINT nx_crypto_hash_key_size = sizeof(nx_crypto_hash_key) << 3; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ diff --git a/crypto_libraries/src/nx_crypto_method_self_test_3des.c b/crypto_libraries/src/nx_crypto_method_self_test_3des.c index 8ec618e6..46d9e90b 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_3des.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_3des.c @@ -31,7 +31,7 @@ #endif -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* 8f4f7aab25043720f4fbae01aedf071c68a283689b08ad20 */ static UCHAR key_1[] = { @@ -95,7 +95,7 @@ static UCHAR output[72]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_3des PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -128,6 +128,10 @@ static UCHAR output[72]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_3des(NX_CRYPTO_METHOD *crypto_method_3des, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_aes.c b/crypto_libraries/src/nx_crypto_method_self_test_aes.c index f0919c8d..6fbd1a84 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_aes.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_aes.c @@ -26,7 +26,7 @@ /* Include necessary system files. */ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST #define INPUT_OUTPUT_LENGTH (16) /* 02CF1E1D9796AD3395D8126757B6FC7C705F082FB85270427760AC173759CE07 */ @@ -122,7 +122,7 @@ static UCHAR output[INPUT_OUTPUT_LENGTH]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_aes PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -155,6 +155,10 @@ static UCHAR output[INPUT_OUTPUT_LENGTH]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_aes(NX_CRYPTO_METHOD *crypto_method_aes, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_des.c b/crypto_libraries/src/nx_crypto_method_self_test_des.c index 46998a2b..9df96187 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_des.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_des.c @@ -31,7 +31,7 @@ #endif -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST #define INPUT_OUTPUT_LENGTH 64 @@ -68,7 +68,7 @@ static UCHAR output[INPUT_OUTPUT_LENGTH]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_des PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -101,6 +101,10 @@ static UCHAR output[INPUT_OUTPUT_LENGTH]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_des(NX_CRYPTO_METHOD *crypto_method_des, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_drbg.c b/crypto_libraries/src/nx_crypto_method_self_test_drbg.c index c590cb2b..bf2d320a 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_drbg.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_drbg.c @@ -28,7 +28,7 @@ #include "nx_crypto_drbg.h" #include "nx_crypto_aes.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* [AES-128 use df] @@ -138,7 +138,7 @@ static UCHAR drbg_test_entropy_count_npr; /* FUNCTION RELEASE */ /* */ /* drbg_test_get_entropy_pr PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -175,6 +175,10 @@ static UCHAR drbg_test_entropy_count_npr; /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP static UINT drbg_test_get_entropy_pr(UCHAR *entropy, UINT *entropy_len, UINT entropy_max_len) diff --git a/crypto_libraries/src/nx_crypto_method_self_test_ecdh.c b/crypto_libraries/src/nx_crypto_method_self_test_ecdh.c index 654e6382..8b99721f 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_ecdh.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_ecdh.c @@ -26,7 +26,7 @@ /* Include necessary system files. */ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* 7fc1c44f7f432927f404922107eae9d10b26ed35527d66d9858c58be388c98a1 981a1b7c098a26747a723b171cae16670de0c320a82b1cfcbe77d2f807a217b5 */ @@ -61,7 +61,7 @@ extern NX_CRYPTO_METHOD crypto_method_ec_secp256; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_ecdh PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -94,6 +94,10 @@ extern NX_CRYPTO_METHOD crypto_method_ec_secp256; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_ecdh(NX_CRYPTO_METHOD *crypto_method_ecdh, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_ecdsa.c b/crypto_libraries/src/nx_crypto_method_self_test_ecdsa.c index 717fa17c..ae357656 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_ecdsa.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_ecdsa.c @@ -27,7 +27,7 @@ #include "nx_crypto_method_self_test.h" #include "nx_crypto_ecdsa.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST extern NX_CRYPTO_METHOD crypto_method_ec_secp256; extern NX_CRYPTO_METHOD crypto_method_sha256; @@ -52,7 +52,7 @@ static UCHAR scratch_buffer[4000]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_ecdsa PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -86,6 +86,10 @@ static UCHAR scratch_buffer[4000]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_ecdsa(NX_CRYPTO_METHOD *crypto_method_ecdsa, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_hmac_md5.c b/crypto_libraries/src/nx_crypto_method_self_test_hmac_md5.c index 9a7ff721..f558fef2 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_hmac_md5.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_hmac_md5.c @@ -27,7 +27,7 @@ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* BF8D54470B5F365F14F84C0E046DE4053DE7A05DB847CD2C9844632082F588602EA3885DEF9CA21B8B46AA7CB9588938 */ static UCHAR key_1[] = { @@ -57,7 +57,7 @@ static ULONG output[4]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_hmac_md5 PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -91,6 +91,10 @@ static ULONG output[4]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_hmac_md5(NX_CRYPTO_METHOD *crypto_method_hmac_md5, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_hmac_sha.c b/crypto_libraries/src/nx_crypto_method_self_test_hmac_sha.c index 86dc1248..a59fcf61 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_hmac_sha.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_hmac_sha.c @@ -26,7 +26,7 @@ /* Include necessary system files. */ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* 39567E74085C7B4C94BCED431A18F109BBACEF73471C0E00B7FA0B1C4F979576B5F1025AD5ADAA1246A6974CEB6BEC30CF5CA14F65231F31F24338707AD35B7C */ static UCHAR key_1_96[] = { @@ -207,7 +207,7 @@ static ULONG output[16]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_hmac_sha PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -241,6 +241,10 @@ static ULONG output[16]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_hmac_sha(NX_CRYPTO_METHOD *crypto_method_hmac_sha, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_md5.c b/crypto_libraries/src/nx_crypto_method_self_test_md5.c index 750bfa71..65e02d0e 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_md5.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_md5.c @@ -26,7 +26,7 @@ /* Include necessary system files. */ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* f149e41d848f59276cfddd743bafa9a90e1ee4a263a118142b33e3702176ef0a59f8237a1cb51b42f3ded6b202d9af0997898fdd03cf60bda951c514547a0850cec25444ae2f24cb711bfbafcc3956c941d3de69f155e3f8b10f06db5f37359b772ddd43e1035a0a0d3db33242d5843033833b0dd43b870c6bf60e8deab55f317cc3273f5e3ba747f0cb65050cb7228796210d9254873643008d45f29cfd6c5b060c9a */ static UCHAR plain_1[] = { @@ -56,7 +56,7 @@ static ULONG output[4]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_md5 PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -89,6 +89,10 @@ static ULONG output[4]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_md5(NX_CRYPTO_METHOD *crypto_method_md5, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_pkcs1.c b/crypto_libraries/src/nx_crypto_method_self_test_pkcs1.c index c3c1b6a7..bdca1ae6 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_pkcs1.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_pkcs1.c @@ -27,7 +27,7 @@ #include "nx_crypto_method_self_test.h" #include "nx_crypto_pkcs1_v1.5.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST static UCHAR pub_e_2048[] = {0x01, 0x00, 0x01}; @@ -109,7 +109,7 @@ extern NX_CRYPTO_METHOD crypto_method_sha256; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_pkcs1 PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -143,6 +143,10 @@ extern NX_CRYPTO_METHOD crypto_method_sha256; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_pkcs1(NX_CRYPTO_METHOD *crypto_method_pkcs1, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_prf.c b/crypto_libraries/src/nx_crypto_method_self_test_prf.c index a1cce84c..a80c2591 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_prf.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_prf.c @@ -26,7 +26,7 @@ /* Include necessary system files. */ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST static UCHAR secret_sha1[] = { 0x86, 0xec, 0x88, 0xbb }; static UCHAR label_sha1[] = { 0xc8, 0x37, 0xaf, 0x7d }; @@ -112,7 +112,7 @@ static UCHAR output[256]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_prf PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -145,6 +145,10 @@ static UCHAR output[256]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_prf(NX_CRYPTO_METHOD *crypto_method_prf, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_rsa.c b/crypto_libraries/src/nx_crypto_method_self_test_rsa.c index 45f5c2d4..1ca4109c 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_rsa.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_rsa.c @@ -27,7 +27,7 @@ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* 00010001 */ static const UCHAR pub_e_1024[] = { @@ -559,7 +559,7 @@ static UCHAR output[512]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_rsa PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -592,6 +592,10 @@ static UCHAR output[512]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_rsa(NX_CRYPTO_METHOD *crypto_method, diff --git a/crypto_libraries/src/nx_crypto_method_self_test_sha.c b/crypto_libraries/src/nx_crypto_method_self_test_sha.c index 33ab6d54..626f674f 100644 --- a/crypto_libraries/src/nx_crypto_method_self_test_sha.c +++ b/crypto_libraries/src/nx_crypto_method_self_test_sha.c @@ -26,7 +26,7 @@ /* Include necessary system files. */ #include "nx_crypto_method_self_test.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST /* 7c9c67323a1df1adbfe5ceb415eaef0155ece2820f4d50c1ec22cba4928ac656c83fe585db6a78ce40bc42757aba7e5a3f582428d6ca68d0c3978336a6efb729613e8d9979016204bfd921322fdd5222183554447de5e6e9bbe6edf76d7b71e18dc2e8d6dc89b7398364f652fafc734329aafa3dcd45d4f31e388e4fafd7fc6495f37ca5cbab7f54d586463da4bfeaa3bae09f7b8e9239d832b4f0a733aa609cc1f8d4 */ static UCHAR plain_1[] = { @@ -194,7 +194,7 @@ static ULONG output[16]; /* FUNCTION RELEASE */ /* */ /* nx_crypto_method_self_test_sha PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -227,6 +227,10 @@ static ULONG output[16]; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_self_test_sha(NX_CRYPTO_METHOD *crypto_method_sha, diff --git a/crypto_libraries/src/nx_crypto_module_start.c b/crypto_libraries/src/nx_crypto_module_start.c index 322d7520..0381a200 100644 --- a/crypto_libraries/src/nx_crypto_module_start.c +++ b/crypto_libraries/src/nx_crypto_module_start.c @@ -27,7 +27,7 @@ #include "nx_crypto.h" #include "nx_crypto_hmac_sha2.h" -#ifdef NX_CRYPTO_FIPS +#ifdef NX_CRYPTO_SELF_TEST #define NX_CRYPTO_INTEGRITY_TEST_CHECK(status) \ if(status) \ @@ -92,14 +92,14 @@ extern NX_CRYPTO_METHOD crypto_method_hmac_sha256; extern const CHAR nx_crypto_hash_key[]; extern const UINT nx_crypto_hash_key_size; static UCHAR nx_crypto_hmac_output[64]; -static NX_CRYPTO_SHA256_HMAC nx_crypto_fips_hmac; +static NX_CRYPTO_SHA256_HMAC nx_crypto_self_test_hmac; /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_hardware_rand_initialize PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -140,6 +140,10 @@ static NX_CRYPTO_SHA256_HMAC nx_crypto_fips_hmac; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* 06-02-2021 Bhupendra Naphade Modified comment(s), */ +/* renamed FIPS symbol to */ +/* self-test, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP void _nx_crypto_hardware_rand_initialize_stm32f4(void) @@ -358,7 +362,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_integrity_test(void) UINT status; status = _nx_crypto_method_hmac_sha256_operation(NX_CRYPTO_AUTHENTICATE, /* op */ - (VOID*)&nx_crypto_fips_hmac, + (VOID*)&nx_crypto_self_test_hmac, &crypto_method_hmac_sha256, /* Method */ (UCHAR*)nx_crypto_hash_key, nx_crypto_hash_key_size, @@ -366,7 +370,7 @@ UINT status; (ULONG)_nx_crypto_module_hash_value - (ULONG)&_nx_crypto_module_program_begin, NX_CRYPTO_NULL, /* iv_ptr, not used */ nx_crypto_hmac_output, sizeof(nx_crypto_hmac_output), - &nx_crypto_fips_hmac, sizeof(nx_crypto_fips_hmac), + &nx_crypto_self_test_hmac, sizeof(nx_crypto_self_test_hmac), NX_CRYPTO_NULL, NX_CRYPTO_NULL); NX_CRYPTO_INTEGRITY_TEST_CHECK(status) diff --git a/nx_secure/inc/nx_secure_tls.h b/nx_secure/inc/nx_secure_tls.h index e40664ac..37a16d5c 100644 --- a/nx_secure/inc/nx_secure_tls.h +++ b/nx_secure/inc/nx_secure_tls.h @@ -26,7 +26,7 @@ /* COMPONENT DEFINITION RELEASE */ /* */ /* nx_secure_tls.h PORTABLE C */ -/* 6.1.6 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -67,6 +67,9 @@ /* 04-02-2021 Yuxin Zhou Modified comment(s), and */ /* updated product constants, */ /* resulting in version 6.1.6 */ +/* 06-02-2021 Yuxin Zhou Modified comment(s), and */ +/* updated product constants, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ @@ -127,7 +130,7 @@ extern "C" { #define AZURE_RTOS_NETX_SECURE #define NETX_SECURE_MAJOR_VERSION 6 #define NETX_SECURE_MINOR_VERSION 1 -#define NETX_SECURE_PATCH_VERSION 6 +#define NETX_SECURE_PATCH_VERSION 7 /* The following symbols are defined for backward compatibility reasons. */ #define EL_PRODUCT_NETX_SECURE diff --git a/nx_secure/inc/nx_secure_x509.h b/nx_secure/inc/nx_secure_x509.h index 4e57252b..b71c0ce4 100644 --- a/nx_secure/inc/nx_secure_x509.h +++ b/nx_secure/inc/nx_secure_x509.h @@ -26,7 +26,7 @@ /* COMPONENT DEFINITION RELEASE */ /* */ /* nx_secure_x509.h PORTABLE C */ -/* 6.1.6 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -47,6 +47,10 @@ /* 04-02-2021 Timothy Stapko Modified comment(s), */ /* removed dependency on TLS, */ /* resulting in version 6.1.6 */ +/* 06-02-2021 Timothy Stapko Modified comment(s), */ +/* supported hardware EC */ +/* private key, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ @@ -179,6 +183,7 @@ extern "C" { #define NX_SECURE_X509_KEY_TYPE_NONE 0x00000000 /* Default value for no key. */ #define NX_SECURE_X509_KEY_TYPE_RSA_PKCS1_DER 0x00000001 /* DER-encoded PKCS-1 RSA private key. */ #define NX_SECURE_X509_KEY_TYPE_EC_DER 0x00000002 /* DER-encoded EC private key. */ +#define NX_SECURE_X509_KEY_TYPE_HARDWARE 0x00000003 /* Hardware private key */ /* ASN.1 Format: diff --git a/nx_secure/src/nx_secure_tls_hash_record.c b/nx_secure/src/nx_secure_tls_hash_record.c index 567cb8e4..4b90e9db 100644 --- a/nx_secure/src/nx_secure_tls_hash_record.c +++ b/nx_secure/src/nx_secure_tls_hash_record.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_hash_record PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -73,6 +73,9 @@ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* supported chained packet, */ /* resulting in version 6.1 */ +/* 06-02-2021 Timothy Stapko Modified comment(s), */ +/* fixed compiler warning, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_hash_record(NX_SECURE_TLS_SESSION *tls_session, @@ -82,7 +85,7 @@ UINT _nx_secure_tls_hash_record(NX_SECURE_TLS_SESSION *tls_session, UCHAR *mac_secret) { UINT hash_size; -UINT status = NX_SECURE_TLS_MISSING_CRYPTO_ROUTINE;; +UINT status = NX_SECURE_TLS_MISSING_CRYPTO_ROUTINE; const NX_CRYPTO_METHOD *authentication_method; UCHAR adjusted_sequence_num[8]; VOID *metadata; diff --git a/nx_secure/src/nx_secure_tls_process_client_key_exchange.c b/nx_secure/src/nx_secure_tls_process_client_key_exchange.c index 53091a40..aa5e2823 100644 --- a/nx_secure/src/nx_secure_tls_process_client_key_exchange.c +++ b/nx_secure/src/nx_secure_tls_process_client_key_exchange.c @@ -31,7 +31,7 @@ static UCHAR _nx_secure_client_padded_pre_master[600]; /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_client_key_exchange PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -80,6 +80,10 @@ static UCHAR _nx_secure_client_padded_pre_master[600]; /* ECC find curve method, */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* 06-02-2021 Timothy Stapko Modified comment(s), */ +/* supported hardware EC */ +/* private key, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_process_client_key_exchange(NX_SECURE_TLS_SESSION *tls_session, @@ -360,7 +364,8 @@ UINT private_key_length; /* Check for user-defined key types. */ user_defined_key = NX_FALSE; - if ((local_certificate -> nx_secure_x509_private_key_type & NX_SECURE_X509_KEY_TYPE_USER_DEFINED_MASK) != 0x0) + if (((local_certificate -> nx_secure_x509_private_key_type & NX_SECURE_X509_KEY_TYPE_USER_DEFINED_MASK) != 0x0) || + ( local_certificate -> nx_secure_x509_private_key_type == NX_SECURE_X509_KEY_TYPE_HARDWARE)) { user_defined_key = NX_TRUE; } diff --git a/nx_secure/src/nx_secure_tls_send_certificate_verify.c b/nx_secure/src/nx_secure_tls_send_certificate_verify.c index 5110b4f4..fd60b31b 100644 --- a/nx_secure/src/nx_secure_tls_send_certificate_verify.c +++ b/nx_secure/src/nx_secure_tls_send_certificate_verify.c @@ -40,7 +40,7 @@ static const UCHAR _NX_SECURE_OID_SHA256[] = {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09 /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_certificate_verify PORTABLE C */ -/* 6.1.6 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -91,6 +91,10 @@ static const UCHAR _NX_SECURE_OID_SHA256[] = {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09 /* 04-02-2021 Timothy Stapko Modified comment(s), */ /* updated X.509 return value, */ /* resulting in version 6.1.6 */ +/* 06-02-2021 Timothy Stapko Modified comment(s), */ +/* supported hardware EC */ +/* private key, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_send_certificate_verify(NX_SECURE_TLS_SESSION *tls_session, @@ -122,6 +126,7 @@ const CHAR client_context[] = "TLS 1.3, client CertificateVerify\0"; /* Includes const NX_CRYPTO_METHOD *curve_method_cert; NX_SECURE_EC_PRIVATE_KEY *ec_privkey; NX_SECURE_EC_PUBLIC_KEY *ec_pubkey; +NX_SECURE_EC_PRIVATE_KEY ec_hardware_privkey; NX_CRYPTO_EXTENDED_OUTPUT extended_output; #endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */ @@ -762,7 +767,19 @@ NX_CRYPTO_EXTENDED_OUTPUT extended_output; } #endif - ec_privkey = &local_certificate -> nx_secure_x509_private_key.ec_private_key; + /* Check for hardware key types before encrypting the hash to produce the signature. */ + if(local_certificate -> nx_secure_x509_private_key_type == NX_SECURE_X509_KEY_TYPE_HARDWARE) + { + /* The certificate private key is stored in a secure element or similar. Just pass the private/user key data to the driver. */ + ec_hardware_privkey.nx_secure_ec_private_key = local_certificate -> nx_secure_x509_private_key.user_key.key_data; + ec_hardware_privkey.nx_secure_ec_private_key_length = (USHORT)local_certificate -> nx_secure_x509_private_key.user_key.key_length; + ec_hardware_privkey.nx_secure_ec_named_curve = local_certificate -> nx_secure_x509_public_key.ec_public_key.nx_secure_ec_named_curve; + ec_privkey = &ec_hardware_privkey; + } + else + { + ec_privkey = &local_certificate -> nx_secure_x509_private_key.ec_private_key; + } ec_pubkey = &local_certificate -> nx_secure_x509_public_key.ec_public_key; /* Find out which named curve the local certificate is using. */ diff --git a/nx_secure/src/nx_secure_tls_send_record.c b/nx_secure/src/nx_secure_tls_send_record.c index a8ceff01..4ef47b86 100644 --- a/nx_secure/src/nx_secure_tls_send_record.c +++ b/nx_secure/src/nx_secure_tls_send_record.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_record PORTABLE C */ -/* 6.1 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -84,6 +84,8 @@ /* fixed race condition for */ /* multithread transmission, */ /* resulting in version 6.1 */ +/* 06-02-2021 Timothy Stapko Modified comment(s), */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_send_record(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet, @@ -160,10 +162,6 @@ NX_PACKET *current_packet; send_packet -> nx_packet_length += iv_size; } - /* Back off the prepend_ptr for TLS Record header. Note the packet_length field is adjusted - prior to nx_tcp_socket_send() below. */ - //send_packet -> nx_packet_prepend_ptr -= NX_SECURE_TLS_RECORD_HEADER_SIZE; - /* Ensure there is enough room for the record header. */ if ((ULONG)(send_packet -> nx_packet_prepend_ptr - send_packet -> nx_packet_data_start) < NX_SECURE_TLS_RECORD_HEADER_SIZE) { diff --git a/nx_secure/src/nx_secure_x509_certificate_initialize.c b/nx_secure/src/nx_secure_x509_certificate_initialize.c index 09e98ce1..d130ea02 100644 --- a/nx_secure/src/nx_secure_x509_certificate_initialize.c +++ b/nx_secure/src/nx_secure_x509_certificate_initialize.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_x509_certificate_initialize PORTABLE C */ -/* 6.1.5 */ +/* 6.1.7 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -102,6 +102,10 @@ /* 04-02-2021 Timothy Stapko Modified comment(s), */ /* removed dependency on TLS, */ /* resulting in version 6.1.6 */ +/* 06-02-2021 Timothy Stapko Modified comment(s), */ +/* supported hardware EC */ +/* private key, */ +/* resulting in version 6.1.7 */ /* */ /**************************************************************************/ UINT _nx_secure_x509_certificate_initialize(NX_SECURE_X509_CERT *certificate, @@ -180,6 +184,12 @@ NX_SECURE_EC_PRIVATE_KEY *ec_key; status = _nx_secure_x509_ec_private_key_parse(private_key, priv_len, &bytes_processed, ec_key); break; #endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */ + + case NX_SECURE_X509_KEY_TYPE_HARDWARE: + certificate -> nx_secure_x509_private_key.user_key.key_data = private_key; + certificate -> nx_secure_x509_private_key.user_key.key_length = priv_len; + status = NX_SUCCESS; + break; case NX_SECURE_X509_KEY_TYPE_NONE: default: /* Unknown or invalid key type, return error. */ |
