From 1241782724c12d92129f3d0111deb0d8b5de6566 Mon Sep 17 00:00:00 2001 From: Terence Hampson Date: Thu, 29 Feb 2024 15:33:46 -0500 Subject: [PATCH] Have PairingSession::EncodeSessionParameters require local MRP values (#32324) * Have PairingSession::EncodeSessionParameters require local MRP values --- src/protocols/secure_channel/CASESession.cpp | 4 ++-- src/protocols/secure_channel/PASESession.cpp | 4 ++-- src/protocols/secure_channel/PairingSession.cpp | 10 +--------- src/protocols/secure_channel/PairingSession.h | 4 ++-- .../secure_channel/tests/TestPairingSession.cpp | 3 +-- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index ee8feaefb5f93d..30d1f71cb0ff64 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -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()); @@ -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(); diff --git a/src/protocols/secure_channel/PASESession.cpp b/src/protocols/secure_channel/PASESession.cpp index ab3007b26258a9..50b186100841e0 100644 --- a/src/protocols/secure_channel/PASESession.cpp +++ b/src/protocols/secure_channel/PASESession.cpp @@ -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"); @@ -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); diff --git a/src/protocols/secure_channel/PairingSession.cpp b/src/protocols/secure_channel/PairingSession.cpp index 80e048597578be..6a6d03f43ebc65 100644 --- a/src/protocols/secure_channel/PairingSession.cpp +++ b/src/protocols/secure_channel/PairingSession.cpp @@ -90,17 +90,9 @@ void PairingSession::DiscardExchange() } } -CHIP_ERROR PairingSession::EncodeSessionParameters(TLV::Tag tag, const Optional & 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( diff --git a/src/protocols/secure_channel/PairingSession.h b/src/protocols/secure_channel/PairingSession.h index e8849822de57e1..8ed9f269b9a32c 100644 --- a/src/protocols/secure_channel/PairingSession.h +++ b/src/protocols/secure_channel/PairingSession.h @@ -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 & mrpLocalConfig, + static CHIP_ERROR EncodeSessionParameters(TLV::Tag tag, const ReliableMessageProtocolConfig & mrpLocalConfig, TLV::TLVWriter & tlvWriter); protected: @@ -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 mLocalMRPConfig; + ReliableMessageProtocolConfig mLocalMRPConfig = GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig()); SessionParameters mRemoteSessionParams; private: diff --git a/src/protocols/secure_channel/tests/TestPairingSession.cpp b/src/protocols/secure_channel/tests/TestPairingSession.cpp index ac1c4537888bc8..e0e4a7cd9601c8 100644 --- a/src/protocols/secure_channel/tests/TestPairingSession.cpp +++ b/src/protocols/secure_channel/tests/TestPairingSession.cpp @@ -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);