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

Properly manage operational key lifecycle for fail-safe #19277

Merged
merged 36 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f29b087
Properly manage operational key lifecycle for fail-safe
tcarmelveilleux Jun 7, 2022
afe825d
Merge remote-tracking branch 'upstream/master' into keystore-wip2
tcarmelveilleux Jun 7, 2022
538eed3
Fix merge of upstream
tcarmelveilleux Jun 7, 2022
d7d2be9
Restyled by whitespace
restyled-commits Jun 7, 2022
7adf8df
Restyled by clang-format
restyled-commits Jun 7, 2022
cfe632e
Revert unintended testing changes
tcarmelveilleux Jun 7, 2022
09e9f93
Add remove operation
tcarmelveilleux Jun 7, 2022
1f63076
Fix CI and add tests to support further tests
tcarmelveilleux Jun 7, 2022
1037160
Fix more CI
tcarmelveilleux Jun 7, 2022
a719d77
Restyled by clang-format
restyled-commits Jun 7, 2022
65742b1
Darwin changes to use the new setup
bzbarsky-apple Jun 8, 2022
9350b1f
Added unit test and HasOpKeypairForFabric()
tcarmelveilleux Jun 8, 2022
b44d4d7
Restyled by clang-format
restyled-commits Jun 8, 2022
7f422cd
Restyled by gn
restyled-commits Jun 8, 2022
2d01768
Apply review comments from @msandstedt
tcarmelveilleux Jun 8, 2022
a7062a3
Merge pull request #4 from bzbarsky-apple/testing
tcarmelveilleux Jun 8, 2022
6d36c2c
Add plumbing for init of controllers
tcarmelveilleux Jun 8, 2022
f89a544
Restyled by clang-format
restyled-commits Jun 8, 2022
bb698d3
Fix darwin tests
bzbarsky-apple Jun 8, 2022
d145381
Merge pull request #5 from bzbarsky-apple/testing
tcarmelveilleux Jun 8, 2022
a3f25a2
Fix CI and address review comments
tcarmelveilleux Jun 8, 2022
95f98d6
Merge remote-tracking branch 'upstream/master' into keystore-wip2
tcarmelveilleux Jun 8, 2022
59cb65a
Fix comment typos
tcarmelveilleux Jun 8, 2022
622121b
Apply review comments from @bzbarsky-apple and @tehampson
tcarmelveilleux Jun 9, 2022
f3d9cfb
Restyled by clang-format
restyled-commits Jun 9, 2022
9b5a0e4
Fix more comments
tcarmelveilleux Jun 9, 2022
e351173
Restyled by clang-format
restyled-commits Jun 9, 2022
4d16e81
Fix CI
tcarmelveilleux Jun 9, 2022
7686d00
Merge remote-tracking branch 'upstream/master' into keystore-wip2
tcarmelveilleux Jun 9, 2022
c2db517
Fix cirque
tcarmelveilleux Jun 9, 2022
c68bbf6
Restyled by clang-format
restyled-commits Jun 9, 2022
cf8c225
Update src/crypto/tests/TestPersistentStorageOpKeyStore.cpp
woody-apple Jun 9, 2022
7a701eb
Address review comments
tcarmelveilleux Jun 9, 2022
7de88ed
Merge remote-tracking branch 'origin/keystore-wip2' into keystore-wip2
tcarmelveilleux Jun 9, 2022
94aafd7
Fix CI
tcarmelveilleux Jun 10, 2022
1f8717b
More clang-tidy fixes
tcarmelveilleux Jun 10, 2022
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/commands/common/CHIPCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack()
#endif

ReturnLogErrorOnFailure(mDefaultStorage.Init());
ReturnLogErrorOnFailure(mOperationalKeystore.Init(&mDefaultStorage));

chip::Controller::FactoryInitParams factoryInitParams;

factoryInitParams.fabricIndependentStorage = &mDefaultStorage;
factoryInitParams.operationalKeystore = &mOperationalKeystore;

// Init group data provider that will be used for all group keys and IPKs for the
// chip-tool-configured fabrics. This is OK to do once since the fabric tables
Expand Down
3 changes: 3 additions & 0 deletions examples/chip-tool/commands/common/CHIPCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <commands/common/CredentialIssuerCommands.h>
#include <commands/example/ExampleCredentialIssuerCommands.h>
#include <credentials/GroupDataProviderImpl.h>
#include <crypto/PersistentStorageOperationalKeystore.h>

#pragma once

Expand Down Expand Up @@ -115,6 +116,8 @@ class CHIPCommand : public Command

PersistentStorage mDefaultStorage;
PersistentStorage mCommissionerStorage;
chip::PersistentStorageOperationalKeystore mOperationalKeystore;

chip::Credentials::GroupDataProviderImpl mGroupDataProvider{ kMaxGroupsPerFabric, kMaxGroupKeysPerFabric };
CredentialIssuerCommands * mCredIssuerCmds;

Expand Down
4 changes: 3 additions & 1 deletion src/app/CASEClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ CHIP_ERROR CASEClient::EstablishSession(PeerId peer, const Transport::PeerAddres
const ReliableMessageProtocolConfig & remoteMRPConfig,
SessionEstablishmentDelegate * delegate)
{
VerifyOrReturnError(mInitParams.fabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT);

// Create a UnauthenticatedSession for CASE pairing.
Optional<SessionHandle> session = mInitParams.sessionManager->CreateUnauthenticatedSession(peerAddress, remoteMRPConfig);
VerifyOrReturnError(session.HasValue(), CHIP_ERROR_NO_MEMORY);
Expand All @@ -45,7 +47,7 @@ CHIP_ERROR CASEClient::EstablishSession(PeerId peer, const Transport::PeerAddres

mCASESession.SetGroupDataProvider(mInitParams.groupDataProvider);
ReturnErrorOnFailure(mCASESession.EstablishSession(
*mInitParams.sessionManager, mInitParams.fabricTable, mInitParams.fabricIndex, peer.GetNodeId(), exchange,
*mInitParams.sessionManager, mInitParams.fabricTable, ScopedNodeId{ peer.GetNodeId(), mInitParams.fabricIndex }, exchange,
mInitParams.sessionResumptionStorage, mInitParams.certificateValidityPolicy, delegate, mInitParams.mrpLocalConfig));

return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/app/OperationalDeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy,
}

/**
* @brief Get the raw Fabric ID assigned to the device.
* @brief Get the fabricIndex
*/
FabricIndex GetFabricIndex() const { return mFabricIndex; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ bool emberAfGeneralCommissioningClusterArmFailSafeCallback(app::CommandHandler *
FailSafeContext & failSafeContext = DeviceLayer::DeviceControlServer::DeviceControlSvr().GetFailSafeContext();
Commands::ArmFailSafeResponse::Type response;

ChipLogProgress(FailSafe, "GeneralCommissioning: Received ArmFailSafe (%us)",
static_cast<unsigned>(commandData.expiryLengthSeconds));

/*
* If the fail-safe timer is not fully disarmed, don't allow arming a new fail-safe.
* If the fail-safe timer was not currently armed, then the fail-safe timer SHALL be armed.
Expand Down Expand Up @@ -214,7 +217,10 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
MATTER_TRACE_EVENT_SCOPE("CommissioningComplete", "GeneralCommissioning");

DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr();
const auto & failSafe = server->GetFailSafeContext();
auto & failSafe = server->GetFailSafeContext();
auto & fabricTable = Server::GetInstance().GetFabricTable();

ChipLogProgress(FailSafe, "GeneralCommissioning: Received CommissioningComplete");

Commands::CommissioningCompleteResponse::Type response;
if (!failSafe.IsFailSafeArmed())
Expand All @@ -231,16 +237,34 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
!failSafe.MatchesFabricIndex(commandObj->GetAccessingFabricIndex()))
{
response.errorCode = CommissioningError::kInvalidAuthentication;
ChipLogError(FailSafe, "GeneralCommissioning: Got commissioning complete in invalid security context");
}
else
{
if (failSafe.NocCommandHasBeenInvoked())
{
CHIP_ERROR err = fabricTable.CommitPendingFabricData();
tcarmelveilleux marked this conversation as resolved.
Show resolved Hide resolved
if (err != CHIP_NO_ERROR)
{
ChipLogError(FailSafe, "GeneralCommissioning: Failed to commit pending fabric data: %" CHIP_ERROR_FORMAT,
err.Format());
}
else
{
ChipLogProgress(FailSafe, "GeneralCommissioning: Successfully commited pending fabric data");
}
CheckSuccess(err, Failure);
}

/*
* Pass fabric of commissioner to DeviceControlSvr.
* This allows device to send messages back to commissioner.
* Once bindings are implemented, this may no longer be needed.
*/
CheckSuccess(server->CommissioningComplete(handle->AsSecureSession()->GetPeerNodeId(), handle->GetFabricIndex()),
Failure);
failSafe.DisarmFailSafe();
CheckSuccess(
server->PostCommissioningCompleteEvent(handle->AsSecureSession()->GetPeerNodeId(), handle->GetFabricIndex()),
Failure);

Breadcrumb::Set(commandPath.mEndpointId, 0);
response.errorCode = CommissioningError::kOk;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void Instance::OnResult(Status commissioningError, CharSpan debugText, int32_t i
}
if (commissioningError == Status::kSuccess)
{
DeviceLayer::DeviceControlServer::DeviceControlSvr().ConnectNetworkForOperational(
DeviceLayer::DeviceControlServer::DeviceControlSvr().PostConnectedToOperationalNetworkEvent(
ByteSpan(mLastNetworkID, mLastNetworkIDLen));
mLastConnectErrorValue.SetNull();
}
Expand Down
Loading