Skip to content

Commit 4310433

Browse files
tehampsonpull[bot]
authored andcommitted
Invalidate CASE resumption storage when UpdateNOC is called (#19860)
Using FabricTable::Delegate callback we clean up CASE resumption storage for associated fabric index on UpdateNOC
1 parent 8e8c116 commit 4310433

File tree

5 files changed

+68
-31
lines changed

5 files changed

+68
-31
lines changed

src/app/server/Server.h

+15-16
Original file line numberDiff line numberDiff line change
@@ -396,21 +396,7 @@ class Server
396396
void OnFabricDeletedFromStorage(FabricTable & fabricTable, FabricIndex fabricIndex) override
397397
{
398398
(void) fabricTable;
399-
auto & sessionManager = mServer->GetSecureSessionManager();
400-
sessionManager.FabricRemoved(fabricIndex);
401-
402-
// Remove all CASE session resumption state
403-
auto * sessionResumptionStorage = mServer->GetSessionResumptionStorage();
404-
if (sessionResumptionStorage != nullptr)
405-
{
406-
CHIP_ERROR err = sessionResumptionStorage->DeleteAll(fabricIndex);
407-
if (err != CHIP_NO_ERROR)
408-
{
409-
ChipLogError(AppServer,
410-
"Warning, failed to delete session resumption state for fabric index 0x%x: %" CHIP_ERROR_FORMAT,
411-
static_cast<unsigned>(fabricIndex), err.Format());
412-
}
413-
}
399+
ClearCASEResumptionStateOnFabricChange(fabricIndex);
414400

415401
Credentials::GroupDataProvider * groupDataProvider = mServer->GetGroupDataProvider();
416402
if (groupDataProvider != nullptr)
@@ -440,10 +426,23 @@ class Server
440426
void OnFabricNOCUpdated(chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override
441427
{
442428
(void) fabricTable;
443-
(void) fabricIndex;
429+
ClearCASEResumptionStateOnFabricChange(fabricIndex);
444430
}
445431

446432
private:
433+
void ClearCASEResumptionStateOnFabricChange(chip::FabricIndex fabricIndex)
434+
{
435+
auto * sessionResumptionStorage = mServer->GetSessionResumptionStorage();
436+
VerifyOrReturn(sessionResumptionStorage != nullptr);
437+
CHIP_ERROR err = sessionResumptionStorage->DeleteAll(fabricIndex);
438+
if (err != CHIP_NO_ERROR)
439+
{
440+
ChipLogError(AppServer,
441+
"Warning, failed to delete session resumption state for fabric index 0x%x: %" CHIP_ERROR_FORMAT,
442+
static_cast<unsigned>(fabricIndex), err.Format());
443+
}
444+
}
445+
447446
Server * mServer = nullptr;
448447
};
449448

src/controller/CHIPDeviceControllerFactory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
174174
stateParams.sessionResumptionStorage = std::move(sessionResumptionStorage);
175175

176176
auto delegate = chip::Platform::MakeUnique<ControllerFabricDelegate>();
177-
ReturnErrorOnFailure(delegate->Init(stateParams.sessionMgr, stateParams.groupDataProvider));
177+
ReturnErrorOnFailure(delegate->Init(stateParams.sessionResumptionStorage.get(), stateParams.groupDataProvider));
178178
stateParams.fabricTableDelegate = delegate.get();
179179
ReturnErrorOnFailure(stateParams.fabricTable->AddFabricDelegate(stateParams.fabricTableDelegate));
180180
delegate.release();

src/controller/CHIPDeviceControllerFactory.h

+20-12
Original file line numberDiff line numberDiff line change
@@ -170,28 +170,24 @@ class DeviceControllerFactory
170170
class ControllerFabricDelegate final : public chip::FabricTable::Delegate
171171
{
172172
public:
173-
CHIP_ERROR Init(SessionManager * sessionManager, Credentials::GroupDataProvider * groupDataProvider)
173+
CHIP_ERROR Init(SessionResumptionStorage * sessionResumptionStorage, Credentials::GroupDataProvider * groupDataProvider)
174174
{
175-
VerifyOrReturnError(sessionManager != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
175+
VerifyOrReturnError(sessionResumptionStorage != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
176176
VerifyOrReturnError(groupDataProvider != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
177177

178-
mSessionManager = sessionManager;
179-
mGroupDataProvider = groupDataProvider;
178+
mSessionResumptionStorage = sessionResumptionStorage;
179+
mGroupDataProvider = groupDataProvider;
180180
return CHIP_NO_ERROR;
181181
};
182182

183183
void OnFabricDeletedFromStorage(FabricTable & fabricTable, FabricIndex fabricIndex) override
184184
{
185185
(void) fabricTable;
186-
187-
if (mSessionManager != nullptr)
188-
{
189-
mSessionManager->FabricRemoved(fabricIndex);
190-
}
191186
if (mGroupDataProvider != nullptr)
192187
{
193188
mGroupDataProvider->RemoveFabric(fabricIndex);
194189
}
190+
ClearCASEResumptionStateOnFabricChange(fabricIndex);
195191
};
196192

197193
void OnFabricRetrievedFromStorage(FabricTable & fabricTable, FabricIndex fabricIndex) override
@@ -209,12 +205,24 @@ class DeviceControllerFactory
209205
void OnFabricNOCUpdated(chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override
210206
{
211207
(void) fabricTable;
212-
(void) fabricIndex;
208+
ClearCASEResumptionStateOnFabricChange(fabricIndex);
213209
}
214210

215211
private:
216-
SessionManager * mSessionManager = nullptr;
217-
Credentials::GroupDataProvider * mGroupDataProvider = nullptr;
212+
void ClearCASEResumptionStateOnFabricChange(chip::FabricIndex fabricIndex)
213+
{
214+
VerifyOrReturn(mSessionResumptionStorage != nullptr);
215+
CHIP_ERROR err = mSessionResumptionStorage->DeleteAll(fabricIndex);
216+
if (err != CHIP_NO_ERROR)
217+
{
218+
ChipLogError(AppServer,
219+
"Warning, failed to delete session resumption state for fabric index 0x%x: %" CHIP_ERROR_FORMAT,
220+
static_cast<unsigned>(fabricIndex), err.Format());
221+
}
222+
}
223+
224+
Credentials::GroupDataProvider * mGroupDataProvider = nullptr;
225+
SessionResumptionStorage * mSessionResumptionStorage = nullptr;
218226
};
219227

220228
private:

src/transport/SessionManager.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ uint32_t EncryptedPacketBufferHandle::GetMessageCounter() const
7272

7373
SessionManager::SessionManager() : mState(State::kNotReady) {}
7474

75-
SessionManager::~SessionManager() {}
75+
SessionManager::~SessionManager()
76+
{
77+
this->Shutdown();
78+
}
7679

7780
CHIP_ERROR SessionManager::Init(System::Layer * systemLayer, TransportMgrBase * transportMgr,
7881
Transport::MessageCounterManagerInterface * messageCounterManager,
@@ -82,6 +85,7 @@ CHIP_ERROR SessionManager::Init(System::Layer * systemLayer, TransportMgrBase *
8285
VerifyOrReturnError(transportMgr != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
8386
VerifyOrReturnError(storageDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
8487
VerifyOrReturnError(fabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
88+
ReturnErrorOnFailure(fabricTable->AddFabricDelegate(this));
8589

8690
mState = State::kInitialized;
8791
mSystemLayer = systemLayer;
@@ -102,6 +106,10 @@ CHIP_ERROR SessionManager::Init(System::Layer * systemLayer, TransportMgrBase *
102106

103107
void SessionManager::Shutdown()
104108
{
109+
if (mFabricTable != nullptr)
110+
{
111+
mFabricTable->RemoveFabricDelegate(this);
112+
}
105113
mMessageCounterManager = nullptr;
106114

107115
mState = State::kNotReady;

src/transport/SessionManager.h

+23-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class EncryptedPacketBufferHandle final : private System::PacketBufferHandle
120120
EncryptedPacketBufferHandle(PacketBufferHandle && aBuffer) : PacketBufferHandle(std::move(aBuffer)) {}
121121
};
122122

123-
class DLL_EXPORT SessionManager : public TransportMgrDelegate
123+
class DLL_EXPORT SessionManager : public TransportMgrDelegate, public FabricTable::Delegate
124124
{
125125
public:
126126
SessionManager();
@@ -246,6 +246,28 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate
246246
using SessionHandleCallback = bool (*)(void * context, SessionHandle & sessionHandle);
247247
CHIP_ERROR ForEachSessionHandle(void * context, SessionHandleCallback callback);
248248

249+
//// FabricTable::Delegate Implementation ////
250+
void OnFabricDeletedFromStorage(FabricTable & fabricTable, FabricIndex fabricIndex) override
251+
{
252+
(void) fabricTable;
253+
this->FabricRemoved(fabricIndex);
254+
}
255+
void OnFabricRetrievedFromStorage(FabricTable & fabricTable, FabricIndex fabricIndex) override
256+
{
257+
(void) fabricTable;
258+
(void) fabricIndex;
259+
}
260+
void OnFabricPersistedToStorage(FabricTable & fabricTable, FabricIndex fabricIndex) override
261+
{
262+
(void) fabricTable;
263+
(void) fabricIndex;
264+
}
265+
void OnFabricNOCUpdated(chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override
266+
{
267+
(void) fabricTable;
268+
(void) fabricIndex;
269+
}
270+
249271
private:
250272
/**
251273
* The State of a secure transport object.

0 commit comments

Comments
 (0)