-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an access control delegate implementation for the Darwin framewor…
…k. (#16546)
- Loading branch information
1 parent
b24efd9
commit 2b7a67e
Showing
6 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* 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. | ||
*/ | ||
#pragma once | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface CHIPControllerAccessControl : NSObject | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
+ (instancetype)new NS_UNAVAILABLE; | ||
+ (instancetype)alloc NS_UNAVAILABLE; | ||
|
||
/** | ||
* Initialize the access control module. Must be called on the Matter task | ||
* queue. | ||
*/ | ||
+ (void)init; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* 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. | ||
*/ | ||
|
||
#import "CHIPControllerAccessControl.h" | ||
|
||
#include <access/AccessControl.h> | ||
#include <access/Privilege.h> | ||
#include <access/RequestPath.h> | ||
#include <access/SubjectDescriptor.h> | ||
#include <app-common/zap-generated/ids/Clusters.h> | ||
#include <lib/core/CHIPError.h> | ||
|
||
using namespace chip; | ||
using namespace chip::Access; | ||
using namespace chip::app::Clusters; | ||
|
||
namespace { | ||
// TODO: Maybe consider making this configurable? See also | ||
// CHIPIMDispatch.mm. | ||
constexpr EndpointId kSupportedEndpoint = 0; | ||
|
||
// TODO: Make the policy more configurable by consumers. | ||
class AccessControlDelegate : public Access::AccessControl::Delegate { | ||
CHIP_ERROR Check( | ||
const SubjectDescriptor & subjectDescriptor, const RequestPath & requestPath, Privilege requestPrivilege) override | ||
{ | ||
if (requestPath.endpoint != kSupportedEndpoint || requestPath.cluster != OtaSoftwareUpdateProvider::Id) { | ||
// We only allow access to OTA software update provider. | ||
return CHIP_ERROR_ACCESS_DENIED; | ||
} | ||
|
||
if (requestPrivilege != Privilege::kOperate) { | ||
// The commands on OtaSoftwareUpdateProvider all require | ||
// Operate; we should not be asked for anything else. | ||
return CHIP_ERROR_ACCESS_DENIED; | ||
} | ||
|
||
if (subjectDescriptor.authMode != AuthMode::kCase && subjectDescriptor.authMode != AuthMode::kPase) { | ||
// No idea who is asking; deny for now. | ||
return CHIP_ERROR_ACCESS_DENIED; | ||
} | ||
|
||
// TODO do we care about the fabric index here? Probably not. | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
}; | ||
|
||
AccessControlDelegate gDelegate; | ||
} // anonymous namespace | ||
|
||
@implementation CHIPControllerAccessControl | ||
|
||
+ (void)init | ||
{ | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
GetAccessControl().Init(&gDelegate); | ||
}); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters