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

[chip-tool] Create ChipToolCheckInDelegate #32885

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static_library("chip-tool-utils") {
"commands/common/BDXDiagnosticLogsServerDelegate.cpp",
"commands/common/CHIPCommand.cpp",
"commands/common/CHIPCommand.h",
"commands/common/ChipToolCheckInDelegate.cpp",
"commands/common/ChipToolCheckInDelegate.h",
"commands/common/Command.cpp",
"commands/common/Command.h",
"commands/common/Commands.cpp",
Expand Down
3 changes: 2 additions & 1 deletion examples/chip-tool/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "CHIPCommand.h"

#include <commands/common/ChipToolCheckInDelegate.h>
#include <controller/CHIPDeviceControllerFactory.h>
#include <credentials/attestation_verifier/FileAttestationTrustStore.h>
#include <lib/core/CHIPConfig.h>
Expand Down Expand Up @@ -52,7 +53,7 @@ chip::Credentials::GroupDataProviderImpl CHIPCommand::sGroupDataProvider{ kMaxGr
// All fabrics share the same ICD client storage.
chip::app::DefaultICDClientStorage CHIPCommand::sICDClientStorage;
chip::Crypto::RawKeySessionKeystore CHIPCommand::sSessionKeystore;
chip::app::DefaultCheckInDelegate CHIPCommand::sCheckInDelegate;
ChipToolCheckInDelegate CHIPCommand::sCheckInDelegate;
chip::app::CheckInHandler CHIPCommand::sCheckInHandler;

namespace {
Expand Down
4 changes: 2 additions & 2 deletions examples/chip-tool/commands/common/CHIPCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

#include <TracingCommandLineArgument.h>
#include <app/icd/client/CheckInHandler.h>
#include <app/icd/client/DefaultCheckInDelegate.h>
#include <app/icd/client/DefaultICDClientStorage.h>
#include <commands/common/ChipToolCheckInDelegate.h>
#include <commands/common/CredentialIssuerCommands.h>
#include <commands/example/ExampleCredentialIssuerCommands.h>
#include <credentials/GroupDataProviderImpl.h>
Expand Down Expand Up @@ -164,7 +164,7 @@ class CHIPCommand : public Command

static chip::Credentials::GroupDataProviderImpl sGroupDataProvider;
static chip::app::DefaultICDClientStorage sICDClientStorage;
static chip::app::DefaultCheckInDelegate sCheckInDelegate;
static ChipToolCheckInDelegate sCheckInDelegate;
static chip::app::CheckInHandler sCheckInHandler;
CredentialIssuerCommands * mCredIssuerCmds;

Expand Down
76 changes: 76 additions & 0 deletions examples/chip-tool/commands/common/ChipToolCheckInDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.
*/

#include "ChipToolCheckInDelegate.h"

#include <app/icd/client/RefreshKeySender.h>
#include <crypto/CHIPCryptoPAL.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace chip;
using namespace chip::app;

CHIP_ERROR ChipToolCheckInDelegate::Init(ICDClientStorage * storage, InteractionModelEngine * engine)
{
VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(mpStorage == nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(engine != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
mpStorage = storage;
mpImEngine = engine;
return CHIP_NO_ERROR;
}

void ChipToolCheckInDelegate::OnCheckInComplete(const ICDClientInfo & clientInfo)
{
ChipLogProgress(
ICD, "Check In Message processing complete: start_counter=%" PRIu32 " offset=%" PRIu32 " nodeid=" ChipLogFormatScopedNodeId,
clientInfo.start_icd_counter, clientInfo.offset, ChipLogValueScopedNodeId(clientInfo.peer_node));
}

RefreshKeySender * ChipToolCheckInDelegate::OnKeyRefreshNeeded(ICDClientInfo & clientInfo, ICDClientStorage * clientStorage)
{
CHIP_ERROR err = CHIP_NO_ERROR;
RefreshKeySender::RefreshKeyBuffer newKey;

err = Crypto::DRBG_get_bytes(newKey.Bytes(), newKey.Capacity());
if (err != CHIP_NO_ERROR)
{
ChipLogError(ICD, "Generation of new key failed: %" CHIP_ERROR_FORMAT, err.Format());
return nullptr;
}

return Platform::New<RefreshKeySender>(this, clientInfo, clientStorage, mpImEngine, newKey);
}

void ChipToolCheckInDelegate::OnKeyRefreshDone(RefreshKeySender * refreshKeySender, CHIP_ERROR error)
{
if (error == CHIP_NO_ERROR)
{
ChipLogProgress(ICD, "Re-registration with new key completed successfully");
}
else
{
ChipLogError(ICD, "Re-registration with new key failed with error : %" CHIP_ERROR_FORMAT, error.Format());
// The callee can take corrective action based on the error received.
}
if (refreshKeySender != nullptr)
{
Platform::Delete(refreshKeySender);
refreshKeySender = nullptr;
}
}
40 changes: 40 additions & 0 deletions examples/chip-tool/commands/common/ChipToolCheckInDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* 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.
*/

#pragma once

#include <set>

#include <app/InteractionModelEngine.h>
#include <app/icd/client/CheckInDelegate.h>
#include <app/icd/client/ICDClientStorage.h>

class ChipToolCheckInDelegate : public chip::app::CheckInDelegate
{
public:
virtual ~ChipToolCheckInDelegate() {}
CHIP_ERROR Init(chip::app::ICDClientStorage * storage, chip::app::InteractionModelEngine * engine);
void OnCheckInComplete(const chip::app::ICDClientInfo & clientInfo) override;
chip::app::RefreshKeySender * OnKeyRefreshNeeded(chip::app::ICDClientInfo & clientInfo,
chip::app::ICDClientStorage * clientStorage) override;
void OnKeyRefreshDone(chip::app::RefreshKeySender * refreshKeySender, CHIP_ERROR error) override;

private:
chip::app::ICDClientStorage * mpStorage = nullptr;
chip::app::InteractionModelEngine * mpImEngine = nullptr;
};
2 changes: 2 additions & 0 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ config("config") {

executable("darwin-framework-tool") {
sources = [
"${chip_root}/examples/chip-tool/commands/common/ChipToolCheckInDelegate.cpp",
"${chip_root}/examples/chip-tool/commands/common/ChipToolCheckInDelegate.h",
"${chip_root}/examples/chip-tool/commands/common/Command.cpp",
"${chip_root}/examples/chip-tool/commands/common/Command.h",
"${chip_root}/examples/chip-tool/commands/common/Commands.cpp",
Expand Down
2 changes: 2 additions & 0 deletions examples/tv-casting-app/tv-casting-common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ chip_data_model("tv-casting-common") {
"${chip_root}/examples/chip-tool/commands/clusters/ModelCommand.h",
"${chip_root}/examples/chip-tool/commands/common/BDXDiagnosticLogsServerDelegate.cpp",
"${chip_root}/examples/chip-tool/commands/common/CHIPCommand.h",
"${chip_root}/examples/chip-tool/commands/common/ChipToolCheckInDelegate.cpp",
"${chip_root}/examples/chip-tool/commands/common/ChipToolCheckInDelegate.h",
"${chip_root}/examples/chip-tool/commands/common/Command.cpp",
"${chip_root}/examples/chip-tool/commands/common/Command.h",
"${chip_root}/examples/chip-tool/commands/common/Commands.cpp",
Expand Down
Loading