Skip to content

Commit a2a45fe

Browse files
author
Paweł Andruszkiewicz
committed
Bundle OpenSSL3 modules
Change-Id: Ic6f620d1770bb2426610b25b0da0340e1f3ba713 (cherry picked from commit b09b5a0c1ef7720b6c1d31aef3859441182408a2)
1 parent 7036ee0 commit a2a45fe

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,33 @@ IF (WITH_SSL_PATH AND (APPLE OR WIN32 OR LINUX_STANDALONE))
896896
MESSAGE(STATUS "CRYPTO_FULL_NAME ${CRYPTO_FULL_NAME}")
897897
MESSAGE(STATUS "OPENSSL_FULL_NAME ${OPENSSL_FULL_NAME}")
898898
ENDIF()
899+
900+
FIND_PATH(OPENSSL_MODULES_DIR
901+
NAMES ossl-modules
902+
NO_CMAKE_PATH
903+
NO_CMAKE_ENVIRONMENT_PATH
904+
HINTS ${WITH_SSL_PATH}
905+
PATH_SUFFIXES lib lib64
906+
)
907+
908+
IF(OPENSSL_MODULES_DIR)
909+
SET(OPENSSL_MODULES_DIR "${OPENSSL_MODULES_DIR}/ossl-modules")
910+
FILE(TO_CMAKE_PATH "${OPENSSL_MODULES_DIR}" OPENSSL_MODULES_DIR)
911+
MESSAGE(STATUS "OPENSSL_MODULES_DIR ${OPENSSL_MODULES_DIR}")
912+
913+
IF(WIN32)
914+
SET(_module_ext "dll")
915+
ELSEIF(APPLE)
916+
SET(_module_ext "dylib")
917+
ELSE()
918+
SET(_module_ext "so")
919+
ENDIF()
920+
921+
FILE(GLOB OPENSSL_MODULES_LIST "${OPENSSL_MODULES_DIR}/*.${_module_ext}")
922+
MESSAGE(STATUS "OPENSSL_MODULES_LIST ${OPENSSL_MODULES_LIST}")
923+
924+
add_definitions(-DBUNDLE_OPENSSL_MODULES)
925+
ENDIF()
899926
ENDIF()
900927

901928
if (NOT BUILD_SOURCE_PACKAGE)

mysqlshdk/shellcore/shell_init.cc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0,
@@ -22,11 +22,16 @@
2222
*/
2323

2424
#include "shellcore/shell_init.h"
25+
2526
#include <curl/curl.h>
2627
#include <mysql.h>
2728
#include <stdlib.h>
2829
#include <stdexcept>
2930

31+
#include "mysqlshdk/libs/utils/utils_file.h"
32+
#include "mysqlshdk/libs/utils/utils_general.h"
33+
#include "mysqlshdk/libs/utils/utils_path.h"
34+
3035
#ifdef HAVE_V8
3136
namespace shcore {
3237
extern void JScript_context_init();
@@ -36,6 +41,23 @@ extern void JScript_context_fini();
3641

3742
namespace mysqlsh {
3843

44+
namespace {
45+
46+
void init_openssl_modules() {
47+
#ifdef BUNDLE_OPENSSL_MODULES
48+
constexpr auto k_env_var = "OPENSSL_MODULES";
49+
50+
// don't override path set by the user
51+
if (!::getenv(k_env_var)) {
52+
shcore::setenv(
53+
k_env_var,
54+
shcore::path::join_path(shcore::get_library_folder(), "ossl-modules"));
55+
}
56+
#endif
57+
}
58+
59+
} // namespace
60+
3961
void thread_init() { mysql_thread_init(); }
4062

4163
void thread_end() { mysql_thread_end(); }
@@ -51,6 +73,7 @@ void global_init() {
5173

5274
srand(time(0));
5375
curl_global_init(CURL_GLOBAL_ALL);
76+
init_openssl_modules();
5477
}
5578

5679
void global_end() {

packaging/rpm/mysql-shell.spec.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Copyright (c) 2016, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2016, 2023, Oracle and/or its affiliates.
33
#
44
# This program is free software; you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License, version 2.0,
@@ -277,6 +277,8 @@ rm -f %{buildroot}%{_datadir}/mysqlsh/{LICENSE,README}
277277
%if 0%{?bundled_openssl:1}
278278
%{_prefix}/lib/mysqlsh/libcrypto*
279279
%{_prefix}/lib/mysqlsh/libssl*
280+
# we assume OpenSSL3 is bundled and it has the modules
281+
%{_prefix}/lib/mysqlsh/ossl-modules/*
280282
%endif
281283
%if 0%{?bundled_python:1}
282284
%{_prefix}/lib/mysqlsh/include/python*

src/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ if(BUNDLED_OPENSSL)
157157
DESTINATION ${INSTALL_BINDIR}
158158
COMPONENT main
159159
)
160+
161+
IF(OPENSSL_MODULES_DIR)
162+
# Copy the OpenSSL modules to the build dir (for running tests in build tree)
163+
ADD_CUSTOM_COMMAND(TARGET mysqlsh POST_BUILD
164+
COMMAND ${CMAKE_COMMAND} -E make_directory "${CONFIG_BINARY_DIR}/${INSTALL_LIBDIR}/ossl-modules"
165+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OPENSSL_MODULES_LIST}
166+
"${CONFIG_BINARY_DIR}/${INSTALL_LIBDIR}/ossl-modules")
167+
168+
# Install/bundle the OpenSSL modules
169+
INSTALL(PROGRAMS ${OPENSSL_MODULES_LIST}
170+
DESTINATION "${INSTALL_LIBDIR}/ossl-modules"
171+
COMPONENT main
172+
)
173+
ENDIF()
160174
ELSE()
161175
# Copy the OpenSSL libraries to the build dir (for running tests in build tree)
162176
ADD_CUSTOM_COMMAND(TARGET mysqlsh POST_BUILD
@@ -204,6 +218,10 @@ if(BUNDLED_OPENSSL)
204218
COMPONENT main
205219
)
206220
ENDIF()
221+
222+
IF(OPENSSL_MODULES_DIR)
223+
install_bundled_binaries(BINARIES ${OPENSSL_MODULES_LIST} DESTINATION "${INSTALL_LIBDIR}/ossl-modules" TARGET mysqlsh)
224+
ENDIF()
207225
ENDIF()
208226
endif()
209227

0 commit comments

Comments
 (0)