From 7633a0157bc6f6a3fdd444040115bd2d3c623056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Mon, 12 Nov 2018 10:30:51 +0100 Subject: [PATCH] Several fixes (#313) * Refs #3760. Several fixes. * Support of OpenSSL 1.0.2 * Fixing compilation error on ROS2 --- cmake/packaging/Config.cmake.in | 3 ++ configure.ac | 2 +- src/cpp/CMakeLists.txt | 6 ++++ src/cpp/security/authentication/PKIDH.cpp | 36 +++++++++++++++++++++-- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/cmake/packaging/Config.cmake.in b/cmake/packaging/Config.cmake.in index 2648d7b1009..6170e283208 100644 --- a/cmake/packaging/Config.cmake.in +++ b/cmake/packaging/Config.cmake.in @@ -22,4 +22,7 @@ endif() set_and_check(@PROJECT_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") set_and_check(@PROJECT_NAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@") +find_package(fastcdr REQUIRED) +@FASTRTPS_PACKAGE_OPT_DEPS@ + include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake) diff --git a/configure.ac b/configure.ac index 4b7f809f4ca..13efac25e83 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ # Define variables for the FastRTPS version number. # m4_define([version_major],[1]) -m4_define([version_minor],[6]) +m4_define([version_minor],[7]) m4_define([version_micro],[0]) AC_INIT([fastrtps], [version_major.version_minor.version_micro], [support@eprosima.com], [eProsima FastRTPS], [http://eprosima.com/]) diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index e0283b01314..b4d8da11c28 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -442,6 +442,12 @@ elseif(NOT EPROSIMA_INSTALLER) # Create CMake package config file ############################################################################### include(CMakePackageConfigHelpers) + + # Add fastrtps dependencies in its CMake config file. + if(SECURITY) + set(FASTRTPS_PACKAGE_OPT_DEPS "find_package(OpenSSL REQUIRED)") + endif() + configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/packaging/Config.cmake.in ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}-config.cmake INSTALL_DESTINATION ${DATA_INSTALL_DIR}$/${PROJECT_NAME}/cmake${MSVCARCH_DIR_EXTENSION_EXT} diff --git a/src/cpp/security/authentication/PKIDH.cpp b/src/cpp/security/authentication/PKIDH.cpp index 4b6ac63e638..bb906dc782c 100644 --- a/src/cpp/security/authentication/PKIDH.cpp +++ b/src/cpp/security/authentication/PKIDH.cpp @@ -684,7 +684,12 @@ static bool store_dh_public_key(EVP_PKEY* dhkey, std::vector& buffer, SecurityException& exception) { bool returnedValue = false; - DH* dh = EVP_PKEY_get0_DH(dhkey); + DH* dh = +#if IS_OPENSSL_1_1 + EVP_PKEY_get0_DH(dhkey); +#else + dhkey->pkey.dh; +#endif if(dh != nullptr) { @@ -705,11 +710,18 @@ static bool store_dh_public_key(EVP_PKEY* dhkey, std::vector& buffer, returnedValue = true; } else + { exception = _SecurityException_("Cannot serialize public key"); + } } else { - EC_KEY* ec = EVP_PKEY_get0_EC_KEY(dhkey); + EC_KEY* ec = +#if IS_OPENSSL_1_1 + EVP_PKEY_get0_EC_KEY(dhkey); +#else + dhkey->pkey.ec; +#endif if (ec != nullptr) { auto grp = EC_KEY_get0_group(ec); @@ -761,18 +773,26 @@ static EVP_PKEY* generate_dh_peer_key(const std::vector& buffer, Securi return key; } else + { exception = _SecurityException_("OpenSSL library cannot set dh in pkey"); + } EVP_PKEY_free(key); } else + { exception = _SecurityException_("OpenSSL library cannot create pkey"); + } } else + { exception = _SecurityException_("Cannot deserialize public key"); + } } else + { exception = _SecurityException_("OpenSSL library cannot create dh"); + } } else { @@ -782,7 +802,11 @@ static EVP_PKEY* generate_dh_peer_key(const std::vector& buffer, Securi { const unsigned char* pointer = buffer.data(); +#if IS_OPENSSL_1_1 if(EC_KEY_oct2key(ec, pointer, buffer.size(), NULL) > 0) +#else + if(o2i_ECPublicKey(&ec, &pointer, buffer.size()) != nullptr) +#endif { EVP_PKEY* key = EVP_PKEY_new(); @@ -793,20 +817,28 @@ static EVP_PKEY* generate_dh_peer_key(const std::vector& buffer, Securi return key; } else + { exception = _SecurityException_("OpenSSL library cannot set ec in pkey"); + } EVP_PKEY_free(key); } else + { exception = _SecurityException_("OpenSSL library cannot create pkey"); + } } else + { exception = _SecurityException_("Cannot deserialize public key"); + } EC_KEY_free(ec); } else + { exception = _SecurityException_("OpenSSL library cannot create ec"); + } } return nullptr;