-
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.
[Yaml] Add a test adding a new fabric from an existing fabric (#25969)
* [chip-tool] Add GetCommissionerRootCertificate command [chip-tool] Add IssueNocChain command * Add src/app/tests/suites/Test_AddNewFabricFromExistingFabric.yaml test working with the chip-tool python yaml runner --------- Co-authored-by: Andrei Litvin <[email protected]>
- Loading branch information
Showing
15 changed files
with
483 additions
and
16 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
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
50 changes: 50 additions & 0 deletions
50
examples/chip-tool/commands/pairing/GetCommissionerRootCertificateCommand.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,50 @@ | ||
/* | ||
* Copyright (c) 2023 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. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "../common/CHIPCommand.h" | ||
|
||
#include "ToTLVCert.h" | ||
|
||
class GetCommissionerRootCertificateCommand : public CHIPCommand | ||
{ | ||
public: | ||
GetCommissionerRootCertificateCommand(CredentialIssuerCommands * credIssuerCommands) : | ||
CHIPCommand("get-commissioner-root-certificate", credIssuerCommands, | ||
"Returns a base64-encoded RCAC prefixed with: 'base64:'") | ||
{} | ||
|
||
/////////// CHIPCommand Interface ///////// | ||
CHIP_ERROR RunCommand() override | ||
{ | ||
chip::ByteSpan span; | ||
ReturnErrorOnFailure(GetIdentityRootCertificate(GetIdentity(), span)); | ||
|
||
std::string rcac; | ||
ReturnErrorOnFailure(ToTLVCert(span, rcac)); | ||
ChipLogProgress(chipTool, "RCAC: %s", rcac.c_str()); | ||
|
||
ReturnErrorOnFailure(RemoteDataModelLogger::LogGetCommissionerRootCertificate(rcac.c_str())); | ||
|
||
SetCommandExitStatus(CHIP_NO_ERROR); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(10); } | ||
}; |
86 changes: 86 additions & 0 deletions
86
examples/chip-tool/commands/pairing/IssueNOCChainCommand.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,86 @@ | ||
/* | ||
* Copyright (c) 2023 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. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "../common/CHIPCommand.h" | ||
|
||
#include "ToTLVCert.h" | ||
|
||
class IssueNOCChainCommand : public CHIPCommand | ||
{ | ||
public: | ||
IssueNOCChainCommand(CredentialIssuerCommands * credIssuerCommands) : | ||
CHIPCommand("issue-noc-chain", credIssuerCommands, | ||
"Returns a base64-encoded NOC, ICAC, RCAC, and IPK prefixed with: 'base64:'"), | ||
mDeviceNOCChainCallback(OnDeviceNOCChainGeneration, this) | ||
{ | ||
AddArgument("elements", &mNOCSRElements, "NOCSRElements encoded in hexadecimal"); | ||
AddArgument("node-id", 0, UINT64_MAX, &mNodeId, "The target node id"); | ||
} | ||
|
||
/////////// CHIPCommand Interface ///////// | ||
CHIP_ERROR RunCommand() override | ||
{ | ||
auto & commissioner = CurrentCommissioner(); | ||
ReturnErrorOnFailure(commissioner.IssueNOCChain(mNOCSRElements, mNodeId, &mDeviceNOCChainCallback)); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(10); } | ||
|
||
static void OnDeviceNOCChainGeneration(void * context, CHIP_ERROR status, const chip::ByteSpan & noc, | ||
const chip::ByteSpan & icac, const chip::ByteSpan & rcac, | ||
chip::Optional<chip::IdentityProtectionKeySpan> ipk, | ||
chip::Optional<chip::NodeId> adminSubject) | ||
{ | ||
auto command = static_cast<IssueNOCChainCommand *>(context); | ||
|
||
auto err = status; | ||
VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err)); | ||
|
||
std::string nocStr; | ||
err = ToTLVCert(noc, nocStr); | ||
VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err)); | ||
ChipLogProgress(chipTool, "NOC: %s", nocStr.c_str()); | ||
|
||
std::string icacStr; | ||
err = ToTLVCert(icac, icacStr); | ||
VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err)); | ||
ChipLogProgress(chipTool, "ICAC: %s", icacStr.c_str()); | ||
|
||
std::string rcacStr; | ||
err = ToTLVCert(rcac, rcacStr); | ||
VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err)); | ||
ChipLogProgress(chipTool, "RCAC: %s", rcacStr.c_str()); | ||
|
||
auto ipkValue = ipk.ValueOr(chip::Crypto::IdentityProtectionKeySpan()); | ||
std::string ipkStr; | ||
err = ToBase64(ipkValue, ipkStr); | ||
VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err)); | ||
ChipLogProgress(chipTool, "IPK: %s", ipkStr.c_str()); | ||
|
||
err = RemoteDataModelLogger::LogIssueNOCChain(nocStr.c_str(), icacStr.c_str(), rcacStr.c_str(), ipkStr.c_str()); | ||
command->SetCommandExitStatus(err); | ||
} | ||
|
||
private: | ||
chip::Callback::Callback<chip::Controller::OnNOCChainGeneration> mDeviceNOCChainCallback; | ||
chip::ByteSpan mNOCSRElements; | ||
chip::NodeId mNodeId; | ||
}; |
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,52 @@ | ||
/* | ||
* Copyright (c) 2023 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. | ||
* | ||
*/ | ||
|
||
#include "ToTLVCert.h" | ||
|
||
#include <credentials/CHIPCert.h> | ||
#include <lib/support/Base64.h> | ||
|
||
constexpr const char kBase64Header[] = "base64:"; | ||
constexpr size_t kBase64HeaderLen = ArraySize(kBase64Header) - 1; | ||
|
||
CHIP_ERROR ToBase64(const chip::ByteSpan & input, std::string & outputAsPrefixedBase64) | ||
{ | ||
chip::Platform::ScopedMemoryBuffer<char> base64String; | ||
base64String.Alloc(kBase64HeaderLen + BASE64_ENCODED_LEN(input.size()) + 1); | ||
VerifyOrReturnError(base64String.Get() != nullptr, CHIP_ERROR_NO_MEMORY); | ||
|
||
auto encodedLen = chip::Base64Encode(input.data(), static_cast<uint16_t>(input.size()), base64String.Get() + kBase64HeaderLen); | ||
if (encodedLen) | ||
{ | ||
memcpy(base64String.Get(), kBase64Header, kBase64HeaderLen); | ||
encodedLen = static_cast<uint16_t>(encodedLen + kBase64HeaderLen); | ||
} | ||
base64String.Get()[encodedLen] = '\0'; | ||
outputAsPrefixedBase64 = std::string(base64String.Get(), encodedLen); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR ToTLVCert(const chip::ByteSpan & derEncodedCertificate, std::string & tlvCertAsPrefixedBase64) | ||
{ | ||
uint8_t chipCertBuffer[chip::Credentials::kMaxCHIPCertLength]; | ||
chip::MutableByteSpan chipCertBytes(chipCertBuffer); | ||
ReturnErrorOnFailure(chip::Credentials::ConvertX509CertToChipCert(derEncodedCertificate, chipCertBytes)); | ||
ReturnErrorOnFailure(ToBase64(chipCertBytes, tlvCertAsPrefixedBase64)); | ||
return CHIP_NO_ERROR; | ||
} |
Oops, something went wrong.