Skip to content

Commit a30fc3c

Browse files
committed
more comments
1 parent 993edbd commit a30fc3c

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

src/protocols/secure_channel/CASESession.cpp

+5-11
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ CHIP_ERROR CASESession::SendSigma1()
853853
ReturnErrorOnFailure(GenerateSigmaResumeMIC(encodeSigma1Inputs.initiatorRandom, encodeSigma1Inputs.resumptionId,
854854
ByteSpan(kKDFS1RKeyInfo), ByteSpan(kResume1MIC_Nonce), resumeMICSpan));
855855

856-
encodeSigma1Inputs.initiatorResumeMICSpan = resumeMICSpan;
856+
encodeSigma1Inputs.initiatorResumeMIC = resumeMICSpan;
857857
encodeSigma1Inputs.sessionResumptionRequested = true;
858858
}
859859
}
@@ -897,8 +897,6 @@ CHIP_ERROR CASESession::EncodeSigma1(System::PacketBufferHandle & msg, EncodeSig
897897
{
898898
MATTER_TRACE_SCOPE("EncodeSigma1", "CASESession");
899899

900-
// The API Contract requires the passed PacketBufferHandle to be empty
901-
VerifyOrReturnError(msg.IsNull(), CHIP_ERROR_INCORRECT_STATE);
902900
VerifyOrReturnError(input.initiatorEphPubKey != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
903901

904902
size_t dataLen = EstimateStructOverhead(kSigmaParamRandomNumberSize, // initiatorRandom
@@ -932,7 +930,7 @@ CHIP_ERROR CASESession::EncodeSigma1(System::PacketBufferHandle & msg, EncodeSig
932930
if (input.sessionResumptionRequested)
933931
{
934932
ReturnErrorOnFailure(tlvWriter.Put(AsTlvContextTag(Sigma1Tags::kResumptionID), input.resumptionId));
935-
ReturnErrorOnFailure(tlvWriter.Put(AsTlvContextTag(Sigma1Tags::kResume1MIC), input.initiatorResumeMICSpan));
933+
ReturnErrorOnFailure(tlvWriter.Put(AsTlvContextTag(Sigma1Tags::kResume1MIC), input.initiatorResumeMIC));
936934
}
937935

938936
ReturnErrorOnFailure(tlvWriter.EndContainer(outerContainerType));
@@ -1110,7 +1108,7 @@ CASESession::NextStep CASESession::HandleSigma1(System::PacketBufferHandle && ms
11101108
parsedSigma1.resumptionId.size() == SessionResumptionStorage::kResumptionIdSize &&
11111109
CHIP_NO_ERROR ==
11121110
TryResumeSession(SessionResumptionStorage::ConstResumptionIdView(parsedSigma1.resumptionId.data()),
1113-
parsedSigma1.initiatorResumeMICSpan, parsedSigma1.initiatorRandom))
1111+
parsedSigma1.initiatorResumeMIC, parsedSigma1.initiatorRandom))
11141112
{
11151113
std::copy(parsedSigma1.initiatorRandom.begin(), parsedSigma1.initiatorRandom.end(), mInitiatorRandom);
11161114
std::copy(parsedSigma1.resumptionId.begin(), parsedSigma1.resumptionId.end(), mResumeResumptionId.begin());
@@ -1175,8 +1173,6 @@ CHIP_ERROR CASESession::EncodeSigma2Resume(System::PacketBufferHandle & msgR2Res
11751173
{
11761174
MATTER_TRACE_SCOPE("EncodeSigma2Resume", "CASESession");
11771175

1178-
// The API Contract requires the passed PacketBufferHandle to be empty
1179-
VerifyOrReturnError(msgR2Resume.IsNull(), CHIP_ERROR_INCORRECT_STATE);
11801176
VerifyOrReturnError(input.responderMrpConfig != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
11811177

11821178
size_t maxDatalLen = EstimateStructOverhead(SessionResumptionStorage::kResumptionIdSize, // resumptionID
@@ -1338,8 +1334,6 @@ CHIP_ERROR CASESession::PrepareSigma2(EncodeSigma2Inputs & outSigma2Data)
13381334

13391335
CHIP_ERROR CASESession::EncodeSigma2(System::PacketBufferHandle & msgR2, EncodeSigma2Inputs & input)
13401336
{
1341-
// The API Contract requires the passed PacketBufferHandle to be empty
1342-
VerifyOrReturnError(msgR2.IsNull(), CHIP_ERROR_INCORRECT_STATE);
13431337
VerifyOrReturnError(input.responderEphPubKey != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
13441338
VerifyOrReturnError(input.msgR2Encrypted, CHIP_ERROR_INCORRECT_STATE);
13451339
// Check if length of msgR2Encrypted is set and is at least larger than the MIC length
@@ -2351,8 +2345,8 @@ CHIP_ERROR CASESession::ParseSigma1(TLV::ContiguousBufferTLVReader & tlvReader,
23512345
if (err == CHIP_NO_ERROR && tlvReader.GetTag() == AsTlvContextTag(Sigma1Tags::kResume1MIC))
23522346
{
23532347
resume1MICTagFound = true;
2354-
ReturnErrorOnFailure(tlvReader.GetByteView(outParsedSigma1.initiatorResumeMICSpan));
2355-
VerifyOrReturnError(outParsedSigma1.initiatorResumeMICSpan.size() == CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES,
2348+
ReturnErrorOnFailure(tlvReader.GetByteView(outParsedSigma1.initiatorResumeMIC));
2349+
VerifyOrReturnError(outParsedSigma1.initiatorResumeMIC.size() == CHIP_CRYPTO_AEAD_MIC_LENGTH_BYTES,
23562350
CHIP_ERROR_INVALID_CASE_PARAMETER);
23572351
err = tlvReader.Next();
23582352
}

src/protocols/secure_channel/CASESession.h

+8-11
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
210210
ByteSpan destinationId;
211211
bool sessionResumptionRequested = false;
212212
ByteSpan resumptionId;
213-
ByteSpan initiatorResumeMICSpan;
213+
ByteSpan initiatorResumeMIC;
214214
};
215215

216216
struct EncodeSigma1Inputs : Sigma1Param
@@ -251,12 +251,11 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
251251
* @brief Encodes a Sigma1 message into TLV format and allocates a buffer for it, which is owned by the PacketBufferHandle
252252
*outparam.
253253
*
254-
* @param outMsg PacketBufferHandle passed by reference. The handle must be empty prior to calling this method,
255-
* as a new buffer will be allocated and assigned to it within the method.
254+
* @param outMsg PacketBufferHandle passed by reference. A new buffer will be allocated and assigned to it within the
255+
*method.
256256
*
257257
* @param inParam a struct containing all the values that will be encoded into TLV format
258258
*
259-
* @note the passed PacketBufferHandle `outMsg` must not be holding an existing PacketBuffer.
260259
**/
261260
static CHIP_ERROR EncodeSigma1(System::PacketBufferHandle & outMsg, EncodeSigma1Inputs & inParam);
262261

@@ -274,7 +273,7 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
274273
* These values will be valid as long as the buffer that the passed-in tlvReader is reading from is valid.
275274
*
276275
* On success, either the sessionResumptionRequested field will be set to true
277-
* and the resumptionID and initiatorResumeMICSpan fields will be set to
276+
* and the resumptionID and initiatorResumeMIC fields will be set to
278277
* valid values, or the sessionResumptionRequested field will be set to false.
279278
*/
280279
CHIP_ERROR ParseSigma1(TLV::ContiguousBufferTLVReader & tlvReader, ParsedSigma1 & parsedMessage);
@@ -283,12 +282,11 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
283282
* @brief Encodes a Sigma2 message into TLV format and allocates a buffer for it, which is owned by the PacketBufferHandle
284283
*outparam.
285284
*
286-
* @param outMsg PacketBufferHandle passed by reference. The handle must be empty prior to calling this method,
287-
* as a new buffer will be allocated and assigned to it within the method.
285+
* @param outMsg PacketBufferHandle passed by reference. A new buffer will be allocated and assigned to it within the
286+
*method.
288287
*
289288
* @param inParam a struct containing all the values that will be encoded into TLV format
290289
*
291-
* @note the passed PacketBufferHandle `outMsg` must be in a null state.
292290
**/
293291

294292
static CHIP_ERROR EncodeSigma2(System::PacketBufferHandle & outMsg, EncodeSigma2Inputs & inParam);
@@ -297,12 +295,11 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
297295
* @brief Encodes a Sigma2_Resume message into TLV format and allocates a buffer for it, which is owned by the
298296
*PacketBufferHandle outparam.
299297
*
300-
* @param outMsg PacketBufferHandle passed by reference. The handle must be empty prior to calling this method,
301-
* as a new buffer will be allocated and assigned to it within the method.
298+
* @param outMsg PacketBufferHandle passed by reference. A new buffer will be allocated and assigned to it within the
299+
*method.
302300
*
303301
* @param inParam a struct containing all the values that will be encoded into TLV format
304302
*
305-
* @note the passed PacketBufferHandle `outMsg` must be in a null state.
306303
**/
307304
static CHIP_ERROR EncodeSigma2Resume(System::PacketBufferHandle & outMsg, EncodeSigma2ResumeInputs & inParam);
308305

src/protocols/secure_channel/tests/TestCASESession.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ TEST_F(TestCASESession, EncodeSigma1Test)
967967
CHIP_NO_ERROR);
968968

969969
encodeParams.resumptionId = ByteSpan(resumptionId.data(), resumptionId.size());
970-
encodeParams.initiatorResumeMICSpan = ByteSpan(encodeParams.initiatorResume1MICBuffer);
970+
encodeParams.initiatorResumeMIC = ByteSpan(encodeParams.initiatorResume1MICBuffer);
971971
encodeParams.sessionResumptionRequested = true;
972972

973973
System::PacketBufferHandle msg2;
@@ -990,7 +990,7 @@ TEST_F(TestCASESession, EncodeSigma1Test)
990990
ByteSpan(encodeParams.initiatorEphPubKey->ConstBytes(), encodeParams.initiatorEphPubKey->Length())));
991991

992992
EXPECT_TRUE(parseParams.resumptionId.data_equal(encodeParams.resumptionId));
993-
EXPECT_TRUE(parseParams.initiatorResumeMICSpan.data_equal(encodeParams.initiatorResumeMICSpan));
993+
EXPECT_TRUE(parseParams.initiatorResumeMIC.data_equal(encodeParams.initiatorResumeMIC));
994994
EXPECT_TRUE(parseParams.initiatorMrpParamsPresent);
995995
}
996996
// Release EphemeralKeyPair

0 commit comments

Comments
 (0)