Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit febc716

Browse files
committedAug 13, 2024·
Add AccessRestrictionList support
1 parent dc5bba7 commit febc716

27 files changed

+2180
-8
lines changed
 

‎examples/network-manager-app/linux/args.gni

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ chip_project_config_include_dirs = [
2222
]
2323

2424
chip_config_network_layer_ble = false
25+
chip_enable_access_restrictions = true

‎examples/network-manager-app/network-manager-common/network-manager-app.zap

+65-1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,24 @@
314314
"define": "ACCESS_CONTROL_CLUSTER",
315315
"side": "server",
316316
"enabled": 1,
317+
"commands": [
318+
{
319+
"name": "ReviewFabricRestrictions",
320+
"code": 0,
321+
"mfgCode": null,
322+
"source": "client",
323+
"isIncoming": 1,
324+
"isEnabled": 1
325+
},
326+
{
327+
"name": "ReviewFabricRestrictionsResponse",
328+
"code": 1,
329+
"mfgCode": null,
330+
"source": "server",
331+
"isIncoming": 0,
332+
"isEnabled": 1
333+
}
334+
],
317335
"attributes": [
318336
{
319337
"name": "ACL",
@@ -395,6 +413,38 @@
395413
"maxInterval": 65534,
396414
"reportableChange": 0
397415
},
416+
{
417+
"name": "CommissioningARL",
418+
"code": 5,
419+
"mfgCode": null,
420+
"side": "server",
421+
"type": "array",
422+
"included": 1,
423+
"storageOption": "External",
424+
"singleton": 0,
425+
"bounded": 0,
426+
"defaultValue": null,
427+
"reportable": 1,
428+
"minInterval": 1,
429+
"maxInterval": 65534,
430+
"reportableChange": 0
431+
},
432+
{
433+
"name": "ARL",
434+
"code": 6,
435+
"mfgCode": null,
436+
"side": "server",
437+
"type": "array",
438+
"included": 1,
439+
"storageOption": "External",
440+
"singleton": 0,
441+
"bounded": 0,
442+
"defaultValue": "",
443+
"reportable": 1,
444+
"minInterval": 1,
445+
"maxInterval": 65534,
446+
"reportableChange": 0
447+
},
398448
{
399449
"name": "GeneratedCommandList",
400450
"code": 65528,
@@ -453,7 +503,7 @@
453503
"storageOption": "RAM",
454504
"singleton": 0,
455505
"bounded": 0,
456-
"defaultValue": "0",
506+
"defaultValue": "1",
457507
"reportable": 1,
458508
"minInterval": 1,
459509
"maxInterval": 65534,
@@ -490,6 +540,20 @@
490540
"mfgCode": null,
491541
"side": "server",
492542
"included": 1
543+
},
544+
{
545+
"name": "AccessRestrictionEntryChanged",
546+
"code": 2,
547+
"mfgCode": null,
548+
"side": "server",
549+
"included": 1
550+
},
551+
{
552+
"name": "FabricRestrictionReviewUpdate",
553+
"code": 3,
554+
"mfgCode": null,
555+
"side": "server",
556+
"included": 1
493557
}
494558
]
495559
},

‎examples/platform/linux/AppMain.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
#include "AppMain.h"
104104
#include "CommissionableInit.h"
105105

106+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
107+
#include "ExampleAccessRestriction.h"
108+
#include <app/server/DefaultArlStorage.h>
109+
#endif
110+
106111
#if CHIP_DEVICE_LAYER_TARGET_DARWIN
107112
#include <platform/Darwin/NetworkCommissioningDriver.h>
108113
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
@@ -121,6 +126,7 @@ using namespace chip::DeviceLayer;
121126
using namespace chip::Inet;
122127
using namespace chip::Transport;
123128
using namespace chip::app::Clusters;
129+
using namespace chip::Access;
124130

125131
// Network comissioning implementation
126132
namespace {
@@ -593,6 +599,18 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
593599
chip::app::RuntimeOptionsProvider::Instance().SetSimulateNoInternalTime(
594600
LinuxDeviceOptions::GetInstance().mSimulateNoInternalTime);
595601

602+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
603+
if (LinuxDeviceOptions::GetInstance().accessRestrictionEntries.HasValue())
604+
{
605+
initParams.accessRestriction = new ExampleAccessRestriction();
606+
initParams.arlStorage = new app::DefaultArlStorage();
607+
for (const auto & entry : LinuxDeviceOptions::GetInstance().accessRestrictionEntries.Value())
608+
{
609+
VerifyOrDie(AccessRestriction::CreateCommissioningEntry(entry) == CHIP_NO_ERROR);
610+
}
611+
}
612+
#endif
613+
596614
// Init ZCL Data Model and CHIP App Server
597615
Server::GetInstance().Init(initParams);
598616

‎examples/platform/linux/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import("//build_overrides/chip.gni")
16+
import("//build_overrides/jsoncpp.gni")
1617
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
1718
import("${chip_root}/src/app/common_flags.gni")
1819
import("${chip_root}/src/lib/core/core.gni")
@@ -94,6 +95,7 @@ source_set("app-main") {
9495
"${chip_root}/src/controller:gen_check_chip_controller_headers",
9596
"${chip_root}/src/lib",
9697
"${chip_root}/src/platform/logging:default",
98+
jsoncpp_root,
9799
]
98100
deps = [
99101
":ota-test-event-trigger",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/*
20+
* AccessRestriction implementation for Linux examples.
21+
*/
22+
23+
#pragma once
24+
25+
#include <access/AccessRestriction.h>
26+
#include <app-common/zap-generated/cluster-objects.h>
27+
#include <app/EventLogging.h>
28+
29+
namespace chip {
30+
namespace Access {
31+
32+
class ExampleAccessRestriction : public AccessRestriction
33+
{
34+
public:
35+
ExampleAccessRestriction() : AccessRestriction() {}
36+
37+
~ExampleAccessRestriction() {}
38+
39+
protected:
40+
CHIP_ERROR DoRequestFabricRestrictionReview(const FabricIndex fabricIndex, uint64_t token, const std::vector<Entry> & arl)
41+
{
42+
// this example simply removes all restrictions and will generate AccessRestrictionEntryChanged events
43+
while (Access::GetAccessControl().GetAccessRestriction()->DeleteEntry(0, fabricIndex) == CHIP_NO_ERROR)
44+
;
45+
46+
chip::app::Clusters::AccessControl::Events::FabricRestrictionReviewUpdate::Type event{ .fabricIndex = fabricIndex };
47+
EventNumber eventNumber;
48+
ReturnErrorOnFailure(chip::app::LogEvent(event, 0, eventNumber));
49+
50+
return CHIP_NO_ERROR;
51+
}
52+
};
53+
54+
} // namespace Access
55+
} // namespace chip

‎examples/platform/linux/Options.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <app/server/OnboardingCodesUtil.h>
2727

2828
#include <crypto/CHIPCryptoPAL.h>
29+
#include <json/json.h>
2930
#include <lib/core/CHIPError.h>
3031
#include <lib/support/Base64.h>
3132
#include <lib/support/BytesToHex.h>
@@ -47,6 +48,11 @@
4748

4849
using namespace chip;
4950
using namespace chip::ArgParser;
51+
using namespace chip::Platform;
52+
53+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
54+
using namespace chip::Access;
55+
#endif
5056

5157
namespace {
5258
LinuxDeviceOptions gDeviceOptions;
@@ -82,6 +88,9 @@ enum
8288
kDeviceOption_TraceFile,
8389
kDeviceOption_TraceLog,
8490
kDeviceOption_TraceDecode,
91+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
92+
kDeviceOption_UseAccessRestrictions,
93+
#endif
8594
kOptionCSRResponseCSRIncorrectType,
8695
kOptionCSRResponseCSRNonceIncorrectType,
8796
kOptionCSRResponseCSRNonceTooLong,
@@ -154,6 +163,9 @@ OptionDef sDeviceOptionDefs[] = {
154163
{ "trace_log", kArgumentRequired, kDeviceOption_TraceLog },
155164
{ "trace_decode", kArgumentRequired, kDeviceOption_TraceDecode },
156165
#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
157169
{ "cert_error_csr_incorrect_type", kNoArgument, kOptionCSRResponseCSRIncorrectType },
158170
{ "cert_error_csr_existing_keypair", kNoArgument, kOptionCSRResponseCSRExistingKeyPair },
159171
{ "cert_error_csr_nonce_incorrect_type", kNoArgument, kOptionCSRResponseCSRNonceIncorrectType },
@@ -280,6 +292,11 @@ const char * sDeviceOptionHelp =
280292
" --trace_decode <1/0>\n"
281293
" A value of 1 enables traces decoding, 0 disables this (default 0).\n"
282294
#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
295+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
296+
" --enable-access-restrictions <CommissioningARL JSON>\n"
297+
" Enable ACL cluster access restrictions with the provided JSON CommissioningARL. Example:\n"
298+
" \"[{\\\"endpoint\\\": 1,\\\"cluster\\\": 2,\\\"restrictions\\\": [{\\\"type\\\": 0,\\\"id\\\": 3}]}]\"\n"
299+
#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
283300
" --cert_error_csr_incorrect_type\n"
284301
" Configure the CSRResponse to be built with an invalid CSR type.\n"
285302
" --cert_error_csr_existing_keypair\n"
@@ -320,6 +337,40 @@ const char * sDeviceOptionHelp =
320337
#endif
321338
"\n";
322339

340+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
341+
bool ParseAccessRestrictionEntriesFromJson(const char * jsonString,
342+
std::vector<Platform::SharedPtr<AccessRestriction::Entry>> & entries)
343+
{
344+
Json::Value root;
345+
Json::Reader reader;
346+
VerifyOrReturnValue(reader.parse(jsonString, root), false);
347+
348+
for (Json::Value::const_iterator eIt = root.begin(); eIt != root.end(); eIt++)
349+
{
350+
auto entry = MakeShared<AccessRestriction::Entry>();
351+
352+
entry->endpointNumber = static_cast<EndpointId>((*eIt)["endpoint"].asUInt());
353+
entry->clusterId = static_cast<ClusterId>((*eIt)["cluster"].asUInt());
354+
355+
Json::Value restrictions = (*eIt)["restrictions"];
356+
for (Json::Value::const_iterator rIt = restrictions.begin(); rIt != restrictions.end(); rIt++)
357+
{
358+
AccessRestriction::Restriction restriction;
359+
restriction.restrictionType = static_cast<AccessRestriction::Type>((*rIt)["type"].asInt());
360+
if ((*rIt).isMember("id"))
361+
{
362+
restriction.id.SetValue((*rIt)["id"].asUInt());
363+
}
364+
entry->restrictions.push_back(restriction);
365+
}
366+
367+
entries.push_back(entry);
368+
}
369+
370+
return true;
371+
}
372+
#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
373+
323374
bool Base64ArgToVector(const char * arg, size_t maxSize, std::vector<uint8_t> & outVector)
324375
{
325376
size_t maxBase64Size = BASE64_ENCODED_LEN(maxSize);
@@ -529,6 +580,18 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
529580
break;
530581
#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
531582

583+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
584+
case kDeviceOption_UseAccessRestrictions: {
585+
std::vector<Platform::SharedPtr<AccessRestriction::Entry>> accessRestrictionEntries;
586+
retval = ParseAccessRestrictionEntriesFromJson(aValue, accessRestrictionEntries);
587+
if (retval)
588+
{
589+
LinuxDeviceOptions::GetInstance().accessRestrictionEntries.SetValue(std::move(accessRestrictionEntries));
590+
}
591+
}
592+
break;
593+
#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
594+
532595
case kOptionCSRResponseCSRIncorrectType:
533596
LinuxDeviceOptions::GetInstance().mCSRResponseOptions.csrIncorrectType = true;
534597
break;

‎examples/platform/linux/Options.h

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <string>
2929
#include <vector>
3030

31+
#include <access/AccessConfig.h>
3132
#include <inet/InetInterface.h>
3233
#include <lib/core/CHIPError.h>
3334
#include <lib/core/Optional.h>
@@ -38,6 +39,10 @@
3839
#include <credentials/DeviceAttestationCredsProvider.h>
3940
#include <testing/CustomCSRResponse.h>
4041

42+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
43+
#include <access/AccessRestriction.h>
44+
#endif
45+
4146
struct LinuxDeviceOptions
4247
{
4348
chip::PayloadContents payload;
@@ -81,6 +86,9 @@ struct LinuxDeviceOptions
8186
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
8287
int32_t subscriptionCapacity = CHIP_IM_MAX_NUM_SUBSCRIPTIONS;
8388
int32_t subscriptionResumptionRetryIntervalSec = -1;
89+
#endif
90+
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
91+
chip::Optional<std::vector<chip::Platform::SharedPtr<chip::Access::AccessRestriction::Entry>>> accessRestrictionEntries;
8492
#endif
8593
static LinuxDeviceOptions & GetInstance();
8694
};

‎scripts/tools/check_includes_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,5 @@
185185
'src/app/icd/client/DefaultICDStorageKey.h': {'vector'},
186186
'src/controller/CHIPDeviceController.cpp': {'string'},
187187
'src/qrcodetool/setup_payload_commands.cpp': {'string'},
188+
'src/access/AccessRestriction.h': {'vector', 'map'},
188189
}

‎src/access/AccessConfig.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
*
3+
* Copyright (c) 2020-2024 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#pragma once
19+
20+
#if CHIP_HAVE_CONFIG_H
21+
#include <access/AccessBuildConfig.h>
22+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.