Skip to content

Commit

Permalink
Integrating Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alami-Amine committed Jan 7, 2025
1 parent c6018c1 commit a50db92
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/protocols/secure_channel/CASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ CASESession::NextStep CASESession::HandleSigma1(System::PacketBufferHandle && ms
SetPeerSessionId(parsedSigma1.initiatorSessionId);

// Set the Session parameters provided in the Sigma1 message
if (parsedSigma1.initiatorSessionParamsPresent)
if (parsedSigma1.initiatorSessionParamStructPresent)
{
SetRemoteSessionParameters(parsedSigma1.initiatorSessionParams);
mExchangeCtxt.Value()->GetSessionHandle()->AsUnauthenticatedSession()->SetRemoteSessionParameters(
Expand Down Expand Up @@ -2328,7 +2328,7 @@ CHIP_ERROR CASESession::ParseSigma1(TLV::ContiguousBufferTLVReader & tlvReader,
{
ReturnErrorOnFailure(DecodeSessionParametersIfPresent(AsTlvContextTag(Sigma1Tags::kInitiatorSessionParams), tlvReader,
outParsedSigma1.initiatorSessionParams));
outParsedSigma1.initiatorSessionParamsPresent = true;
outParsedSigma1.initiatorSessionParamStructPresent = true;

err = tlvReader.Next();
}
Expand Down
4 changes: 3 additions & 1 deletion src/protocols/secure_channel/CASESession.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
struct ParsedSigma1 : Sigma1Param
{
ByteSpan initiatorEphPubKey;
bool initiatorSessionParamsPresent = false;
bool initiatorSessionParamStructPresent = false;
SessionParameters initiatorSessionParams;
};

Expand Down Expand Up @@ -275,6 +275,8 @@ class DLL_EXPORT CASESession : public Messaging::UnsolicitedMessageHandler,
* On success, either the sessionResumptionRequested field will be set to true
* and the resumptionID and initiatorResumeMIC fields will be set to
* valid values, or the sessionResumptionRequested field will be set to false.
*
* @note Calls to this function must always be made with a newly created and fresh ParsedSigma1 parameter.
*/
static CHIP_ERROR ParseSigma1(TLV::ContiguousBufferTLVReader & tlvReader, ParsedSigma1 & parsedMessage);

Expand Down
12 changes: 9 additions & 3 deletions src/protocols/secure_channel/tests/TestPairingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ struct DecodeSessionParamsTestCase
bool includeEndContainer = true;
};

constexpr uint8_t kSessionParamsStructTag = 1;

void EncodeSessionParamsHelper(const DecodeSessionParamsTestCase & testCase, TLV::TLVWriter & writer)
{

TLVType sessionParamsContainer = kTLVType_NotSpecified;
EXPECT_EQ(writer.StartContainer(ContextTag(1), kTLVType_Structure, sessionParamsContainer), CHIP_NO_ERROR);
EXPECT_EQ(writer.StartContainer(ContextTag(kSessionParamsStructTag), kTLVType_Structure, sessionParamsContainer),
CHIP_NO_ERROR);

writer.Put(ContextTag(SessionParameters::Tag::kSessionIdleInterval), testCase.mrpConfig.mIdleRetransTimeout.count());
writer.Put(ContextTag(SessionParameters::Tag::kSessionActiveInterval), testCase.mrpConfig.mActiveRetransTimeout.count());
Expand All @@ -150,8 +153,11 @@ void EncodeSessionParamsHelper(const DecodeSessionParamsTestCase & testCase, TLV

if (testCase.testFutureProofing)
{
// Choosing a tag that is much higher than the current highest tag value in the Specification
constexpr uint8_t kFutureProofTlvElementTag = 17;

uint32_t futureProofTlvElement = 0x777666;
writer.Put(ContextTag(8), futureProofTlvElement);
writer.Put(ContextTag(kFutureProofTlvElementTag), futureProofTlvElement);
}

if (testCase.includeEndContainer)
Expand Down Expand Up @@ -336,7 +342,7 @@ TEST_F(TestPairingSession, TestDecodeSessionParameters)
bool testCaseFailed = false;
CHIP_ERROR err = CHIP_NO_ERROR;

err = DecodeSessionParametersIfPresent(ContextTag(1), reader, decodedParams);
err = DecodeSessionParametersIfPresent(ContextTag(kSessionParamsStructTag), reader, decodedParams);
if (err != testCase.expectedErrorDecodeParams)
{
printf("\nDecodeSessionParametersIfPresent returned Unexpected error code: %" CHIP_ERROR_FORMAT, err.Format());
Expand Down

0 comments on commit a50db92

Please sign in to comment.