Skip to content

Commit 3389397

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Make SessionResumptionStorage injectable in controller. (#28422)
* Make SessionResumptionStorage injectable in controller. Fixes #28351 * Address review comment.
1 parent 7a2e0de commit 3389397

3 files changed

+49
-12
lines changed

src/controller/CHIPDeviceControllerFactory.cpp

+21-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ CHIP_ERROR DeviceControllerFactory::Init(FactoryInitParams params)
6565
mOperationalKeystore = params.operationalKeystore;
6666
mOpCertStore = params.opCertStore;
6767
mCertificateValidityPolicy = params.certificateValidityPolicy;
68+
mSessionResumptionStorage = params.sessionResumptionStorage;
6869
mEnableServerInteractions = params.enableServerInteractions;
6970

7071
CHIP_ERROR err = InitSystemState(params);
@@ -94,6 +95,7 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState()
9495
params.operationalKeystore = mOperationalKeystore;
9596
params.opCertStore = mOpCertStore;
9697
params.certificateValidityPolicy = mCertificateValidityPolicy;
98+
params.sessionResumptionStorage = mSessionResumptionStorage;
9799
}
98100

99101
return InitSystemState(params);
@@ -195,12 +197,24 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
195197
tempFabricTable = stateParams.fabricTable;
196198
}
197199

198-
auto sessionResumptionStorage = chip::Platform::MakeUnique<SimpleSessionResumptionStorage>();
199-
ReturnErrorOnFailure(sessionResumptionStorage->Init(params.fabricIndependentStorage));
200-
stateParams.sessionResumptionStorage = std::move(sessionResumptionStorage);
200+
SessionResumptionStorage * sessionResumptionStorage;
201+
if (params.sessionResumptionStorage == nullptr)
202+
{
203+
auto ownedSessionResumptionStorage = chip::Platform::MakeUnique<SimpleSessionResumptionStorage>();
204+
ReturnErrorOnFailure(ownedSessionResumptionStorage->Init(params.fabricIndependentStorage));
205+
stateParams.ownedSessionResumptionStorage = std::move(ownedSessionResumptionStorage);
206+
stateParams.externalSessionResumptionStorage = nullptr;
207+
sessionResumptionStorage = stateParams.ownedSessionResumptionStorage.get();
208+
}
209+
else
210+
{
211+
stateParams.ownedSessionResumptionStorage = nullptr;
212+
stateParams.externalSessionResumptionStorage = params.sessionResumptionStorage;
213+
sessionResumptionStorage = stateParams.externalSessionResumptionStorage;
214+
}
201215

202216
auto delegate = chip::Platform::MakeUnique<ControllerFabricDelegate>();
203-
ReturnErrorOnFailure(delegate->Init(stateParams.sessionResumptionStorage.get(), stateParams.groupDataProvider));
217+
ReturnErrorOnFailure(delegate->Init(sessionResumptionStorage, stateParams.groupDataProvider));
204218
stateParams.fabricTableDelegate = delegate.get();
205219
ReturnErrorOnFailure(stateParams.fabricTable->AddFabricDelegate(stateParams.fabricTableDelegate));
206220
delegate.release();
@@ -222,7 +236,7 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
222236

223237
// Enable listening for session establishment messages.
224238
ReturnErrorOnFailure(stateParams.caseServer->ListenForSessionEstablishment(
225-
stateParams.exchangeMgr, stateParams.sessionMgr, stateParams.fabricTable, stateParams.sessionResumptionStorage.get(),
239+
stateParams.exchangeMgr, stateParams.sessionMgr, stateParams.fabricTable, sessionResumptionStorage,
226240
stateParams.certificateValidityPolicy, stateParams.groupDataProvider));
227241

228242
//
@@ -256,7 +270,7 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
256270

257271
CASEClientInitParams sessionInitParams = {
258272
.sessionManager = stateParams.sessionMgr,
259-
.sessionResumptionStorage = stateParams.sessionResumptionStorage.get(),
273+
.sessionResumptionStorage = sessionResumptionStorage,
260274
.certificateValidityPolicy = stateParams.certificateValidityPolicy,
261275
.exchangeMgr = stateParams.exchangeMgr,
262276
.fabricTable = stateParams.fabricTable,
@@ -373,6 +387,7 @@ void DeviceControllerFactory::Shutdown()
373387
mOperationalKeystore = nullptr;
374388
mOpCertStore = nullptr;
375389
mCertificateValidityPolicy = nullptr;
390+
mSessionResumptionStorage = nullptr;
376391
}
377392

378393
void DeviceControllerSystemState::Shutdown()

src/controller/CHIPDeviceControllerFactory.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <credentials/GroupDataProvider.h>
3535
#include <credentials/OperationalCertificateStore.h>
3636
#include <credentials/attestation_verifier/DeviceAttestationVerifier.h>
37+
#include <protocols/secure_channel/SessionResumptionStorage.h>
3738

3839
namespace chip {
3940

@@ -106,8 +107,8 @@ struct SetupParams
106107
};
107108

108109
// TODO everything other than the fabric storage, group data provider, OperationalKeystore,
109-
// OperationalCertificateStore and SessionKeystore here should be removed. We're blocked
110-
// because of the need to support !CHIP_DEVICE_LAYER
110+
// OperationalCertificateStore, SessionKeystore, and SessionResumptionStorage here should
111+
// be removed. We're blocked because of the need to support !CHIP_DEVICE_LAYER
111112
struct FactoryInitParams
112113
{
113114
System::Layer * systemLayer = nullptr;
@@ -121,6 +122,7 @@ struct FactoryInitParams
121122
FabricTable * fabricTable = nullptr;
122123
OperationalKeystore * operationalKeystore = nullptr;
123124
Credentials::OperationalCertificateStore * opCertStore = nullptr;
125+
SessionResumptionStorage * sessionResumptionStorage = nullptr;
124126
#if CONFIG_NETWORK_LAYER_BLE
125127
Ble::BleLayer * bleLayer = nullptr;
126128
#endif
@@ -257,6 +259,7 @@ class DeviceControllerFactory
257259
Crypto::OperationalKeystore * mOperationalKeystore = nullptr;
258260
Credentials::OperationalCertificateStore * mOpCertStore = nullptr;
259261
Credentials::CertificateValidityPolicy * mCertificateValidityPolicy = nullptr;
262+
SessionResumptionStorage * mSessionResumptionStorage = nullptr;
260263
bool mEnableServerInteractions = false;
261264
};
262265

src/controller/CHIPDeviceControllerSystemState.h

+23-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,18 @@ struct DeviceControllerSystemStateParams
8585
Credentials::GroupDataProvider * groupDataProvider = nullptr;
8686
Crypto::SessionKeystore * sessionKeystore = nullptr;
8787

88+
// NOTE: Exactly one of externalSessionResumptionStorage (externally provided,
89+
// externally owned) or ownedSessionResumptionStorage (managed by the system
90+
// state) must be non-null.
91+
SessionResumptionStorage * externalSessionResumptionStorage = nullptr;
92+
8893
// Params that will be deallocated via Platform::Delete in
8994
// DeviceControllerSystemState::Shutdown.
9095
DeviceTransportMgr * transportMgr = nullptr;
91-
Platform::UniquePtr<SimpleSessionResumptionStorage> sessionResumptionStorage;
96+
// NOTE: Exactly one of externalSessionResumptionStorage (externally provided,
97+
// externally owned) or ownedSessionResumptionStorage (managed by the system
98+
// state) must be non-null.
99+
Platform::UniquePtr<SimpleSessionResumptionStorage> ownedSessionResumptionStorage;
92100
Credentials::CertificateValidityPolicy * certificateValidityPolicy = nullptr;
93101
SessionManager * sessionMgr = nullptr;
94102
Protocols::SecureChannel::UnsolicitedStatusHandler * unsolicitedStatusHandler = nullptr;
@@ -132,8 +140,18 @@ class DeviceControllerSystemState
132140
mCASESessionManager(params.caseSessionManager), mSessionSetupPool(params.sessionSetupPool),
133141
mCASEClientPool(params.caseClientPool), mGroupDataProvider(params.groupDataProvider), mTimerDelegate(params.timerDelegate),
134142
mReportScheduler(params.reportScheduler), mSessionKeystore(params.sessionKeystore),
135-
mFabricTableDelegate(params.fabricTableDelegate), mSessionResumptionStorage(std::move(params.sessionResumptionStorage))
143+
mFabricTableDelegate(params.fabricTableDelegate),
144+
mOwnedSessionResumptionStorage(std::move(params.ownedSessionResumptionStorage))
136145
{
146+
if (mOwnedSessionResumptionStorage)
147+
{
148+
mSessionResumptionStorage = mOwnedSessionResumptionStorage.get();
149+
}
150+
else
151+
{
152+
mSessionResumptionStorage = params.externalSessionResumptionStorage;
153+
}
154+
137155
#if CONFIG_NETWORK_LAYER_BLE
138156
mBleLayer = params.bleLayer;
139157
#endif
@@ -172,7 +190,7 @@ class DeviceControllerSystemState
172190
mUnsolicitedStatusHandler != nullptr && mExchangeMgr != nullptr && mMessageCounterManager != nullptr &&
173191
mFabrics != nullptr && mCASESessionManager != nullptr && mSessionSetupPool != nullptr && mCASEClientPool != nullptr &&
174192
mGroupDataProvider != nullptr && mReportScheduler != nullptr && mTimerDelegate != nullptr &&
175-
mSessionKeystore != nullptr;
193+
mSessionKeystore != nullptr && mSessionResumptionStorage != nullptr;
176194
};
177195

178196
System::Layer * SystemLayer() const { return mSystemLayer; };
@@ -221,7 +239,8 @@ class DeviceControllerSystemState
221239
app::reporting::ReportScheduler * mReportScheduler = nullptr;
222240
Crypto::SessionKeystore * mSessionKeystore = nullptr;
223241
FabricTable::Delegate * mFabricTableDelegate = nullptr;
224-
Platform::UniquePtr<SimpleSessionResumptionStorage> mSessionResumptionStorage;
242+
SessionResumptionStorage * mSessionResumptionStorage = nullptr;
243+
Platform::UniquePtr<SimpleSessionResumptionStorage> mOwnedSessionResumptionStorage;
225244

226245
// If mTempFabricTable is not null, it was created during
227246
// DeviceControllerFactory::InitSystemState and needs to be

0 commit comments

Comments
 (0)