-
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.
Added parameter to Objective-C CHIPDeviceController to accept PAA cer… (
#17035) * Added parameter to Objective-C CHIPDeviceController to accept PAA certificates from Objective-C client Fixes #14126 Change overview Added a new parameter to CHIPDeviceController that is an array of NSData PAA certificates. Created an Objective-C bridge for the AttestationTrustStore class. The PAA certificates provided by the client are passed to the default device attestation verifier. If the client passes a nil value for the parameter then the testing root store is used. Testing Used an Objective-C client to pass valid certificates to ensure device attestation procedure succeeded with an m5stack device. Passed in nil to ensure the device attestation procedure used the test PAA certificates. * Restyled by whitespace * Restyled by clang-format * Update src/darwin/Framework/CHIP/CHIPAttestationTrustStoreBridge.mm Co-authored-by: Boris Zbarsky <[email protected]> * Update src/darwin/Framework/CHIP/CHIPAttestationTrustStoreBridge.mm Co-authored-by: Boris Zbarsky <[email protected]> * Updated files: examples/chip-tool-darwin/commands/common/CHIPCommandBridge.mm src/darwin/CHIPTool/CHIPTool/Framework Helpers/DefaultsUtils.m src/darwin/Framework/CHIP/BUILD.gn src/darwin/Framework/CHIP/CHIPAttestationTrustStoreBridge.mm src/darwin/Framework/CHIP/CHIPDeviceController.h src/darwin/Framework/CHIP/CHIPDeviceController.mm * Restyled by gn Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Justin Wood <[email protected]> Co-authored-by: Boris Zbarsky <[email protected]>
- Loading branch information
Showing
7 changed files
with
117 additions
and
6 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
36 changes: 36 additions & 0 deletions
36
src/darwin/Framework/CHIP/CHIPAttestationTrustStoreBridge.h
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. | ||
*/ | ||
|
||
#import "CHIPError_Internal.h" | ||
#include <credentials/attestation_verifier/DeviceAttestationVerifier.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
class CHIPAttestationTrustStoreBridge : public chip::Credentials::AttestationTrustStore { | ||
public: | ||
~CHIPAttestationTrustStoreBridge() {}; | ||
|
||
void Init(NSArray<NSData *> * paaCerts); | ||
|
||
CHIP_ERROR GetProductAttestationAuthorityCert( | ||
const chip::ByteSpan & skid, chip::MutableByteSpan & outPaaDerBuffer) const override; | ||
|
||
private: | ||
NSArray<NSData *> * mPaaCerts; | ||
}; | ||
|
||
NS_ASSUME_NONNULL_END |
45 changes: 45 additions & 0 deletions
45
src/darwin/Framework/CHIP/CHIPAttestationTrustStoreBridge.mm
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,45 @@ | ||
/** | ||
* | ||
* 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 "CHIPAttestationTrustStoreBridge.h" | ||
|
||
static chip::ByteSpan asByteSpan(NSData * value) { return chip::ByteSpan(static_cast<const uint8_t *>(value.bytes), value.length); } | ||
|
||
void CHIPAttestationTrustStoreBridge::Init(NSArray<NSData *> * paaCerts) { mPaaCerts = paaCerts; } | ||
|
||
CHIP_ERROR CHIPAttestationTrustStoreBridge::GetProductAttestationAuthorityCert( | ||
const chip::ByteSpan & skid, chip::MutableByteSpan & outPaaDerBuffer) const | ||
{ | ||
VerifyOrReturnError(skid.size() == chip::Crypto::kSubjectKeyIdentifierLength, CHIP_ERROR_INVALID_ARGUMENT); | ||
|
||
size_t paaIdx; | ||
chip::ByteSpan candidate; | ||
|
||
for (paaIdx = 0; paaIdx < mPaaCerts.count; ++paaIdx) { | ||
uint8_t skidBuf[chip::Crypto::kSubjectKeyIdentifierLength] = { 0 }; | ||
candidate = asByteSpan(mPaaCerts[paaIdx]); | ||
chip::MutableByteSpan candidateSkidSpan { skidBuf }; | ||
VerifyOrReturnError( | ||
CHIP_NO_ERROR == chip::Crypto::ExtractSKIDFromX509Cert(candidate, candidateSkidSpan), CHIP_ERROR_INTERNAL); | ||
|
||
if (skid.data_equal(candidateSkidSpan)) { | ||
// Found a match | ||
return CopySpanToMutableSpan(candidate, outPaaDerBuffer); | ||
} | ||
} | ||
return CHIP_ERROR_CA_CERT_NOT_FOUND; | ||
} |
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