diff --git a/CHANGELOG.md b/CHANGELOG.md index afa31f1bc8..a05c5468f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### NEXT + +- C++: Update libsrtp to pre-3.0. + ### 3.13.16 - Node: Add new `worker.on('subprocessclose')` event ([PR #1307](https://github.com/versatica/mediasoup/pull/1307)). diff --git a/worker/include/RTC/SrtpSession.hpp b/worker/include/RTC/SrtpSession.hpp index fa14a14760..b50f6d9b87 100644 --- a/worker/include/RTC/SrtpSession.hpp +++ b/worker/include/RTC/SrtpSession.hpp @@ -38,13 +38,13 @@ namespace RTC ~SrtpSession(); public: - bool EncryptRtp(const uint8_t** data, int* len); - bool DecryptSrtp(uint8_t* data, int* len); - bool EncryptRtcp(const uint8_t** data, int* len); - bool DecryptSrtcp(uint8_t* data, int* len); + bool EncryptRtp(const uint8_t** data, size_t* len); + bool DecryptSrtp(uint8_t* data, size_t* len); + bool EncryptRtcp(const uint8_t** data, size_t* len); + bool DecryptSrtcp(uint8_t* data, size_t* len); void RemoveStream(uint32_t ssrc) { - srtp_remove_stream(this->session, uint32_t{ htonl(ssrc) }); + srtp_stream_remove(this->session, uint32_t{ htonl(ssrc) }); } private: diff --git a/worker/src/RTC/PipeTransport.cpp b/worker/src/RTC/PipeTransport.cpp index 8706f5a60b..ff39616228 100644 --- a/worker/src/RTC/PipeTransport.cpp +++ b/worker/src/RTC/PipeTransport.cpp @@ -484,9 +484,9 @@ namespace RTC } const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); - if (HasSrtp() && !this->srtpSendSession->EncryptRtp(&data, &intLen)) + if (HasSrtp() && !this->srtpSendSession->EncryptRtp(&data, &len)) { if (cb) { @@ -497,8 +497,6 @@ namespace RTC return; } - auto len = static_cast(intLen); - this->tuple->Send(data, len, cb); // Increase send transmission. @@ -515,15 +513,13 @@ namespace RTC } const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); - if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen)) + if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &len)) { return; } - auto len = static_cast(intLen); - this->tuple->Send(data, len); // Increase send transmission. @@ -542,15 +538,13 @@ namespace RTC packet->Serialize(RTC::RTCP::Buffer); const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); - if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen)) + if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &len)) { return; } - auto len = static_cast(intLen); - this->tuple->Send(data, len); // Increase send transmission. @@ -638,11 +632,9 @@ namespace RTC } // Decrypt the SRTP packet. - auto intLen = static_cast(len); - - if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast(data), &intLen)) + if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast(data), &len)) { - RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast(intLen)); + RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); if (!packet) { @@ -663,7 +655,7 @@ namespace RTC return; } - RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast(intLen)); + RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); if (!packet) { @@ -700,9 +692,7 @@ namespace RTC } // Decrypt the SRTCP packet. - auto intLen = static_cast(len); - - if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast(data), &intLen)) + if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast(data), &len)) { return; } @@ -715,7 +705,7 @@ namespace RTC return; } - RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, static_cast(intLen)); + RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, len); if (!packet) { diff --git a/worker/src/RTC/PlainTransport.cpp b/worker/src/RTC/PlainTransport.cpp index f985dc8fa8..f6da989dd3 100644 --- a/worker/src/RTC/PlainTransport.cpp +++ b/worker/src/RTC/PlainTransport.cpp @@ -764,9 +764,9 @@ namespace RTC } const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); - if (HasSrtp() && !this->srtpSendSession->EncryptRtp(&data, &intLen)) + if (HasSrtp() && !this->srtpSendSession->EncryptRtp(&data, &len)) { if (cb) { @@ -777,8 +777,6 @@ namespace RTC return; } - auto len = static_cast(intLen); - this->tuple->Send(data, len, cb); // Increase send transmission. @@ -795,15 +793,13 @@ namespace RTC } const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); - if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen)) + if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &len)) { return; } - auto len = static_cast(intLen); - if (this->rtcpMux) { this->tuple->Send(data, len); @@ -829,15 +825,13 @@ namespace RTC packet->Serialize(RTC::RTCP::Buffer); const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); - if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen)) + if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &len)) { return; } - auto len = static_cast(intLen); - if (this->rtcpMux) { this->tuple->Send(data, len); @@ -933,11 +927,9 @@ namespace RTC } // Decrypt the SRTP packet. - auto intLen = static_cast(len); - - if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast(data), &intLen)) + if (HasSrtp() && !this->srtpRecvSession->DecryptSrtp(const_cast(data), &len)) { - RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast(intLen)); + RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); if (!packet) { @@ -958,7 +950,7 @@ namespace RTC return; } - RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast(intLen)); + RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); if (!packet) { @@ -1031,9 +1023,7 @@ namespace RTC } // Decrypt the SRTCP packet. - auto intLen = static_cast(len); - - if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast(data), &intLen)) + if (HasSrtp() && !this->srtpRecvSession->DecryptSrtcp(const_cast(data), &len)) { return; } @@ -1107,7 +1097,7 @@ namespace RTC return; } - RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, static_cast(intLen)); + RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, len); if (!packet) { diff --git a/worker/src/RTC/SrtpSession.cpp b/worker/src/RTC/SrtpSession.cpp index 5c2c810e0f..0f6566786d 100644 --- a/worker/src/RTC/SrtpSession.cpp +++ b/worker/src/RTC/SrtpSession.cpp @@ -189,12 +189,12 @@ namespace RTC } } - bool SrtpSession::EncryptRtp(const uint8_t** data, int* len) + bool SrtpSession::EncryptRtp(const uint8_t** data, size_t* len) { MS_TRACE(); // Ensure that the resulting SRTP packet fits into the encrypt buffer. - if (static_cast(*len) + SRTP_MAX_TRAILER_LEN > EncryptBufferSize) + if (*len + SRTP_MAX_TRAILER_LEN > EncryptBufferSize) { MS_WARN_TAG(srtp, "cannot encrypt RTP packet, size too big (%i bytes)", *len); @@ -239,7 +239,7 @@ namespace RTC return true; } - bool SrtpSession::DecryptSrtp(uint8_t* data, int* len) + bool SrtpSession::DecryptSrtp(uint8_t* data, size_t* len) { MS_TRACE(); @@ -255,12 +255,12 @@ namespace RTC return true; } - bool SrtpSession::EncryptRtcp(const uint8_t** data, int* len) + bool SrtpSession::EncryptRtcp(const uint8_t** data, size_t* len) { MS_TRACE(); // Ensure that the resulting SRTCP packet fits into the encrypt buffer. - if (static_cast(*len) + SRTP_MAX_TRAILER_LEN > EncryptBufferSize) + if (*len + SRTP_MAX_TRAILER_LEN > EncryptBufferSize) { MS_WARN_TAG(srtp, "cannot encrypt RTCP packet, size too big (%i bytes)", *len); @@ -285,7 +285,7 @@ namespace RTC return true; } - bool SrtpSession::DecryptSrtcp(uint8_t* data, int* len) + bool SrtpSession::DecryptSrtcp(uint8_t* data, size_t* len) { MS_TRACE(); diff --git a/worker/src/RTC/WebRtcTransport.cpp b/worker/src/RTC/WebRtcTransport.cpp index a795fef798..e699a26ed5 100644 --- a/worker/src/RTC/WebRtcTransport.cpp +++ b/worker/src/RTC/WebRtcTransport.cpp @@ -708,9 +708,9 @@ namespace RTC } const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); - if (!this->srtpSendSession->EncryptRtp(&data, &intLen)) + if (!this->srtpSendSession->EncryptRtp(&data, &len)) { if (cb) { @@ -721,8 +721,6 @@ namespace RTC return; } - auto len = static_cast(intLen); - this->iceServer->GetSelectedTuple()->Send(data, len, cb); // Increase send transmission. @@ -739,7 +737,7 @@ namespace RTC } const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); // Ensure there is sending SRTP session. if (!this->srtpSendSession) @@ -749,13 +747,11 @@ namespace RTC return; } - if (!this->srtpSendSession->EncryptRtcp(&data, &intLen)) + if (!this->srtpSendSession->EncryptRtcp(&data, &len)) { return; } - auto len = static_cast(intLen); - this->iceServer->GetSelectedTuple()->Send(data, len); // Increase send transmission. @@ -774,7 +770,7 @@ namespace RTC packet->Serialize(RTC::RTCP::Buffer); const uint8_t* data = packet->GetData(); - auto intLen = static_cast(packet->GetSize()); + auto len = packet->GetSize(); // Ensure there is sending SRTP session. if (!this->srtpSendSession) @@ -784,13 +780,11 @@ namespace RTC return; } - if (!this->srtpSendSession->EncryptRtcp(&data, &intLen)) + if (!this->srtpSendSession->EncryptRtcp(&data, &len)) { return; } - auto len = static_cast(intLen); - this->iceServer->GetSelectedTuple()->Send(data, len); // Increase send transmission. @@ -957,11 +951,9 @@ namespace RTC } // Decrypt the SRTP packet. - auto intLen = static_cast(len); - - if (!this->srtpRecvSession->DecryptSrtp(const_cast(data), &intLen)) + if (!this->srtpRecvSession->DecryptSrtp(const_cast(data), &len)) { - RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast(intLen)); + RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); if (!packet) { @@ -982,7 +974,7 @@ namespace RTC return; } - RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, static_cast(intLen)); + RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); if (!packet) { @@ -1028,14 +1020,12 @@ namespace RTC } // Decrypt the SRTCP packet. - auto intLen = static_cast(len); - - if (!this->srtpRecvSession->DecryptSrtcp(const_cast(data), &intLen)) + if (!this->srtpRecvSession->DecryptSrtcp(const_cast(data), &len)) { return; } - RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, static_cast(intLen)); + RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, len); if (!packet) { diff --git a/worker/subprojects/libsrtp2.wrap b/worker/subprojects/libsrtp2.wrap index aa1b767f2d..39d0c26aef 100644 --- a/worker/subprojects/libsrtp2.wrap +++ b/worker/subprojects/libsrtp2.wrap @@ -1,8 +1,8 @@ [wrap-file] -directory = libsrtp-4c9f0956f2933ac0650208d69c8d897625ba6301 -source_url = https://github.com/versatica/libsrtp/archive/4c9f0956f2933ac0650208d69c8d897625ba6301.zip -source_filename = libsrtp-4c9f0956f2933ac0650208d69c8d897625ba6301.zip -source_hash = 4f3af61e26df398569605fc4bcf377587ca2d8bd34b2b4bf9cdb9590cadbd662 +directory = libsrtp-37d88ecac103f4e2a5336099c64b155ba4ca3b0c +source_url = https://github.com/versatica/libsrtp/archive/37d88ecac103f4e2a5336099c64b155ba4ca3b0c.zip +source_filename = libsrtp-37d88ecac103f4e2a5336099c64b155ba4ca3b0c.zip +source_hash = edf8b2c7a27ed6b6aac64c8d6a165379d3a0042bd420706b4a1825acc182441d [provide] libsrtp2 = libsrtp2_dep