Skip to content

Commit

Permalink
OpenSSL3: Fix bundled modules search path on Windows
Browse files Browse the repository at this point in the history
Also add error output for module loading problems
  • Loading branch information
Warlockbugs committed Jul 15, 2024
1 parent 9e083a3 commit 5ac9906
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/mangosd/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include <openssl/provider.h>
#include <openssl/err.h>

#include <boost/program_options.hpp>
#include <boost/version.hpp>
#include <boost/filesystem.hpp>

#include <iostream>
#include <string>
Expand Down Expand Up @@ -179,16 +181,20 @@ int main(int argc, char* argv[])

DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
// Load OpenSSL 3.0+ providers
#ifdef _WIN32
// For bundled OpenSSL library
OSSL_PROVIDER_set_default_search_path(nullptr, boost::filesystem::current_path().string().c_str());
#endif
OSSL_PROVIDER* openssl_legacy = OSSL_PROVIDER_load(nullptr, "legacy");
if (!openssl_legacy)
{
sLog.outError("OpenSSL3: Failed to load Legacy provider");
sLog.outError("OpenSSL3: Failed to load Legacy provider: %s", ERR_error_string(ERR_get_error(), NULL));
return 1;
}
OSSL_PROVIDER* openssl_default = OSSL_PROVIDER_load(nullptr, "default");
if (!openssl_default)
{
sLog.outError("OpenSSL3: Failed to load Default provider");
sLog.outError("OpenSSL3: Failed to load Default provider: %s", ERR_error_string(ERR_get_error(), NULL));
OSSL_PROVIDER_unload(openssl_legacy);
return 1;
}
Expand Down
10 changes: 8 additions & 2 deletions src/realmd/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include <openssl/provider.h>
#include <openssl/err.h>

#include <boost/program_options.hpp>
#include <boost/version.hpp>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>

#include <iostream>
#include <string>
Expand Down Expand Up @@ -177,16 +179,20 @@ int main(int argc, char* argv[])

DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
// Load OpenSSL 3.0+ providers
#ifdef _WIN32
// For bundled OpenSSL library
OSSL_PROVIDER_set_default_search_path(nullptr, boost::filesystem::current_path().string().c_str());
#endif
OSSL_PROVIDER* openssl_legacy = OSSL_PROVIDER_load(nullptr, "legacy");
if (!openssl_legacy)
{
sLog.outError("OpenSSL3: Failed to load Legacy provider");
sLog.outError("OpenSSL3: Failed to load Legacy provider: %s", ERR_error_string(ERR_get_error(), NULL));
return 1;
}
OSSL_PROVIDER* openssl_default = OSSL_PROVIDER_load(nullptr, "default");
if (!openssl_default)
{
sLog.outError("OpenSSL3: Failed to load Default provider");
sLog.outError("OpenSSL3: Failed to load Default provider: %s", ERR_error_string(ERR_get_error(), NULL));
OSSL_PROVIDER_unload(openssl_legacy);
return 1;
}
Expand Down

0 comments on commit 5ac9906

Please sign in to comment.