Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the --dac_provider option from all clusters apps to common place. #36886

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions examples/all-clusters-app/linux/AppOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> sEndUserSupportLogFilePath;
static chip::Optional<std::string> sNetworkDiagnosticsLogFilePath;
static chip::Optional<std::string> sCrashLogFilePath;
Expand All @@ -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<uint16_t>(atoi(value))));
Expand Down Expand Up @@ -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 },
Expand All @@ -102,8 +95,6 @@ OptionSet * AppOptions::GetOptions()

static OptionSet options = {
AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS",
" --dac_provider <filepath>\n"
" A json file with data used by the example dac provider to validate device attestation procedure.\n"
" --min_commissioning_timeout <value>\n"
" The minimum time in seconds during which commissioning session establishment is allowed by the Node.\n"
" --end_user_support_log <value>\n"
Expand All @@ -117,11 +108,6 @@ OptionSet * AppOptions::GetOptions()
return &options;
}

chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider()
{
return &mDacProvider;
}

chip::Optional<std::string> AppOptions::GetEndUserSupportLogFilePath()
{
return sEndUserSupportLogFilePath;
Expand Down
3 changes: 0 additions & 3 deletions examples/all-clusters-app/linux/AppOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@

#include "AppMain.h"

#include <app/tests/suites/credentials/TestHarnessDACProvider.h>

#include <string>

class AppOptions
{
public:
static chip::ArgParser::OptionSet * GetOptions();
static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider();
static chip::Optional<std::string> GetEndUserSupportLogFilePath();
static chip::Optional<std::string> GetNetworkDiagnosticsLogFilePath();
static chip::Optional<std::string> GetCrashLogFilePath();
Expand Down
1 change: 0 additions & 1 deletion examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
2 changes: 0 additions & 2 deletions examples/all-clusters-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 0 additions & 15 deletions examples/all-clusters-minimal-app/linux/AppOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(atoi(value))));
Expand All @@ -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 <filepath>\n"
" A json file with data used by the example dac provider to validate device attestation procedure.\n"
" --min_commissioning_timeout <value>\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;
}
3 changes: 0 additions & 3 deletions examples/all-clusters-minimal-app/linux/AppOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@

#include "AppMain.h"

#include <app/tests/suites/credentials/TestHarnessDACProvider.h>

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,
Expand Down
1 change: 0 additions & 1 deletion examples/all-clusters-minimal-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand Down
2 changes: 0 additions & 2 deletions examples/all-clusters-minimal-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
25 changes: 5 additions & 20 deletions examples/placeholder/linux/AppOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t> gInteractiveModePort;

Expand All @@ -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;
Expand All @@ -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 <filepath>\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 <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 <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;
Expand Down
3 changes: 0 additions & 3 deletions examples/placeholder/linux/AppOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@

#include "AppMain.h"

#include <app/tests/suites/credentials/TestHarnessDACProvider.h>

class AppOptions
{
public:
static chip::ArgParser::OptionSet * GetOptions();
static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider();
static bool GetInteractiveMode();
static chip::Optional<uint16_t> GetInteractiveModePort();

Expand Down
2 changes: 0 additions & 2 deletions examples/placeholder/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
1 change: 1 addition & 0 deletions examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
16 changes: 15 additions & 1 deletion examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/SafeInt.h>

#include <app/tests/suites/credentials/TestHarnessDACProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>

#if ENABLE_TRACING
Expand Down Expand Up @@ -126,6 +127,7 @@ enum
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
kDeviceOption_WiFi_PAF,
#endif
kDeviceOption_DacProvider,
};

constexpr unsigned kAppUsageLength = 64;
Expand All @@ -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
Expand Down Expand Up @@ -201,6 +203,7 @@ OptionDef sDeviceOptionDefs[] = {
#if CHIP_WITH_NLFAULTINJECTION
{ "faults", kArgumentRequired, kDeviceOption_FaultInjection },
#endif
{ "dac_provider", kArgumentRequired, kDeviceOption_DacProvider },
{}
};

Expand Down Expand Up @@ -363,6 +366,8 @@ const char * sDeviceOptionHelp =
" --faults <fault-string,...>\n"
" Inject specified fault(s) at runtime.\n"
#endif
" --dac_provider <filepath>\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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -777,5 +790,6 @@ LinuxDeviceOptions & LinuxDeviceOptions::GetInstance()
{
gDeviceOptions.dacProvider = chip::Credentials::Examples::GetExampleDACProvider();
}

return gDeviceOptions;
}
1 change: 1 addition & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct LinuxDeviceOptions
chip::Optional<uint16_t> discriminator;
chip::Optional<std::vector<uint8_t>> spake2pVerifier;
chip::Optional<std::vector<uint8_t>> spake2pSalt;
chip::Optional<std::string> dacProviderFile;
uint32_t spake2pIterations = 0; // When not provided (0), will default elsewhere
uint32_t mBleDevice = 0;
bool wifiSupports5g = false;
Expand Down
8 changes: 7 additions & 1 deletion src/app/tests/suites/credentials/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Loading