Commit 221583f6 authored by johan's avatar johan

Move srtp from ortp to mediastreamer2

parent 92d3730c
......@@ -59,6 +59,7 @@ option(ENABLE_STATIC "Build static library (default is shared library)." NO)
option(ENABLE_DEBUG_LOGS "Enable the display of traces showing the execution of the library." NO)
option(ENABLE_FIXED_POINT "Turn on fixed point computations." ${ENABLE_FIXED_POINT_DEFAULT_VALUE})
option(ENABLE_RELATIVE_PREFIX "Find resources relatively to the installation directory." NO)
option(ENABLE_SRTP "Build with the SRTP transport support." YES)
option(ENABLE_ZRTP "Build with ZRTP support." YES)
option(ENABLE_SOUND "Can be used to turn off all possible sound backends." YES)
......@@ -89,6 +90,14 @@ cmake_dependent_option(ENABLE_VPX "Build mediastreamer2 with VPX codec." YES "EN
list(APPEND CMAKE_MODULE_PATH ${CMAKE_PREFIX_PATH}/share/cmake/Modules)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(ENABLE_SRTP)
find_package(SRTP)
if(NOT SRTP_FOUND)
message(WARNING "Could not find SRTP library, Mediastreamer2 will be compiled without SRTP support.")
set(ENABLE_SRTP OFF CACHE BOOL "Build with the SRTP transport support." FORCE)
endif()
endif()
include(CheckIncludeFile)
include(CheckLibraryExists)
......@@ -244,6 +253,10 @@ include_directories(
if(ENABLE_VIDEO)
include_directories(src/voip)
endif()
if(SRTP_FOUND)
include_directories(${SRTP_INCLUDE_DIRS})
endif()
if(BZRTP_FOUND)
include_directories(${BZRTP_INCLUDE_DIRS})
endif()
......@@ -300,6 +313,9 @@ endif()
if(ENABLE_FIXED_POINT)
set(MS_FIXED_POINT 1)
endif()
if(SRTP_FOUND)
set(HAVE_SRTP 1)
endif()
if(ENABLE_ALSA)
set(__ALSA_ENABLED__ 1)
endif()
......
......@@ -1005,6 +1005,66 @@ case "$target_os" in
;;
esac
dnl check for libsrtp support (secure rtp)
AC_ARG_WITH(srtp,
AC_HELP_STRING([--with-srtp], [Set prefix where libsrtp can be found or "none" to disable (ex:/usr or /usr/local) [[default=/usr]]]),
[srtp_prefix=$withval],
[srtp_prefix=/usr]
)
if test "${srtp_prefix}" != "none" ; then
if test "${srtp_prefix}" != "/usr" || test "$mingw_found" = "yes" ; then
SRTP_CFLAGS="-I${srtp_prefix}/include -I${srtp_prefix}/include/srtp"
SRTP_LIBS="-L${srtp_prefix}/lib"
fi
SRTP_LIBS="$SRTP_LIBS -lsrtp"
dnl check srtp headers
have_srtp=no
CPPFLAGS_save=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $SRTP_CFLAGS"
AC_CHECK_HEADER([srtp/srtp.h],have_srtp_headers=yes)
CPPFLAGS=$CPPFLAGS_save
dnl check for srtp lib
LDFLAGS_save=$LDFLAGS
LDFLAGS="$LDFLAGS $SRTP_LIBS"
LIBS_save=$LIBS
AC_CHECK_LIB(srtp,srtp_init,have_srtp_lib=yes)
AC_CHECK_LIB(srtp,srtp_shutdown,[AC_DEFINE([HAVE_SRTP_SHUTDOWN],1,[Defined when srtp_shutdown() exists.])])
LDFLAGS=$LDFLAGS_save
LIBS=$LIBS_save
if test "$have_srtp_headers$have_srtp_lib" = "yesyes" ; then
have_srtp=yes
if test "$test_for_broken_srtp" = yes; then
LDFLAGS_save=$LDFLAGS
LDFLAGS="$LDFLAGS $SRTP_LIBS"
LIBS_save=$LIBS
AC_CHECK_LIB(srtp,sha1_update,[
AC_MSG_ERROR([This libsrtp version exports symbols conflicting with polar ssl, resulting in a bad execution path.
Please use the one from git://git.linphone.org/srtp.git
You could also track resolution of defect on https://github.com/cisco/libsrtp/issues/28
If you are not linking against polar ssl, you may prefer to skip this test with --enable-broken-srtp
])], have_srtp=yes)
LDFLAGS=$LDFLAGS_save
LIBS=$LIBS_save
fi
AC_DEFINE(HAVE_SRTP, 1, [Defined when srtp support is compiled])
else
AC_MSG_NOTICE([Could not find libsrtp headers or lib, cryto transport disabled.])
SRTP_CFLAGS=
SRTP_LIBS=
fi
AC_SUBST(SRTP_CFLAGS)
AC_SUBST(SRTP_LIBS)
else
have_srtp=no
SRTP_CFLAGS=
SRTP_LIBS=
fi
dnl check for libzrtp support (RFC 6189: Media Path Key Agreement for Unicast Secure RTP)
AC_ARG_ENABLE(zrtp,
[AS_HELP_STRING([--enable-zrtp], [Turn on or off compilation of zrtp (default=no)])],
......
......@@ -35,6 +35,7 @@ typedef struct srtp_ctx_t *MSSrtpCtx;
#include <mediastreamer2/qualityindicator.h>
#include <mediastreamer2/ice.h>
#include <mediastreamer2/zrtp.h>
#include <mediastreamer2/ms_srtp.h>
#define PAYLOAD_TYPE_FLAG_CAN_RECV PAYLOAD_TYPE_USER_FLAG_1
......@@ -157,9 +158,6 @@ struct _MediaStream {
* @addtogroup audio_stream_api
* @{
**/
MS2_PUBLIC bool_t media_stream_srtp_supported(void);
MS2_PUBLIC void media_stream_set_rtcp_information(MediaStream *stream, const char *cname, const char *tool);
MS2_PUBLIC void media_stream_get_local_rtp_stats(MediaStream *stream, rtp_stats_t *stats);
......@@ -177,9 +175,6 @@ MS2_PUBLIC void media_stream_enable_adaptive_jittcomp(MediaStream *stream, bool_
**/
MS2_PUBLIC bool_t media_stream_enable_srtp(MediaStream* stream, MSCryptoSuite suite, const char* snd_key, const char* rcv_key);
MS2_PUBLIC int media_stream_set_srtp_recv_key(MediaStream *stream, MSCryptoSuite suite, const char* key, bool_t keyisb64);
MS2_PUBLIC int media_stream_set_srtp_send_key(MediaStream *stream, MSCryptoSuite suite, const char* key, bool_t keyisb64);
/**
* @param[in] stream MediaStream object
* @return true if stream is encrypted
......
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2006-2014 Belledonne Communications, Grenoble
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ms_srtp_h
#define ms_srtp_h
#if defined(HAVE_SRTP)
#if defined(ANDROID) || !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
// Android and Windows phone don't use make install
# include <srtp.h>
#else
# include <srtp/srtp.h>
#endif /* ANDROID */
#else /* HAVE_SRTP */
typedef void* srtp_t;
typedef int err_status_t;
typedef struct srtp_policy srtp_policy_t;
#endif /* HAVE_SRTP */
/*srtp defines all this stuff*/
#undef PACKAGE_BUGREPORT
#undef PACKAGE_NAME
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#include <ortp/rtpsession.h>
#include "mediastreamer2/mscommon.h"
#ifdef __cplusplus
extern "C"{
#endif
/* defined in mediastream.h */
struct _MediaStream;
enum _MSCryptoSuite;
/**
* Check if SRTP is supported
* @return true if SRTP is supported
*/
MS2_PUBLIC bool_t ms_srtp_supported(void);
/**
* Set srtp receiver key for the given media stream.
* If no srtp session exists on the stream it is created, if it already exists srtp policy is created/modified for the receiver side of the stream.
*
* @param[in/out] stream The mediastream to operate on
* @param[in] suite The srtp crypto suite to use
* @param[in] key Srtp master key and master salt in a base 64 NULL terminated string
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_set_srtp_recv_key_b64(struct _MediaStream *stream, enum _MSCryptoSuite suite, const char* key);
/**
* Set srtp receiver key for the given media stream.
* If no srtp session exists on the stream it is created, if it already exists srtp policy is created/modified for the receiver side of the stream.
*
* @param[in/out] stream The mediastream to operate on
* @param[in] suite The srtp crypto suite to use
* @param[in] key Srtp master key and master salt
* @param[in] key_length key buffer length
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_set_srtp_recv_key(struct _MediaStream *stream, enum _MSCryptoSuite suite, const char* key, size_t key_length);
/**
* Set srtp sender key for the given media stream.
* If no srtp session exists on the stream it is created, if it already exists srtp policy is created/modified for the sender side of the stream.
*
* @param[in/out] stream The mediastream to operate on
* @param[in] suite The srtp crypto suite to use
* @param[in] key Srtp master key and master salt in a base 64 NULL terminated string
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_set_srtp_send_key_b64(struct _MediaStream *stream, enum _MSCryptoSuite suite, const char* key);
/**
* Set srtp sender key for the given media stream.
* If no srtp session exists on the stream it is created, if it already exists srtp policy is created/modified for the sender side of the stream.
*
* @param[in/out] stream The mediastream to operate on
* @param[in] suite The srtp crypto suite to use
* @param[in] key Srtp master key and master salt
* @param[in] key_length key buffer length
* @return 0 on success, error code otherwise
*/
MS2_PUBLIC int media_stream_set_srtp_send_key(struct _MediaStream *stream, enum _MSCryptoSuite suite, const char* key, size_t key_length);
/**
* Deallocate ressources for a srtp session
*
* @param[in/out] session SRTP session to be terminated
* @return 0 on success
*/
MS2_PUBLIC err_status_t ms_srtp_dealloc(srtp_t session);
#ifdef __cplusplus
}
#endif
#endif /* ms_srtp_h */
......@@ -25,7 +25,6 @@ if(MSVC)
find_library(LIBMINGWEX NAMES mingwex)
endif()
find_program(AWK_PROGRAM awk)
if(NOT AWK_PROGRAM)
message(FATAL_ERROR "You need the awk program to build mediastreamer2.")
......@@ -153,6 +152,7 @@ set(VOIP_SOURCE_FILES
voip/qualityindicator.c
voip/ringstream.c
voip/zrtp.c
crypto/ms_srtp.c
)
if(ENABLE_ALSA)
......@@ -339,6 +339,9 @@ endif()
if(BZRTP_FOUND)
list(APPEND VOIP_LIBS ${BZRTP_LIBRARIES})
endif()
if(SRTP_FOUND)
list(APPEND VOIP_LIBS ${SRTP_LIBRARIES})
endif()
if(GSM_FOUND)
list(APPEND VOIP_LIBS ${GSM_LIBRARIES})
endif()
......
......@@ -51,7 +51,8 @@ libmediastreamer_voip_la_LIBADD= libmediastreamer_base.la \
$(LIBV4LCONVERT_LIBS) \
$(SPANDSP_LIBS) \
$(PCAP_LIBS) \
$(OPUS_LIBS)
$(OPUS_LIBS) \
$(SRTP_LIBS)
if LIBBZRTP
......@@ -98,7 +99,8 @@ libmediastreamer_voip_la_SOURCES+= voip/private.h \
voip/bitratedriver.c \
voip/qosanalyzer.c voip/qosanalyzer.h \
voip/bitratecontrol.c \
voip/zrtp.c
voip/zrtp.c \
crypto/ms_srtp.c
else
libmediastreamer_base_la_SOURCES+= ortp-deps/logging.c \
ortp-deps/port.c \
......@@ -384,7 +386,8 @@ AM_CFLAGS=\
$(SPANDSP_CFLAGS) \
$(MSSILK_CFLAGS) \
$(PCAP_CFLAGS) \
$(OPUS_CFLAGS)
$(OPUS_CFLAGS) \
$(SRTP_FLAGS)
AM_CXXFLAGS=\
$(STRICT_OPTIONS) \
......
This diff is collapsed.
......@@ -19,22 +19,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ortp/port.h"
#include "ortp/ortp_srtp.h"
#include "ortp/b64.h"
#include "mediastreamer2/mediastream.h"
#include "private.h"
#ifdef ORTP_HAVE_SRTP
#if defined(ANDROID) || (defined(WIN32) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
// Android and Windows phone don't use make install
#include <srtp_priv.h>
#else
#include <srtp/srtp_priv.h>
#endif
#endif /*ORTP_HAVE_SRTP*/
#include <ctype.h>
......@@ -42,7 +30,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer-config.h"
#endif
#ifndef MS_MINIMAL_MTU
/*this is used for determining the minimum size of recv buffers for RTP packets
Keep 1500 for maximum interoparibility*/
......@@ -185,7 +172,7 @@ const char * media_stream_type_str(MediaStream *stream) {
void ms_media_stream_sessions_uninit(MSMediaStreamSessions *sessions){
if (sessions->srtp_session) {
ortp_srtp_dealloc(sessions->srtp_session);
ms_srtp_dealloc(sessions->srtp_session);
sessions->srtp_session=NULL;
}
if (sessions->rtp_session) {
......@@ -250,206 +237,9 @@ void media_stream_enable_adaptive_jittcomp(MediaStream *stream, bool_t enabled)
rtp_session_enable_adaptive_jitter_compensation(stream->sessions.rtp_session, enabled);
}
#ifdef ORTP_HAVE_SRTP
static int check_srtp_session_created(MediaStream *stream){
if (stream->sessions.srtp_session==NULL){
err_status_t err;
srtp_t session;
RtpTransport *rtp=NULL,*rtcp=NULL;
RtpTransportModifier *rtp_modifier, *rtcp_modifier;
err = ortp_srtp_create(&session, NULL);
if (err != 0) {
ms_error("Failed to create srtp session (%d)", err);
return -1;
}
stream->sessions.srtp_session=session;
srtp_transport_modifier_new(session,&rtp_modifier,&rtcp_modifier);
rtp_session_get_transports(stream->sessions.rtp_session,&rtp,&rtcp);
/*if transports are set, we assume they are meta transporters, otherwise create them*/
if (rtp==NULL&&rtcp==NULL){
meta_rtp_transport_new(&rtp, TRUE, NULL, 0);
meta_rtp_transport_new(&rtcp, FALSE, NULL, 0);
}
meta_rtp_transport_append_modifier(rtp, rtp_modifier);
meta_rtp_transport_append_modifier(rtcp, rtcp_modifier);
rtp_session_set_transports(stream->sessions.rtp_session,rtp,rtcp);
stream->sessions.is_secured=TRUE;
}
return 0;
}
static int add_srtp_stream(srtp_t srtp, MSCryptoSuite suite, uint32_t ssrc, const char* b64_key, bool_t keyisb64, bool_t inbound)
{
srtp_policy_t policy;
uint8_t* key;
int key_size;
err_status_t err;
unsigned b64_key_length;
ssrc_t ssrc_conf;
memset(&policy,0,sizeof(policy));
switch(suite){
case MS_AES_128_SHA1_32:
crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
// srtp doc says: not adapted to rtcp...
crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtcp);
break;
case MS_AES_128_NO_AUTH:
crypto_policy_set_aes_cm_128_null_auth(&policy.rtp);
// srtp doc says: not adapted to rtcp...
crypto_policy_set_aes_cm_128_null_auth(&policy.rtcp);
break;
case MS_NO_CIPHER_SHA1_80:
crypto_policy_set_null_cipher_hmac_sha1_80(&policy.rtp);
crypto_policy_set_null_cipher_hmac_sha1_80(&policy.rtcp);
break;
case MS_AES_128_SHA1_80: /*default mode*/
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
break;
case MS_AES_256_SHA1_80:
crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtp);
crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtcp);
break;
case MS_AES_256_SHA1_32:
crypto_policy_set_aes_cm_256_hmac_sha1_32(&policy.rtp);
crypto_policy_set_aes_cm_256_hmac_sha1_32(&policy.rtcp);
break;
case MS_CRYPTO_SUITE_INVALID:
return -1;
break;
}
if (keyisb64==TRUE) {
b64_key_length = strlen(b64_key);
key_size = b64_decode(b64_key, b64_key_length, 0, 0);
if (key_size != policy.rtp.cipher_key_len) {
ortp_error("Key size (%d) doesn't match the selected srtp profile (required %d)",
key_size,
policy.rtp.cipher_key_len);
return -1;
}
key = (uint8_t*) ortp_malloc0(key_size+2); /*srtp uses padding*/
if (b64_decode(b64_key, b64_key_length, key, key_size) != key_size) {
ortp_error("Error decoding key");
ortp_free(key);
return -1;
}
} else {
key=(uint8_t *)b64_key;
}
if (!inbound)
policy.allow_repeat_tx=1; /*necessary for telephone-events*/
/*ssrc_conf.type=inbound ? ssrc_any_inbound : ssrc_specific;*/
ssrc_conf.type=ssrc_specific;
ssrc_conf.value=ssrc;
policy.ssrc = ssrc_conf;
policy.key = key;
policy.next = NULL;
err = srtp_add_stream(srtp, &policy);
if (err != err_status_ok) {
ortp_error("Failed to add stream to srtp session (%d)", err);
if (keyisb64==TRUE) {
ortp_free(key);
}
return -1;
}
if (keyisb64==TRUE) {
ortp_free(key);
}
return 0;
}
static uint32_t find_other_ssrc(srtp_t srtp, uint32_t ssrc){
srtp_stream_ctx_t *stream;
for (stream=srtp->stream_list;stream!=NULL;stream=stream->next){
if (stream->ssrc!=ssrc) return stream->ssrc;
}
return 0;
}
#endif
#ifdef ORTP_HAVE_SRTP
#define _ORTP_HAVE_SRTP 1
#else
#define _ORTP_HAVE_SRTP 0
#endif
bool_t media_stream_srtp_supported(void){
return _ORTP_HAVE_SRTP & ortp_srtp_supported();
}
int media_stream_set_srtp_recv_key(MediaStream *stream, MSCryptoSuite suite, const char* key, bool_t keyisb64){
if (!media_stream_srtp_supported()) {
ms_error("ortp srtp support disabled in oRTP or mediastreamer2");
return -1;
}
#ifdef ORTP_HAVE_SRTP
{
uint32_t ssrc,send_ssrc;
bool_t updated=FALSE;
if (check_srtp_session_created(stream)==-1)
return -1;
/*check if a previous key was configured, in which case remove it*/
send_ssrc=rtp_session_get_send_ssrc(stream->sessions.rtp_session);
ssrc=find_other_ssrc(stream->sessions.srtp_session,htonl(send_ssrc));
/*careful: remove_stream takes the SSRC in network byte order...*/
if (ortp_srtp_remove_stream(stream->sessions.srtp_session,ssrc)==0)
updated=TRUE;
ssrc=rtp_session_get_recv_ssrc(stream->sessions.rtp_session);
ms_message("media_stream_set_srtp_recv_key(): %s key %s",updated ? "changing to" : "starting with", key);
return add_srtp_stream(stream->sessions.srtp_session,suite,ssrc,key,keyisb64,TRUE);
}
#else
return -1;
#endif
}
int media_stream_set_srtp_send_key(MediaStream *stream, MSCryptoSuite suite, const char* key, bool_t keyisb64){
if (!media_stream_srtp_supported()) {
ms_error("ortp srtp support disabled in oRTP or mediastreamer2");
return -1;
}
#ifdef ORTP_HAVE_SRTP
{
uint32_t ssrc;
bool_t updated=FALSE;
if (check_srtp_session_created(stream)==-1)
return -1;
/*check if a previous key was configured, in which case remove it*/
ssrc=rtp_session_get_send_ssrc(stream->sessions.rtp_session);
if (ssrc!=0){
/*careful: remove_stream takes the SSRC in network byte order...*/
if (ortp_srtp_remove_stream(stream->sessions.srtp_session,htonl(ssrc))==0)
updated=TRUE;
}
ms_message("media_stream_set_srtp_send_key(): %s key %s",updated ? "changing to" : "starting with", key);
return add_srtp_stream(stream->sessions.srtp_session,suite,ssrc,key,keyisb64,FALSE);
}
#else
return -1;
#endif
}
/*deprecated*/
bool_t media_stream_enable_srtp(MediaStream *stream, MSCryptoSuite suite, const char *snd_key, const char *rcv_key) {
return media_stream_set_srtp_recv_key(stream,suite,rcv_key,TRUE)==0 && media_stream_set_srtp_send_key(stream,suite,snd_key,TRUE)==0;
return media_stream_set_srtp_recv_key_b64(stream,suite,rcv_key)==0 && media_stream_set_srtp_send_key_b64(stream,suite,snd_key)==0;
}
const MSQualityIndicator *media_stream_get_quality_indicator(MediaStream *stream){
......
......@@ -32,6 +32,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/mscommon.h"
#include "mediastreamer2/mscodecutils.h"
#include "mediastreamer2/msfilter.h"
#include "mediastreamer2/ms_srtp.h"
#include "private.h"
#ifdef __cplusplus
extern "C"{
......@@ -246,6 +248,7 @@ void ms_voip_init(){
ms_message ("Skiping ms_voip_init, because [%i] ref",ms_voip_ref);
return;
}
ms_srtp_init();
ms_factory_init_voip(ms_factory_get_fallback());
}
......@@ -319,6 +322,7 @@ void ms_voip_exit(){
ms_message ("Skiping ms_voip_exit, still [%i] ref",ms_voip_ref);
return;
}
ms_srtp_shutdown();
ms_factory_uninit_voip(ms_factory_get_fallback());
}
......
......@@ -86,6 +86,17 @@ void video_stream_open_player(VideoStream *stream, MSFilter *sink);
void video_stream_close_player(VideoStream *stream);
/**
* Initialise srtp library, shall be called once but multiple call is supported
* @return 0 on success, error code from srtp/crypto/include/err.h otherwise
*/
MS2_PUBLIC err_status_t ms_srtp_init(void);
/**
* Shutdown the srtp library
*/
MS2_PUBLIC void ms_srtp_shutdown(void);
#ifdef __cplusplus
}
#endif
......
......@@ -29,7 +29,6 @@
#undef PACKAGE_STRING
#undef PACKAGE_TARNAME
#undef PACKAGE_VERSION
#include <srtp/srtp.h>
#include <bzrtp/bzrtp.h>
struct _MSZrtpContext{
......@@ -119,9 +118,9 @@ static int32_t ms_zrtp_srtpSecretsAvailable(void* clientData, bzrtpSrtpSecrets_t
memcpy(key + secrets->peerSrtpKeyLength, secrets->peerSrtpSalt, secrets->peerSrtpSaltLength);
if (secrets->authTagAlgo == ZRTP_AUTHTAG_HS32){
media_stream_set_srtp_recv_key(userData->stream, MS_AES_128_SHA1_32, (const char *)key, FALSE);
media_stream_set_srtp_recv_key(userData->stream, MS_AES_128_SHA1_32, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength));
}else if (secrets->authTagAlgo == ZRTP_AUTHTAG_HS80){
media_stream_set_srtp_recv_key(userData->stream, MS_AES_128_SHA1_80, (const char *)key, FALSE);
media_stream_set_srtp_recv_key(userData->stream, MS_AES_128_SHA1_80, (const char *)key, (secrets->peerSrtpKeyLength+secrets->peerSrtpSaltLength));
}else{
ms_fatal("unsupported auth tag");
}
......@@ -134,9 +133,9 @@ static int32_t ms_zrtp_srtpSecretsAvailable(void* clientData, bzrtpSrtpSecrets_t
memcpy(key + secrets->selfSrtpKeyLength, secrets->selfSrtpSalt, secrets->selfSrtpSaltLength);
if (secrets->authTagAlgo == ZRTP_AUTHTAG_HS32){
media_stream_set_srtp_send_key(userData->stream, MS_AES_128_SHA1_32, (const char *)key, FALSE);
media_stream_set_srtp_send_key(userData->stream, MS_AES_128_SHA1_32, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength));
}else if (secrets->authTagAlgo == ZRTP_AUTHTAG_HS80){
media_stream_set_srtp_send_key(userData->stream, MS_AES_128_SHA1_80, (const char *)key, FALSE);
media_stream_set_srtp_send_key(userData->stream, MS_AES_128_SHA1_80, (const char *)key, (secrets->selfSrtpKeyLength+secrets->selfSrtpSaltLength));
}else{
ms_fatal("unsupported auth tag");
}
......
......@@ -101,8 +101,8 @@ static void basic_audio_stream() {
AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE);
stats_t margaux_stats;
RtpProfile* profile = rtp_profile_new("default profile");
char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE);
char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE);
reset_stats(&marielle_stats);
reset_stats(&margaux_stats);
......@@ -110,6 +110,65 @@ static void basic_audio_stream() {
rtp_profile_set_payload (profile,0,&payload_type_pcmu8000);
CU_ASSERT_EQUAL(audio_stream_start_full(margaux
, profile
, MARIELLE_IP
, MARIELLE_RTP_PORT
, MARIELLE_IP
, MARIELLE_RTCP_PORT
, 0
, 50
, NULL
, recorded_file
, NULL
, NULL
, 0),0);
CU_ASSERT_EQUAL(audio_stream_start_full(marielle
, profile
, MARGAUX_IP
, MARGAUX_RTP_PORT
, MARGAUX_IP
, MARGAUX_RTCP_PORT
, 0
, 50
, hello_file
, NULL
, NULL
, NULL
, 0),0);
ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE);
CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000));
audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp);
audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp);
/* No packet loss is assumed */
CU_ASSERT_EQUAL(marielle_stats.rtp.sent,margaux_stats.rtp.recv);
audio_stream_stop(marielle);
audio_stream_stop(margaux);
unlink(recorded_file);
ms_free(recorded_file);
ms_free(hello_file);
}
static void encrypted_audio_stream() {
AudioStream * marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE);
stats_t marielle_stats;
AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE);
stats_t margaux_stats;
RtpProfile* profile = rtp_profile_new("default profile");
char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE);
char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE);
reset_stats(&marielle_stats);
reset_stats(&margaux_stats);
rtp_profile_set_payload (profile,0,&payload_type_pcmu8000);
CU_ASSERT_EQUAL(audio_stream_start_full(margaux
, profile
......@@ -139,6 +198,9 @@ static void basic_audio_stream() {
, NULL
, 0),0);
CU_ASSERT_FATAL(media_stream_set_srtp_send_key_b64((MediaStream *)marielle, MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0);
CU_ASSERT_FATAL(media_stream_set_srtp_recv_key_b64((MediaStream *)margaux, MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") ==0);
ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE);
CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000));
......@@ -153,8 +215,8 @@ static void basic_audio_stream() {
audio_stream_stop(margaux);
unlink(recorded_file);
ms_free(recorded_file);
ms_free(hello_file);
ms_free(recorded_file);
ms_free(hello_file);
}
#if 0
......@@ -200,6 +262,7 @@ static void audio_stream_dtmf(int codec_payload, int initial_bitrate,int target_
static test_t tests[] = {
{ "Basic audio stream", basic_audio_stream },
{ "Encrypted audio stream", encrypted_audio_stream },
};
test_suite_t audio_stream_test_suite