Skip to content

Commit

Permalink
Refs 11914. Make p11 windows installer friendly
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>
  • Loading branch information
Miguel Barro committed Dec 9, 2021
1 parent 92e0e6b commit 803b532
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 50 deletions.
54 changes: 36 additions & 18 deletions cmake/modules/FindLibP11.cmake
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
# Find libp11
# FindLibP11
#
# LIBP11_INCLUDE_DIR
# LIBP11_LIBRARIES
# LIBP11_FOUND
# Generates an imported target associated to an available pksc11 library:
#
# + On linux relies on the apt package libp11-dev
#
# + On Windows the library must be build from sources available at https://github.com/OpenSC/libp11.git
# Given that each user must build its own binaries the following environment variables must be set to hint
# where to locate headers and binaries (semicolon-separated list see https://cmake.org/cmake/help/v3.22/variable/PackageName_ROOT.html):
# + LibP11_ROOT_32 -> to reference sources and 32 bit binaries location
# + LibP11_ROOT_64 -> to reference sources and 64 bit binaries location

if(TARGET eProsima_p11)
return()
endif()

IF (LIBP11_INCLUDE_DIR)
SET(LIBP11_FIND_QUIETLY TRUE)
ENDIF (LIBP11_INCLUDE_DIR)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(LibP11_ROOT "$ENV{LibP11_ROOT_32}")
else()
set(LibP11_ROOT "$ENV{LibP11_ROOT_64}")
endif()

FIND_PATH(LIBP11_INCLUDE_DIR libp11.h)
find_path(LIBP11_INCLUDE_DIR NAMES libp11.h HINTS ${LibP11_ROOT})
find_library(LIBP11_LIBRARY NAMES libp11.a libp11.lib HINTS ${LibP11_ROOT})

SET(LIBP11_NAMES p11 libp11)
FIND_LIBRARY(LIBP11_LIBRARY NAMES ${LIBP11_NAMES} )
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibP11 DEFAULT_MSG LIBP11_LIBRARY LIBP11_INCLUDE_DIR)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibP11 DEFAULT_MSG LIBP11_LIBRARY LIBP11_INCLUDE_DIR)
if(LibP11_FOUND)
# add the target
add_library(eProsima_p11 STATIC IMPORTED)

IF(LIBP11_FOUND)
SET( LIBP11_LIBRARIES ${LIBP11_LIBRARY} )
ELSE(LIBP11_FOUND)
SET( LIBP11_LIBRARIES )
ENDIF(LIBP11_FOUND)
# update the properties
set_target_properties(eProsima_p11 PROPERTIES
IMPORTED_LOCATION "${LIBP11_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LIBP11_INCLUDE_DIR}"
)
endif()

MARK_AS_ADVANCED( LIBP11_LIBRARY LIBP11_INCLUDE_DIR )
# clean local variables
unset(LIBP11_INCLUDE_DIR)
unset(LIBP11_LIBRARY)
unset(LibP11_ROOT)
4 changes: 1 addition & 3 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC
${TINYXML2_INCLUDE_DIR}
$<$<BOOL:${ANDROID}>:${ANDROID_IFADDRS_INCLUDE_DIR}>
${THIRDPARTY_BOOST_INCLUDE_DIR}
${LIBP11_INCLUDE_DIR}
)

# No need to expose linked libs when target is a shared library on MSVC.
Expand All @@ -441,9 +440,8 @@ target_link_libraries(${PROJECT_NAME} ${PRIVACY} fastcdr foonathan_memory
${TINYXML2_LIBRARY}
$<$<BOOL:${LINK_SSL}>:OpenSSL::SSL$<SEMICOLON>OpenSSL::Crypto$<$<BOOL:${WIN32}>:$<SEMICOLON>crypt32.lib>>
$<$<BOOL:${WIN32}>:iphlpapi$<SEMICOLON>Shlwapi>
${LIBP11_LIBRARIES}
${THIRDPARTY_BOOST_LINK_LIBS}
PRIVATE eProsima_atomic
PRIVATE eProsima_atomic $<TARGET_NAME_IF_EXISTS:eProsima_p11>
)

if(MSVC OR MSVC_IDE)
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/security/authentication/PKIDH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ static EVP_PKEY* load_private_key(
pkidh.pkcs11_provider.reset(new detail::Pkcs11Provider());
}
return pkidh.pkcs11_provider->load_private_key(certificate, file, password, exception);
#endif // HAVE_LIBP11
#else // HAVE_LIBP11
static_cast<void>(pkidh);
exception = _SecurityException_(std::string("PKCS11 URIs require libp11 ") + file);
return nullptr;

#endif // HAVE_LIBP11
}

exception = _SecurityException_(std::string("Unsupported URI format ") + file);
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/utils/SystemInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ FileWatchHandle SystemInfo::watch_file(
break;
}
}));
#endif // defined(_WIN32) || defined(__unix__)
#else // defined(_WIN32) || defined(__unix__)
static_cast<void>(filename);
static_cast<void>(callback);
return FileWatchHandle();
#endif // defined(_WIN32) || defined(__unix__)
}

void SystemInfo::stop_watching_file(
Expand Down
19 changes: 15 additions & 4 deletions test/blackbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,15 @@ if(FASTRTPS_API_TESTS)
)
target_include_directories(BlackboxTests_FastRTPS PRIVATE
${Asio_INCLUDE_DIR}
${LIBP11_INCLUDE_DIR}
api/fastrtps_deprecated)
target_link_libraries(BlackboxTests_FastRTPS fastrtps fastcdr foonathan_memory GTest::gtest ${LIBP11_LIBRARIES})
target_link_libraries(BlackboxTests_FastRTPS
fastrtps
fastcdr
foonathan_memory
GTest::gtest
$<TARGET_NAME_IF_EXISTS:eProsima_p11>
)

add_blackbox_gtest(BlackboxTests_FastRTPS SOURCES ${BLACKBOXTESTS_TEST_SOURCE}
ENVIRONMENTS "CERTS_PATH=${PROJECT_SOURCE_DIR}/test/certs"
"TOPIC_RANDOM_NUMBER=${TOPIC_RANDOM_NUMBER}"
Expand Down Expand Up @@ -319,9 +325,14 @@ if(FASTDDS_PIM_API_TESTS)
)
target_include_directories(BlackboxTests_DDS_PIM PRIVATE
${Asio_INCLUDE_DIR}
${LIBP11_INCLUDE_DIR}
api/dds-pim)
target_link_libraries(BlackboxTests_DDS_PIM fastrtps fastcdr foonathan_memory GTest::gtest ${LIBP11_LIBRARIES})
target_link_libraries(BlackboxTests_DDS_PIM
fastrtps
fastcdr
foonathan_memory
GTest::gtest
$<TARGET_NAME_IF_EXISTS:eProsima_p11>
)
add_blackbox_gtest(BlackboxTests_DDS_PIM SOURCES ${DDS_BLACKBOXTESTS_SOURCE}
ENVIRONMENTS "CERTS_PATH=${PROJECT_SOURCE_DIR}/test/certs"
"TOPIC_RANDOM_NUMBER=${TOPIC_RANDOM_NUMBER}"
Expand Down
3 changes: 1 addition & 2 deletions test/unittest/security/accesscontrol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ target_include_directories(AccessControlTests PRIVATE
${OPENSSL_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/src/cpp
${LIBP11_INCLUDE_DIR}
)

target_link_libraries(AccessControlTests
Expand All @@ -95,7 +94,7 @@ target_link_libraries(AccessControlTests
foonathan_memory
$<$<BOOL:${WIN32}>:ws2_32>
${TINYXML2_LIBRARY}
${LIBP11_LIBRARIES}
$<TARGET_NAME_IF_EXISTS:eProsima_p11>
)

if(MSVC OR MSVC_IDE)
Expand Down
3 changes: 1 addition & 2 deletions test/unittest/security/authentication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ target_include_directories(BuiltinPKIDH PRIVATE
${OPENSSL_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/src/cpp
${LIBP11_INCLUDE_DIR}
)
target_link_libraries(BuiltinPKIDH
GTest::gtest
${OPENSSL_LIBRARIES}
fastcdr
foonathan_memory
$<$<BOOL:${WIN32}>:ws2_32>
${LIBP11_LIBRARIES}
$<TARGET_NAME_IF_EXISTS:eProsima_p11>
)
add_gtest(BuiltinPKIDH
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/BuiltinPKIDHTests.cpp
Expand Down
36 changes: 18 additions & 18 deletions test/unittest/transport/TCPv4Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ TEST_F(TCPv4Tests, send_and_receive_between_secure_ports_client_verifies)
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
while (!sent)
{
Locators input_begin(locator_list.begin());
Locators input_end(locator_list.end());
Locators l_input_begin(locator_list.begin());
Locators l_input_end(locator_list.end());

sent =
send_resource_list.at(0)->send(message, 5, &input_begin, &input_end,
send_resource_list.at(0)->send(message, 5, &l_input_begin, &l_input_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Expand Down Expand Up @@ -633,11 +633,11 @@ TEST_F(TCPv4Tests, send_and_receive_between_secure_ports_server_verifies)
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
while (!sent)
{
Locators input_begin(locator_list.begin());
Locators input_end(locator_list.end());
Locators l_input_begin(locator_list.begin());
Locators l_input_end(locator_list.end());

sent =
send_resource_list.at(0)->send(message, 5, &input_begin, &input_end,
send_resource_list.at(0)->send(message, 5, &l_input_begin, &l_input_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Expand Down Expand Up @@ -735,11 +735,11 @@ TEST_F(TCPv4Tests, send_and_receive_between_both_secure_ports)
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
while (!sent)
{
Locators input_begin(locator_list.begin());
Locators input_end(locator_list.end());
Locators l_input_begin(locator_list.begin());
Locators l_input_end(locator_list.end());

sent =
send_resource_list.at(0)->send(message, 5, &input_begin, &input_end,
send_resource_list.at(0)->send(message, 5, &l_input_begin, &l_input_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Expand Down Expand Up @@ -839,11 +839,11 @@ TEST_F(TCPv4Tests, send_and_receive_between_both_secure_ports_untrusted)
int count = 0;
while (!sent && count < 30)
{
Locators input_begin(locator_list.begin());
Locators input_end(locator_list.end());
Locators l_input_begin(locator_list.begin());
Locators l_input_end(locator_list.end());

sent =
send_resource_list.at(0)->send(message, 5, &input_begin, &input_end,
send_resource_list.at(0)->send(message, 5, &l_input_begin, &l_input_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
++count;
Expand Down Expand Up @@ -943,11 +943,11 @@ TEST_F(TCPv4Tests, send_and_receive_between_secure_clients_1)
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
while (!sent)
{
Locators input_begin(locator_list.begin());
Locators input_end(locator_list.end());
Locators l_input_begin(locator_list.begin());
Locators l_input_end(locator_list.end());

sent =
send_resource_list.at(0)->send(message, 5, &input_begin, &input_end,
send_resource_list.at(0)->send(message, 5, &l_input_begin, &l_input_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Expand Down Expand Up @@ -1132,10 +1132,10 @@ TEST_F(TCPv4Tests, send_and_receive_between_secure_ports_untrusted_server)
int count = 0;
while (!sent && count < 30)
{
Locators input_begin(locator_list.begin());
Locators input_end(locator_list.end());
Locators l_input_begin(locator_list.begin());
Locators l_input_end(locator_list.end());
sent =
send_resource_list.at(0)->send(message, 5, &input_begin, &input_end,
send_resource_list.at(0)->send(message, 5, &l_input_begin, &l_input_end,
(std::chrono::steady_clock::now() + std::chrono::microseconds(100)));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
++count;
Expand Down

0 comments on commit 803b532

Please sign in to comment.