diff --git a/examples/all-clusters-app/linux/AppOptions.cpp b/examples/all-clusters-app/linux/AppOptions.cpp index bd5147102715eb..1abab56a486856 100644 --- a/examples/all-clusters-app/linux/AppOptions.cpp +++ b/examples/all-clusters-app/linux/AppOptions.cpp @@ -29,14 +29,11 @@ using chip::ArgParser::OptionDef; using chip::ArgParser::OptionSet; using chip::ArgParser::PrintArgError; -constexpr uint16_t kOptionDacProviderFilePath = 0xFF01; constexpr uint16_t kOptionMinCommissioningTimeout = 0xFF02; constexpr uint16_t kOptionEndUserSupportFilePath = 0xFF03; constexpr uint16_t kOptionNetworkDiagnosticsFilePath = 0xFF04; constexpr uint16_t kOptionCrashFilePath = 0xFF05; -static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider; - static chip::Optional sEndUserSupportLogFilePath; static chip::Optional sNetworkDiagnosticsLogFilePath; static chip::Optional sCrashLogFilePath; @@ -51,9 +48,6 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id bool retval = true; switch (identifier) { - case kOptionDacProviderFilePath: - mDacProvider.Init(value); - break; case kOptionMinCommissioningTimeout: { auto & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager(); commissionMgr.OverrideMinCommissioningTimeout(chip::System::Clock::Seconds16(static_cast(atoi(value)))); @@ -92,7 +86,6 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id OptionSet * AppOptions::GetOptions() { static OptionDef optionsDef[] = { - { "dac_provider", kArgumentRequired, kOptionDacProviderFilePath }, { "min_commissioning_timeout", kArgumentRequired, kOptionMinCommissioningTimeout }, { "end_user_support_log", kArgumentRequired, kOptionEndUserSupportFilePath }, { "network_diagnostics_log", kArgumentRequired, kOptionNetworkDiagnosticsFilePath }, @@ -102,8 +95,6 @@ OptionSet * AppOptions::GetOptions() static OptionSet options = { AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS", - " --dac_provider \n" - " A json file with data used by the example dac provider to validate device attestation procedure.\n" " --min_commissioning_timeout \n" " The minimum time in seconds during which commissioning session establishment is allowed by the Node.\n" " --end_user_support_log \n" @@ -117,11 +108,6 @@ OptionSet * AppOptions::GetOptions() return &options; } -chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider() -{ - return &mDacProvider; -} - chip::Optional AppOptions::GetEndUserSupportLogFilePath() { return sEndUserSupportLogFilePath; diff --git a/examples/all-clusters-app/linux/AppOptions.h b/examples/all-clusters-app/linux/AppOptions.h index 69c1af83b72909..735c904c045939 100644 --- a/examples/all-clusters-app/linux/AppOptions.h +++ b/examples/all-clusters-app/linux/AppOptions.h @@ -20,15 +20,12 @@ #include "AppMain.h" -#include - #include class AppOptions { public: static chip::ArgParser::OptionSet * GetOptions(); - static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider(); static chip::Optional GetEndUserSupportLogFilePath(); static chip::Optional GetNetworkDiagnosticsLogFilePath(); static chip::Optional GetCrashLogFilePath(); diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 64dcf06e90736b..4de95821692fae 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -93,7 +93,6 @@ source_set("chip-all-clusters-common") { "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/platform/linux:app-main", "${chip_root}/src/app:attribute-persistence", - "${chip_root}/src/app/tests/suites/credentials:dac_provider", "${chip_root}/src/lib", "${chip_root}/third_party/jsoncpp", ] diff --git a/examples/all-clusters-app/linux/main.cpp b/examples/all-clusters-app/linux/main.cpp index cd1e88c87e3108..2d83c132eec1d3 100644 --- a/examples/all-clusters-app/linux/main.cpp +++ b/examples/all-clusters-app/linux/main.cpp @@ -31,8 +31,6 @@ int main(int argc, char * argv[]) ChipLinuxAppInit(argc, argv, AppOptions::GetOptions(), chip::MakeOptional(kNetworkCommissioningEndpointSecondary)) == 0); VerifyOrDie(InitBindingHandlers() == CHIP_NO_ERROR); - LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider(); - ChipLinuxAppMainLoop(); return 0; diff --git a/examples/all-clusters-minimal-app/linux/AppOptions.cpp b/examples/all-clusters-minimal-app/linux/AppOptions.cpp index c3f80a2302a484..617d1f5fa30ed6 100644 --- a/examples/all-clusters-minimal-app/linux/AppOptions.cpp +++ b/examples/all-clusters-minimal-app/linux/AppOptions.cpp @@ -25,19 +25,13 @@ using chip::ArgParser::OptionDef; using chip::ArgParser::OptionSet; using chip::ArgParser::PrintArgError; -constexpr uint16_t kOptionDacProviderFilePath = 0xFF01; constexpr uint16_t kOptionMinCommissioningTimeout = 0xFF02; -static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider; - bool AppOptions::HandleOptions(const char * program, OptionSet * options, int identifier, const char * name, const char * value) { bool retval = true; switch (identifier) { - case kOptionDacProviderFilePath: - mDacProvider.Init(value); - break; case kOptionMinCommissioningTimeout: { auto & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager(); commissionMgr.OverrideMinCommissioningTimeout(chip::System::Clock::Seconds16(static_cast(atoi(value)))); @@ -55,23 +49,14 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id OptionSet * AppOptions::GetOptions() { static OptionDef optionsDef[] = { - { "dac_provider", chip::ArgParser::kArgumentRequired, kOptionDacProviderFilePath }, { "min_commissioning_timeout", chip::ArgParser::kArgumentRequired, kOptionMinCommissioningTimeout }, {}, }; static OptionSet options = { AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS", - " --dac_provider \n" - " A json file with data used by the example dac provider to validate device attestation procedure.\n" " --min_commissioning_timeout \n" " The minimum time in seconds during which commissioning session establishment is allowed by the Node.\n" }; - return &options; } - -chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider() -{ - return &mDacProvider; -} diff --git a/examples/all-clusters-minimal-app/linux/AppOptions.h b/examples/all-clusters-minimal-app/linux/AppOptions.h index 3073c66176331f..e8088429ad3fcb 100644 --- a/examples/all-clusters-minimal-app/linux/AppOptions.h +++ b/examples/all-clusters-minimal-app/linux/AppOptions.h @@ -20,13 +20,10 @@ #include "AppMain.h" -#include - class AppOptions { public: static chip::ArgParser::OptionSet * GetOptions(); - static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider(); private: static bool HandleOptions(const char * program, chip::ArgParser::OptionSet * options, int identifier, const char * name, diff --git a/examples/all-clusters-minimal-app/linux/BUILD.gn b/examples/all-clusters-minimal-app/linux/BUILD.gn index ea25284906df07..e7e76e1c246ac1 100644 --- a/examples/all-clusters-minimal-app/linux/BUILD.gn +++ b/examples/all-clusters-minimal-app/linux/BUILD.gn @@ -34,7 +34,6 @@ source_set("chip-all-clusters-common") { deps = [ "${chip_root}/examples/all-clusters-minimal-app/all-clusters-common", "${chip_root}/examples/platform/linux:app-main", - "${chip_root}/src/app/tests/suites/credentials:dac_provider", "${chip_root}/src/lib", ] diff --git a/examples/all-clusters-minimal-app/linux/main.cpp b/examples/all-clusters-minimal-app/linux/main.cpp index 766a5820d0eed3..493a497e1bc6f7 100644 --- a/examples/all-clusters-minimal-app/linux/main.cpp +++ b/examples/all-clusters-minimal-app/linux/main.cpp @@ -31,8 +31,6 @@ int main(int argc, char * argv[]) ChipLinuxAppInit(argc, argv, AppOptions::GetOptions(), chip::MakeOptional(kNetworkCommissioningEndpointSecondary)) == 0); VerifyOrDie(InitBindingHandlers() == CHIP_NO_ERROR); - LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider(); - ChipLinuxAppMainLoop(); return 0; } diff --git a/examples/placeholder/linux/AppOptions.cpp b/examples/placeholder/linux/AppOptions.cpp index 115f17a4782ed2..d18dcce8ab7d15 100644 --- a/examples/placeholder/linux/AppOptions.cpp +++ b/examples/placeholder/linux/AppOptions.cpp @@ -22,11 +22,9 @@ using chip::ArgParser::OptionDef; using chip::ArgParser::OptionSet; using chip::ArgParser::PrintArgError; -constexpr uint16_t kOptionDacProviderFilePath = 0xFF01; constexpr uint16_t kOptionInteractiveMode = 0xFF02; constexpr uint16_t kOptionInteractiveModePort = 0xFF03; -static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider; static bool gInteractiveMode = false; static chip::Optional gInteractiveModePort; @@ -35,9 +33,6 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id bool retval = true; switch (identifier) { - case kOptionDacProviderFilePath: - mDacProvider.Init(value); - break; case kOptionInteractiveMode: gInteractiveMode = true; break; @@ -56,30 +51,20 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id OptionSet * AppOptions::GetOptions() { static OptionDef optionsDef[] = { - { "dac_provider", chip::ArgParser::kArgumentRequired, kOptionDacProviderFilePath }, { "interactive", chip::ArgParser::kNoArgument, kOptionInteractiveMode }, { "port", chip::ArgParser::kArgumentRequired, kOptionInteractiveModePort }, {}, }; - static OptionSet options = { - AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS", - " --dac_provider \n" - " A json file with data used by the example dac provider to validate device attestation procedure.\n" - " --interactive\n" - " Enable server interactive mode.\n" - " --port \n" - " Specify the listening port for the server interactive mode.\n" - }; + static OptionSet options = { AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS", + " --interactive\n" + " Enable server interactive mode.\n" + " --port \n" + " Specify the listening port for the server interactive mode.\n" }; return &options; } -chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider() -{ - return &mDacProvider; -} - bool AppOptions::GetInteractiveMode() { return gInteractiveMode; diff --git a/examples/placeholder/linux/AppOptions.h b/examples/placeholder/linux/AppOptions.h index 1451f325184111..eca79b2ab86c93 100644 --- a/examples/placeholder/linux/AppOptions.h +++ b/examples/placeholder/linux/AppOptions.h @@ -20,13 +20,10 @@ #include "AppMain.h" -#include - class AppOptions { public: static chip::ArgParser::OptionSet * GetOptions(); - static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider(); static bool GetInteractiveMode(); static chip::Optional GetInteractiveModePort(); diff --git a/examples/placeholder/linux/main.cpp b/examples/placeholder/linux/main.cpp index 6485044a7ed6d8..74bd4604387428 100644 --- a/examples/placeholder/linux/main.cpp +++ b/examples/placeholder/linux/main.cpp @@ -65,8 +65,6 @@ int main(int argc, char * argv[]) { VerifyOrDie(ChipLinuxAppInit(argc, argv, AppOptions::GetOptions()) == 0); - LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider(); - auto & server = InteractiveServer::GetInstance(); if (AppOptions::GetInteractiveMode()) { diff --git a/examples/platform/linux/BUILD.gn b/examples/platform/linux/BUILD.gn index e3d00b1db200a9..7fbaa311814cc9 100644 --- a/examples/platform/linux/BUILD.gn +++ b/examples/platform/linux/BUILD.gn @@ -102,6 +102,7 @@ source_set("app-main") { ":ota-test-event-trigger", "${chip_root}/examples/providers:device_info_provider", "${chip_root}/src/app/server", + "${chip_root}/src/app/tests/suites/credentials:dac_provider", ] if (current_os != "nuttx") { diff --git a/examples/platform/linux/Options.cpp b/examples/platform/linux/Options.cpp index 30732ae7e0a034..e3b7ba42675f41 100644 --- a/examples/platform/linux/Options.cpp +++ b/examples/platform/linux/Options.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #if ENABLE_TRACING @@ -126,6 +127,7 @@ enum #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF kDeviceOption_WiFi_PAF, #endif + kDeviceOption_DacProvider, }; constexpr unsigned kAppUsageLength = 64; @@ -140,7 +142,7 @@ OptionDef sDeviceOptionDefs[] = { #if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF { "wifipaf", kArgumentRequired, kDeviceOption_WiFi_PAF }, #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF -#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA +#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI #if CHIP_ENABLE_OPENTHREAD { "thread", kNoArgument, kDeviceOption_Thread }, #endif // CHIP_ENABLE_OPENTHREAD @@ -201,6 +203,7 @@ OptionDef sDeviceOptionDefs[] = { #if CHIP_WITH_NLFAULTINJECTION { "faults", kArgumentRequired, kDeviceOption_FaultInjection }, #endif + { "dac_provider", kArgumentRequired, kDeviceOption_DacProvider }, {} }; @@ -363,6 +366,8 @@ const char * sDeviceOptionHelp = " --faults \n" " Inject specified fault(s) at runtime.\n" #endif + " --dac_provider \n" + " A json file with data used by the example dac provider to validate device attestation procedure.\n" "\n"; #if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS @@ -734,6 +739,14 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, break; } #endif + case kDeviceOption_DacProvider: { + LinuxDeviceOptions::GetInstance().dacProviderFile.SetValue(aValue); + static chip::Credentials::Examples::TestHarnessDACProvider testDacProvider; + testDacProvider.Init(gDeviceOptions.dacProviderFile.Value().c_str()); + + LinuxDeviceOptions::GetInstance().dacProvider = &testDacProvider; + break; + } default: PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName); retval = false; @@ -777,5 +790,6 @@ LinuxDeviceOptions & LinuxDeviceOptions::GetInstance() { gDeviceOptions.dacProvider = chip::Credentials::Examples::GetExampleDACProvider(); } + return gDeviceOptions; } diff --git a/examples/platform/linux/Options.h b/examples/platform/linux/Options.h index 11a9061efcade8..d9b1716bd39e95 100644 --- a/examples/platform/linux/Options.h +++ b/examples/platform/linux/Options.h @@ -49,6 +49,7 @@ struct LinuxDeviceOptions chip::Optional discriminator; chip::Optional> spake2pVerifier; chip::Optional> spake2pSalt; + chip::Optional dacProviderFile; uint32_t spake2pIterations = 0; // When not provided (0), will default elsewhere uint32_t mBleDevice = 0; bool wifiSupports5g = false; diff --git a/src/app/tests/suites/credentials/BUILD.gn b/src/app/tests/suites/credentials/BUILD.gn index d7a49f58ab590a..c27683edcc4a68 100644 --- a/src/app/tests/suites/credentials/BUILD.gn +++ b/src/app/tests/suites/credentials/BUILD.gn @@ -30,8 +30,14 @@ source_set("dac_provider") { "${chip_root}/src/credentials", "${chip_root}/src/crypto", "${chip_root}/src/lib", - "${chip_root}/third_party/jsoncpp", ] + # nuttx keeps a copy of jsoncpp, so don't add it as a dependency + # when building for nuttx, otherwise the build will fail at link + # time due to duplicate symbols + if (current_os != "nuttx") { + deps += [ "${chip_root}/third_party/jsoncpp" ] + } + public_configs = [ ":default_config" ] }