|
26 | 26 | #include <app/server/OnboardingCodesUtil.h>
|
27 | 27 |
|
28 | 28 | #include <crypto/CHIPCryptoPAL.h>
|
| 29 | +#include <json/json.h> |
29 | 30 | #include <lib/core/CHIPError.h>
|
30 | 31 | #include <lib/support/Base64.h>
|
31 | 32 | #include <lib/support/BytesToHex.h>
|
|
47 | 48 |
|
48 | 49 | using namespace chip;
|
49 | 50 | using namespace chip::ArgParser;
|
| 51 | +using namespace chip::Platform; |
| 52 | + |
| 53 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 54 | +using namespace chip::Access; |
| 55 | +#endif |
50 | 56 |
|
51 | 57 | namespace {
|
52 | 58 | LinuxDeviceOptions gDeviceOptions;
|
|
82 | 88 | kDeviceOption_TraceFile,
|
83 | 89 | kDeviceOption_TraceLog,
|
84 | 90 | kDeviceOption_TraceDecode,
|
| 91 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 92 | + kDeviceOption_CommissioningArlEntries, |
| 93 | + kDeviceOption_ArlEntries, |
| 94 | +#endif |
85 | 95 | kOptionCSRResponseCSRIncorrectType,
|
86 | 96 | kOptionCSRResponseCSRNonceIncorrectType,
|
87 | 97 | kOptionCSRResponseCSRNonceTooLong,
|
@@ -154,6 +164,10 @@ OptionDef sDeviceOptionDefs[] = {
|
154 | 164 | { "trace_log", kArgumentRequired, kDeviceOption_TraceLog },
|
155 | 165 | { "trace_decode", kArgumentRequired, kDeviceOption_TraceDecode },
|
156 | 166 | #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
|
| 167 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 168 | + { "commissioning-arl-entries", kArgumentRequired, kDeviceOption_CommissioningArlEntries }, |
| 169 | + { "arl-entries", kArgumentRequired, kDeviceOption_ArlEntries }, |
| 170 | +#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
157 | 171 | { "cert_error_csr_incorrect_type", kNoArgument, kOptionCSRResponseCSRIncorrectType },
|
158 | 172 | { "cert_error_csr_existing_keypair", kNoArgument, kOptionCSRResponseCSRExistingKeyPair },
|
159 | 173 | { "cert_error_csr_nonce_incorrect_type", kNoArgument, kOptionCSRResponseCSRNonceIncorrectType },
|
@@ -280,6 +294,14 @@ const char * sDeviceOptionHelp =
|
280 | 294 | " --trace_decode <1/0>\n"
|
281 | 295 | " A value of 1 enables traces decoding, 0 disables this (default 0).\n"
|
282 | 296 | #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
|
| 297 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 298 | + " --commissioning-arl-entries <CommissioningARL JSON>\n" |
| 299 | + " Enable ACL cluster access restrictions used during commissioning with the provided JSON. Example:\n" |
| 300 | + " \"[{\\\"endpoint\\\": 1,\\\"cluster\\\": 1105,\\\"restrictions\\\": [{\\\"type\\\": 0,\\\"id\\\": 0}]}]\"\n" |
| 301 | + " --arl-entries <ARL JSON>\n" |
| 302 | + " Enable ACL cluster access restrictions applied to fabric index 1 with the provided JSON. Example:\n" |
| 303 | + " \"[{\\\"endpoint\\\": 1,\\\"cluster\\\": 1105,\\\"restrictions\\\": [{\\\"type\\\": 0,\\\"id\\\": 0}]}]\"\n" |
| 304 | +#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
283 | 305 | " --cert_error_csr_incorrect_type\n"
|
284 | 306 | " Configure the CSRResponse to be built with an invalid CSR type.\n"
|
285 | 307 | " --cert_error_csr_existing_keypair\n"
|
@@ -320,6 +342,39 @@ const char * sDeviceOptionHelp =
|
320 | 342 | #endif
|
321 | 343 | "\n";
|
322 | 344 |
|
| 345 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 346 | +bool ParseAccessRestrictionEntriesFromJson(const char * jsonString, std::vector<AccessRestrictionProvider::Entry> & entries) |
| 347 | +{ |
| 348 | + Json::Value root; |
| 349 | + Json::Reader reader; |
| 350 | + VerifyOrReturnValue(reader.parse(jsonString, root), false); |
| 351 | + |
| 352 | + for (Json::Value::const_iterator eIt = root.begin(); eIt != root.end(); eIt++) |
| 353 | + { |
| 354 | + AccessRestrictionProvider::Entry entry; |
| 355 | + |
| 356 | + entry.endpointNumber = static_cast<EndpointId>((*eIt)["endpoint"].asUInt()); |
| 357 | + entry.clusterId = static_cast<ClusterId>((*eIt)["cluster"].asUInt()); |
| 358 | + |
| 359 | + Json::Value restrictions = (*eIt)["restrictions"]; |
| 360 | + for (Json::Value::const_iterator rIt = restrictions.begin(); rIt != restrictions.end(); rIt++) |
| 361 | + { |
| 362 | + AccessRestrictionProvider::Restriction restriction; |
| 363 | + restriction.restrictionType = static_cast<AccessRestrictionProvider::Type>((*rIt)["type"].asUInt()); |
| 364 | + if ((*rIt).isMember("id")) |
| 365 | + { |
| 366 | + restriction.id.SetValue((*rIt)["id"].asUInt()); |
| 367 | + } |
| 368 | + entry.restrictions.push_back(restriction); |
| 369 | + } |
| 370 | + |
| 371 | + entries.push_back(entry); |
| 372 | + } |
| 373 | + |
| 374 | + return true; |
| 375 | +} |
| 376 | +#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 377 | + |
323 | 378 | bool Base64ArgToVector(const char * arg, size_t maxSize, std::vector<uint8_t> & outVector)
|
324 | 379 | {
|
325 | 380 | size_t maxBase64Size = BASE64_ENCODED_LEN(maxSize);
|
@@ -529,6 +584,28 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
|
529 | 584 | break;
|
530 | 585 | #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
|
531 | 586 |
|
| 587 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 588 | + // TODO(#35189): change to use a path to JSON files instead |
| 589 | + case kDeviceOption_CommissioningArlEntries: { |
| 590 | + std::vector<AccessRestrictionProvider::Entry> entries; |
| 591 | + retval = ParseAccessRestrictionEntriesFromJson(aValue, entries); |
| 592 | + if (retval) |
| 593 | + { |
| 594 | + LinuxDeviceOptions::GetInstance().commissioningArlEntries.SetValue(std::move(entries)); |
| 595 | + } |
| 596 | + } |
| 597 | + break; |
| 598 | + case kDeviceOption_ArlEntries: { |
| 599 | + std::vector<AccessRestrictionProvider::Entry> entries; |
| 600 | + retval = ParseAccessRestrictionEntriesFromJson(aValue, entries); |
| 601 | + if (retval) |
| 602 | + { |
| 603 | + LinuxDeviceOptions::GetInstance().arlEntries.SetValue(std::move(entries)); |
| 604 | + } |
| 605 | + } |
| 606 | + break; |
| 607 | +#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 608 | + |
532 | 609 | case kOptionCSRResponseCSRIncorrectType:
|
533 | 610 | LinuxDeviceOptions::GetInstance().mCSRResponseOptions.csrIncorrectType = true;
|
534 | 611 | break;
|
|
0 commit comments