Commit 2ec726c6 authored by johan's avatar johan

Move to bctoolbox for crypto API

parent bc6574e8
......@@ -68,7 +68,6 @@ option(ENABLE_RELATIVE_PREFIX "Find resources relatively to the installation dir
option(ENABLE_TOOLS "Turn on or off compilation of tools." YES)
option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES)
cmake_dependent_option(ENABLE_DTLS "Build with DTLS support." YES "ENABLE_SRTP" NO)
option(ENABLE_SRTP "Build with the SRTP transport support." YES)
cmake_dependent_option(ENABLE_ZRTP "Build with ZRTP support." YES "ENABLE_SRTP" NO)
......@@ -150,7 +149,9 @@ if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
else()
find_package(ORTP REQUIRED)
endif()
find_package(PolarSSL)
find_package(BcToolBox REQUIRED)
if(ENABLE_PCAP)
find_package(PCAP QUIET)
endif()
......@@ -175,7 +176,6 @@ if(ENABLE_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)
set(ENABLE_DTLS OFF CACHE BOOL "Build mediastreamer2 with DTLS support." FORCE)
endif()
endif()
if(ENABLE_ZRTP)
......@@ -189,16 +189,6 @@ if(ENABLE_ZRTP)
set(ENABLE_ZRTP OFF CACHE BOOL "Build mediastreamer2 with ZRTP support." FORCE)
endif()
endif()
if(ENABLE_DTLS AND ENABLE_SRTP) # DTLS requires SRTP
if(NOT POLARSSL_FOUND OR NOT HAVE_SSL_GET_DTLS_SRTP_PROTECTION_PROFILE)
if (NOT POLARSSL_FOUND)
message(WARNING "Could not find polarssl library required by DTLS, mediastreamer2 will be compiled without DTLS support.")
else()
message(WARNING "Polarssl library was found but misses HAVE_SSL_GET_DTLS_SRTP_PROTECTION_PROFILE required by DTLS, mediastreamer2 will be compiled without DTLS support.")
endif()
set(ENABLE_DTLS OFF CACHE BOOL "Build mediastreamer2 with DTLS support." FORCE)
endif()
endif()
if(ENABLE_GSM)
find_package(GSM)
if(NOT GSM_FOUND)
......@@ -320,6 +310,7 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/src
${ORTP_INCLUDE_DIRS}
${BCTOOLBOX_INCLUDE_DIRS}
)
if(BZRTP_FOUND)
......@@ -328,9 +319,6 @@ endif()
if(SRTP_FOUND)
include_directories(${SRTP_INCLUDE_DIRS})
endif()
if(POLARSSL_FOUND)
include_directories(${POLARSSL_INCLUDE_DIRS})
endif()
if(GSM_FOUND)
include_directories(${GSM_INCLUDE_DIRS})
endif()
......@@ -412,9 +400,6 @@ endif()
if(BZRTP_FOUND)
set(HAVE_ZRTP 1)
endif()
if(ENABLE_DTLS)
set(HAVE_DTLS 1)
endif()
if(ENABLE_ALSA)
set(__ALSA_ENABLED__ 1)
endif()
......
############################################################################
# FindPolarSSL.txt
# Copyright (C) 2015 Belledonne Communications, Grenoble France
# FindiBcToolBox.cmake
# Copyright (C) 2016 Belledonne Communications, Grenoble France
#
############################################################################
#
......@@ -20,58 +20,37 @@
#
############################################################################
#
# - Find the polarssl include file and library
# - Find the bctoolbox include file and library
#
# POLARSSL_FOUND - system has polarssl
# POLARSSL_INCLUDE_DIRS - the polarssl include directory
# POLARSSL_LIBRARIES - The libraries needed to use polarssl
# BCTOOLBOX_FOUND - system has BC Toolbox
# BCTOOLBOX_INCLUDE_DIRS - the BC Toolbox include directory
# BCTOOLBOX_LIBRARIES - The libraries needed to use BC Toolbox
include(CMakePushCheckState)
include(CheckIncludeFile)
include(CheckCSourceCompiles)
include(CheckSymbolExists)
set(_POLARSSL_ROOT_PATHS
set(_BCTOOLBOX_ROOT_PATHS
${CMAKE_INSTALL_PREFIX}
)
find_path(POLARSSL_INCLUDE_DIRS
NAMES polarssl/ssl.h
HINTS _POLARSSL_ROOT_PATHS
find_path(BCTOOLBOX_INCLUDE_DIRS
NAMES bctoolbox/crypto.h
HINTS _BCTOOLBOX_ROOT_PATHS
PATH_SUFFIXES include
)
if(POLARSSL_INCLUDE_DIRS)
set(HAVE_POLARSSL_SSL_H 1)
endif()
find_library(POLARSSL_LIBRARIES
NAMES polarssl
HINTS _POLARSSL_ROOT_PATHS
find_library(BCTOOLBOX_LIBRARIES
NAMES bctoolbox
HINTS _BCTOOLBOX_ROOT_PATHS
PATH_SUFFIXES bin lib
)
if(POLARSSL_LIBRARIES)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${POLARSSL_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${POLARSSL_LIBRARIES})
check_c_source_compiles("#include <polarssl/version.h>
#include <polarssl/x509.h>
#if POLARSSL_VERSION_NUMBER >= 0x01030000
#include <polarssl/compat-1.2.h>
#endif
int main(int argc, char *argv[]) {
x509parse_crtpath(0,0);
return 0;
}"
X509PARSE_CRTPATH_OK)
check_symbol_exists(ssl_get_dtls_srtp_protection_profile "polarssl/ssl.h" HAVE_SSL_GET_DTLS_SRTP_PROTECTION_PROFILE)
cmake_pop_check_state()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PolarSSL
find_package_handle_standard_args(BcToolBox
DEFAULT_MSG
POLARSSL_INCLUDE_DIRS POLARSSL_LIBRARIES HAVE_POLARSSL_SSL_H
BCTOOLBOX_INCLUDE_DIRS BCTOOLBOX_LIBRARIES
)
mark_as_advanced(POLARSSL_INCLUDE_DIRS POLARSSL_LIBRARIES HAVE_POLARSSL_SSL_H X509PARSE_CRTPATH_OK HAVE_SSL_GET_DTLS_SRTP_PROTECTION_PROFILE)
mark_as_advanced(BCTOOLBOX_INCLUDE_DIRS BCTOOLBOX_LIBRARIES)
......@@ -372,6 +372,7 @@ endif()
set(VOIP_LIBS
${BCTOOLBOX_LIBRARIES}
${ORTP_LIBRARIES}
mediastreamer_base
)
......@@ -395,9 +396,6 @@ endif()
if(SRTP_FOUND)
list(APPEND VOIP_LIBS ${SRTP_LIBRARIES})
endif()
if(POLARSSL_FOUND)
list(APPEND VOIP_LIBS ${POLARSSL_LIBRARIES})
endif()
if(GSM_FOUND)
list(APPEND VOIP_LIBS ${GSM_LIBRARIES})
endif()
......
This diff is collapsed.
......@@ -118,6 +118,7 @@
#include "mediastreamer2/stun_udp.h"
#include "mediastreamer2/stun.h"
#include "ortp/ortp.h"
#include "bctoolbox/crypto.h"
static char *ipaddr(const StunAddress4 *addr)
{
......@@ -1328,25 +1329,6 @@ randomPort(void)
}
#ifndef HAVE_POLARSSL_SSL_H
void
stunCalculateIntegrity_longterm(char* hmac, const char* input, int length,
const char *username, const char *realm, const char *password)
{
strncpy(hmac,"hmac-not-implemented",20);
ms_error("hmac-not-implemented for stun, mediastreamer2 needs polarssl dependency");
}
void
stunCalculateIntegrity_shortterm(char* hmac, const char* input, int length, const char* key)
{
strncpy(hmac,"hmac-not-implemented",20);
ms_error("hmac-not-implemented for stun, mediastreamer2 needs polarssl dependency");
}
#else
#include "polarssl/sha1.h"
#include "polarssl/md5.h"
void
stunCalculateIntegrity_longterm(char* hmac, const char* input, int length,
const char *username, const char *realm, const char *password)
......@@ -1355,23 +1337,21 @@ stunCalculateIntegrity_longterm(char* hmac, const char* input, int length,
char HA1_text[1024];
snprintf(HA1_text, sizeof(HA1_text), "%s:%s:%s", username, realm, password);
md5((unsigned char *)HA1_text, strlen(HA1_text), HA1);
bctoolbox_md5((unsigned char *)HA1_text, strlen(HA1_text), HA1);
sha1_hmac(HA1, sizeof(HA1),
bctoolbox_hmacSha1(HA1, sizeof(HA1),
(const unsigned char*) input, length,
(unsigned char*)hmac);
20, (unsigned char*)hmac); /* SHA1 output length is 20 bytes, get them all */
}
void
stunCalculateIntegrity_shortterm(char* hmac, const char* input, int length, const char* key)
{
sha1_hmac((const unsigned char *)key, strlen(key),
bctoolbox_hmacSha1((const unsigned char *)key, strlen(key),
(const unsigned char*) input, length,
(unsigned char*)hmac);
20, (unsigned char*)hmac); /* SHA1 output length is 20 bytes, get them all */
}
#endif
uint32_t
stunCalculateFingerprint(const char* input, int length)
{
......
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