Skip to content
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

Fix DTLS fragment exceeds MTU size if the certificate is large #1343

Closed
wants to merge 6 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions worker/src/RTC/DtlsTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,8 @@ namespace RTC
return;
}

int64_t read;
char* data{ nullptr };

read = BIO_get_mem_data(this->sslBioToNetwork, &data); // NOLINT
const int64_t read = BIO_get_mem_data(this->sslBioToNetwork, &data); // NOLINT

if (read <= 0)
{
Expand All @@ -1201,9 +1199,37 @@ namespace RTC

MS_DEBUG_DEV("%" PRIu64 " bytes of DTLS data ready to sent to the peer", read);

// Notify the listener.
this->listener->OnDtlsTransportSendData(
this, reinterpret_cast<uint8_t*>(data), static_cast<size_t>(read));
if (read <= DtlsMtu)
{
// Notify the listener.
this->listener->OnDtlsTransportSendData(
this, reinterpret_cast<uint8_t*>(data), static_cast<size_t>(read));
}
else
{
MS_WARN_TAG(
dtls,
"data to be sent is longer than DTLS MTU, fragmenting it [len:%" PRIi64 ", DtlsMtu:%i]",
read,
DtlsMtu);

size_t offset{ 0u };

while (offset < read)
{
auto* fragmentData = reinterpret_cast<uint8_t*>(data + offset);
auto fragmentLen = static_cast<size_t>(read) - offset >= DtlsMtu
? DtlsMtu
: static_cast<size_t>(read) - offset;

MS_DEBUG_DEV("sending fragment [offset:%zu, len:%zu]", offset, fragmentLen);

// Notify the listener.
this->listener->OnDtlsTransportSendData(this, fragmentData, fragmentLen);

offset += fragmentLen;
}
}

// Clear the BIO buffer.
// NOTE: the (void) avoids the -Wunused-value warning.
Expand Down
Loading