50
50
#include < transport/SessionManager.h>
51
51
52
52
namespace {
53
-
53
+ // TBEDataTags works for both sigma-2-tbedata and sigma-3-tbedata as they have the same tag numbers for the elements common between
54
+ // them.
54
55
enum class TBEDataTags : uint8_t
55
56
{
56
57
kSenderNOC = 1 ,
@@ -59,6 +60,8 @@ enum class TBEDataTags : uint8_t
59
60
kResumptionID = 4 ,
60
61
};
61
62
63
+ // TBSDataTags works for both sigma-2-tbsdata and sigma-3-tbsdata as they have the same tag numbers for the elements common between
64
+ // them.
62
65
enum class TBSDataTags : uint8_t
63
66
{
64
67
kSenderNOC = 1 ,
@@ -69,30 +72,30 @@ enum class TBSDataTags : uint8_t
69
72
70
73
enum class Sigma1Tags : uint8_t
71
74
{
72
- kInitiatorRandom = 1 ,
73
- kInitiatorSessionId = 2 ,
74
- kDestinationId = 3 ,
75
- kInitiatorPubKey = 4 ,
76
- kInitiatorMRPParams = 5 ,
77
- kResumptionID = 6 ,
78
- kResume1MIC = 7 ,
75
+ kInitiatorRandom = 1 ,
76
+ kInitiatorSessionId = 2 ,
77
+ kDestinationId = 3 ,
78
+ kInitiatorEphPubKey = 4 ,
79
+ kInitiatorSessionParams = 5 ,
80
+ kResumptionID = 6 ,
81
+ kResume1MIC = 7 ,
79
82
};
80
83
81
84
enum class Sigma2Tags : uint8_t
82
85
{
83
- kResponderRandom = 1 ,
84
- kResponderSessionId = 2 ,
85
- kResponderEphPubKey = 3 ,
86
- kEncrypted2 = 4 ,
87
- kResponderMRPParams = 5 ,
86
+ kResponderRandom = 1 ,
87
+ kResponderSessionId = 2 ,
88
+ kResponderEphPubKey = 3 ,
89
+ kEncrypted2 = 4 ,
90
+ kResponderSessionParams = 5 ,
88
91
};
89
92
90
- enum class Sigma2ResTags : uint8_t
93
+ enum class Sigma2ResumeTags : uint8_t
91
94
{
92
- kResumptionID = 1 ,
93
- kSigma2ResumeMIC = 2 ,
94
- kResponderSessionID = 3 ,
95
- kResponderMRPParams = 4 ,
95
+ kResumptionID = 1 ,
96
+ kSigma2ResumeMIC = 2 ,
97
+ kResponderSessionID = 3 ,
98
+ kResponderSessionParams = 4 ,
96
99
};
97
100
98
101
enum class Sigma3Tags : uint8_t
@@ -104,7 +107,7 @@ enum class Sigma3Tags : uint8_t
104
107
template <typename Enum>
105
108
constexpr chip::TLV::Tag AsTlvContextTag (Enum e)
106
109
{
107
- return chip::TLV::ContextTag (static_cast <std:: underlying_type_t <Enum>> (e));
110
+ return chip::TLV::ContextTag (chip::to_underlying (e));
108
111
}
109
112
110
113
} // namespace
@@ -794,7 +797,6 @@ CHIP_ERROR CASESession::SendSigma1()
794
797
{
795
798
MATTER_TRACE_SCOPE (" SendSigma1" , " CASESession" );
796
799
797
- System::PacketBufferHandle msgR1;
798
800
uint8_t destinationIdentifier[kSHA256_Hash_Length ] = { 0 };
799
801
800
802
// Struct that will be used as input to EncodeSigma1() method
@@ -812,7 +814,7 @@ CHIP_ERROR CASESession::SendSigma1()
812
814
mEphemeralKey = mFabricsTable ->AllocateEphemeralKeypairForCASE ();
813
815
VerifyOrReturnError (mEphemeralKey != nullptr , CHIP_ERROR_NO_MEMORY);
814
816
ReturnErrorOnFailure (mEphemeralKey ->Initialize (ECPKeyTarget::ECDH));
815
- encodeSigma1Inputs.pEphPubKey = &mEphemeralKey ->Pubkey ();
817
+ encodeSigma1Inputs.initiatorEphPubKey = &mEphemeralKey ->Pubkey ();
816
818
817
819
// Fill in the random value
818
820
ReturnErrorOnFailure (DRBG_get_bytes (mInitiatorRandom , sizeof (mInitiatorRandom )));
@@ -847,7 +849,7 @@ CHIP_ERROR CASESession::SendSigma1()
847
849
{
848
850
// Found valid resumption state, try to resume the session.
849
851
encodeSigma1Inputs.resumptionId = mResumeResumptionId ;
850
- MutableByteSpan resumeMICSpan (encodeSigma1Inputs.initiatorResume1MIC );
852
+ MutableByteSpan resumeMICSpan (encodeSigma1Inputs.initiatorResume1MICBuffer );
851
853
ReturnErrorOnFailure (GenerateSigmaResumeMIC (encodeSigma1Inputs.initiatorRandom , encodeSigma1Inputs.resumptionId ,
852
854
ByteSpan (kKDFS1RKeyInfo ), ByteSpan (kResume1MIC_Nonce ), resumeMICSpan));
853
855
@@ -856,6 +858,8 @@ CHIP_ERROR CASESession::SendSigma1()
856
858
}
857
859
}
858
860
861
+ System::PacketBufferHandle msgR1;
862
+
859
863
// Encode Sigma1 in CHIP TLV Format
860
864
ReturnErrorOnFailure (EncodeSigma1 (msgR1, encodeSigma1Inputs));
861
865
@@ -893,9 +897,9 @@ CHIP_ERROR CASESession::EncodeSigma1(System::PacketBufferHandle & msg, EncodeSig
893
897
{
894
898
MATTER_TRACE_SCOPE (" EncodeSigma1" , " CASESession" );
895
899
896
- // the PacketBufferHandler should be empty
900
+ // The API Contract requires the passed PacketBufferHandle to be empty
897
901
VerifyOrReturnError (msg.IsNull (), CHIP_ERROR_INCORRECT_STATE);
898
- VerifyOrReturnError (input.pEphPubKey != nullptr , CHIP_ERROR_INCORRECT_STATE );
902
+ VerifyOrReturnError (input.initiatorEphPubKey != nullptr , CHIP_ERROR_INVALID_ARGUMENT );
899
903
900
904
size_t dataLen = EstimateStructOverhead (kSigmaParamRandomNumberSize , // initiatorRandom
901
905
sizeof (uint16_t ), // initiatorSessionId,
@@ -910,20 +914,20 @@ CHIP_ERROR CASESession::EncodeSigma1(System::PacketBufferHandle & msg, EncodeSig
910
914
VerifyOrReturnError (!msg.IsNull (), CHIP_ERROR_NO_MEMORY);
911
915
912
916
System::PacketBufferTLVWriter tlvWriter;
913
- TLVType outerContainerType = kTLVType_NotSpecified ;
914
-
915
917
tlvWriter.Init (std::move (msg));
918
+
919
+ TLVType outerContainerType = kTLVType_NotSpecified ;
916
920
ReturnErrorOnFailure (tlvWriter.StartContainer (AnonymousTag (), kTLVType_Structure , outerContainerType));
917
921
ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma1Tags::kInitiatorRandom ), input.initiatorRandom ));
918
922
ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma1Tags::kInitiatorSessionId ), input.initiatorSessionId ));
919
923
ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma1Tags::kDestinationId ), input.destinationId ));
920
924
921
- ReturnErrorOnFailure (tlvWriter.PutBytes (AsTlvContextTag (Sigma1Tags::kInitiatorPubKey ), *input.pEphPubKey ,
922
- static_cast <uint32_t >(input.pEphPubKey ->Length ())));
925
+ ReturnErrorOnFailure (tlvWriter.PutBytes (AsTlvContextTag (Sigma1Tags::kInitiatorEphPubKey ), *input.initiatorEphPubKey ,
926
+ static_cast <uint32_t >(input.initiatorEphPubKey ->Length ())));
923
927
924
- VerifyOrReturnError (input.initiatorMrpConfig != nullptr , CHIP_ERROR_INCORRECT_STATE );
928
+ VerifyOrReturnError (input.initiatorMrpConfig != nullptr , CHIP_ERROR_INVALID_ARGUMENT );
925
929
ReturnErrorOnFailure (
926
- EncodeSessionParameters (AsTlvContextTag (Sigma1Tags::kInitiatorMRPParams ), *input.initiatorMrpConfig , tlvWriter));
930
+ EncodeSessionParameters (AsTlvContextTag (Sigma1Tags::kInitiatorSessionParams ), *input.initiatorMrpConfig , tlvWriter));
927
931
928
932
if (input.sessionResumptionRequested )
929
933
{
@@ -942,21 +946,22 @@ CHIP_ERROR CASESession::HandleSigma1_and_SendSigma2(System::PacketBufferHandle &
942
946
MATTER_TRACE_SCOPE (" HandleSigma1_and_SendSigma2" , " CASESession" );
943
947
944
948
CHIP_ERROR err = CHIP_NO_ERROR;
949
+ Step nextStep = Step::kNone ;
945
950
946
951
// Parse and Validate Received Sigma1, and decide next step
947
- SuccessOrExit (err = HandleSigma1 (std::move (msg)));
952
+ SuccessOrExit (err = HandleSigma1 (std::move (msg), nextStep ));
948
953
949
- switch (mNextStep )
954
+ switch (nextStep )
950
955
{
951
956
case Step::kSendSigma2 : {
952
957
953
958
System::PacketBufferHandle msgR2;
954
959
EncodeSigma2Inputs encodeSigma2;
955
960
956
- MATTER_LOG_METRIC_BEGIN (kMetricDeviceCASESessionSigma2 );
957
-
958
961
SuccessOrExit (err = PrepareSigma2 (encodeSigma2));
959
962
SuccessOrExit (err = EncodeSigma2 (msgR2, encodeSigma2));
963
+
964
+ MATTER_LOG_METRIC_BEGIN (kMetricDeviceCASESessionSigma2 );
960
965
SuccessOrExitAction (err = SendSigma2 (std::move (msgR2)), MATTER_LOG_METRIC_END (kMetricDeviceCASESessionSigma2 , err));
961
966
962
967
mDelegate ->OnSessionEstablishmentStarted ();
@@ -965,12 +970,12 @@ CHIP_ERROR CASESession::HandleSigma1_and_SendSigma2(System::PacketBufferHandle &
965
970
case Step::kSendSigma2Resume : {
966
971
967
972
System::PacketBufferHandle msgR2Resume;
968
- EncodeSigma2ResInputs encodeSigma2Resume;
969
-
970
- MATTER_LOG_METRIC_BEGIN (kMetricDeviceCASESessionSigma2Resume );
973
+ EncodeSigma2ResumeInputs encodeSigma2Resume;
971
974
972
975
SuccessOrExit (err = PrepareSigma2Resume (encodeSigma2Resume));
973
976
SuccessOrExit (err = EncodeSigma2Resume (msgR2Resume, encodeSigma2Resume));
977
+
978
+ MATTER_LOG_METRIC_BEGIN (kMetricDeviceCASESessionSigma2Resume );
974
979
SuccessOrExitAction (err = SendSigma2Resume (std::move (msgR2Resume)),
975
980
MATTER_LOG_METRIC_END (kMetricDeviceCASESessionSigma2Resume , err));
976
981
@@ -1077,8 +1082,7 @@ CHIP_ERROR CASESession::TryResumeSession(SessionResumptionStorage::ConstResumpti
1077
1082
1078
1083
return CHIP_NO_ERROR;
1079
1084
}
1080
-
1081
- CHIP_ERROR CASESession::HandleSigma1 (System::PacketBufferHandle && msg)
1085
+ CHIP_ERROR CASESession::HandleSigma1 (System::PacketBufferHandle && msg, Step & nextStep)
1082
1086
{
1083
1087
MATTER_TRACE_SCOPE (" HandleSigma1" , " CASESession" );
1084
1088
ChipLogProgress (SecureChannel, " Received Sigma1 msg" );
@@ -1088,8 +1092,6 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg)
1088
1092
1089
1093
ReturnErrorOnFailure (mCommissioningHash .AddData (ByteSpan{ msg->Start (), msg->DataLength () }));
1090
1094
1091
- CHIP_ERROR err = CHIP_NO_ERROR;
1092
-
1093
1095
System::PacketBufferTLVReader tlvReader;
1094
1096
tlvReader.Init (std::move (msg));
1095
1097
@@ -1118,7 +1120,7 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg)
1118
1120
std::copy (parsedSigma1.resumptionId .begin (), parsedSigma1.resumptionId .end (), mResumeResumptionId .begin ());
1119
1121
1120
1122
// Next Step is to send Sigma2Resume message to the initiator
1121
- mNextStep = Step::kSendSigma2Resume ;
1123
+ nextStep = Step::kSendSigma2Resume ;
1122
1124
1123
1125
// Early returning here, since the next Step is known to be Sigma2Resume, and no further processing is needed for the
1124
1126
// Sigma1 message
@@ -1129,6 +1131,8 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg)
1129
1131
// mRemotePubKey.Length() == initiatorPubKey.size() == kP256_PublicKey_Length.
1130
1132
memcpy (mRemotePubKey .Bytes (), parsedSigma1.initiatorEphPubKey .data (), mRemotePubKey .Length ());
1131
1133
1134
+ CHIP_ERROR err = CHIP_NO_ERROR;
1135
+
1132
1136
// Attempt to match the initiator's desired destination based on local fabric table.
1133
1137
err = FindLocalNodeFromDestinationId (parsedSigma1.destinationId , parsedSigma1.initiatorRandom );
1134
1138
if (err == CHIP_NO_ERROR)
@@ -1139,7 +1143,7 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg)
1139
1143
// Side-effect of FindLocalNodeFromDestinationId success was that mFabricIndex/mLocalNodeId are now
1140
1144
// set to the local fabric and associated NodeId that was targeted by the initiator.
1141
1145
1142
- mNextStep = Step::kSendSigma2 ;
1146
+ nextStep = Step::kSendSigma2 ;
1143
1147
}
1144
1148
else
1145
1149
{
@@ -1148,15 +1152,15 @@ CHIP_ERROR CASESession::HandleSigma1(System::PacketBufferHandle && msg)
1148
1152
1149
1153
// FindLocalNodeFromDestinationId returns CHIP_ERROR_KEY_NOT_FOUND if validation of DestinationID fails, which will trigger
1150
1154
// status Report with ProtocolCode = NoSharedTrustRoots.
1151
- mNextStep = Step::kSendStatusReport ;
1155
+ nextStep = Step::kSendStatusReport ;
1152
1156
1153
1157
return err;
1154
1158
}
1155
1159
1156
1160
return CHIP_NO_ERROR;
1157
1161
}
1158
1162
1159
- CHIP_ERROR CASESession::PrepareSigma2Resume (EncodeSigma2ResInputs & outSigma2ResData)
1163
+ CHIP_ERROR CASESession::PrepareSigma2Resume (EncodeSigma2ResumeInputs & outSigma2ResData)
1160
1164
{
1161
1165
MATTER_TRACE_SCOPE (" PrepareSigma2Resume" , " CASESession" );
1162
1166
@@ -1178,13 +1182,13 @@ CHIP_ERROR CASESession::PrepareSigma2Resume(EncodeSigma2ResInputs & outSigma2Res
1178
1182
return CHIP_NO_ERROR;
1179
1183
}
1180
1184
1181
- CHIP_ERROR CASESession::EncodeSigma2Resume (System::PacketBufferHandle & msgR2Resume, EncodeSigma2ResInputs & input)
1185
+ CHIP_ERROR CASESession::EncodeSigma2Resume (System::PacketBufferHandle & msgR2Resume, EncodeSigma2ResumeInputs & input)
1182
1186
{
1183
1187
MATTER_TRACE_SCOPE (" EncodeSigma2Resume" , " CASESession" );
1184
1188
1185
- // the passed PacketBufferHandler should be empty
1189
+ // The API Contract requires the passed PacketBufferHandle to be empty
1186
1190
VerifyOrReturnError (msgR2Resume.IsNull (), CHIP_ERROR_INCORRECT_STATE);
1187
- VerifyOrReturnError (input.responderMrpConfig != nullptr , CHIP_ERROR_INCORRECT_STATE );
1191
+ VerifyOrReturnError (input.responderMrpConfig != nullptr , CHIP_ERROR_INVALID_ARGUMENT );
1188
1192
1189
1193
size_t maxDatalLen = EstimateStructOverhead (SessionResumptionStorage::kResumptionIdSize , // resumptionID
1190
1194
CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES, // sigma2ResumeMIC
@@ -1196,17 +1200,17 @@ CHIP_ERROR CASESession::EncodeSigma2Resume(System::PacketBufferHandle & msgR2Res
1196
1200
VerifyOrReturnError (!msgR2Resume.IsNull (), CHIP_ERROR_NO_MEMORY);
1197
1201
1198
1202
System::PacketBufferTLVWriter tlvWriter;
1199
- TLVType outerContainerType = kTLVType_NotSpecified ;
1200
-
1201
1203
tlvWriter.Init (std::move (msgR2Resume));
1202
1204
1205
+ TLVType outerContainerType = kTLVType_NotSpecified ;
1206
+
1203
1207
ReturnErrorOnFailure (tlvWriter.StartContainer (AnonymousTag (), kTLVType_Structure , outerContainerType));
1204
- ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma2ResTags ::kResumptionID ), input.resumptionId ));
1205
- ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma2ResTags ::kSigma2ResumeMIC ), input.resumeMICSpan ));
1206
- ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma2ResTags ::kResponderSessionID ), input.responderSessionId ));
1208
+ ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma2ResumeTags ::kResumptionID ), input.resumptionId ));
1209
+ ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma2ResumeTags ::kSigma2ResumeMIC ), input.resumeMICSpan ));
1210
+ ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (Sigma2ResumeTags ::kResponderSessionID ), input.responderSessionId ));
1207
1211
1208
1212
ReturnErrorOnFailure (
1209
- EncodeSessionParameters (AsTlvContextTag (Sigma2ResTags:: kResponderMRPParams ), *input.responderMrpConfig , tlvWriter));
1213
+ EncodeSessionParameters (AsTlvContextTag (Sigma2ResumeTags:: kResponderSessionParams ), *input.responderMrpConfig , tlvWriter));
1210
1214
1211
1215
ReturnErrorOnFailure (tlvWriter.EndContainer (outerContainerType));
1212
1216
ReturnErrorOnFailure (tlvWriter.Finalize (&msgR2Resume));
@@ -1257,7 +1261,7 @@ CHIP_ERROR CASESession::PrepareSigma2(EncodeSigma2Inputs & outSigma2Data)
1257
1261
mEphemeralKey = mFabricsTable ->AllocateEphemeralKeypairForCASE ();
1258
1262
VerifyOrReturnError (mEphemeralKey != nullptr , CHIP_ERROR_NO_MEMORY);
1259
1263
ReturnErrorOnFailure (mEphemeralKey ->Initialize (ECPKeyTarget::ECDH));
1260
- outSigma2Data.pEphPubKey = &mEphemeralKey ->Pubkey ();
1264
+ outSigma2Data.responderEphPubKey = &mEphemeralKey ->Pubkey ();
1261
1265
1262
1266
// Generate a Shared Secret
1263
1267
ReturnErrorOnFailure (mEphemeralKey ->ECDH_derive_secret (mRemotePubKey , mSharedSecret ));
@@ -1301,9 +1305,10 @@ CHIP_ERROR CASESession::PrepareSigma2(EncodeSigma2Inputs & outSigma2Data)
1301
1305
CHIP_ERROR_NO_MEMORY);
1302
1306
1303
1307
TLVWriter tlvWriter;
1308
+ tlvWriter.Init (outSigma2Data.msgR2Encrypted .Get (), msgR2SignedEncLen);
1309
+
1304
1310
TLVType outerContainerType = kTLVType_NotSpecified ;
1305
1311
1306
- tlvWriter.Init (outSigma2Data.msgR2Encrypted .Get (), msgR2SignedEncLen);
1307
1312
ReturnErrorOnFailure (tlvWriter.StartContainer (AnonymousTag (), kTLVType_Structure , outerContainerType));
1308
1313
ReturnErrorOnFailure (tlvWriter.Put (AsTlvContextTag (TBEDataTags::kSenderNOC ), nocCert));
1309
1314
if (!icaCert.empty ())
@@ -1344,14 +1349,13 @@ CHIP_ERROR CASESession::PrepareSigma2(EncodeSigma2Inputs & outSigma2Data)
1344
1349
1345
1350
CHIP_ERROR CASESession::EncodeSigma2 (System::PacketBufferHandle & msgR2, EncodeSigma2Inputs & input)
1346
1351
{
1347
- // the PacketBufferHandler should be empty
1352
+ // The API Contract requires the passed PacketBufferHandle to be empty
1348
1353
VerifyOrReturnError (msgR2.IsNull (), CHIP_ERROR_INCORRECT_STATE);
1349
- VerifyOrReturnError (input.pEphPubKey != nullptr , CHIP_ERROR_INCORRECT_STATE);
1350
- // Check if msgR2Encrypted is not nullptr
1354
+ VerifyOrReturnError (input.responderEphPubKey != nullptr , CHIP_ERROR_INVALID_ARGUMENT);
1351
1355
VerifyOrReturnError (input.msgR2Encrypted , CHIP_ERROR_INCORRECT_STATE);
1352
1356
// Check if length of msgR2Encrypted is set and is at least larger than the MIC length
1353
1357
VerifyOrReturnError (input.encrypted2Length > CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES, CHIP_ERROR_INCORRECT_STATE);
1354
- VerifyOrReturnError (input.responderMrpConfig != nullptr , CHIP_ERROR_INCORRECT_STATE );
1358
+ VerifyOrReturnError (input.responderMrpConfig != nullptr , CHIP_ERROR_INVALID_ARGUMENT );
1355
1359
1356
1360
size_t dataLen = EstimateStructOverhead (kSigmaParamRandomNumberSize , // responderRandom
1357
1361
sizeof (uint16_t ), // responderSessionId
@@ -1364,23 +1368,25 @@ CHIP_ERROR CASESession::EncodeSigma2(System::PacketBufferHandle & msgR2, EncodeS
1364
1368
VerifyOrReturnError (!msgR2.IsNull (), CHIP_ERROR_NO_MEMORY);
1365
1369
1366
1370
System::PacketBufferTLVWriter tlvWriterMsg2;
1371
+ tlvWriterMsg2.Init (std::move (msgR2));
1372
+
1367
1373
TLVType outerContainerType = kTLVType_NotSpecified ;
1368
1374
1369
- tlvWriterMsg2.Init (std::move (msgR2));
1370
1375
ReturnErrorOnFailure (tlvWriterMsg2.StartContainer (AnonymousTag (), kTLVType_Structure , outerContainerType));
1371
1376
1372
1377
ReturnErrorOnFailure (tlvWriterMsg2.PutBytes (AsTlvContextTag (Sigma2Tags::kResponderRandom ), &input.responderRandom [0 ],
1373
1378
sizeof (input.responderRandom )));
1374
1379
ReturnErrorOnFailure (tlvWriterMsg2.Put (AsTlvContextTag (Sigma2Tags::kResponderSessionId ), input.responderSessionId ));
1375
1380
1376
- ReturnErrorOnFailure (tlvWriterMsg2.PutBytes (AsTlvContextTag (Sigma2Tags::kResponderEphPubKey ), *input.pEphPubKey ,
1377
- static_cast <uint32_t >(input.pEphPubKey ->Length ())));
1381
+ ReturnErrorOnFailure (tlvWriterMsg2.PutBytes (AsTlvContextTag (Sigma2Tags::kResponderEphPubKey ), *input.responderEphPubKey ,
1382
+ static_cast <uint32_t >(input.responderEphPubKey ->Length ())));
1378
1383
1379
1384
ReturnErrorOnFailure (tlvWriterMsg2.PutBytes (AsTlvContextTag (Sigma2Tags::kEncrypted2 ), input.msgR2Encrypted .Get (),
1380
1385
static_cast <uint32_t >(input.encrypted2Length )));
1386
+ input.msgR2Encrypted .Free ();
1381
1387
1382
1388
ReturnErrorOnFailure (
1383
- EncodeSessionParameters (AsTlvContextTag (Sigma2Tags::kResponderMRPParams ), *input.responderMrpConfig , tlvWriterMsg2));
1389
+ EncodeSessionParameters (AsTlvContextTag (Sigma2Tags::kResponderSessionParams ), *input.responderMrpConfig , tlvWriterMsg2));
1384
1390
1385
1391
ReturnErrorOnFailure (tlvWriterMsg2.EndContainer (outerContainerType));
1386
1392
ReturnErrorOnFailure (tlvWriterMsg2.Finalize (&msgR2));
@@ -1649,7 +1655,7 @@ CHIP_ERROR CASESession::HandleSigma2(System::PacketBufferHandle && msg)
1649
1655
// Retrieve responderMRPParams if present
1650
1656
if (tlvReader.Next () != CHIP_END_OF_TLV)
1651
1657
{
1652
- SuccessOrExit (err = DecodeMRPParametersIfPresent (AsTlvContextTag (Sigma2Tags::kResponderMRPParams ), tlvReader));
1658
+ SuccessOrExit (err = DecodeMRPParametersIfPresent (AsTlvContextTag (Sigma2Tags::kResponderSessionParams ), tlvReader));
1653
1659
mExchangeCtxt .Value ()->GetSessionHandle ()->AsUnauthenticatedSession ()->SetRemoteSessionParameters (
1654
1660
GetRemoteSessionParameters ());
1655
1661
}
@@ -2327,15 +2333,15 @@ CHIP_ERROR CASESession::ParseSigma1(TLV::ContiguousBufferTLVReader & tlvReader,
2327
2333
ReturnErrorOnFailure (tlvReader.GetByteView (outParsedSigma1.destinationId ));
2328
2334
VerifyOrReturnError (outParsedSigma1.destinationId .size () == kSHA256_Hash_Length , CHIP_ERROR_INVALID_CASE_PARAMETER);
2329
2335
2330
- ReturnErrorOnFailure (tlvReader.Next (AsTlvContextTag (Sigma1Tags::kInitiatorPubKey )));
2336
+ ReturnErrorOnFailure (tlvReader.Next (AsTlvContextTag (Sigma1Tags::kInitiatorEphPubKey )));
2331
2337
ReturnErrorOnFailure (tlvReader.GetByteView (outParsedSigma1.initiatorEphPubKey ));
2332
2338
VerifyOrReturnError (outParsedSigma1.initiatorEphPubKey .size () == kP256_PublicKey_Length , CHIP_ERROR_INVALID_CASE_PARAMETER);
2333
2339
2334
2340
// Optional members start here.
2335
2341
CHIP_ERROR err = tlvReader.Next ();
2336
- if (err == CHIP_NO_ERROR && tlvReader.GetTag () == AsTlvContextTag (Sigma1Tags::kInitiatorMRPParams ))
2342
+ if (err == CHIP_NO_ERROR && tlvReader.GetTag () == AsTlvContextTag (Sigma1Tags::kInitiatorSessionParams ))
2337
2343
{
2338
- ReturnErrorOnFailure (DecodeMRPParametersIfPresent (AsTlvContextTag (Sigma1Tags::kInitiatorMRPParams ), tlvReader));
2344
+ ReturnErrorOnFailure (DecodeMRPParametersIfPresent (AsTlvContextTag (Sigma1Tags::kInitiatorSessionParams ), tlvReader));
2339
2345
outParsedSigma1.initiatorMrpParamsPresent = true ;
2340
2346
2341
2347
err = tlvReader.Next ();
0 commit comments