Skip to content

Commit

Permalink
fix group messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
hnnajh committed Dec 6, 2023
1 parent 15f187a commit efd7902
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,28 +201,8 @@ CHIP_ERROR SessionManager::PrepareMessage(const SessionHandle & sessionHandle, P
packetHeader.SetSessionId(keyContext->GetKeyHash());
CryptoContext::NonceStorage nonce;
CryptoContext::BuildNonce(nonce, packetHeader.GetSecurityFlags(), packetHeader.GetMessageCounter(), sourceNodeId);
CHIP_ERROR err = CHIP_NO_ERROR;
if (sessionHandle->GetSessionType() == Transport::Session::SessionType::kSecure)
{
SecureSession * session = sessionHandle->AsSecureSession();
VerifyOrReturnError(session == nullptr, CHIP_ERROR_NOT_CONNECTED);
if (session->GetPeerAddress().GetTransportType() == Transport::Type::kTcp)
{
// support large payloads
err = SecureMessageCodec::Encrypt(CryptoContext(keyContext), nonce, payloadHeader, packetHeader, message,
kLargePayloadMaxMessageSizeBytes);
}
else
{
err = SecureMessageCodec::Encrypt(CryptoContext(keyContext), nonce, payloadHeader, packetHeader, message,
kMaxAppMessageLen);
}
}
else
{
err = SecureMessageCodec::Encrypt(CryptoContext(keyContext), nonce, payloadHeader, packetHeader, message,
kMaxAppMessageLen);
}
CHIP_ERROR err = SecureMessageCodec::Encrypt(CryptoContext(keyContext), nonce, payloadHeader, packetHeader, message,
kMaxAppMessageLen);
keyContext->Release();
ReturnErrorOnFailure(err);

Expand Down Expand Up @@ -258,7 +238,17 @@ CHIP_ERROR SessionManager::PrepareMessage(const SessionHandle & sessionHandle, P
NodeId sourceNodeId = session->GetLocalScopedNodeId().GetNodeId();
CryptoContext::BuildNonce(nonce, packetHeader.GetSecurityFlags(), messageCounter, sourceNodeId);

ReturnErrorOnFailure(SecureMessageCodec::Encrypt(session->GetCryptoContext(), nonce, payloadHeader, packetHeader, message));
if (session->GetPeerAddress().GetTransportType() == Transport::Type::kTcp)
{
// support large payloads
ReturnErrorOnFailure(SecureMessageCodec::Encrypt(session->GetCryptoContext(), nonce, payloadHeader, packetHeader, message,
kLargePayloadMaxMessageSizeBytes));
}
else
{
ReturnErrorOnFailure(SecureMessageCodec::Encrypt(session->GetCryptoContext(), nonce, payloadHeader, packetHeader, message,
kMaxAppMessageLen));
}

#if CHIP_PROGRESS_LOGGING
destination = session->GetPeerNodeId();
Expand Down

0 comments on commit efd7902

Please sign in to comment.