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

Managed ACL: Add AccessRestrictionList support #34932

Merged
merged 28 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c2fdd06
Add AccessRestrictionList support
tleacmcsa Jul 30, 2024
20f0b6a
Update src/access/AccessConfig.h
tleacmcsa Aug 19, 2024
04651f9
Reworked data manipulators and other cleanup
tleacmcsa Aug 20, 2024
03ea9d0
Fixed encode/decode so reading CommissioningARL and Arl attributes work
tleacmcsa Aug 21, 2024
cbff3b5
Merge branch 'project-chip:master' into arl-feature
tleacmcsa Aug 21, 2024
5a161e7
Reworked ARL storage
tleacmcsa Aug 22, 2024
459bee4
Review fixes
tleacmcsa Aug 22, 2024
d0928e7
Fixed GetEntries vector pointer arg
tleacmcsa Aug 22, 2024
dcc85c7
Updated core restriction logic/integration
tleacmcsa Aug 22, 2024
a3d1300
Restyled by clang-format
restyled-commits Aug 22, 2024
81effc2
fixed include check for renamed AccessRestrictionProvider.h file
tleacmcsa Aug 22, 2024
1c34d96
M-ACL updates
tleacmcsa Aug 23, 2024
d46ab30
Merge branch 'project-chip:master' into arl-feature
tleacmcsa Aug 23, 2024
9809516
Add plumbing for subject descriptor IsCommissioning field
tcarmelveilleux Aug 23, 2024
8ac75f8
Fix crash
tcarmelveilleux Aug 23, 2024
b151a0f
Use new IsCommissioning in ARL check
tleacmcsa Aug 23, 2024
1d463a0
Updates for review comments
tleacmcsa Aug 25, 2024
92bec3f
Merge remote-tracking branch 'upstream/master' into arl-feature
tleacmcsa Aug 25, 2024
b1ae8e3
restyled
tleacmcsa Aug 25, 2024
7cf925c
Review updates
tleacmcsa Aug 26, 2024
9dc45e8
Merge remote-tracking branch 'upstream/master' into arl-feature
tleacmcsa Aug 26, 2024
d27dfb6
restyled
tleacmcsa Aug 26, 2024
91d4f19
Merge remote-tracking branch 'upstream/master' into arl-feature
tleacmcsa Aug 26, 2024
cbcd55a
Updated ARL tests per review comments
tleacmcsa Aug 26, 2024
25bd650
work around nuttx and jsoncpp contention
tleacmcsa Aug 27, 2024
31a7ddd
Merge branch 'master' into arl-feature
tleacmcsa Aug 27, 2024
141c555
Review comments and nuttx build failure fix attempt
tleacmcsa Aug 27, 2024
3d976bf
review updates
tleacmcsa Aug 27, 2024
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
1 change: 1 addition & 0 deletions examples/network-manager-app/linux/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ chip_project_config_include_dirs = [
]

chip_config_network_layer_ble = false
chip_enable_access_restrictions = true
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -1623,16 +1623,23 @@ endpoint 0 {
server cluster AccessControl {
emits event AccessControlEntryChanged;
emits event AccessControlExtensionChanged;
emits event AccessRestrictionEntryChanged;
emits event FabricRestrictionReviewUpdate;
callback attribute acl;
callback attribute extension;
callback attribute subjectsPerAccessControlEntry;
callback attribute targetsPerAccessControlEntry;
callback attribute accessControlEntriesPerFabric;
callback attribute commissioningARL;
callback attribute arl;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute attributeList;
ram attribute featureMap default = 0;
ram attribute featureMap default = 1;
callback attribute clusterRevision;

handle command ReviewFabricRestrictions;
handle command ReviewFabricRestrictionsResponse;
}

server cluster BasicInformation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,24 @@
"define": "ACCESS_CONTROL_CLUSTER",
"side": "server",
"enabled": 1,
"commands": [
{
"name": "ReviewFabricRestrictions",
"code": 0,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "ReviewFabricRestrictionsResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
{
"name": "ACL",
Expand Down Expand Up @@ -395,6 +413,38 @@
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "CommissioningARL",
"code": 5,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": null,
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ARL",
"code": 6,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down Expand Up @@ -453,7 +503,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"defaultValue": "1",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
Expand Down Expand Up @@ -490,6 +540,20 @@
"mfgCode": null,
"side": "server",
"included": 1
},
{
"name": "AccessRestrictionEntryChanged",
"code": 2,
"mfgCode": null,
"side": "server",
"included": 1
},
{
"name": "FabricRestrictionReviewUpdate",
"code": 3,
"mfgCode": null,
"side": "server",
"included": 1
}
]
},
Expand Down
18 changes: 18 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
#include "AppMain.h"
#include "CommissionableInit.h"

#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
#include "ExampleAccessRestriction.h"
#include <app/server/DefaultArlStorage.h>
#endif

#if CHIP_DEVICE_LAYER_TARGET_DARWIN
#include <platform/Darwin/NetworkCommissioningDriver.h>
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
Expand All @@ -121,6 +126,7 @@ using namespace chip::DeviceLayer;
using namespace chip::Inet;
using namespace chip::Transport;
using namespace chip::app::Clusters;
using namespace chip::Access;

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

#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
if (LinuxDeviceOptions::GetInstance().accessRestrictionEntries.HasValue())
{
initParams.accessRestriction = new ExampleAccessRestriction();
initParams.arlStorage = new app::DefaultArlStorage();
for (const auto & entry : LinuxDeviceOptions::GetInstance().accessRestrictionEntries.Value())
{
VerifyOrDie(AccessRestriction::CreateCommissioningEntry(entry) == CHIP_NO_ERROR);
}
}
#endif

// Init ZCL Data Model and CHIP App Server
Server::GetInstance().Init(initParams);

Expand Down
2 changes: 2 additions & 0 deletions examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import("//build_overrides/chip.gni")
import("//build_overrides/jsoncpp.gni")
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
import("${chip_root}/src/app/common_flags.gni")
import("${chip_root}/src/lib/core/core.gni")
Expand Down Expand Up @@ -94,6 +95,7 @@ source_set("app-main") {
"${chip_root}/src/controller:gen_check_chip_controller_headers",
"${chip_root}/src/lib",
"${chip_root}/src/platform/logging:default",
jsoncpp_root,
]
deps = [
":ota-test-event-trigger",
Expand Down
55 changes: 55 additions & 0 deletions examples/platform/linux/ExampleAccessRestriction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* AccessRestriction implementation for Linux examples.
*/

#pragma once

#include <access/AccessRestriction.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app/EventLogging.h>

namespace chip {
namespace Access {

class ExampleAccessRestriction : public AccessRestriction
{
public:
ExampleAccessRestriction() : AccessRestriction() {}

~ExampleAccessRestriction() {}

protected:
CHIP_ERROR DoRequestFabricRestrictionReview(const FabricIndex fabricIndex, uint64_t token, const std::vector<Entry> & arl)
{
// this example simply removes all restrictions and will generate AccessRestrictionEntryChanged events
while (Access::GetAccessControl().GetAccessRestriction()->DeleteEntry(0, fabricIndex) == CHIP_NO_ERROR)
;

chip::app::Clusters::AccessControl::Events::FabricRestrictionReviewUpdate::Type event{ .fabricIndex = fabricIndex };
EventNumber eventNumber;
ReturnErrorOnFailure(chip::app::LogEvent(event, 0, eventNumber));

return CHIP_NO_ERROR;
}
};

} // namespace Access
} // namespace chip
63 changes: 63 additions & 0 deletions examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <app/server/OnboardingCodesUtil.h>

#include <crypto/CHIPCryptoPAL.h>
#include <json/json.h>
#include <lib/core/CHIPError.h>
#include <lib/support/Base64.h>
#include <lib/support/BytesToHex.h>
Expand All @@ -47,6 +48,11 @@

using namespace chip;
using namespace chip::ArgParser;
using namespace chip::Platform;

#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
using namespace chip::Access;
#endif

namespace {
LinuxDeviceOptions gDeviceOptions;
Expand Down Expand Up @@ -82,6 +88,9 @@ enum
kDeviceOption_TraceFile,
kDeviceOption_TraceLog,
kDeviceOption_TraceDecode,
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
kDeviceOption_UseAccessRestrictions,
#endif
kOptionCSRResponseCSRIncorrectType,
kOptionCSRResponseCSRNonceIncorrectType,
kOptionCSRResponseCSRNonceTooLong,
Expand Down Expand Up @@ -154,6 +163,9 @@ OptionDef sDeviceOptionDefs[] = {
{ "trace_log", kArgumentRequired, kDeviceOption_TraceLog },
{ "trace_decode", kArgumentRequired, kDeviceOption_TraceDecode },
#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
{ "enable-access-restrictions", kArgumentRequired, kDeviceOption_UseAccessRestrictions },
#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
{ "cert_error_csr_incorrect_type", kNoArgument, kOptionCSRResponseCSRIncorrectType },
{ "cert_error_csr_existing_keypair", kNoArgument, kOptionCSRResponseCSRExistingKeyPair },
{ "cert_error_csr_nonce_incorrect_type", kNoArgument, kOptionCSRResponseCSRNonceIncorrectType },
Expand Down Expand Up @@ -280,6 +292,11 @@ const char * sDeviceOptionHelp =
" --trace_decode <1/0>\n"
" A value of 1 enables traces decoding, 0 disables this (default 0).\n"
#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
" --enable-access-restrictions <CommissioningARL JSON>\n"
" Enable ACL cluster access restrictions with the provided JSON CommissioningARL. Example:\n"
" \"[{\\\"endpoint\\\": 1,\\\"cluster\\\": 2,\\\"restrictions\\\": [{\\\"type\\\": 0,\\\"id\\\": 3}]}]\"\n"
tleacmcsa marked this conversation as resolved.
Show resolved Hide resolved
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
" --cert_error_csr_incorrect_type\n"
" Configure the CSRResponse to be built with an invalid CSR type.\n"
" --cert_error_csr_existing_keypair\n"
Expand Down Expand Up @@ -320,6 +337,40 @@ const char * sDeviceOptionHelp =
#endif
"\n";

#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
bool ParseAccessRestrictionEntriesFromJson(const char * jsonString,
std::vector<Platform::SharedPtr<AccessRestriction::Entry>> & entries)
{
Json::Value root;
Json::Reader reader;
VerifyOrReturnValue(reader.parse(jsonString, root), false);

for (Json::Value::const_iterator eIt = root.begin(); eIt != root.end(); eIt++)
{
auto entry = MakeShared<AccessRestriction::Entry>();

entry->endpointNumber = static_cast<EndpointId>((*eIt)["endpoint"].asUInt());
entry->clusterId = static_cast<ClusterId>((*eIt)["cluster"].asUInt());

Json::Value restrictions = (*eIt)["restrictions"];
for (Json::Value::const_iterator rIt = restrictions.begin(); rIt != restrictions.end(); rIt++)
{
AccessRestriction::Restriction restriction;
restriction.restrictionType = static_cast<AccessRestriction::Type>((*rIt)["type"].asInt());
if ((*rIt).isMember("id"))
{
restriction.id.SetValue((*rIt)["id"].asUInt());
}
entry->restrictions.push_back(restriction);
}

entries.push_back(entry);
}

return true;
}
#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS

bool Base64ArgToVector(const char * arg, size_t maxSize, std::vector<uint8_t> & outVector)
{
size_t maxBase64Size = BASE64_ENCODED_LEN(maxSize);
Expand Down Expand Up @@ -529,6 +580,18 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
break;
#endif // CHIP_CONFIG_TRANSPORT_TRACE_ENABLED

#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
case kDeviceOption_UseAccessRestrictions: {
std::vector<Platform::SharedPtr<AccessRestriction::Entry>> accessRestrictionEntries;
retval = ParseAccessRestrictionEntriesFromJson(aValue, accessRestrictionEntries);
if (retval)
{
LinuxDeviceOptions::GetInstance().accessRestrictionEntries.SetValue(std::move(accessRestrictionEntries));
}
}
break;
#endif // CHIP_CONFIG_USE_ACCESS_RESTRICTIONS

case kOptionCSRResponseCSRIncorrectType:
LinuxDeviceOptions::GetInstance().mCSRResponseOptions.csrIncorrectType = true;
break;
Expand Down
8 changes: 8 additions & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string>
#include <vector>

#include <access/AccessConfig.h>
#include <inet/InetInterface.h>
#include <lib/core/CHIPError.h>
#include <lib/core/Optional.h>
Expand All @@ -38,6 +39,10 @@
#include <credentials/DeviceAttestationCredsProvider.h>
#include <testing/CustomCSRResponse.h>

#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
#include <access/AccessRestriction.h>
#endif

struct LinuxDeviceOptions
{
chip::PayloadContents payload;
Expand Down Expand Up @@ -81,6 +86,9 @@ struct LinuxDeviceOptions
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
int32_t subscriptionCapacity = CHIP_IM_MAX_NUM_SUBSCRIPTIONS;
int32_t subscriptionResumptionRetryIntervalSec = -1;
#endif
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
chip::Optional<std::vector<chip::Platform::SharedPtr<chip::Access::AccessRestriction::Entry>>> accessRestrictionEntries;
#endif
static LinuxDeviceOptions & GetInstance();
};
Expand Down
1 change: 1 addition & 0 deletions scripts/tools/check_includes_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,5 @@
'src/app/icd/client/DefaultICDStorageKey.h': {'vector'},
'src/controller/CHIPDeviceController.cpp': {'string'},
'src/qrcodetool/setup_payload_commands.cpp': {'string'},
'src/access/AccessRestriction.h': {'vector', 'map'},
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading