From 6b91e1840cd6ed539657dfebbc3d4aff6720bd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Thu, 25 Jul 2024 12:10:37 +0300 Subject: [PATCH] common: Fix crash with RCE_SRTP without Crypto++ --- src/session.cc | 13 +++++++------ test/test_5_srtp_zrtp.cpp | 14 -------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/session.cc b/src/session.cc index b0200318..e32625a6 100644 --- a/src/session.cc +++ b/src/session.cc @@ -107,17 +107,18 @@ uvgrtp::media_stream* uvgrtp::session::create_stream(uint16_t src_port, uint16_t rtp_errno = RTP_INVALID_VALUE; return nullptr; } + + if (rce_flags & RCE_SRTP && !uvgrtp::crypto::enabled()) + { + UVG_LOG_ERROR("RCE_SRTP requires inclusion of Crypto++ during compilation!"); + rtp_errno = RTP_GENERIC_ERROR; + return nullptr; + } uvgrtp::media_stream* stream = new uvgrtp::media_stream(cname_, remote_address_, local_address_, src_port, dst_port, fmt, sf_, rce_flags); if (rce_flags & RCE_SRTP) { - if (!uvgrtp::crypto::enabled()) { - UVG_LOG_ERROR("Recompile uvgRTP with -D__RTP_CRYPTO__"); - delete stream; - rtp_errno = RTP_GENERIC_ERROR; - return nullptr; - } session_mtx_.lock(); if (!zrtp_) { diff --git a/test/test_5_srtp_zrtp.cpp b/test/test_5_srtp_zrtp.cpp index ad1b264d..7d927a96 100644 --- a/test/test_5_srtp_zrtp.cpp +++ b/test/test_5_srtp_zrtp.cpp @@ -50,13 +50,6 @@ void test_user_key(Key_length len) std::cout << "Starting ZRTP sender thread" << std::endl; uvgrtp::context ctx; - if (!ctx.crypto_enabled()) - { - std::cout << "Please link crypto to uvgRTP library in order to tests its SRTP user keys!" << std::endl; - FAIL(); - return; - } - uint8_t *key = new uint8_t[len]; uint8_t salt[SALT_SIZE_BYTES] = { 0 }; @@ -188,13 +181,6 @@ TEST(EncryptionTests, zrtp) { uvgrtp::context ctx; - if (!ctx.crypto_enabled()) - { - std::cout << "Please link crypto to uvgRTP library in order to tests its ZRTP feature!" << std::endl; - FAIL(); - return; - } - uvgrtp::session* sender_session = ctx.create_session(RECEIVER_ADDRESS, SENDER_ADDRESS); uvgrtp::session* receiver_session = ctx.create_session(SENDER_ADDRESS, RECEIVER_ADDRESS);