[Asterisk-code-review] res srtp: Add support for libsrtp2 (asterisk[13])

Joshua Colp asteriskteam at digium.com
Tue Jun 6 05:00:57 CDT 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/5722 )

Change subject: res_srtp: Add support for libsrtp2
......................................................................


res_srtp: Add support for libsrtp2

ASTERISK-25294 #close
Reported by: Tzafrir Cohen

ASTERISK-26976 #close
Reported by: Alex

Change-Id: I789b1c3d1ed31365bbd9339fa58ef36f48833c40
---
M autoconf/ast_ext_lib.m4
M configure
M configure.ac
M include/asterisk/autoconfig.h.in
M res/res_srtp.c
A res/srtp/srtp_compat.h
6 files changed, 461 insertions(+), 58 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit



diff --git a/autoconf/ast_ext_lib.m4 b/autoconf/ast_ext_lib.m4
index 2c73b40..cd5a3a7 100644
--- a/autoconf/ast_ext_lib.m4
+++ b/autoconf/ast_ext_lib.m4
@@ -164,3 +164,39 @@
 fi
 m4_ifval([$7], [AH_TEMPLATE(m4_bpatsubst([[HAVE_$1_VERSION]], [(.*)]), [Define to the version of the $2 library.])])
 ])
+
+# Check if the previously discovered library can be dynamically linked.
+#
+# AST_EXT_LIB_CHECK_SHARED([package], [library], [function], [header],
+#	 [extra libs], [extra cflags], [action-if-true], [action-if-false])
+AC_DEFUN([AST_EXT_LIB_CHECK_SHARED],
+[
+if test "x${PBX_$1}" = "x1"; then
+   ast_ext_lib_check_shared_saved_libs="${LIBS}"
+   ast_ext_lib_check_shared_saved_ldflags="${LDFLAGS}"
+   ast_ext_lib_check_shared_saved_cflags="${CFLAGS}"
+   LIBS="${LIBS} ${$1_LIB} $5"
+   LDFLAGS="${LDFLAGS} -shared -fPIC"
+   CFLAGS="${CFLAGS} ${$1_INCLUDE} $6"
+   AC_MSG_CHECKING(for the ability of -l$2 to be linked in a shared object)
+   AC_LINK_IFELSE(
+   [
+       AC_LANG_PROGRAM(
+           [#include <$4>],
+           [$3();]
+       )
+   ],
+   [
+      AC_MSG_RESULT(yes)
+      $7
+   ],
+   [
+      AC_MSG_RESULT(no)
+      $8
+   ]
+   )
+   CFLAGS="${ast_ext_lib_check_shared_saved_cflags}"
+   LDFLAGS="${ast_ext_lib_check_shared_saved_ldflags}"
+   LIBS="${ast_ext_lib_check_shared_saved_libs}"
+fi
+])
diff --git a/configure b/configure
index 879ed6d..c0d6a8f 100755
--- a/configure
+++ b/configure
@@ -32637,6 +32637,308 @@
    else
       ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
       CFLAGS="${CFLAGS} "
+      as_ac_Lib=`$as_echo "ac_cv_lib_srtp2_${pbxfuncname}" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${pbxfuncname} in -lsrtp2" >&5
+$as_echo_n "checking for ${pbxfuncname} in -lsrtp2... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsrtp2 ${pbxlibdir}  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ${pbxfuncname} ();
+int
+main ()
+{
+return ${pbxfuncname} ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval "$as_ac_Lib=yes"
+else
+  eval "$as_ac_Lib=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+eval ac_res=\$$as_ac_Lib
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
+  AST_SRTP_FOUND=yes
+else
+  AST_SRTP_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+   fi
+
+   # now check for the header.
+   if test "${AST_SRTP_FOUND}" = "yes"; then
+      SRTP_LIB="${pbxlibdir} -lsrtp2 "
+      # if --with-SRTP=DIR has been specified, use it.
+      if test "x${SRTP_DIR}" != "x"; then
+         SRTP_INCLUDE="-I${SRTP_DIR}/include"
+      fi
+      SRTP_INCLUDE="${SRTP_INCLUDE} "
+      if test "xsrtp2/srtp.h" = "x" ; then	# no header, assume found
+         SRTP_HEADER_FOUND="1"
+      else				# check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${SRTP_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "srtp2/srtp.h" "ac_cv_header_srtp2_srtp_h" "$ac_includes_default"
+if test "x$ac_cv_header_srtp2_srtp_h" = xyes; then :
+  SRTP_HEADER_FOUND=1
+else
+  SRTP_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+      fi
+      if test "x${SRTP_HEADER_FOUND}" = "x0" ; then
+         SRTP_LIB=""
+         SRTP_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then		# only checking headers -> no library
+            SRTP_LIB=""
+         fi
+         PBX_SRTP=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_SRTP 1
+_ACEOF
+
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_SRTP_VERSION 2
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+
+if test "x${PBX_SRTP}" = "x1"; then
+   ast_ext_lib_check_shared_saved_libs="${LIBS}"
+   ast_ext_lib_check_shared_saved_ldflags="${LDFLAGS}"
+   ast_ext_lib_check_shared_saved_cflags="${CFLAGS}"
+   LIBS="${LIBS} ${SRTP_LIB} "
+   LDFLAGS="${LDFLAGS} -shared -fPIC"
+   CFLAGS="${CFLAGS} ${SRTP_INCLUDE} "
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the ability of -lsrtp2 to be linked in a shared object" >&5
+$as_echo_n "checking for the ability of -lsrtp2 to be linked in a shared object... " >&6; }
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+       #include <srtp2/srtp.h>
+int
+main ()
+{
+srtp_init();
+
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+
+else
+
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: ***" >&5
+$as_echo "$as_me: WARNING: ***" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** libsrtp2 could not be linked as a shared object." >&5
+$as_echo "$as_me: WARNING: *** libsrtp2 could not be linked as a shared object." >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** Try compiling libsrtp2 manually. Configure libsrtp2" >&5
+$as_echo "$as_me: WARNING: *** Try compiling libsrtp2 manually. Configure libsrtp2" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** with ./configure --prefix=/usr replacing /usr with" >&5
+$as_echo "$as_me: WARNING: *** with ./configure --prefix=/usr replacing /usr with" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** the prefix of your choice, and then make with" >&5
+$as_echo "$as_me: WARNING: *** the prefix of your choice, and then make with" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** 'make libsrtp2.so'" >&5
+$as_echo "$as_me: WARNING: *** 'make libsrtp2.so'" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: ***" >&5
+$as_echo "$as_me: WARNING: ***" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** After re-installing libsrtp2, re-run the Asterisk" >&5
+$as_echo "$as_me: WARNING: *** After re-installing libsrtp2, re-run the Asterisk" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** configure script." >&5
+$as_echo "$as_me: WARNING: *** configure script." >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: ***" >&5
+$as_echo "$as_me: WARNING: ***" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** If you do not need SRTP support re-run configure" >&5
+$as_echo "$as_me: WARNING: *** If you do not need SRTP support re-run configure" >&2;}
+    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** with the --without-srtp option." >&5
+$as_echo "$as_me: WARNING: *** with the --without-srtp option." >&2;}
+    exit 1
+
+
+
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+   CFLAGS="${ast_ext_lib_check_shared_saved_cflags}"
+   LDFLAGS="${ast_ext_lib_check_shared_saved_ldflags}"
+   LIBS="${ast_ext_lib_check_shared_saved_libs}"
+fi
+
+
+if test "x$PBX_SRTP" = x1;
+then
+
+if test "x${PBX_SRTP_SHUTDOWN}" != "x1" -a "${USE_SRTP_SHUTDOWN}" != "no"; then
+   pbxlibdir=""
+   # if --with-SRTP_SHUTDOWN=DIR has been specified, use it.
+   if test "x${SRTP_SHUTDOWN_DIR}" != "x"; then
+      if test -d ${SRTP_SHUTDOWN_DIR}/lib; then
+         pbxlibdir="-L${SRTP_SHUTDOWN_DIR}/lib"
+      else
+         pbxlibdir="-L${SRTP_SHUTDOWN_DIR}"
+      fi
+   fi
+   pbxfuncname="srtp_shutdown"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_SRTP_SHUTDOWN_FOUND=yes
+   else
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
+      as_ac_Lib=`$as_echo "ac_cv_lib_srtp2_${pbxfuncname}" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${pbxfuncname} in -lsrtp2" >&5
+$as_echo_n "checking for ${pbxfuncname} in -lsrtp2... " >&6; }
+if eval \${$as_ac_Lib+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lsrtp2 ${pbxlibdir}  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ${pbxfuncname} ();
+int
+main ()
+{
+return ${pbxfuncname} ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  eval "$as_ac_Lib=yes"
+else
+  eval "$as_ac_Lib=no"
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+eval ac_res=\$$as_ac_Lib
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+if eval test \"x\$"$as_ac_Lib"\" = x"yes"; then :
+  AST_SRTP_SHUTDOWN_FOUND=yes
+else
+  AST_SRTP_SHUTDOWN_FOUND=no
+fi
+
+      CFLAGS="${ast_ext_lib_check_save_CFLAGS}"
+   fi
+
+   # now check for the header.
+   if test "${AST_SRTP_SHUTDOWN_FOUND}" = "yes"; then
+      SRTP_SHUTDOWN_LIB="${pbxlibdir} -lsrtp2 "
+      # if --with-SRTP_SHUTDOWN=DIR has been specified, use it.
+      if test "x${SRTP_SHUTDOWN_DIR}" != "x"; then
+         SRTP_SHUTDOWN_INCLUDE="-I${SRTP_SHUTDOWN_DIR}/include"
+      fi
+      SRTP_SHUTDOWN_INCLUDE="${SRTP_SHUTDOWN_INCLUDE} "
+      if test "xsrtp2/srtp.h" = "x" ; then	# no header, assume found
+         SRTP_SHUTDOWN_HEADER_FOUND="1"
+      else				# check for the header
+         ast_ext_lib_check_saved_CPPFLAGS="${CPPFLAGS}"
+         CPPFLAGS="${CPPFLAGS} ${SRTP_SHUTDOWN_INCLUDE}"
+         ac_fn_c_check_header_mongrel "$LINENO" "srtp2/srtp.h" "ac_cv_header_srtp2_srtp_h" "$ac_includes_default"
+if test "x$ac_cv_header_srtp2_srtp_h" = xyes; then :
+  SRTP_SHUTDOWN_HEADER_FOUND=1
+else
+  SRTP_SHUTDOWN_HEADER_FOUND=0
+fi
+
+
+         CPPFLAGS="${ast_ext_lib_check_saved_CPPFLAGS}"
+      fi
+      if test "x${SRTP_SHUTDOWN_HEADER_FOUND}" = "x0" ; then
+         SRTP_SHUTDOWN_LIB=""
+         SRTP_SHUTDOWN_INCLUDE=""
+      else
+         if test "x${pbxfuncname}" = "x" ; then		# only checking headers -> no library
+            SRTP_SHUTDOWN_LIB=""
+         fi
+         PBX_SRTP_SHUTDOWN=1
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_SRTP_SHUTDOWN 1
+_ACEOF
+
+      fi
+   fi
+fi
+
+
+
+    # libsrtp2 removed support for PRNG, so we require OpenSSL
+    if test "x$PBX_OPENSSL" != x1;
+    then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: ***" >&5
+$as_echo "$as_me: WARNING: ***" >&2;}
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** OpenSSL required when using libsrtp2, checking for libsrtp instead." >&5
+$as_echo "$as_me: WARNING: *** OpenSSL required when using libsrtp2, checking for libsrtp instead." >&2;}
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: ***" >&5
+$as_echo "$as_me: WARNING: ***" >&2;}
+        PBX_SRTP=0
+    fi
+fi
+
+if test "x$PBX_SRTP" != x1;
+then
+
+if test "x${PBX_SRTP}" != "x1" -a "${USE_SRTP}" != "no"; then
+   pbxlibdir=""
+   # if --with-SRTP=DIR has been specified, use it.
+   if test "x${SRTP_DIR}" != "x"; then
+      if test -d ${SRTP_DIR}/lib; then
+         pbxlibdir="-L${SRTP_DIR}/lib"
+      else
+         pbxlibdir="-L${SRTP_DIR}"
+      fi
+   fi
+   pbxfuncname="srtp_init"
+   if test "x${pbxfuncname}" = "x" ; then   # empty lib, assume only headers
+      AST_SRTP_FOUND=yes
+   else
+      ast_ext_lib_check_save_CFLAGS="${CFLAGS}"
+      CFLAGS="${CFLAGS} "
       as_ac_Lib=`$as_echo "ac_cv_lib_srtp_${pbxfuncname}" | $as_tr_sh`
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${pbxfuncname} in -lsrtp" >&5
 $as_echo_n "checking for ${pbxfuncname} in -lsrtp... " >&6; }
