diff --git a/CHANGELOG.md b/CHANGELOG.md index afa31f1bc8..dbbf6c418c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### NEXT + +- C++: Update libsrtp to v3.0-alpha. + ### 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..20755dc656 100644 --- a/worker/src/RTC/SrtpSession.cpp +++ b/worker/src/RTC/SrtpSession.cpp @@ -189,14 +189,14 @@ 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); + MS_WARN_TAG(srtp, "cannot encrypt RTP packet, size too big (%zu bytes)", *len); return false; } @@ -224,7 +224,7 @@ namespace RTC std::memcpy(encryptBuffer, *data, *len); - const srtp_err_status_t err = srtp_protect(this->session, static_cast(encryptBuffer), len); + const srtp_err_status_t err = srtp_protect(this->session, encryptBuffer, len); if (DepLibSRTP::IsError(err)) { @@ -239,11 +239,11 @@ namespace RTC return true; } - bool SrtpSession::DecryptSrtp(uint8_t* data, int* len) + bool SrtpSession::DecryptSrtp(uint8_t* data, size_t* len) { MS_TRACE(); - const srtp_err_status_t err = srtp_unprotect(this->session, static_cast(data), len); + const srtp_err_status_t err = srtp_unprotect(this->session, data, len); if (DepLibSRTP::IsError(err)) { @@ -255,22 +255,21 @@ 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); + MS_WARN_TAG(srtp, "cannot encrypt RTCP packet, size too big (%zu bytes)", *len); return false; } std::memcpy(EncryptBuffer, *data, *len); - const srtp_err_status_t err = - srtp_protect_rtcp(this->session, static_cast(EncryptBuffer), len); + const srtp_err_status_t err = srtp_protect_rtcp(this->session, EncryptBuffer, len); if (DepLibSRTP::IsError(err)) { @@ -285,11 +284,11 @@ namespace RTC return true; } - bool SrtpSession::DecryptSrtcp(uint8_t* data, int* len) + bool SrtpSession::DecryptSrtcp(uint8_t* data, size_t* len) { MS_TRACE(); - const srtp_err_status_t err = srtp_unprotect_rtcp(this->session, static_cast(data), len); + const srtp_err_status_t err = srtp_unprotect_rtcp(this->session, data, len); if (DepLibSRTP::IsError(err)) { 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..d0181794b0 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-3.0-alpha +source_url = https://github.com/versatica/libsrtp/archive/v3.0-alpha.zip +source_filename = libsrtp-3.0-alpha.zip +source_hash = 946a472b888ca8d51df172def7681f3f9b14768109ffd22af08fddb1be77d2c6 [provide] libsrtp2 = libsrtp2_dep