-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update buffer allocation strategy and maximum buffer size when using TCP as transport #30404
Changes from 9 commits
a419234
0bad674
72421bd
976cb70
94d1d8c
200dea3
84adb59
15f187a
efd7902
ae12f9a
1c2c52c
53ec6de
f0609dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +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 = SecureMessageCodec::Encrypt(CryptoContext(keyContext), nonce, payloadHeader, packetHeader, message); | ||
CHIP_ERROR err = SecureMessageCodec::Encrypt(CryptoContext(keyContext), nonce, payloadHeader, packetHeader, message, | ||
kMaxAppMessageLen); | ||
keyContext->Release(); | ||
ReturnErrorOnFailure(err); | ||
|
||
|
@@ -237,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing the max size into Encrypt() by having this logic here, a better approach might be to have a utility function hanging off the Session that returns this. It could be in the Session object or could also be in the SessionManager, potentially. That utility can be called from inside Encrypt(and elsewhere) for checks. |
||
{ | ||
// 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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,8 @@ static_assert(detail::kMaxApplicationPayloadAndMICSizeBytes > kMaxTagLen, "Need | |
// tag we will not have source/destination node IDs, but above we are including | ||
// those in the header sizes. | ||
static constexpr size_t kMaxAppMessageLen = detail::kMaxApplicationPayloadAndMICSizeBytes - kMaxTagLen; | ||
// large payload limit | ||
static constexpr size_t kLargePayloadMaxMessageSizeBytes = 128000; | ||
hnnajh marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have added a ''CHIP_CONFIG_MAX_TCP_PAYLOAD_SIZE_BYTES 1000000" in a TCPConfig.h file as part of #30339 |
||
|
||
static constexpr uint16_t kMsgUnicastSessionIdUnsecured = 0x0000; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this argument? Why wouldn't callers just pass
msgBuf->TotalLength()
for it?Either this argument should not exist, or the documentation needs to do a much better job of explaining what this is for and how it should be used.
My temptation is towards the former: why does the crypto stuff care about this length? It doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this argument is meant to provide the method the maximum length of payload's length
that means we can't just pass msgBuf->TotalLength() because that would bypass the check :) , i think this place is okay since that check is common for all the places that's calling SecureMessageCodec::Encrypt(