@@ -32719,26 +33021,29 @@
 #define HAVE_SRTP 1
 _ACEOF
 
+         cat >>confdefs.h <<_ACEOF
+#define HAVE_SRTP_VERSION 1
+_ACEOF
+
       fi
    fi
 fi
 
 
 
-if test "$PBX_SRTP" = "1";
-then
-    saved_libs="${LIBS}"
-    saved_ldflags="${LDFLAGS}"
-    saved_cflags="${CFLAGS}"
-    LIBS="${LIBS} ${SRTP_LIB}"
-    LDFLAGS="${LDFLAGS} -shared -fPIC"
-    CFLAGS="${CFLAGS} ${SRTP_INCLUDE}"
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the ability of -lsrtp to be linked in a shared object" >&5
+if test "x${PBX_SRTP}" = "x1"; then
+   ast_ext_lib_check_shared_saved_libs="${LIBS}"
+   ast_ext_lib_check_shared_saved_ldflags="${LDFLAGS}"
+   ast_ext_lib_check_shared_saved_cflags="${CFLAGS}"
+   LIBS="${LIBS} ${SRTP_LIB} "
+   LDFLAGS="${LDFLAGS} -shared -fPIC"
+   CFLAGS="${CFLAGS} ${SRTP_INCLUDE} "
+   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the ability of -lsrtp to be linked in a shared object" >&5
 $as_echo_n "checking for the ability of -lsrtp to be linked in a shared object... " >&6; }
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
-        #include <srtp/srtp.h>
+       #include <srtp/srtp.h>
 int
 main ()
 {
@@ -32750,12 +33055,16 @@
 
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
+
+
 else
 
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
+
         { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: ***" >&5
 $as_echo "$as_me: WARNING: ***" >&2;}
         { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** libsrtp could not be linked as a shared object." >&5
@@ -32766,8 +33075,8 @@
 $as_echo "$as_me: WARNING: *** with ./configure CFLAGS=-fPIC --prefix=/usr" >&2;}
         { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** replacing /usr with the prefix of your choice." >&5
 $as_echo "$as_me: WARNING: *** replacing /usr with the prefix of your choice." >&2;}
-        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** After re-installing libsrtp" >&5
-$as_echo "$as_me: WARNING: *** After re-installing libsrtp" >&2;}
+        { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** After re-installing libsrtp, re-run the Asterisk" >&5
+$as_echo "$as_me: WARNING: *** After re-installing libsrtp, re-run the Asterisk" >&2;}
         { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** configure script." >&5
 $as_echo "$as_me: WARNING: *** configure script." >&2;}
         { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: ***" >&5
@@ -32779,14 +33088,18 @@
         exit 1
 
 
+
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-    LIBS="${saved_libs}"
-    LDFLAGS="${saved_ldflags}"
-    CFLAGS="${saved_cflags}"
+   CFLAGS="${ast_ext_lib_check_shared_saved_cflags}"
+   LDFLAGS="${ast_ext_lib_check_shared_saved_ldflags}"
+   LIBS="${ast_ext_lib_check_shared_saved_libs}"
 fi
 
+
+    if test "x$PBX_SRTP" = x1;
+    then
 
 if test "x${PBX_SRTP_SHUTDOWN}" != "x1" -a "${USE_SRTP_SHUTDOWN}" != "no"; then
    pbxlibdir=""
@@ -32891,6 +33204,8 @@
 fi
 
 
+    fi
+fi
 
 for ver in 2.0 2.2 2.4 2.6; do
 
diff --git a/configure.ac b/configure.ac
index bf98ad3..e36f2de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2425,46 +2425,59 @@
         AST_C_DEFINE_CHECK([SSL_OP_NO_TLSV1_2], [SSL_OP_NO_TLSv1_2], [openssl/ssl.h])
 fi
 
-AST_EXT_LIB_CHECK([SRTP], [srtp], [srtp_init], [srtp/srtp.h])
+AST_EXT_LIB_CHECK([SRTP], [srtp2], [srtp_init], [srtp2/srtp.h], [], [], [2])
+AST_EXT_LIB_CHECK_SHARED([SRTP], [srtp2], [srtp_init], [srtp2/srtp.h], [], [], [], [
+    AC_MSG_WARN([***])
+    AC_MSG_WARN([*** libsrtp2 could not be linked as a shared object.])
+    AC_MSG_WARN([*** Try compiling libsrtp2 manually. Configure libsrtp2])
+    AC_MSG_WARN([*** with ./configure --prefix=/usr replacing /usr with])
+    AC_MSG_WARN([*** the prefix of your choice, and then make with])
+    AC_MSG_WARN([*** 'make libsrtp2.so'])
+    AC_MSG_WARN([***])
+    AC_MSG_WARN([*** After re-installing libsrtp2, re-run the Asterisk])
+    AC_MSG_WARN([*** configure script.])
+    AC_MSG_WARN([***])
+    AC_MSG_WARN([*** If you do not need SRTP support re-run configure])
+    AC_MSG_WARN([*** with the --without-srtp option.])
+    exit 1
+])
 
-if test "$PBX_SRTP" = "1";
+if test "x$PBX_SRTP" = x1;
 then
-    saved_libs="${LIBS}"
-    saved_ldflags="${LDFLAGS}"
-    saved_cflags="${CFLAGS}"
-    LIBS="${LIBS} ${SRTP_LIB}"
-    LDFLAGS="${LDFLAGS} -shared -fPIC"
-    CFLAGS="${CFLAGS} ${SRTP_INCLUDE}"
-    AC_MSG_CHECKING(for the ability of -lsrtp to be linked in a shared object)
-    AC_LINK_IFELSE(
-    [
-        AC_LANG_PROGRAM(
-            [#include <srtp/srtp.h>],
-            [srtp_init();]
-        )
-    ],
-    [ AC_MSG_RESULT(yes) ],
-    [
-        AC_MSG_RESULT(no)
-        AC_MSG_WARN(***)
-        AC_MSG_WARN(*** libsrtp could not be linked as a shared object.)
-        AC_MSG_WARN(*** Try compiling libsrtp manually. Configure libsrtp)
-        AC_MSG_WARN(*** with ./configure CFLAGS=-fPIC --prefix=/usr)
-        AC_MSG_WARN(*** replacing /usr with the prefix of your choice.)
-        AC_MSG_WARN(*** After re-installing libsrtp, re-run the Asterisk)
-        AC_MSG_WARN(*** configure script.)
-        AC_MSG_WARN(***)
-        AC_MSG_WARN(*** If you do not need SRTP support re-run configure)
-        AC_MSG_WARN(*** with the --without-srtp option.)
-        exit 1
-    ]
-    )
-    LIBS="${saved_libs}"
-    LDFLAGS="${saved_ldflags}"
-    CFLAGS="${saved_cflags}"
+    AST_EXT_LIB_CHECK([SRTP_SHUTDOWN], [srtp2], [srtp_shutdown], [srtp2/srtp.h])
+
+    # libsrtp2 removed support for PRNG, so we require OpenSSL
+    if test "x$PBX_OPENSSL" != x1;
+    then
+        AC_MSG_WARN([***])
+        AC_MSG_WARN([*** OpenSSL required when using libsrtp2, checking for libsrtp instead.])
+        AC_MSG_WARN([***])
+        PBX_SRTP=0
+    fi
 fi
 
-AST_EXT_LIB_CHECK([SRTP_SHUTDOWN], [srtp], [srtp_shutdown], [srtp/srtp.h])
+if test "x$PBX_SRTP" != x1;
+then
+    AST_EXT_LIB_CHECK([SRTP], [srtp], [srtp_init], [srtp/srtp.h], [], [], [1])
+    AST_EXT_LIB_CHECK_SHARED([SRTP], [srtp], [srtp_init], [srtp/srtp.h], [], [], [], [
+        AC_MSG_WARN([***])
+        AC_MSG_WARN([*** libsrtp could not be linked as a shared object.])
+        AC_MSG_WARN([*** Try compiling libsrtp manually. Configure libsrtp])
+        AC_MSG_WARN([*** with ./configure CFLAGS=-fPIC --prefix=/usr])
+        AC_MSG_WARN([*** replacing /usr with the prefix of your choice.])
+        AC_MSG_WARN([*** After re-installing libsrtp, re-run the Asterisk])
+        AC_MSG_WARN([*** configure script.])
+        AC_MSG_WARN([***])
+        AC_MSG_WARN([*** If you do not need SRTP support re-run configure])
+        AC_MSG_WARN([*** with the --without-srtp option.])
+        exit 1
+    ])
+
+    if test "x$PBX_SRTP" = x1;
+    then
+        AST_EXT_LIB_CHECK([SRTP_SHUTDOWN], [srtp], [srtp_shutdown], [srtp/srtp.h])
+    fi
+fi
 
 for ver in 2.0 2.2 2.4 2.6; do
 	AST_PKG_CONFIG_CHECK([GMIME], gmime-$ver)
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index e7128e6..723d84d 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -871,6 +871,9 @@
 /* Define to 1 if SRTP has the SRTP Library Shutdown Function feature. */
 #undef HAVE_SRTP_SHUTDOWN
 
+/* Define to the version of the srtp library. */
+#undef HAVE_SRTP_VERSION
+
 /* Define to 1 if you have the ISDN SS7 library. */
 #undef HAVE_SS7
 
diff --git a/res/res_srtp.c b/res/res_srtp.c
index 97773c1..a76128f 100644
--- a/res/res_srtp.c
+++ b/res/res_srtp.c
@@ -39,11 +39,18 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include <srtp/srtp.h>
-#ifdef HAVE_OPENSSL
-#include <openssl/rand.h>
+#if HAVE_SRTP_VERSION > 1
+# include <srtp2/srtp.h>
+# include <srtp2/crypto_types.h>
+# include "srtp/srtp_compat.h"
+# include <openssl/rand.h>
 #else
-#include <srtp/crypto_kernel.h>
+# include <srtp/srtp.h>
+# ifdef HAVE_OPENSSL
+#  include <openssl/rand.h>
+# else
+#  include <srtp/crypto_kernel.h>
+# endif
 #endif
 
 #include "asterisk/lock.h"
diff --git a/res/srtp/srtp_compat.h b/res/srtp/srtp_compat.h
new file mode 100644
index 0000000..4ab39f3
--- /dev/null
+++ b/res/srtp/srtp_compat.h
@@ -0,0 +1,29 @@
+#ifndef AST_SRTP_COMPAT_H
+#define AST_SRTP_COMPAT_H
+
+/* Compatibility for libsrtp 2.x */
+
+#define crypto_policy_t srtp_crypto_policy_t
+
+#define AES_128_ICM SRTP_AES_ICM
+#define HMAC_SHA1 SRTP_HMAC_SHA1
+
+#define err_status_t srtp_err_status_t
+#define err_status_ok srtp_err_status_ok
+#define err_status_fail srtp_err_status_fail
+#define err_status_bad_param srtp_err_status_bad_param
+#define err_status_alloc_fail srtp_err_status_alloc_fail
+#define err_status_dealloc_fail srtp_err_status_dealloc_fail
+#define err_status_init_fail srtp_err_status_init_fail
+#define err_status_terminus srtp_err_status_terminus
+#define err_status_auth_fail srtp_err_status_auth_fail
+#define err_status_cipher_fail srtp_err_status_cipher_fail
+#define err_status_replay_fail srtp_err_status_replay_fail
+#define err_status_replay_old srtp_err_status_replay_old
+#define err_status_algo_fail srtp_err_status_algo_fail
+#define err_status_no_such_op srtp_err_status_no_such_op
+#define err_status_no_ctx srtp_err_status_no_ctx
+#define err_status_cant_check srtp_err_status_cant_check
+#define err_status_key_expired srtp_err_status_key_expired
+
+#endif /* AST_SRTP_COMPAT_H */

-- 
To view, visit https://gerrit.asterisk.org/5722
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I789b1c3d1ed31365bbd9339fa58ef36f48833c40
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list