Commit c4e2c1c5 authored by johan's avatar johan

Add wrapper to mbedTLS v2

+fix tester when build using cmake
parent 19923c26
......@@ -66,7 +66,19 @@ find_package(CUnit)
set(ENABLE_TESTS OFF CACHE BOOL "Enable compilation of tests" FORCE)
endif()
endif()
find_package(PolarSSL REQUIRED)
find_package(MbedTLS)
if (MBEDTLS_FOUND)
message("Use mbedTLS")
else()
find_package(PolarSSL)
if (POLARSSL_FOUND)
message("Use polarSSL")
else()
message(FATAL_ERROR " No polarSSL or mbedTLS found")
endif()
endif()
find_package(XML2)
if(XML2_FOUND)
......@@ -92,14 +104,22 @@ if(STRICT_OPTIONS_CPP)
string(REPLACE ";" " " STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP}")
endif()
if (MBEDTLS_FOUND)
include_directories(
include
${CMAKE_CURRENT_BINARY_DIR}
${MBEDTLS_INCLUDE_DIRS}
)
set(LIBS ${MBEDTLS_LIBRARIES})
else ()
include_directories(
include
${CMAKE_CURRENT_BINARY_DIR}
${POLARSSL_INCLUDE_DIRS}
)
set(LIBS ${POLARSSL_LIBRARIES})
endif()
include_directories(
include
${CMAKE_CURRENT_BINARY_DIR}
${POLARSSL_INCLUDE_DIRS}
)
set(LIBS ${POLARSSL_LIBRARIES})
if(CUNIT_FOUND)
include_directories(${CUNIT_INCLUDE_DIRS})
list(APPEND LIBS ${CUNIT_LIBRARIES})
......
############################################################################
# FindMdebTLS.txt
# Copyright (C) 2015 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
############################################################################
#
# - Find the mbedTLS include file and library
#
# MBEDTLS_FOUND - system has mbedTLS
# MBEDTLS_INCLUDE_DIRS - the mbedTLS include directory
# MBEDTLS_LIBRARIES - The libraries needed to use mbedTLS
include(CMakePushCheckState)
include(CheckIncludeFile)
include(CheckCSourceCompiles)
include(CheckSymbolExists)
set(_MBEDTLS_ROOT_PATHS
${CMAKE_INSTALL_PREFIX}
)
find_path(MBEDTLS_INCLUDE_DIRS
NAMES mbedtls/ssl.h
HINTS _MBEDTLS_ROOT_PATHS
PATH_SUFFIXES include
)
# find the three mbedtls library
find_library(MBEDTLS_LIBRARY
NAMES mbedtls
HINTS _MBEDTLS_ROOT_PATHS
PATH_SUFFIXES bin lib
)
if (MBEDTLS_LIBRARY)
find_library(MBEDX509_LIBRARY
NAMES mbedx509
HINTS _MBEDTLS_ROOT_PATHS
PATH_SUFFIXES bin lib
)
endif()
if (MBEDX509_LIBRARY)
find_library(MBEDCRYPTO_LIBRARY
NAMES mbedcrypto
HINTS _MBEDTLS_ROOT_PATHS
PATH_SUFFIXES bin lib
)
endif()
# check we have a mbedTLS version 2 or above(all functions are prefixed mbedtls_)
if (MBEDCRYPTO_LIBRARY)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${MBEDTLS_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY})
check_symbol_exists(mbedtls_ssl_init "mbedtls/ssl.h" MBEDTLS_V2)
cmake_pop_check_state()
endif()
if (MBEDTLS_V2)
set (MBEDTLS_LIBRARIES
${MBEDTLS_LIBRARY}
${MBEDX509_LIBRARY}
${MBEDCRYPTO_LIBRARY}
)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MbedTLS
DEFAULT_MSG
MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARIES
)
mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARIES)
......@@ -31,29 +31,71 @@ if test "$found_cunit" = "no" ; then
])
fi
dnl check polarssl
dnl check mbedtls unless we specified a with-polarssl
crypto_lib=mbedtls
AC_ARG_WITH( polarssl,
[ --with-polarssl Set prefix where polarssl or mbedTLS can be found (ex:/usr, /usr/local)[default=PREFIX] ],
[ polarssl_prefix=${withval}],[ polarssl_prefix=${prefix} ])
[ --with-polarssl Set prefix where polarssl can be found (ex:/usr, /usr/local)[default=PREFIX], if set, force usage of polarssl instead of mbedtls when both are present ],
[
polarssl_prefix=${withval}
crypto_lib=polarssl
],[ polarssl_prefix=${prefix} ])
if test "$crypto_lib" == "mbedtls" ; then
AC_ARG_WITH( mbedtls,
[ --with-mbedtls Set prefix where mbedTLS can be found (ex:/usr, /usr/local)[default=PREFIX] ],
[ mbedtls_prefix=${withval} ],[ mbedtls_prefix=${prefix} ])
if test "mbedtls_prefix" != "NONE" ; then
MBEDTLS_CFLAGS="-I${mbedtls_prefix}/include"
MBEDTLS_LIBS="-L${mbedtls_prefix}/lib"
fi
LIBS_save=$LIBS
LIBS="$LIBS $MBEDTLS_LIBS"
AC_CHECK_LIB(mbedtls, mbedtls_ssl_init, [
mbedtls_found=yes
MBEDTLS_LIBS="$MBEDTLS_LIBS -lmbedtls -lmbedx509 -lmbedcrypto"
AC_MSG_NOTICE("Use mbed TLS as crypto library")
],
[mbdetls_found=no],
[-lmbedx509 -lmbedcrypto]
)
LIBS=$LIBS_save
AC_SUBST(MBEDTLS_LIBS)
AC_SUBST(MBEDTLS_CFLAGS)
fi
AM_CONDITIONAL(LIBMBEDTLS, test x$mbedtls_found == xyes)
dnl check polarssl if no mbedtls was found
polarssl_found=no
if test "$mbedtls_found" != "yes" ; then
if test "$polarssl_prefix" != "NONE" ; then
POLARSSL_CFLAGS="-I${polarssl_prefix}/include"
POLARSSL_LIBS="-L${polarssl_prefix}/lib"
fi
LIBS_save=$LIBS
LIBS="$LIBS $POLARSSL_LIBS"
AC_CHECK_LIB(polarssl, ssl_init , [
POLARSSL_LIBS="$POLARSSL_LIBS -lpolarssl"
polarssl_found=yes
AC_MSG_NOTICE("Use polar SSL as crypto library")
],
[AC_MSG_ERROR([MbedTLS nor PolarSSL library not found])])
LIBS=$LIBS_save
if test "$polarssl_prefix" != "NONE" ; then
POLARSSL_CFLAGS="-I${polarssl_prefix}/include"
POLARSSL_LIBS="-L${polarssl_prefix}/lib"
AC_SUBST(POLARSSL_LIBS)
AC_SUBST(POLARSSL_CFLAGS)
fi
LIBS_save=$LIBS
LIBS="$LIBS $POLARSSL_LIBS"
AC_CHECK_LIB(mbedtls, ssl_init , [POLARSSL_LIBS="$POLARSSL_LIBS -lmbedtls"],
[
AC_CHECK_LIB(polarssl, ssl_init, [POLARSSL_LIBS="$POLARSSL_LIBS -lpolarssl"],
[ AC_MSG_ERROR([Polarssl or mbedTLS library not found]) ]
)
])
LIBS=$LIBS_save
AC_SUBST(POLARSSL_LIBS)
AC_SUBST(POLARSSL_CFLAGS)
AM_CONDITIONAL(LIBPOLARSSL, test x$polarssl_found == xyes)
dnl check libxml2
PKG_CHECK_MODULES(LIBXML2, [libxml-2.0] ,[libxml2_found=yes] ,foo=bar)
......
......@@ -22,13 +22,23 @@
set(SOURCE_FILES
bzrtp.c
cryptoPolarssl.c
cryptoUtils.c
packetParser.c
pgpwords.c
stateMachine.c
zidCache.c
)
if (POLARSSL_FOUND)
set(SOURCE_FILES
${SOURCE_FILES}
cryptoPolarssl.c
)
elseif (MBEDTLS_FOUND)
set(SOURCE_FILES
${SOURCE_FILES}
cryptoMbedtls.c
)
endif()
apply_compile_flags(SOURCE_FILES "CPP")
......
lib_LTLIBRARIES = libbzrtp.la
libbzrtp_la_LIBADD= $(POLARSSL_LIBS) $(LIBXML2_LIBS)
libbzrtp_la_SOURCES= bzrtp.c cryptoPolarssl.c cryptoUtils.c packetParser.c zidCache.c stateMachine.c pgpwords.c
libbzrtp_la_LDFLAGS=-fvisibility=hidden -no-undefined
libbzrtp_la_LIBADD= $(LIBXML2_LIBS)
libbzrtp_la_SOURCES= bzrtp.c cryptoUtils.c packetParser.c zidCache.c stateMachine.c pgpwords.c
AM_CPPFLAGS= -I$(top_srcdir)/include
AM_CFLAGS= $(POLARSSL_CFLAGS) $(LIBXML2_CFLAGS)
AM_CFLAGS= $(LIBXML2_CFLAGS)
if LIBPOLARSSL
libbzrtp_la_LIBADD += $(POLARSSL_LIBS)
libbzrtp_la_SOURCES += cryptoPolarssl.c
AM_CFLAGS += $(POLARSSL_CFLAGS)
endif
if LIBMBEDTLS
libbzrtp_la_LIBADD += $(MBEDTLS_LIBS)
libbzrtp_la_SOURCES += cryptoMbedtls.c
AM_CFLAGS += $(MBEDTLS_CFLAGS)
endif
libbzrtp_la_LDFLAGS=-fvisibility=hidden -no-undefined
This diff is collapsed.
......@@ -47,7 +47,7 @@
* - CipherBlock: AES128(Mandatory)
* - Auth Tag: HMAC-SHA132 and HMAC-SHA180 (These are mandatory for SRTP and depends on the SRTP implementation thus we can just suppose they are both available)
* - Key Agreement: DHM3k(Mandatory), DHM2k(optional and shall not be used except on low power devices)
* - Sas: base32(Mandatory)
* - Sas: base32(Mandatory), b256(pgp words)
*/
uint8_t bzrtpCrypto_getAvailableCryptoTypes(uint8_t algoType, uint8_t availableTypes[7]) {
......
......@@ -27,7 +27,6 @@ set(TEST_SOURCES
testUtils.c
../src/bzrtp.c
../src/cryptoPolarssl.c
../src/cryptoUtils.c
../src/packetParser.c
../src/pgpwords.c
......@@ -35,6 +34,18 @@ set(TEST_SOURCES
../src/zidCache.c
)
if (POLARSSL_FOUND)
set(TEST_SOURCES
${TEST_SOURCES}
../src/cryptoPolarssl.c
)
elseif (MBEDTLS_FOUND)
set(TEST_SOURCES
${TEST_SOURCES}
../src/cryptoMbedtls.c
)
endif()
apply_compile_flags(TEST_SOURCES "CPP")
add_executable(bzrtpTest ${TEST_SOURCES})
......@@ -44,4 +55,15 @@ target_link_libraries(bzrtpTest ${CUNIT_LIBRARIES} bzrtp)
if(HAVE_SQRT)
target_link_libraries(bzrtpTest m)
endif()
unset(PATTERN_FILES_IN_TEST_DIR CACHE)
find_file(PATTERN_FILES_IN_TEST_DIR
ZIDAlice.txt ${CMAKE_CURRENT_BINARY_DIR}
)
if (NOT PATTERN_FILES_IN_TEST_DIR)
file(COPY ZIDAlice.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ZIDBob.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif()
add_test(NAME bzrtpTest COMMAND bzrtpTest)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment