multiplex: Add flag checks for starting ZRTP manually
This commit is contained in:
parent
6cbade8179
commit
e39fc25a5a
|
@ -56,16 +56,16 @@ namespace uvgrtp {
|
||||||
rtp_format_t fmt, std::shared_ptr<uvgrtp::socketfactory> sfp, int rce_flags);
|
rtp_format_t fmt, std::shared_ptr<uvgrtp::socketfactory> sfp, int rce_flags);
|
||||||
~media_stream();
|
~media_stream();
|
||||||
|
|
||||||
/* Initialize traditional RTP session
|
/* Initialize traditional RTP session. ZRTP can be started via add_zrtp_ctx()
|
||||||
* Allocate Connection/Reader/Writer objects and initialize them
|
* Allocate Connection/Reader/Writer objects and initialize them
|
||||||
*
|
*
|
||||||
* Return RTP_OK on success
|
* Return RTP_OK on success
|
||||||
* Return RTP_MEMORY_ERROR if allocation failed
|
* Return RTP_MEMORY_ERROR if allocation failed
|
||||||
*
|
*
|
||||||
* Other error return codes are defined in {conn,writer,reader}.hh */
|
* Other error return codes are defined in {conn,writer,reader}.hh */
|
||||||
rtp_error_t init();
|
rtp_error_t init(std::shared_ptr<uvgrtp::zrtp> zrtp);
|
||||||
|
|
||||||
/* Initialize Secure RTP session
|
/* Initialize Secure RTP session with automatic ZRTP negotiation
|
||||||
* Allocate Connection/Reader/Writer objects and initialize them
|
* Allocate Connection/Reader/Writer objects and initialize them
|
||||||
*
|
*
|
||||||
* Return RTP_OK on success
|
* Return RTP_OK on success
|
||||||
|
@ -74,8 +74,9 @@ namespace uvgrtp {
|
||||||
* TODO document all error codes!
|
* TODO document all error codes!
|
||||||
*
|
*
|
||||||
* Other error return codes are defined in {conn,writer,reader,srtp}.hh */
|
* Other error return codes are defined in {conn,writer,reader,srtp}.hh */
|
||||||
rtp_error_t init(std::shared_ptr<uvgrtp::zrtp> zrtp);
|
rtp_error_t init_auto_zrtp(std::shared_ptr<uvgrtp::zrtp> zrtp);
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
rtp_error_t add_zrtp_ctx();
|
rtp_error_t add_zrtp_ctx();
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -321,8 +321,9 @@ rtp_error_t uvgrtp::media_stream::install_packet_handlers()
|
||||||
return RTP_OK;
|
return RTP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtp_error_t uvgrtp::media_stream::init()
|
rtp_error_t uvgrtp::media_stream::init(std::shared_ptr<uvgrtp::zrtp> zrtp)
|
||||||
{
|
{
|
||||||
|
zrtp_ = zrtp;
|
||||||
if (init_connection() != RTP_OK) {
|
if (init_connection() != RTP_OK) {
|
||||||
UVG_LOG_ERROR("Failed to initialize the underlying socket");
|
UVG_LOG_ERROR("Failed to initialize the underlying socket");
|
||||||
return free_resources(RTP_GENERIC_ERROR);
|
return free_resources(RTP_GENERIC_ERROR);
|
||||||
|
@ -343,7 +344,8 @@ rtp_error_t uvgrtp::media_stream::init()
|
||||||
|
|
||||||
/* If we are using ZRTP, we only install the ZRTP handler first. Rest of the handlers are installed after ZRTP is
|
/* If we are using ZRTP, we only install the ZRTP handler first. Rest of the handlers are installed after ZRTP is
|
||||||
finished. If ZRTP is not enabled, we can install all the required handlers now */
|
finished. If ZRTP is not enabled, we can install all the required handlers now */
|
||||||
if ((rce_flags_ & RCE_SRTP_KMNGMNT_ZRTP) && zrtp_) {
|
if ((rce_flags_ & RCE_ZRTP_DIFFIE_HELLMAN_MODE || rce_flags_ & RCE_ZRTP_MULTISTREAM_MODE
|
||||||
|
|| rce_flags_ & RCE_SRTP_KMNGMNT_ZRTP ) && zrtp_) {
|
||||||
reception_flow_->install_handler(
|
reception_flow_->install_handler(
|
||||||
3, remote_ssrc_,
|
3, remote_ssrc_,
|
||||||
std::bind(&uvgrtp::zrtp::packet_handler, zrtp_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
|
std::bind(&uvgrtp::zrtp::packet_handler, zrtp_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,
|
||||||
|
@ -360,10 +362,10 @@ rtp_error_t uvgrtp::media_stream::init()
|
||||||
return start_components();
|
return start_components();
|
||||||
}
|
}
|
||||||
|
|
||||||
rtp_error_t uvgrtp::media_stream::init(std::shared_ptr<uvgrtp::zrtp> zrtp)
|
rtp_error_t uvgrtp::media_stream::init_auto_zrtp(std::shared_ptr<uvgrtp::zrtp> zrtp)
|
||||||
{
|
{
|
||||||
zrtp_ = zrtp;
|
zrtp_ = zrtp;
|
||||||
rtp_error_t ret = init();
|
rtp_error_t ret = init(zrtp_);
|
||||||
if (ret != RTP_OK) {
|
if (ret != RTP_OK) {
|
||||||
UVG_LOG_ERROR("Failed to initialize media stream");
|
UVG_LOG_ERROR("Failed to initialize media stream");
|
||||||
return free_resources(ret);
|
return free_resources(ret);
|
||||||
|
|
|
@ -119,9 +119,24 @@ uvgrtp::media_stream* uvgrtp::session::create_stream(uint16_t src_port, uint16_t
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session_mtx_.lock();
|
||||||
|
if (!zrtp_) {
|
||||||
|
zrtp_ = std::shared_ptr<uvgrtp::zrtp>(new uvgrtp::zrtp());
|
||||||
|
}
|
||||||
|
session_mtx_.unlock();
|
||||||
|
|
||||||
if (rce_flags & RCE_SRTP_REPLAY_PROTECTION)
|
if (rce_flags & RCE_SRTP_REPLAY_PROTECTION)
|
||||||
rce_flags |= RCE_SRTP_AUTHENTICATE_RTP;
|
rce_flags |= RCE_SRTP_AUTHENTICATE_RTP;
|
||||||
|
|
||||||
|
/* With flags RCE_SRTP_KMNGMNT_ZRTP enabled, start ZRTP negotiation automatically. NOTE! This only works when
|
||||||
|
* not doing socket multiplexing.
|
||||||
|
*
|
||||||
|
* More info on flags: When using ZRTP, you have the following options:
|
||||||
|
* 1. Use flags RCE_SRTP + RCE_SRTP_KMNGMNT_ZRTP + negotiation mode flag
|
||||||
|
* -> This way ZRTP negotiation is started automatically
|
||||||
|
* 2. Use flags RCE_SRTP + negotiation mode flag
|
||||||
|
* -> Use add_zrtp_ctx() function to start ZRTP negotiation manually
|
||||||
|
*/
|
||||||
if (rce_flags & RCE_SRTP_KMNGMNT_ZRTP) {
|
if (rce_flags & RCE_SRTP_KMNGMNT_ZRTP) {
|
||||||
|
|
||||||
if (rce_flags & (RCE_SRTP_KEYSIZE_192 | RCE_SRTP_KEYSIZE_256)) {
|
if (rce_flags & (RCE_SRTP_KEYSIZE_192 | RCE_SRTP_KEYSIZE_256)) {
|
||||||
|
@ -136,20 +151,14 @@ uvgrtp::media_stream* uvgrtp::session::create_stream(uint16_t src_port, uint16_t
|
||||||
rce_flags |= RCE_ZRTP_DIFFIE_HELLMAN_MODE;
|
rce_flags |= RCE_ZRTP_DIFFIE_HELLMAN_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
session_mtx_.lock();
|
if (stream->init_auto_zrtp(zrtp_) != RTP_OK) {
|
||||||
if (!zrtp_) {
|
|
||||||
zrtp_ = std::shared_ptr<uvgrtp::zrtp> (new uvgrtp::zrtp());
|
|
||||||
}
|
|
||||||
session_mtx_.unlock();
|
|
||||||
|
|
||||||
if (stream->init(zrtp_) != RTP_OK) {
|
|
||||||
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), src_port, dst_port);
|
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), src_port, dst_port);
|
||||||
delete stream;
|
delete stream;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else if (rce_flags & RCE_SRTP_KMNGMNT_USER) {
|
} else if (rce_flags & RCE_SRTP_KMNGMNT_USER) {
|
||||||
UVG_LOG_DEBUG("SRTP with user-managed keys enabled, postpone initialization");
|
UVG_LOG_DEBUG("SRTP with user-managed keys enabled, postpone initialization");
|
||||||
if (stream->init() != RTP_OK) {
|
if (stream->init(zrtp_) != RTP_OK) {
|
||||||
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), src_port, dst_port);
|
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), src_port, dst_port);
|
||||||
delete stream;
|
delete stream;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -161,7 +170,7 @@ uvgrtp::media_stream* uvgrtp::session::create_stream(uint16_t src_port, uint16_t
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (stream->init() != RTP_OK) {
|
if (stream->init(zrtp_) != RTP_OK) {
|
||||||
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), src_port, dst_port);
|
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), src_port, dst_port);
|
||||||
delete stream;
|
delete stream;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -244,6 +253,11 @@ uvgrtp::media_stream* uvgrtp::session::create_stream(uint16_t remote_port, uint1
|
||||||
if (rce_flags & RCE_SRTP_REPLAY_PROTECTION)
|
if (rce_flags & RCE_SRTP_REPLAY_PROTECTION)
|
||||||
rce_flags |= RCE_SRTP_AUTHENTICATE_RTP;
|
rce_flags |= RCE_SRTP_AUTHENTICATE_RTP;
|
||||||
|
|
||||||
|
session_mtx_.lock();
|
||||||
|
if (!zrtp_) {
|
||||||
|
zrtp_ = std::shared_ptr<uvgrtp::zrtp>(new uvgrtp::zrtp());
|
||||||
|
}
|
||||||
|
session_mtx_.unlock();
|
||||||
if (rce_flags & RCE_SRTP_KMNGMNT_ZRTP) {
|
if (rce_flags & RCE_SRTP_KMNGMNT_ZRTP) {
|
||||||
|
|
||||||
if (rce_flags & (RCE_SRTP_KEYSIZE_192 | RCE_SRTP_KEYSIZE_256)) {
|
if (rce_flags & (RCE_SRTP_KEYSIZE_192 | RCE_SRTP_KEYSIZE_256)) {
|
||||||
|
@ -258,13 +272,7 @@ uvgrtp::media_stream* uvgrtp::session::create_stream(uint16_t remote_port, uint1
|
||||||
rce_flags |= RCE_ZRTP_DIFFIE_HELLMAN_MODE;
|
rce_flags |= RCE_ZRTP_DIFFIE_HELLMAN_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
session_mtx_.lock();
|
if (stream->init_auto_zrtp(zrtp_) != RTP_OK) {
|
||||||
if (!zrtp_) {
|
|
||||||
zrtp_ = std::shared_ptr<uvgrtp::zrtp>(new uvgrtp::zrtp());
|
|
||||||
}
|
|
||||||
session_mtx_.unlock();
|
|
||||||
|
|
||||||
if (stream->init(zrtp_) != RTP_OK) {
|
|
||||||
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), local_port, remote_port);
|
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), local_port, remote_port);
|
||||||
delete stream;
|
delete stream;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -272,7 +280,7 @@ uvgrtp::media_stream* uvgrtp::session::create_stream(uint16_t remote_port, uint1
|
||||||
}
|
}
|
||||||
else if (rce_flags & RCE_SRTP_KMNGMNT_USER) {
|
else if (rce_flags & RCE_SRTP_KMNGMNT_USER) {
|
||||||
UVG_LOG_DEBUG("SRTP with user-managed keys enabled, postpone initialization");
|
UVG_LOG_DEBUG("SRTP with user-managed keys enabled, postpone initialization");
|
||||||
if (stream->init() != RTP_OK) {
|
if (stream->init(zrtp_) != RTP_OK) {
|
||||||
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), local_port, remote_port);
|
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), local_port, remote_port);
|
||||||
delete stream;
|
delete stream;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -286,7 +294,7 @@ uvgrtp::media_stream* uvgrtp::session::create_stream(uint16_t remote_port, uint1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (stream->init() != RTP_OK) {
|
if (stream->init(zrtp_) != RTP_OK) {
|
||||||
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), local_port, remote_port);
|
UVG_LOG_ERROR("Failed to initialize media stream %s:%d/%d", remote_address_.c_str(), local_port, remote_port);
|
||||||
delete stream;
|
delete stream;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in New Issue