提交 c0541171 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Use libsrtp 2.X

上级 c1b8c7a3
...@@ -47,7 +47,7 @@ SYSTEM_LIBS := pthread ...@@ -47,7 +47,7 @@ SYSTEM_LIBS := pthread
PKG_LIBS := PKG_LIBS :=
PKG_LIBS += libuv >= 1.6.1 PKG_LIBS += libuv >= 1.6.1
PKG_LIBS += openssl >= 1.0.1 PKG_LIBS += openssl >= 1.0.1
PKG_LIBS += libsrtp >= 1.5.2 PKG_LIBS += libsrtp2 >= 2.0.0
# Dependencies source files. # Dependencies source files.
DEP_SOURCES := DEP_SOURCES :=
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
#define MS_DEP_LIBSRTP_H #define MS_DEP_LIBSRTP_H
#include <vector> #include <vector>
#include <srtp/srtp.h> #include <srtp2/srtp.h>
class DepLibSRTP class DepLibSRTP
{ {
public: public:
static void ClassInit(); static void ClassInit();
static void ClassDestroy(); static void ClassDestroy();
static bool IsError(err_status_t code); static bool IsError(srtp_err_status_t code);
static const char* GetErrorString(err_status_t code); static const char* GetErrorString(srtp_err_status_t code);
private: private:
static std::vector<const char*> errors; static std::vector<const char*> errors;
...@@ -19,13 +19,13 @@ private: ...@@ -19,13 +19,13 @@ private:
/* Inline static methods. */ /* Inline static methods. */
inline inline
bool DepLibSRTP::IsError(err_status_t code) bool DepLibSRTP::IsError(srtp_err_status_t code)
{ {
return (code != err_status_ok); return (code != srtp_err_status_ok);
} }
inline inline
const char* DepLibSRTP::GetErrorString(err_status_t code) const char* DepLibSRTP::GetErrorString(srtp_err_status_t code)
{ {
// This throws out_of_range if the given index is not in the vector. // This throws out_of_range if the given index is not in the vector.
return DepLibSRTP::errors.at(code); return DepLibSRTP::errors.at(code);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "common.h" #include "common.h"
#include "DepLibSRTP.h" #include "DepLibSRTP.h"
#include <srtp/srtp.h> #include <srtp2/srtp.h>
namespace RTC namespace RTC
{ {
...@@ -27,8 +27,8 @@ namespace RTC ...@@ -27,8 +27,8 @@ namespace RTC
public: public:
static void ClassInit(); static void ClassInit();
private: // private:
static void onSRTPEvent(srtp_event_data_t* data); // static void onSRTPEvent(srtp_event_data_t* data);
private: private:
static uint8_t encryptBuffer[]; static uint8_t encryptBuffer[];
...@@ -48,7 +48,7 @@ namespace RTC ...@@ -48,7 +48,7 @@ namespace RTC
// Allocated by this. // Allocated by this.
srtp_t session = nullptr; srtp_t session = nullptr;
// Others. // Others.
err_status_t lastError = (err_status_t)0; srtp_err_status_t lastError = (srtp_err_status_t)0;
}; };
/* Inline instance methods. */ /* Inline instance methods. */
...@@ -59,7 +59,7 @@ namespace RTC ...@@ -59,7 +59,7 @@ namespace RTC
const char* error_string; const char* error_string;
error_string = DepLibSRTP::GetErrorString(this->lastError); error_string = DepLibSRTP::GetErrorString(this->lastError);
this->lastError = (err_status_t)0; // Reset it. this->lastError = (srtp_err_status_t)0; // Reset it.
return error_string; return error_string;
} }
......
...@@ -42,7 +42,7 @@ void DepLibSRTP::ClassInit() ...@@ -42,7 +42,7 @@ void DepLibSRTP::ClassInit()
{ {
MS_TRACE(); MS_TRACE();
err_status_t err; srtp_err_status_t err;
err = srtp_init(); err = srtp_init();
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
...@@ -53,7 +53,7 @@ void DepLibSRTP::ClassDestroy() ...@@ -53,7 +53,7 @@ void DepLibSRTP::ClassDestroy()
{ {
MS_TRACE(); MS_TRACE();
err_status_t err; srtp_err_status_t err;
err = srtp_shutdown(); err = srtp_shutdown();
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "MediaSoupError.h" #include "MediaSoupError.h"
#include "Logger.h" #include "Logger.h"
#include <cstring> // std::memset(), std::memcpy() #include <cstring> // std::memset(), std::memcpy()
#include <srtp/srtp_priv.h> // TODO: This allows data->stream->ssrc, but it is not public. Wait ofr libsrtp new API. // #include <srtp2/srtp_priv.h> // TODO: This allows data->stream->ssrc, but it is not public. Wait ofr libsrtp new API.
#define MS_ENCRYPT_BUFFER_SIZE 65536 #define MS_ENCRYPT_BUFFER_SIZE 65536
...@@ -20,40 +20,40 @@ namespace RTC ...@@ -20,40 +20,40 @@ namespace RTC
{ {
/* Set libsrtp event handler. */ /* Set libsrtp event handler. */
err_status_t err; // srtp_err_status_t err;
err = srtp_install_event_handler((srtp_event_handler_func_t*)onSRTPEvent); // err = srtp_install_event_handler((srtp_event_handler_func_t*)onSRTPEvent);
if (DepLibSRTP::IsError(err)) // if (DepLibSRTP::IsError(err))
{ // {
MS_THROW_ERROR("srtp_install_event_handler() failed: %s", DepLibSRTP::GetErrorString(err)); // MS_THROW_ERROR("srtp_install_event_handler() failed: %s", DepLibSRTP::GetErrorString(err));
} // }
} }
void SRTPSession::onSRTPEvent(srtp_event_data_t* data) // void SRTPSession::onSRTPEvent(srtp_event_data_t* data)
{ // {
MS_TRACE(); // MS_TRACE();
const char* event_desc = ""; // const char* event_desc = "";
switch (data->event) // switch (data->event)
{ // {
case event_ssrc_collision: // case event_ssrc_collision:
event_desc = "collision occurred"; // event_desc = "collision occurred";
break; // break;
case event_key_soft_limit: // case event_key_soft_limit:
event_desc = "stream reached the soft key usage limit and will expire soon"; // event_desc = "stream reached the soft key usage limit and will expire soon";
break; // break;
case event_key_hard_limit: // case event_key_hard_limit:
event_desc = "stream reached the hard key usage limit and has expired"; // event_desc = "stream reached the hard key usage limit and has expired";
break; // break;
case event_packet_index_limit: // case event_packet_index_limit:
event_desc = "stream reached the hard packet limit (2^48 packets)"; // event_desc = "stream reached the hard packet limit (2^48 packets)";
break; // break;
} // }
// TODO: u64? // // TODO: u64?
MS_WARN("SSRC %" PRIu64 ": %s", (uint64_t)data->stream->ssrc, event_desc); // MS_WARN("SSRC %" PRIu64 ": %s", (uint64_t)data->stream->ssrc, event_desc);
} // }
/* Instance methods. */ /* Instance methods. */
...@@ -61,7 +61,7 @@ namespace RTC ...@@ -61,7 +61,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
err_status_t err; srtp_err_status_t err;
srtp_policy_t policy; srtp_policy_t policy;
// Set all policy fields to 0. // Set all policy fields to 0.
...@@ -70,12 +70,12 @@ namespace RTC ...@@ -70,12 +70,12 @@ namespace RTC
switch (profile) switch (profile)
{ {
case SRTPProfile::AES_CM_128_HMAC_SHA1_80: case SRTPProfile::AES_CM_128_HMAC_SHA1_80:
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
break; break;
case SRTPProfile::AES_CM_128_HMAC_SHA1_32: case SRTPProfile::AES_CM_128_HMAC_SHA1_32:
crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // NOTE: Must be 80 for RTCP!. srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // NOTE: Must be 80 for RTCP!.
break; break;
default: default:
MS_ABORT("unknown SRTP suite"); MS_ABORT("unknown SRTP suite");
...@@ -114,7 +114,7 @@ namespace RTC ...@@ -114,7 +114,7 @@ namespace RTC
if (this->session) if (this->session)
{ {
err_status_t err; srtp_err_status_t err;
err = srtp_dealloc(this->session); err = srtp_dealloc(this->session);
if (DepLibSRTP::IsError(err)) if (DepLibSRTP::IsError(err))
...@@ -134,7 +134,7 @@ namespace RTC ...@@ -134,7 +134,7 @@ namespace RTC
if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE) if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE)
{ {
MS_WARN("cannot encrypt RTP packet, size too big (%zu bytes)", *len); MS_WARN("cannot encrypt RTP packet, size too big (%zu bytes)", *len);
this->lastError = err_status_fail; this->lastError = srtp_err_status_fail;
return false; return false;
} }
...@@ -175,7 +175,7 @@ namespace RTC ...@@ -175,7 +175,7 @@ namespace RTC
if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE) if (*len + SRTP_MAX_TRAILER_LEN > MS_ENCRYPT_BUFFER_SIZE)
{ {
MS_WARN("cannot encrypt RTCP packet, size too big (%zu bytes)", *len); MS_WARN("cannot encrypt RTCP packet, size too big (%zu bytes)", *len);
this->lastError = err_status_fail; this->lastError = srtp_err_status_fail;
return false; return false;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论