Skip to content

Commit 2249628

Browse files
authored
Move the --dac_provider option from all clusters apps to common place. (project-chip#36886)
* Move the --dac_provider option from all clusters apps to common place. all-clusters-app and all-clusters-minimal-app has the --dac_provider option which lets us inject the custom dacs in the applications. moved this option from these apps to examples/platform/linux so that wide range of applications can levarage this. This would be useful in testing device attestation revocation cases. * fix the nuttx lighting-app build * fix the typo
1 parent 4865e5e commit 2249628

File tree

15 files changed

+29
-68
lines changed

15 files changed

+29
-68
lines changed

examples/all-clusters-app/linux/AppOptions.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ using chip::ArgParser::OptionDef;
2929
using chip::ArgParser::OptionSet;
3030
using chip::ArgParser::PrintArgError;
3131

32-
constexpr uint16_t kOptionDacProviderFilePath = 0xFF01;
3332
constexpr uint16_t kOptionMinCommissioningTimeout = 0xFF02;
3433
constexpr uint16_t kOptionEndUserSupportFilePath = 0xFF03;
3534
constexpr uint16_t kOptionNetworkDiagnosticsFilePath = 0xFF04;
3635
constexpr uint16_t kOptionCrashFilePath = 0xFF05;
3736

38-
static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider;
39-
4037
static chip::Optional<std::string> sEndUserSupportLogFilePath;
4138
static chip::Optional<std::string> sNetworkDiagnosticsLogFilePath;
4239
static chip::Optional<std::string> sCrashLogFilePath;
@@ -51,9 +48,6 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id
5148
bool retval = true;
5249
switch (identifier)
5350
{
54-
case kOptionDacProviderFilePath:
55-
mDacProvider.Init(value);
56-
break;
5751
case kOptionMinCommissioningTimeout: {
5852
auto & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager();
5953
commissionMgr.OverrideMinCommissioningTimeout(chip::System::Clock::Seconds16(static_cast<uint16_t>(atoi(value))));
@@ -92,7 +86,6 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id
9286
OptionSet * AppOptions::GetOptions()
9387
{
9488
static OptionDef optionsDef[] = {
95-
{ "dac_provider", kArgumentRequired, kOptionDacProviderFilePath },
9689
{ "min_commissioning_timeout", kArgumentRequired, kOptionMinCommissioningTimeout },
9790
{ "end_user_support_log", kArgumentRequired, kOptionEndUserSupportFilePath },
9891
{ "network_diagnostics_log", kArgumentRequired, kOptionNetworkDiagnosticsFilePath },
@@ -102,8 +95,6 @@ OptionSet * AppOptions::GetOptions()
10295

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

120-
chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider()
121-
{
122-
return &mDacProvider;
123-
}
124-
125111
chip::Optional<std::string> AppOptions::GetEndUserSupportLogFilePath()
126112
{
127113
return sEndUserSupportLogFilePath;

examples/all-clusters-app/linux/AppOptions.h

-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@
2020

2121
#include "AppMain.h"
2222

23-
#include <app/tests/suites/credentials/TestHarnessDACProvider.h>
24-
2523
#include <string>
2624

2725
class AppOptions
2826
{
2927
public:
3028
static chip::ArgParser::OptionSet * GetOptions();
31-
static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider();
3229
static chip::Optional<std::string> GetEndUserSupportLogFilePath();
3330
static chip::Optional<std::string> GetNetworkDiagnosticsLogFilePath();
3431
static chip::Optional<std::string> GetCrashLogFilePath();

examples/all-clusters-app/linux/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ source_set("chip-all-clusters-common") {
9393
"${chip_root}/examples/all-clusters-app/all-clusters-common",
9494
"${chip_root}/examples/platform/linux:app-main",
9595
"${chip_root}/src/app:attribute-persistence",
96-
"${chip_root}/src/app/tests/suites/credentials:dac_provider",
9796
"${chip_root}/src/lib",
9897
"${chip_root}/third_party/jsoncpp",
9998
]

examples/all-clusters-app/linux/main.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ int main(int argc, char * argv[])
3131
ChipLinuxAppInit(argc, argv, AppOptions::GetOptions(), chip::MakeOptional(kNetworkCommissioningEndpointSecondary)) == 0);
3232
VerifyOrDie(InitBindingHandlers() == CHIP_NO_ERROR);
3333

34-
LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider();
35-
3634
ChipLinuxAppMainLoop();
3735

3836
return 0;

examples/all-clusters-minimal-app/linux/AppOptions.cpp

-15
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,13 @@ using chip::ArgParser::OptionDef;
2525
using chip::ArgParser::OptionSet;
2626
using chip::ArgParser::PrintArgError;
2727

28-
constexpr uint16_t kOptionDacProviderFilePath = 0xFF01;
2928
constexpr uint16_t kOptionMinCommissioningTimeout = 0xFF02;
3029

31-
static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider;
32-
3330
bool AppOptions::HandleOptions(const char * program, OptionSet * options, int identifier, const char * name, const char * value)
3431
{
3532
bool retval = true;
3633
switch (identifier)
3734
{
38-
case kOptionDacProviderFilePath:
39-
mDacProvider.Init(value);
40-
break;
4135
case kOptionMinCommissioningTimeout: {
4236
auto & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager();
4337
commissionMgr.OverrideMinCommissioningTimeout(chip::System::Clock::Seconds16(static_cast<uint16_t>(atoi(value))));
@@ -55,23 +49,14 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id
5549
OptionSet * AppOptions::GetOptions()
5650
{
5751
static OptionDef optionsDef[] = {
58-
{ "dac_provider", chip::ArgParser::kArgumentRequired, kOptionDacProviderFilePath },
5952
{ "min_commissioning_timeout", chip::ArgParser::kArgumentRequired, kOptionMinCommissioningTimeout },
6053
{},
6154
};
6255

6356
static OptionSet options = {
6457
AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS",
65-
" --dac_provider <filepath>\n"
66-
" A json file with data used by the example dac provider to validate device attestation procedure.\n"
6758
" --min_commissioning_timeout <value>\n"
6859
" The minimum time in seconds during which commissioning session establishment is allowed by the Node.\n"
6960
};
70-
7161
return &options;
7262
}
73-
74-
chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider()
75-
{
76-
return &mDacProvider;
77-
}

examples/all-clusters-minimal-app/linux/AppOptions.h

-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020

2121
#include "AppMain.h"
2222

23-
#include <app/tests/suites/credentials/TestHarnessDACProvider.h>
24-
2523
class AppOptions
2624
{
2725
public:
2826
static chip::ArgParser::OptionSet * GetOptions();
29-
static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider();
3027

3128
private:
3229
static bool HandleOptions(const char * program, chip::ArgParser::OptionSet * options, int identifier, const char * name,

examples/all-clusters-minimal-app/linux/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ source_set("chip-all-clusters-common") {
3434
deps = [
3535
"${chip_root}/examples/all-clusters-minimal-app/all-clusters-common",
3636
"${chip_root}/examples/platform/linux:app-main",
37-
"${chip_root}/src/app/tests/suites/credentials:dac_provider",
3837
"${chip_root}/src/lib",
3938
]
4039

examples/all-clusters-minimal-app/linux/main.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ int main(int argc, char * argv[])
3131
ChipLinuxAppInit(argc, argv, AppOptions::GetOptions(), chip::MakeOptional(kNetworkCommissioningEndpointSecondary)) == 0);
3232
VerifyOrDie(InitBindingHandlers() == CHIP_NO_ERROR);
3333

34-
LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider();
35-
3634
ChipLinuxAppMainLoop();
3735
return 0;
3836
}

examples/placeholder/linux/AppOptions.cpp

+5-20
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ using chip::ArgParser::OptionDef;
2222
using chip::ArgParser::OptionSet;
2323
using chip::ArgParser::PrintArgError;
2424

25-
constexpr uint16_t kOptionDacProviderFilePath = 0xFF01;
2625
constexpr uint16_t kOptionInteractiveMode = 0xFF02;
2726
constexpr uint16_t kOptionInteractiveModePort = 0xFF03;
2827

29-
static chip::Credentials::Examples::TestHarnessDACProvider mDacProvider;
3028
static bool gInteractiveMode = false;
3129
static chip::Optional<uint16_t> gInteractiveModePort;
3230

@@ -35,9 +33,6 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id
3533
bool retval = true;
3634
switch (identifier)
3735
{
38-
case kOptionDacProviderFilePath:
39-
mDacProvider.Init(value);
40-
break;
4136
case kOptionInteractiveMode:
4237
gInteractiveMode = true;
4338
break;
@@ -56,30 +51,20 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id
5651
OptionSet * AppOptions::GetOptions()
5752
{
5853
static OptionDef optionsDef[] = {
59-
{ "dac_provider", chip::ArgParser::kArgumentRequired, kOptionDacProviderFilePath },
6054
{ "interactive", chip::ArgParser::kNoArgument, kOptionInteractiveMode },
6155
{ "port", chip::ArgParser::kArgumentRequired, kOptionInteractiveModePort },
6256
{},
6357
};
6458

65-
static OptionSet options = {
66-
AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS",
67-
" --dac_provider <filepath>\n"
68-
" A json file with data used by the example dac provider to validate device attestation procedure.\n"
69-
" --interactive\n"
70-
" Enable server interactive mode.\n"
71-
" --port <port>\n"
72-
" Specify the listening port for the server interactive mode.\n"
73-
};
59+
static OptionSet options = { AppOptions::HandleOptions, optionsDef, "PROGRAM OPTIONS",
60+
" --interactive\n"
61+
" Enable server interactive mode.\n"
62+
" --port <port>\n"
63+
" Specify the listening port for the server interactive mode.\n" };
7464

7565
return &options;
7666
}
7767

78-
chip::Credentials::DeviceAttestationCredentialsProvider * AppOptions::GetDACProvider()
79-
{
80-
return &mDacProvider;
81-
}
82-
8368
bool AppOptions::GetInteractiveMode()
8469
{
8570
return gInteractiveMode;

examples/placeholder/linux/AppOptions.h

-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020

2121
#include "AppMain.h"
2222

23-
#include <app/tests/suites/credentials/TestHarnessDACProvider.h>
24-
2523
class AppOptions
2624
{
2725
public:
2826
static chip::ArgParser::OptionSet * GetOptions();
29-
static chip::Credentials::DeviceAttestationCredentialsProvider * GetDACProvider();
3027
static bool GetInteractiveMode();
3128
static chip::Optional<uint16_t> GetInteractiveModePort();
3229

examples/placeholder/linux/main.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ int main(int argc, char * argv[])
6565
{
6666
VerifyOrDie(ChipLinuxAppInit(argc, argv, AppOptions::GetOptions()) == 0);
6767

68-
LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider();
69-
7068
auto & server = InteractiveServer::GetInstance();
7169
if (AppOptions::GetInteractiveMode())
7270
{

examples/platform/linux/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ source_set("app-main") {
102102
":ota-test-event-trigger",
103103
"${chip_root}/examples/providers:device_info_provider",
104104
"${chip_root}/src/app/server",
105+
"${chip_root}/src/app/tests/suites/credentials:dac_provider",
105106
]
106107

107108
if (current_os != "nuttx") {

examples/platform/linux/Options.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <lib/support/CodeUtils.h>
3535
#include <lib/support/SafeInt.h>
3636

37+
#include <app/tests/suites/credentials/TestHarnessDACProvider.h>
3738
#include <credentials/examples/DeviceAttestationCredsExample.h>
3839

3940
#if ENABLE_TRACING
@@ -126,6 +127,7 @@ enum
126127
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
127128
kDeviceOption_WiFi_PAF,
128129
#endif
130+
kDeviceOption_DacProvider,
129131
};
130132

131133
constexpr unsigned kAppUsageLength = 64;
@@ -140,7 +142,7 @@ OptionDef sDeviceOptionDefs[] = {
140142
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
141143
{ "wifipaf", kArgumentRequired, kDeviceOption_WiFi_PAF },
142144
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
143-
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
145+
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
144146
#if CHIP_ENABLE_OPENTHREAD
145147
{ "thread", kNoArgument, kDeviceOption_Thread },
146148
#endif // CHIP_ENABLE_OPENTHREAD
@@ -201,6 +203,7 @@ OptionDef sDeviceOptionDefs[] = {
201203
#if CHIP_WITH_NLFAULTINJECTION
202204
{ "faults", kArgumentRequired, kDeviceOption_FaultInjection },
203205
#endif
206+
{ "dac_provider", kArgumentRequired, kDeviceOption_DacProvider },
204207
{}
205208
};
206209

@@ -363,6 +366,8 @@ const char * sDeviceOptionHelp =
363366
" --faults <fault-string,...>\n"
364367
" Inject specified fault(s) at runtime.\n"
365368
#endif
369+
" --dac_provider <filepath>\n"
370+
" A json file with data used by the example dac provider to validate device attestation procedure.\n"
366371
"\n";
367372

368373
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
@@ -734,6 +739,14 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
734739
break;
735740
}
736741
#endif
742+
case kDeviceOption_DacProvider: {
743+
LinuxDeviceOptions::GetInstance().dacProviderFile.SetValue(aValue);
744+
static chip::Credentials::Examples::TestHarnessDACProvider testDacProvider;
745+
testDacProvider.Init(gDeviceOptions.dacProviderFile.Value().c_str());
746+
747+
LinuxDeviceOptions::GetInstance().dacProvider = &testDacProvider;
748+
break;
749+
}
737750
default:
738751
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", aProgram, aName);
739752
retval = false;
@@ -777,5 +790,6 @@ LinuxDeviceOptions & LinuxDeviceOptions::GetInstance()
777790
{
778791
gDeviceOptions.dacProvider = chip::Credentials::Examples::GetExampleDACProvider();
779792
}
793+
780794
return gDeviceOptions;
781795
}

examples/platform/linux/Options.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct LinuxDeviceOptions
4949
chip::Optional<uint16_t> discriminator;
5050
chip::Optional<std::vector<uint8_t>> spake2pVerifier;
5151
chip::Optional<std::vector<uint8_t>> spake2pSalt;
52+
chip::Optional<std::string> dacProviderFile;
5253
uint32_t spake2pIterations = 0; // When not provided (0), will default elsewhere
5354
uint32_t mBleDevice = 0;
5455
bool wifiSupports5g = false;

src/app/tests/suites/credentials/BUILD.gn

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ source_set("dac_provider") {
3030
"${chip_root}/src/credentials",
3131
"${chip_root}/src/crypto",
3232
"${chip_root}/src/lib",
33-
"${chip_root}/third_party/jsoncpp",
3433
]
3534

35+
# nuttx keeps a copy of jsoncpp, so don't add it as a dependency
36+
# when building for nuttx, otherwise the build will fail at link
37+
# time due to duplicate symbols
38+
if (current_os != "nuttx") {
39+
deps += [ "${chip_root}/third_party/jsoncpp" ]
40+
}
41+
3642
public_configs = [ ":default_config" ]
3743
}

0 commit comments

Comments
 (0)