Skip to content

Commit

Permalink
Have PairingSession::EncodeSessionParameters require local MRP values (
Browse files Browse the repository at this point in the history
…project-chip#32324)

* Have PairingSession::EncodeSessionParameters require local MRP values
  • Loading branch information
tehampson authored and huangxuyong committed Mar 19, 2024
1 parent c843a9a commit dac25eb
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 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 @@ -477,7 +477,7 @@ CASESession::PrepareForSessionEstablishment(SessionManager & sessionManager, Fab
mFabricsTable = fabricTable;
mRole = CryptoContext::SessionRole::kResponder;
mSessionResumptionStorage = sessionResumptionStorage;
mLocalMRPConfig = mrpLocalConfig;
mLocalMRPConfig = mrpLocalConfig.ValueOr(GetDefaultMRPConfig());

ChipLogDetail(SecureChannel, "Allocated SecureSession (%p) - waiting for Sigma1 msg",
mSecureSessionHolder.Get().Value()->AsSecureSession());
Expand Down Expand Up @@ -525,7 +525,7 @@ CHIP_ERROR CASESession::EstablishSession(SessionManager & sessionManager, Fabric
mFabricsTable = fabricTable;
mFabricIndex = fabricInfo->GetFabricIndex();
mSessionResumptionStorage = sessionResumptionStorage;
mLocalMRPConfig = mrpLocalConfig;
mLocalMRPConfig = mrpLocalConfig.ValueOr(GetDefaultMRPConfig());

mExchangeCtxt->UseSuggestedResponseTimeout(kExpectedSigma1ProcessingTime);
mPeerNodeId = peerScopedNodeId.GetNodeId();
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/secure_channel/PASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ CHIP_ERROR PASESession::WaitForPairing(SessionManager & sessionManager, const Sp
mIterationCount = pbkdf2IterCount;
mNextExpectedMsg.SetValue(MsgType::PBKDFParamRequest);
mPairingComplete = false;
mLocalMRPConfig = mrpLocalConfig;
mLocalMRPConfig = mrpLocalConfig.ValueOr(GetDefaultMRPConfig());

ChipLogDetail(SecureChannel, "Waiting for PBKDF param request");

Expand Down Expand Up @@ -225,7 +225,7 @@ CHIP_ERROR PASESession::Pair(SessionManager & sessionManager, uint32_t peerSetUp

mExchangeCtxt->UseSuggestedResponseTimeout(kExpectedLowProcessingTime);

mLocalMRPConfig = mrpLocalConfig;
mLocalMRPConfig = mrpLocalConfig.ValueOr(GetDefaultMRPConfig());

err = SendPBKDFParamRequest();
SuccessOrExit(err);
Expand Down
10 changes: 1 addition & 9 deletions src/protocols/secure_channel/PairingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,9 @@ void PairingSession::DiscardExchange()
}
}

CHIP_ERROR PairingSession::EncodeSessionParameters(TLV::Tag tag, const Optional<ReliableMessageProtocolConfig> & providedMrpConfig,
CHIP_ERROR PairingSession::EncodeSessionParameters(TLV::Tag tag, const ReliableMessageProtocolConfig & mrpLocalConfig,
TLV::TLVWriter & tlvWriter)
{
// TODO: https://github.com/project-chip/connectedhomeip/issues/30456. Based on the spec we need to send values here now,
// but it is not entirely clear what we should be sending here when `providedMrpConfig.HasValue() == false`. For now we
// are sending the default MRP config values.
ReliableMessageProtocolConfig mrpLocalConfig = GetDefaultMRPConfig();
if (providedMrpConfig.HasValue())
{
mrpLocalConfig = providedMrpConfig.Value();
}
TLV::TLVType mrpParamsContainer;
ReturnErrorOnFailure(tlvWriter.StartContainer(tag, TLV::kTLVType_Structure, mrpParamsContainer));
ReturnErrorOnFailure(
Expand Down
4 changes: 2 additions & 2 deletions src/protocols/secure_channel/PairingSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class DLL_EXPORT PairingSession : public SessionDelegate
/**
* Encode the Session Parameters using the provided TLV tag.
*/
static CHIP_ERROR EncodeSessionParameters(TLV::Tag tag, const Optional<ReliableMessageProtocolConfig> & mrpLocalConfig,
static CHIP_ERROR EncodeSessionParameters(TLV::Tag tag, const ReliableMessageProtocolConfig & mrpLocalConfig,
TLV::TLVWriter & tlvWriter);

protected:
Expand Down Expand Up @@ -238,7 +238,7 @@ class DLL_EXPORT PairingSession : public SessionDelegate

// mLocalMRPConfig is our config which is sent to the other end and used by the peer session.
// mRemoteSessionParams is received from other end and set to our session.
Optional<ReliableMessageProtocolConfig> mLocalMRPConfig;
ReliableMessageProtocolConfig mLocalMRPConfig = GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig());
SessionParameters mRemoteSessionParams;

private:
Expand Down
3 changes: 1 addition & 2 deletions src/protocols/secure_channel/tests/TestPairingSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ void PairingSessionEncodeDecodeMRPParams(nlTestSuite * inSuite, void * inContext
NL_TEST_ASSERT(inSuite,
writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, outerContainerType) == CHIP_NO_ERROR);

NL_TEST_ASSERT(inSuite,
PairingSession::EncodeSessionParameters(TLV::ContextTag(1), MakeOptional(config), writer) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, PairingSession::EncodeSessionParameters(TLV::ContextTag(1), config, writer) == CHIP_NO_ERROR);

NL_TEST_ASSERT(inSuite, writer.EndContainer(outerContainerType) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite, writer.Finalize(&buf) == CHIP_NO_ERROR);
Expand Down

0 comments on commit dac25eb

Please sign in to comment.