isapego commented on a change in pull request #9750:
URL: https://github.com/apache/ignite/pull/9750#discussion_r788125239
##########
File path: modules/platforms/cpp/network/src/network/ssl/ssl_gateway.cpp
##########
@@ -66,77 +66,114 @@ namespace ignite
memset(&functions, 0, sizeof(functions));
}
- common::dynamic::Module SslGateway::LoadSslLibrary(const char*
name)
+ common::dynamic::Module SslGateway::LoadSslLibrary(const
std::string& name, const std::string& homeDir)
{
using namespace common;
using namespace dynamic;
- std::string home = GetEnv(ADDITIONAL_OPENSSL_HOME_ENV);
-
- if (home.empty())
- home = GetEnv("OPENSSL_HOME");
-
std::string fullName = GetDynamicLibraryName(name);
- if (!home.empty())
+ if (!homeDir.empty())
{
- const char* paths[] = {"bin", "lib"};
-
- for (size_t i = 0; i < 2; i++) {
- std::stringstream constructor;
-
- constructor << home << Fs << paths[i] << Fs <<
fullName;
-
- std::string fullPath = constructor.str();
+#ifdef _WIN32
+ const char* binSubDir = "bin";
+#else
+ const char* binSubDir = "lib";
+#endif
+ std::ostringstream oss;
- Module mod = LoadModule(fullPath);
+ oss << homeDir << Fs << binSubDir << Fs << fullName;
- if (mod.IsLoaded())
- return mod;
- }
+ return LoadModule(oss.str());
}
return LoadModule(fullName);
}
void SslGateway::LoadSslLibraries()
{
- libssl = LoadSslLibrary("libssl");
+ using namespace common;
- if (!libssl.IsLoaded())
- {
- libcrypto = LoadSslLibrary("libcrypto-1_1-x64");
- libssl = LoadSslLibrary("libssl-1_1-x64");
- }
+ std::string home = GetEnv(ADDITIONAL_OPENSSL_HOME_ENV);
+ if (home.empty())
+ home = GetEnv("OPENSSL_HOME");
- if (!libssl.IsLoaded())
- {
- libeay32 = LoadSslLibrary("libeay32");
- ssleay32 = LoadSslLibrary("ssleay32");
- }
+ bool isLoaded = false;
- if (!libssl.IsLoaded() && (!libeay32.IsLoaded() ||
!ssleay32.IsLoaded()))
- {
- if (!libssl.IsLoaded())
- throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
- "Can not load neccessary OpenSSL library: libssl");
+ if (!home.empty())
+ isLoaded = TryLoadSslLibraries(home);
+ // Try load from system path.
+ if (!isLoaded)
+ isLoaded = TryLoadSslLibraries("");
+
+ if (!isLoaded)
+ {
+#ifdef _WIN32
std::stringstream ss;
- ss << "Can not load neccessary OpenSSL libraries:";
+ ss << "Can not load necessary OpenSSL libraries:";
+
+ if (!libssl.IsLoaded() || !libcrypto.IsLoaded())
+ {
+ if (!libssl.IsLoaded())
+ ss << " libssl";
- if (!libeay32.IsLoaded())
- ss << " libeay32";
+ if (!libcrypto.IsLoaded())
+ ss << " libcrypto";
+ }
+ else
+ {
+ if (!libeay32.IsLoaded())
+ ss << " libeay32";
- if (!ssleay32.IsLoaded())
- ss << " ssleay32";
+ if (!ssleay32.IsLoaded())
+ ss << " ssleay32";
+ }
std::string res = ss.str();
throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
res.c_str());
+#else
+ if (!libssl.IsLoaded())
+ throw IgniteError(IgniteError::IGNITE_ERR_GENERIC,
+ "Can not load necessary OpenSSL library: libssl");
+#endif
}
}
+ bool SslGateway::TryLoadSslLibraries(const std::string& homeDir) {
+#ifdef _WIN32
+#ifdef _WIN64
+ libcrypto = LoadSslLibrary("libcrypto-3-x64", homeDir);
+ libssl = LoadSslLibrary("libssl-3-x64", homeDir);
+
+ if (!libssl.IsLoaded() || !libcrypto.IsLoaded()) {
+ libcrypto = LoadSslLibrary("libcrypto-1_1-x64", homeDir);
+ libssl = LoadSslLibrary("libssl-1_1-x64", homeDir);
+ }
+#else
+ libcrypto = LoadSslLibrary("libcrypto-3", homeDir);
+ libssl = LoadSslLibrary("libssl-3", homeDir);
+
+ if (!libssl.IsLoaded() || !libcrypto.IsLoaded()) {
+ libcrypto = LoadSslLibrary("libcrypto-1_1", homeDir);
+ libssl = LoadSslLibrary("libssl-1_1", homeDir);
+ }
+#endif
Review comment:
This can probably reduce code duplication. Anyway, just a suggestion, it
is up for you to decide.
```suggestion
#ifdef _WIN64
#define SSL_LIB_POSTFIX "-x64"
#else
#define SSL_LIB_POSTFIX ""
#endif
libcrypto = LoadSslLibrary("libcrypto-3" SSL_LIB_POSTFIX,
homeDir);
libssl = LoadSslLibrary("libssl-3" SSL_LIB_POSTFIX, homeDir);
if (!libssl.IsLoaded() || !libcrypto.IsLoaded()) {
libcrypto = LoadSslLibrary("libcrypto-1_1"
SSL_LIB_POSTFIX, homeDir);
libssl = LoadSslLibrary("libssl-1_1" SSL_LIB_POSTFIX,
homeDir);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]