@@ -1055,29 +1055,34 @@ WEAVE_ERROR WeaveSecurityManager::StartCASESession(WeaveConnection *con, uint64_
10551055
10561056void WeaveSecurityManager::StartCASESession (uint32_t config, uint32_t curveId)
10571057{
1058- WEAVE_ERROR err;
1059- CASE::BeginSessionRequestMessage req;
1060- PacketBuffer* msgBuf = NULL ;
1061- uint16_t sendFlags = 0 ;
1058+ WEAVE_ERROR err;
1059+ PacketBuffer * msgBuf = NULL ;
1060+ uint16_t sendFlags = 0 ;
10621061
10631062 // Allocate a buffer to hold the Begin Session message.
10641063 msgBuf = PacketBuffer::New ();
10651064 VerifyOrExit (msgBuf != NULL , err = WEAVE_ERROR_NO_MEMORY);
10661065
10671066 // Generate the CASE Begin Session message.
1068- req.Reset ();
1069- req.PeerNodeId = mEC ->PeerNodeId ;
1070- req.ProtocolConfig = config;
1071- mCASEEngine ->SetAlternateConfigs (req);
1072- req.CurveId = curveId;
1073- mCASEEngine ->SetAlternateCurves (req);
1074- req.PerformKeyConfirm = true ;
1075- req.SessionKeyId = mSessionKeyId ;
1076- req.EncryptionType = mEncType ;
1077- Platform::Security::OnTimeConsumingCryptoStart ();
1078- err = mCASEEngine ->GenerateBeginSessionRequest (req, msgBuf);
1079- Platform::Security::OnTimeConsumingCryptoDone ();
1080- SuccessOrExit (err);
1067+ {
1068+ CASE::BeginSessionRequestContext reqCtx;
1069+
1070+ reqCtx.Reset ();
1071+ reqCtx.SetIsInitiator (true );
1072+ reqCtx.PeerNodeId = mEC ->PeerNodeId ;
1073+ reqCtx.ProtocolConfig = config;
1074+ mCASEEngine ->SetAlternateConfigs (reqCtx);
1075+ reqCtx.CurveId = curveId;
1076+ mCASEEngine ->SetAlternateCurves (reqCtx);
1077+ reqCtx.SetPerformKeyConfirm (true );
1078+ reqCtx.SessionKeyId = mSessionKeyId ;
1079+ reqCtx.EncryptionType = mEncType ;
1080+
1081+ Platform::Security::OnTimeConsumingCryptoStart ();
1082+ err = mCASEEngine ->GenerateBeginSessionRequest (reqCtx, msgBuf);
1083+ Platform::Security::OnTimeConsumingCryptoDone ();
1084+ SuccessOrExit (err);
1085+ }
10811086
10821087#if WEAVE_CONFIG_ENABLE_RELIABLE_MESSAGING
10831088 if (mCon == NULL )
@@ -1133,12 +1138,15 @@ void WeaveSecurityManager::HandleCASEMessageInitiator(ExchangeContext *ec, const
11331138
11341139 // Decode and process the BeginSessionResponse.
11351140 {
1136- CASE::BeginSessionResponseMessage resp;
1137- resp.Reset ();
1138- resp.PeerNodeId = ec->PeerNodeId ;
1141+ CASE::BeginSessionResponseContext respCtx;
1142+
1143+ respCtx.Reset ();
1144+ respCtx.SetIsInitiator (true );
1145+ respCtx.PeerNodeId = ec->PeerNodeId ;
1146+ respCtx.MsgInfo = msgInfo;
11391147
11401148 Platform::Security::OnTimeConsumingCryptoStart ();
1141- err = secMgr->mCASEEngine ->ProcessBeginSessionResponse (msgBuf, resp );
1149+ err = secMgr->mCASEEngine ->ProcessBeginSessionResponse (msgBuf, respCtx );
11421150 Platform::Security::OnTimeConsumingCryptoDone ();
11431151 SuccessOrExit (err);
11441152 }
@@ -1193,8 +1201,8 @@ void WeaveSecurityManager::HandleCASEMessageInitiator(ExchangeContext *ec, const
11931201 {
11941202 // Process the reconfigure message. If this proposed alternate configuration is not acceptable,
11951203 // the call will fail with an error.
1196- CASE::ReconfigureMessage reconfMsg ;
1197- err = secMgr->mCASEEngine ->ProcessReconfigure (msgBuf, reconfMsg );
1204+ CASE::ReconfigureContext reconfCtx ;
1205+ err = secMgr->mCASEEngine ->ProcessReconfigure (msgBuf, reconfCtx );
11981206 SuccessOrExit (err);
11991207
12001208 // Release the buffer containing the response.
@@ -1208,7 +1216,7 @@ void WeaveSecurityManager::HandleCASEMessageInitiator(ExchangeContext *ec, const
12081216 SuccessOrExit (err);
12091217
12101218 // Restart the CASE session using the peer's propose parameters.
1211- secMgr->StartCASESession (reconfMsg .ProtocolConfig , reconfMsg .CurveId );
1219+ secMgr->StartCASESession (reconfCtx .ProtocolConfig , reconfCtx .CurveId );
12121220 }
12131221
12141222 // Fail if the message is unrecognized.
@@ -1238,12 +1246,12 @@ WEAVE_ERROR WeaveSecurityManager::StartCASESession(WeaveConnection *con, uint64_
12381246
12391247void WeaveSecurityManager::HandleCASESessionStart (ExchangeContext *ec, const IPPacketInfo *pktInfo, const WeaveMessageInfo *msgInfo, PacketBuffer* msgBuf)
12401248{
1241- WEAVE_ERROR err;
1242- WeaveSessionKey * sessionKey;
1243- CASE::BeginSessionRequestMessage req ;
1244- CASE::ReconfigureMessage reconf ;
1245- PacketBuffer * respMsgBuf = NULL ;
1246- uint16_t sendFlags = 0 ;
1249+ WEAVE_ERROR err;
1250+ WeaveSessionKey * sessionKey;
1251+ CASE::BeginSessionRequestContext reqCtx ;
1252+ CASE::ReconfigureContext reconfCtx ;
1253+ PacketBuffer * respMsgBuf = NULL ;
1254+ uint16_t sendFlags = 0 ;
12471255
12481256 State = kState_CASEInProgress ;
12491257 mEC = ec;
@@ -1293,11 +1301,12 @@ void WeaveSecurityManager::HandleCASESessionStart(ExchangeContext *ec, const IPP
12931301#endif
12941302
12951303 // Process the BeginSessionRequest
1296- req.Reset ();
1297- req.PeerNodeId = ec->PeerNodeId ;
1298- reconf.Reset ();
1304+ reqCtx.Reset ();
1305+ reqCtx.PeerNodeId = ec->PeerNodeId ;
1306+ reqCtx.MsgInfo = msgInfo;
1307+ reconfCtx.Reset ();
12991308 Platform::Security::OnTimeConsumingCryptoStart ();
1300- err = mCASEEngine ->ProcessBeginSessionRequest (msgBuf, req, reconf );
1309+ err = mCASEEngine ->ProcessBeginSessionRequest (msgBuf, reqCtx, reconfCtx );
13011310 Platform::Security::OnTimeConsumingCryptoDone ();
13021311 if (err != WEAVE_ERROR_CASE_RECONFIG_REQUIRED)
13031312 SuccessOrExit (err);
@@ -1312,7 +1321,7 @@ void WeaveSecurityManager::HandleCASESessionStart(ExchangeContext *ec, const IPP
13121321 // Encode a CASE Reconfigure message into a new buffer.
13131322 respMsgBuf = PacketBuffer::New ();
13141323 VerifyOrExit (respMsgBuf != NULL , err = WEAVE_ERROR_NO_MEMORY);
1315- err = reconf .Encode (respMsgBuf);
1324+ err = reconfCtx .Encode (respMsgBuf);
13161325 SuccessOrExit (err);
13171326
13181327 // Send the Reconfigure message to the peer.
@@ -1332,32 +1341,35 @@ void WeaveSecurityManager::HandleCASESessionStart(ExchangeContext *ec, const IPP
13321341 // be bound to the connection, such that when the connection closes, the key is removed.
13331342 // Set the RemoveOnIdle flag so that the session will be automatically removed after a period of
13341343 // inactivity (note that this only applies to sessions that are NOT bound to connections).
1335- err = FabricState->AllocSessionKey (ec->PeerNodeId , req .SessionKeyId , ec->Con , sessionKey);
1344+ err = FabricState->AllocSessionKey (ec->PeerNodeId , reqCtx .SessionKeyId , ec->Con , sessionKey);
13361345 SuccessOrExit (err);
13371346 sessionKey->SetLocallyInitiated (false );
13381347 sessionKey->SetRemoveOnIdle (true );
13391348
13401349 // Save the proposed session key id and encryption type.
1341- mSessionKeyId = req.SessionKeyId ;
1342- mEncType = req.EncryptionType ;
1343-
1344- // Prepare the contents of a BeginSessionResponse message to be sent to the initiator.
1345- CASE::BeginSessionResponseMessage resp;
1346- resp.Reset ();
1347- resp.PeerNodeId = ec->PeerNodeId ;
1348- resp.ProtocolConfig = req.ProtocolConfig ;
1349- resp.CurveId = req.CurveId ;
1350- resp.PerformKeyConfirm = true ;
1350+ mSessionKeyId = reqCtx.SessionKeyId ;
1351+ mEncType = reqCtx.EncryptionType ;
13511352
13521353 // Allocate a buffer to hold the encoded BeginSessionResponse message.
13531354 respMsgBuf = PacketBuffer::New ();
13541355 VerifyOrExit (respMsgBuf != NULL , err = WEAVE_ERROR_NO_MEMORY);
13551356
13561357 // Generate the BeginSessionResponse message.
1357- Platform::Security::OnTimeConsumingCryptoStart ();
1358- err = mCASEEngine ->GenerateBeginSessionResponse (resp, respMsgBuf, req);
1359- Platform::Security::OnTimeConsumingCryptoDone ();
1360- SuccessOrExit (err);
1358+ {
1359+ CASE::BeginSessionResponseContext respCtx;
1360+
1361+ respCtx.Reset ();
1362+ respCtx.PeerNodeId = ec->PeerNodeId ;
1363+ respCtx.MsgInfo = msgInfo;
1364+ respCtx.ProtocolConfig = reqCtx.ProtocolConfig ;
1365+ respCtx.CurveId = reqCtx.CurveId ;
1366+ respCtx.SetPerformKeyConfirm (true );
1367+
1368+ Platform::Security::OnTimeConsumingCryptoStart ();
1369+ err = mCASEEngine ->GenerateBeginSessionResponse (respCtx, respMsgBuf, reqCtx);
1370+ Platform::Security::OnTimeConsumingCryptoDone ();
1371+ SuccessOrExit (err);
1372+ }
13611373
13621374 // Send the BeginSessionResponse message to the peer.
13631375 err = ec->SendMessage (kWeaveProfile_Security , kMsgType_CASEBeginSessionResponse , respMsgBuf, sendFlags);
0 commit comments