build fixes

This commit is contained in:
Benjamin Sergeant 2019-09-10 14:05:07 -07:00
parent b11640b477
commit c3238b7e02
3 changed files with 36 additions and 7 deletions

View File

@ -22,9 +22,9 @@ add_library(ixcobra STATIC
set(IXCOBRA_INCLUDE_DIRS set(IXCOBRA_INCLUDE_DIRS
. .
..
../ixcore ../ixcore
../ixcrypto ../ixcrypto
../ixwebsocket
../third_party) ../third_party)
target_include_directories( ixcobra PUBLIC ${IXCOBRA_INCLUDE_DIRS} ) target_include_directories( ixcobra PUBLIC ${IXCOBRA_INCLUDE_DIRS} )

View File

@ -2,18 +2,19 @@
# Author: Benjamin Sergeant # Author: Benjamin Sergeant
# Copyright (c) 2019 Machine Zone, Inc. All rights reserved. # Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
# #
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../CMake;${CMAKE_MODULE_PATH}")
set (IXCRYPTO_SOURCES set (IXCRYPTO_SOURCES
ixcrypto/IXHMac.cpp ixcrypto/IXHMac.cpp
ixcrypto/IXBase64.cpp ixcrypto/IXBase64.cpp
ixcrypto/IXUUid.cpp ixcrypto/IXUuid.cpp
ixcrypto/IXHash.cpp ixcrypto/IXHash.cpp
) )
set (IXCRYPTO_HEADERS set (IXCRYPTO_HEADERS
ixcrypto/IXHMac.h ixcrypto/IXHMac.h
ixcrypto/IXBase64.h ixcrypto/IXBase64.h
ixcrypto/IXUUid.h ixcrypto/IXUuid.h
ixcrypto/IXHash.h ixcrypto/IXHash.h
) )
@ -27,3 +28,27 @@ set(IXCRYPTO_INCLUDE_DIRS
../ixcore) ../ixcore)
target_include_directories( ixcrypto PUBLIC ${IXCRYPTO_INCLUDE_DIRS} ) target_include_directories( ixcrypto PUBLIC ${IXCRYPTO_INCLUDE_DIRS} )
# hmac computation needs a crypto library
if (WIN32)
set(USE_MBED_TLS TRUE)
endif()
target_compile_definitions(ixcrypto PUBLIC IXCRYPTO_USE_TLS)
if (USE_MBED_TLS)
find_package(MbedTLS REQUIRED)
target_include_directories(ixcrypto PUBLIC ${MBEDTLS_INCLUDE_DIRS})
target_link_libraries(ixcrypto ${MBEDTLS_LIBRARIES})
target_compile_definitions(ixcrypto PUBLIC IXCRYPTO_USE_MBED_TLS)
elseif (APPLE)
elseif (WIN32)
else()
find_package(OpenSSL REQUIRED)
add_definitions(${OPENSSL_DEFINITIONS})
message(STATUS "OpenSSL: " ${OPENSSL_VERSION})
include_directories(${OPENSSL_INCLUDE_DIR})
target_link_libraries(ixcrypto ${OPENSSL_LIBRARIES})
target_compile_definitions(ixcrypto PUBLIC IXCRYPTO_USE_OPEN_SSL)
endif()

View File

@ -7,12 +7,14 @@
#include "IXHMac.h" #include "IXHMac.h"
#include "IXBase64.h" #include "IXBase64.h"
#if defined(IXWEBSOCKET_USE_MBED_TLS) #if defined(IXCRYPTO_USE_MBED_TLS)
# include <mbedtls/md.h> # include <mbedtls/md.h>
#elif defined(__APPLE__) #elif defined(__APPLE__)
# include <CommonCrypto/CommonHMAC.h> # include <CommonCrypto/CommonHMAC.h>
#else #elif defined(IXCRYPTO_USE_OPEN_SSL)
# include <openssl/hmac.h> # include <openssl/hmac.h>
#else
# error "Unsupported configuration"
#endif #endif
namespace ix namespace ix
@ -22,7 +24,7 @@ namespace ix
constexpr size_t hashSize = 16; constexpr size_t hashSize = 16;
unsigned char hash[hashSize]; unsigned char hash[hashSize];
#if defined(IXWEBSOCKET_USE_MBED_TLS) #if defined(IXCRYPTO_USE_MBED_TLS)
mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_MD5), mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_MD5),
(unsigned char *) key.c_str(), key.size(), (unsigned char *) key.c_str(), key.size(),
(unsigned char *) data.c_str(), data.size(), (unsigned char *) data.c_str(), data.size(),
@ -32,11 +34,13 @@ namespace ix
key.c_str(), key.size(), key.c_str(), key.size(),
data.c_str(), data.size(), data.c_str(), data.size(),
&hash); &hash);
#else #elif defined(IXCRYPTO_USE_OPEN_SSL)
HMAC(EVP_md5(), HMAC(EVP_md5(),
key.c_str(), (int) key.size(), key.c_str(), (int) key.size(),
(unsigned char *) data.c_str(), (int) data.size(), (unsigned char *) data.c_str(), (int) data.size(),
(unsigned char *) hash, nullptr); (unsigned char *) hash, nullptr);
#else
# error "Unsupported configuration"
#endif #endif
std::string hashString(reinterpret_cast<char*>(hash), hashSize); std::string hashString(reinterpret_cast<char*>(hash), hashSize);