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

Use libsrtp 2.X

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