|
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_UseAccessRestrictions, |
| 93 | +#endif |
85 | 94 | kOptionCSRResponseCSRIncorrectType,
|
86 | 95 | kOptionCSRResponseCSRNonceIncorrectType,
|
87 | 96 | kOptionCSRResponseCSRNonceTooLong,
|
@@ -154,6 +163,9 @@ OptionDef sDeviceOptionDefs[] = {
|
154 | 163 | { "trace_log", kArgumentRequired, kDeviceOption_TraceLog },
|
155 | 164 | { "trace_decode", kArgumentRequired, kDeviceOption_TraceDecode },
|
156 | 165 | #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
|
| 166 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 167 | + { "enable-access-restrictions", kArgumentRequired, kDeviceOption_UseAccessRestrictions }, |
| 168 | +#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
157 | 169 | { "cert_error_csr_incorrect_type", kNoArgument, kOptionCSRResponseCSRIncorrectType },
|
158 | 170 | { "cert_error_csr_existing_keypair", kNoArgument, kOptionCSRResponseCSRExistingKeyPair },
|
159 | 171 | { "cert_error_csr_nonce_incorrect_type", kNoArgument, kOptionCSRResponseCSRNonceIncorrectType },
|
@@ -280,6 +292,9 @@ const char * sDeviceOptionHelp =
|
280 | 292 | " --trace_decode <1/0>\n"
|
281 | 293 | " A value of 1 enables traces decoding, 0 disables this (default 0).\n"
|
282 | 294 | #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
|
| 295 | + " --enable-access-restrictions <CommissioningARL JSON>\n" |
| 296 | + " Enable ACL cluster access restrictions with the provided JSON CommissioningARL. Example:\n" |
| 297 | + " \"[{\\\"endpoint\\\": 1,\\\"cluster\\\": 2,\\\"restrictions\\\": [{\\\"type\\\": 0,\\\"id\\\": 3}]}]\"\n" |
283 | 298 | " --cert_error_csr_incorrect_type\n"
|
284 | 299 | " Configure the CSRResponse to be built with an invalid CSR type.\n"
|
285 | 300 | " --cert_error_csr_existing_keypair\n"
|
@@ -320,6 +335,39 @@ const char * sDeviceOptionHelp =
|
320 | 335 | #endif
|
321 | 336 | "\n";
|
322 | 337 |
|
| 338 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 339 | +bool ParseAccessRestrictionEntriesFromJson(const char * jsonString, std::vector<SharedPtr<AccessRestriction::Entry>> & entries) |
| 340 | +{ |
| 341 | + Json::Value root; |
| 342 | + Json::Reader reader; |
| 343 | + VerifyOrReturnValue(reader.parse(jsonString, root), false); |
| 344 | + |
| 345 | + for (Json::Value::const_iterator eIt = root.begin(); eIt != root.end(); eIt++) |
| 346 | + { |
| 347 | + auto entry = MakeShared<AccessRestriction::Entry>(); |
| 348 | + |
| 349 | + entry->endpointNumber = (*eIt)["endpoint"].asInt(); |
| 350 | + entry->clusterId = (*eIt)["cluster"].asInt(); |
| 351 | + |
| 352 | + Json::Value restrictions = (*eIt)["restrictions"]; |
| 353 | + for (Json::Value::const_iterator rIt = restrictions.begin(); rIt != restrictions.end(); rIt++) |
| 354 | + { |
| 355 | + AccessRestriction::Restriction restriction; |
| 356 | + restriction.restrictionType = static_cast<AccessRestriction::Type>((*rIt)["type"].asInt()); |
| 357 | + if ((*rIt).isMember("id")) |
| 358 | + { |
| 359 | + restriction.id.SetValue((*rIt)["id"].asInt()); |
| 360 | + } |
| 361 | + entry->restrictions.push_back(restriction); |
| 362 | + } |
| 363 | + |
| 364 | + entries.push_back(entry); |
| 365 | + } |
| 366 | + |
| 367 | + return true; |
| 368 | +} |
| 369 | +#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 370 | + |
323 | 371 | bool Base64ArgToVector(const char * arg, size_t maxSize, std::vector<uint8_t> & outVector)
|
324 | 372 | {
|
325 | 373 | size_t maxBase64Size = BASE64_ENCODED_LEN(maxSize);
|
@@ -529,6 +577,18 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
|
529 | 577 | break;
|
530 | 578 | #endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
|
531 | 579 |
|
| 580 | +#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 581 | + case kDeviceOption_UseAccessRestrictions: { |
| 582 | + std::vector<SharedPtr<AccessRestriction::Entry>> accessRestrictionEntries; |
| 583 | + retval = ParseAccessRestrictionEntriesFromJson(aValue, accessRestrictionEntries); |
| 584 | + if (retval) |
| 585 | + { |
| 586 | + LinuxDeviceOptions::GetInstance().accessRestrictionEntries.SetValue(std::move(accessRestrictionEntries)); |
| 587 | + } |
| 588 | + } |
| 589 | + break; |
| 590 | +#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS |
| 591 | + |
532 | 592 | case kOptionCSRResponseCSRIncorrectType:
|
533 | 593 | LinuxDeviceOptions::GetInstance().mCSRResponseOptions.csrIncorrectType = true;
|
534 | 594 | break;
|
|
0 commit comments