From a9e9337e5a523d623be343a771fbd0b44d80f200 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 7 Feb 2022 14:18:58 -0500 Subject: [PATCH 1/3] Validate session type before trying to cast and return the secure session counter --- src/protocols/secure_channel/MessageCounterManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/protocols/secure_channel/MessageCounterManager.cpp b/src/protocols/secure_channel/MessageCounterManager.cpp index 4ccf8a0960a10d..b8d68f8c1781a1 100644 --- a/src/protocols/secure_channel/MessageCounterManager.cpp +++ b/src/protocols/secure_channel/MessageCounterManager.cpp @@ -225,6 +225,9 @@ CHIP_ERROR MessageCounterManager::SendMsgCounterSyncResp(Messaging::ExchangeCont VerifyOrDie(exchangeContext->HasSessionHandle()); + VerifyOrReturnError(exchangeContext->GetSessionHandle()->GetSessionType() == Session::SessionType::kSecure, + CHIP_ERROR_INVALID_ARGUMENT); + // Allocate new buffer. msgBuf = MessagePacketBuffer::New(kSyncRespMsgSize); VerifyOrReturnError(!msgBuf.IsNull(), CHIP_ERROR_NO_MEMORY); From 5c0aa296a1c33af59637c49c8fe651591d37265a Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 7 Feb 2022 14:52:28 -0500 Subject: [PATCH 2/3] Completely remove the counter response: MCSP not yet implemented for groups it seems --- .../secure_channel/MessageCounterManager.cpp | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/protocols/secure_channel/MessageCounterManager.cpp b/src/protocols/secure_channel/MessageCounterManager.cpp index b8d68f8c1781a1..e08b62da52f582 100644 --- a/src/protocols/secure_channel/MessageCounterManager.cpp +++ b/src/protocols/secure_channel/MessageCounterManager.cpp @@ -222,29 +222,20 @@ CHIP_ERROR MessageCounterManager::SendMsgCounterSyncResp(Messaging::ExchangeCont FixedByteSpan challenge) { System::PacketBufferHandle msgBuf; - VerifyOrDie(exchangeContext->HasSessionHandle()); - VerifyOrReturnError(exchangeContext->GetSessionHandle()->GetSessionType() == Session::SessionType::kSecure, + VerifyOrReturnError(exchangeContext->GetSessionHandle()->GetSessionType() == Transport::Session::SessionType::kGroupSession, CHIP_ERROR_INVALID_ARGUMENT); - // Allocate new buffer. - msgBuf = MessagePacketBuffer::New(kSyncRespMsgSize); - VerifyOrReturnError(!msgBuf.IsNull(), CHIP_ERROR_NO_MEMORY); - - { - uint8_t * msg = msgBuf->Start(); - Encoding::LittleEndian::BufferWriter bbuf(msg, kSyncRespMsgSize); - bbuf.Put32( - exchangeContext->GetSessionHandle()->AsSecureSession()->GetSessionMessageCounter().GetLocalMessageCounter().Value()); - bbuf.Put(challenge.data(), kChallengeSize); - VerifyOrReturnError(bbuf.Fit(), CHIP_ERROR_NO_MEMORY); - } - - msgBuf->SetDataLength(kSyncRespMsgSize); + // NOTE: not currently implemented. When implementing, the following should be done: + // - allocate a new buffer: MessagePacketBuffer::New + // - setup payload and place the local message counter + challange in it + // - exchangeContext->SendMessage(Protocols::SecureChannel::MsgType::MsgCounterSyncRsp, ...) + // + // You can view the history of this file for a partial implementation that got + // removed due to it using non-group sessions. - return exchangeContext->SendMessage(Protocols::SecureChannel::MsgType::MsgCounterSyncRsp, std::move(msgBuf), - Messaging::SendFlags(Messaging::SendMessageFlags::kNoAutoRequestAck)); + return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR MessageCounterManager::HandleMsgCounterSyncReq(Messaging::ExchangeContext * exchangeContext, From 8eb9f509720334d29fbe5de616deb216f5521435 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 7 Feb 2022 14:55:02 -0500 Subject: [PATCH 3/3] Fix typo --- src/protocols/secure_channel/MessageCounterManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocols/secure_channel/MessageCounterManager.cpp b/src/protocols/secure_channel/MessageCounterManager.cpp index e08b62da52f582..a94c1b50dc5511 100644 --- a/src/protocols/secure_channel/MessageCounterManager.cpp +++ b/src/protocols/secure_channel/MessageCounterManager.cpp @@ -224,7 +224,7 @@ CHIP_ERROR MessageCounterManager::SendMsgCounterSyncResp(Messaging::ExchangeCont System::PacketBufferHandle msgBuf; VerifyOrDie(exchangeContext->HasSessionHandle()); - VerifyOrReturnError(exchangeContext->GetSessionHandle()->GetSessionType() == Transport::Session::SessionType::kGroupSession, + VerifyOrReturnError(exchangeContext->GetSessionHandle()->GetSessionType() == Transport::Session::SessionType::kGroup, CHIP_ERROR_INVALID_ARGUMENT); // NOTE: not currently implemented. When implementing, the following should be done: