diff --git a/ixcobra/CMakeLists.txt b/ixcobra/CMakeLists.txt index f7245cbd..48d2df22 100644 --- a/ixcobra/CMakeLists.txt +++ b/ixcobra/CMakeLists.txt @@ -22,9 +22,9 @@ add_library(ixcobra STATIC set(IXCOBRA_INCLUDE_DIRS . + .. ../ixcore ../ixcrypto - ../ixwebsocket ../third_party) target_include_directories( ixcobra PUBLIC ${IXCOBRA_INCLUDE_DIRS} ) diff --git a/ixcrypto/CMakeLists.txt b/ixcrypto/CMakeLists.txt index 420c0937..c9ae5497 100644 --- a/ixcrypto/CMakeLists.txt +++ b/ixcrypto/CMakeLists.txt @@ -2,18 +2,19 @@ # Author: Benjamin Sergeant # Copyright (c) 2019 Machine Zone, Inc. All rights reserved. # +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../CMake;${CMAKE_MODULE_PATH}") set (IXCRYPTO_SOURCES ixcrypto/IXHMac.cpp ixcrypto/IXBase64.cpp - ixcrypto/IXUUid.cpp + ixcrypto/IXUuid.cpp ixcrypto/IXHash.cpp ) set (IXCRYPTO_HEADERS ixcrypto/IXHMac.h ixcrypto/IXBase64.h - ixcrypto/IXUUid.h + ixcrypto/IXUuid.h ixcrypto/IXHash.h ) @@ -27,3 +28,27 @@ set(IXCRYPTO_INCLUDE_DIRS ../ixcore) 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() + diff --git a/ixcrypto/ixcrypto/IXHMac.cpp b/ixcrypto/ixcrypto/IXHMac.cpp index 08e07f52..4e203d36 100644 --- a/ixcrypto/ixcrypto/IXHMac.cpp +++ b/ixcrypto/ixcrypto/IXHMac.cpp @@ -7,12 +7,14 @@ #include "IXHMac.h" #include "IXBase64.h" -#if defined(IXWEBSOCKET_USE_MBED_TLS) +#if defined(IXCRYPTO_USE_MBED_TLS) # include #elif defined(__APPLE__) # include -#else +#elif defined(IXCRYPTO_USE_OPEN_SSL) # include +#else +# error "Unsupported configuration" #endif namespace ix @@ -22,7 +24,7 @@ namespace ix constexpr size_t hashSize = 16; 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), (unsigned char *) key.c_str(), key.size(), (unsigned char *) data.c_str(), data.size(), @@ -32,11 +34,13 @@ namespace ix key.c_str(), key.size(), data.c_str(), data.size(), &hash); -#else +#elif defined(IXCRYPTO_USE_OPEN_SSL) HMAC(EVP_md5(), key.c_str(), (int) key.size(), (unsigned char *) data.c_str(), (int) data.size(), (unsigned char *) hash, nullptr); +#else +# error "Unsupported configuration" #endif std::string hashString(reinterpret_cast(hash), hashSize);