Core/Misc: added support for OpenSSL 3, dropped support for OpenSSL 1.0 and fixed build for Fixed build for MariaDB

This commit is contained in:
Daniel S. Reichenbach authored and Ovahlord committed 2023-07-07 21:01:49 +02:00
1 parent 2c94bf0a16
commit a7527a8698
19 files changed
+268 -214

No files matched your search

+73 -76
View File
@@ -7,15 +7,29 @@ FindOpenSSL
Find the OpenSSL encryption library.
This module finds an installed OpenSSL library and determines its version.
.. versionadded:: 3.19
When a version is requested, it can be specified as a simple value or as a
range. For a detailed description of version range usage and capabilities,
refer to the :command:`find_package` command.
.. versionadded:: 3.18
Support for OpenSSL 3.0.
Optional COMPONENTS
^^^^^^^^^^^^^^^^^^^
.. versionadded:: 3.12
This module supports two optional COMPONENTS: ``Crypto`` and ``SSL``. Both
components have associated imported targets, as described below.
Imported Targets
^^^^^^^^^^^^^^^^
.. versionadded:: 3.4
This module defines the following :prop_tgt:`IMPORTED` targets:
``OpenSSL::SSL``
@@ -23,6 +37,8 @@ This module defines the following :prop_tgt:`IMPORTED` targets:
``OpenSSL::Crypto``
The OpenSSL ``crypto`` library, if found.
``OpenSSL::applink``
.. versionadded:: 3.18
The OpenSSL ``applink`` components that might be need to be compiled into
projects under MSVC. This target is available only if found OpenSSL version
is not less than 0.9.8. By linking this target the above OpenSSL targets can
@@ -75,12 +91,13 @@ Hints
^^^^^
Set ``OPENSSL_ROOT_DIR`` to the root directory of an OpenSSL installation.
Set ``OPENSSL_USE_STATIC_LIBS`` to ``TRUE`` to look for static libraries.
Set ``OPENSSL_MSVC_STATIC_RT`` set ``TRUE`` to choose the MT version of the lib.
#]=======================================================================]
set(OPENSSL_EXPECTED_VERSION "1.0")
set(OPENSSL_MAX_VERSION "1.2")
.. versionadded:: 3.4
Set ``OPENSSL_USE_STATIC_LIBS`` to ``TRUE`` to look for static libraries.
.. versionadded:: 3.5
Set ``OPENSSL_MSVC_STATIC_RT`` set ``TRUE`` to choose the MT version of the lib.
#]=======================================================================]
macro(_OpenSSL_test_and_find_dependencies ssl_library crypto_library)
if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND
@@ -106,6 +123,14 @@ function(_OpenSSL_target_add_dependencies target)
set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Threads::Threads )
set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS} )
endif()
if(WIN32 AND OPENSSL_USE_STATIC_LIBS)
if(WINCE)
set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ws2 )
else()
set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ws2_32 )
endif()
set_property( TARGET ${target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES crypt32 )
endif()
endfunction()
if (UNIX)
@@ -126,42 +151,45 @@ endif()
if (WIN32)
# http://www.slproweb.com/products/Win32OpenSSL.html
set(_OPENSSL_MSI_INSTALL_GUID "")
if(PLATFORM EQUAL 64)
set(_OPENSSL_MSI_INSTALL_GUID "117551DB-A110-4BBD-BB05-CFE0BCB3ED31")
set(_OPENSSL_ROOT_HINTS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]"
${OPENSSL_ROOT_DIR}
ENV OPENSSL_ROOT_DIR
)
set(_OPENSSL_ROOT_HINTS
${OPENSSL_ROOT_DIR}
ENV OPENSSL_ROOT_DIR
)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set(_arch "Win64")
file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
set(_OPENSSL_ROOT_PATHS
"${_programfiles}/OpenSSL"
"${_programfiles}/OpenSSL-Win64"
"C:/OpenSSL/"
"C:/OpenSSL-Win64/"
)
list(APPEND _OPENSSL_ROOT_HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]")
set(_OPENSSL_MSI_INSTALL_GUID "117551DB-A110-4BBD-BB05-CFE0BCB3ED31")
else()
set(_OPENSSL_MSI_INSTALL_GUID "A1EEC576-43B9-4E75-9E02-03DA542D2A38")
set(_OPENSSL_ROOT_HINTS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]"
${OPENSSL_ROOT_DIR}
ENV OPENSSL_ROOT_DIR
)
file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
set(_OPENSSL_ROOT_PATHS
"${_programfiles}/OpenSSL"
"${_programfiles}/OpenSSL-Win32"
"C:/OpenSSL/"
"C:/OpenSSL-Win32/"
)
set(_arch "Win32")
set(_progfiles_x86 "ProgramFiles(x86)")
if(NOT "$ENV{${_progfiles_x86}}" STREQUAL "")
# under windows 64 bit machine
file(TO_CMAKE_PATH "$ENV{${_progfiles_x86}}" _programfiles)
else()
# under windows 32 bit machine
file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _programfiles)
endif()
list(APPEND _OPENSSL_ROOT_HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]")
set(_OPENSSL_MSI_INSTALL_GUID "A1EEC576-43B9-4E75-9E02-03DA542D2A38")
endif()
unset(_programfiles)
# If OpenSSL was installed using .msi package instead of .exe, Inno Setup registry values are not written to Uninstall\OpenSSL
# but because it is only a shim around Inno Setup it does write the location of uninstaller which we can use to determine path
get_filename_component(_OPENSSL_MSI_INSTALL_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Inno Setup MSIs\\${_OPENSSL_MSI_INSTALL_GUID};]" DIRECTORY)
if(NOT _OPENSSL_MSI_INSTALL_PATH STREQUAL "/")
list(INSERT _OPENSSL_ROOT_HINTS 0 ${_OPENSSL_MSI_INSTALL_PATH})
list(INSERT _OPENSSL_ROOT_HINTS 2 ${_OPENSSL_MSI_INSTALL_PATH})
endif()
set(_OPENSSL_ROOT_PATHS
"${_programfiles}/OpenSSL"
"${_programfiles}/OpenSSL-${_arch}"
"C:/OpenSSL/"
"C:/OpenSSL-${_arch}/"
)
unset(_programfiles)
unset(_arch)
else ()
set(_OPENSSL_ROOT_HINTS
${OPENSSL_ROOT_DIR}
@@ -169,6 +197,12 @@ else ()
)
endif ()
if(HOMEBREW_PREFIX)
list(APPEND _OPENSSL_ROOT_HINTS
"${HOMEBREW_PREFIX}/opt/openssl@1.1"
"${HOMEBREW_PREFIX}/opt/openssl@3")
endif()
set(_OPENSSL_ROOT_HINTS_AND_PATHS
HINTS ${_OPENSSL_ROOT_HINTS}
PATHS ${_OPENSSL_ROOT_PATHS}
@@ -210,7 +244,7 @@ if(WIN32 AND NOT CYGWIN)
endif ()
# Since OpenSSL 1.1, lib names are like libcrypto32MTd.lib and libssl32MTd.lib
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
if( "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" )
set(_OPENSSL_MSVC_ARCH_SUFFIX "64")
else()
set(_OPENSSL_MSVC_ARCH_SUFFIX "32")
@@ -421,7 +455,7 @@ else()
${_OPENSSL_LIBDIR}
${_OPENSSL_LIBRARY_DIRS}
PATH_SUFFIXES
lib
lib lib64
)
find_library(OPENSSL_CRYPTO_LIBRARY
@@ -433,42 +467,12 @@ else()
${_OPENSSL_LIBDIR}
${_OPENSSL_LIBRARY_DIRS}
PATH_SUFFIXES
lib
lib lib64
)
mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY)
endif()
function(from_hex HEX DEC)
string(TOUPPER "${HEX}" HEX)
set(_res 0)
string(LENGTH "${HEX}" _strlen)
while (_strlen GREATER 0)
math(EXPR _res "${_res} * 16")
string(SUBSTRING "${HEX}" 0 1 NIBBLE)
string(SUBSTRING "${HEX}" 1 -1 HEX)
if (NIBBLE STREQUAL "A")
math(EXPR _res "${_res} + 10")
elseif (NIBBLE STREQUAL "B")
math(EXPR _res "${_res} + 11")
elseif (NIBBLE STREQUAL "C")
math(EXPR _res "${_res} + 12")
elseif (NIBBLE STREQUAL "D")
math(EXPR _res "${_res} + 13")
elseif (NIBBLE STREQUAL "E")
math(EXPR _res "${_res} + 14")
elseif (NIBBLE STREQUAL "F")
math(EXPR _res "${_res} + 15")
else()
math(EXPR _res "${_res} + ${NIBBLE}")
endif()
string(LENGTH "${HEX}" _strlen)
endwhile()
set(${DEC} ${_res} PARENT_SCOPE)
endfunction(from_hex)
set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY})
set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY})
@@ -532,7 +536,7 @@ if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX)
list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH)
if(NOT OPENSSL_VERSION_PATCH STREQUAL "00")
if (NOT OPENSSL_VERSION_PATCH STREQUAL "00")
from_hex("${OPENSSL_VERSION_PATCH}" _tmp)
# 96 is the ASCII code of 'a' minus 1
math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96")
@@ -593,6 +597,7 @@ find_package_handle_standard_args(OpenSSL
OPENSSL_INCLUDE_DIR
VERSION_VAR
OPENSSL_VERSION
HANDLE_VERSION_RANGE
HANDLE_COMPONENTS
FAIL_MESSAGE
"Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR"
@@ -601,14 +606,6 @@ find_package_handle_standard_args(OpenSSL
mark_as_advanced(OPENSSL_INCLUDE_DIR)
if(OPENSSL_FOUND)
message(STATUS "Found OpenSSL library: ${OPENSSL_LIBRARIES}")
message(STATUS "Found OpenSSL headers: ${OPENSSL_INCLUDE_DIR}")
include(EnsureVersion)
ENSURE_VERSION_RANGE("${OPENSSL_EXPECTED_VERSION}" "${OPENSSL_VERSION}" "${OPENSSL_MAX_VERSION}" OPENSSL_VERSION_OK)
if(NOT OPENSSL_VERSION_OK)
message(FATAL_ERROR "TrinityCore needs OpenSSL version ${OPENSSL_EXPECTED_VERSION} but found too new version ${OPENSSL_VERSION}. TrinityCore needs OpenSSL 1.0.x or 1.1.x to work properly. If you still have problems please install OpenSSL 1.0.x if you still have problems search on forum for TCE00022")
endif()
if(NOT TARGET OpenSSL::Crypto AND
(EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR
EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR
@@ -673,7 +670,7 @@ if(OPENSSL_FOUND)
_OpenSSL_target_add_dependencies(OpenSSL::SSL)
endif()
if("${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_FIX}" VERSION_GREATER_EQUAL "0.9.8")
if("${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}" VERSION_GREATER_EQUAL "0.9.8")
if(MSVC)
if(EXISTS "${OPENSSL_INCLUDE_DIR}")
set(_OPENSSL_applink_paths PATHS ${OPENSSL_INCLUDE_DIR})
+39 -34
View File
@@ -1,16 +1,21 @@
TrinityCore uses (parts of or in whole) the following opensource software:
Boost (external)
http://www.boost.org
Version: 1.55
argon2
https://github.com/P-H-C/phc-winner-argon2
Version: 62358ba
Boost Process (Proposed for boost, but its not an official part of it yet. Used to start child processes.)
http://www.highscore.de/boost/process0.5/
Version: 0.5
Boost (a set of C++ libraries)
http://www.boost.org
Version: external
bzip2 (a freely available, patent free, high-quality data compressor)
http://www.bzip.org/
Version: 1.0.6
catch2
https://github.com/catchorg/Catch2
Version: v2.13.0
efws (Entropia File System Watcher - crossplatform file system watcher)
https://bitbucket.org/SpartanJ/efsw
Version: 1.0.0 e6afbec564e249771046c714b0c7f2154e4c7fef
@@ -23,33 +28,37 @@ G3D (a commercial-grade C++ 3D engine available as Open Source (BSD License)
http://g3d.sourceforge.net/
Version: 9.0-Release r4036
gSOAP (a portable development toolkit for C and C++ XML Web services and XML data bindings)
http://gsoap2.sourceforge.net/
Version: 2.8.117
jemalloc (a general-purpose scalable concurrent malloc-implementation)
http://www.canonware.com/jemalloc/
Version: 5.2.1
libreadline (command line editing library)
https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
libMPQ (a library for reading MPQ files)
https://github.com/mbroemme/libmpq/
Version: d59b4cf1d107b5f6a0f67d6bc545c6c6ebef3d74
libzmq (ZeroMQ core engine in C++, implements ZMTP/3.1)
https://github.com/zeromq/libzmq
Version: 4.2.3 stable
MariaDB:
https://mariadb.org/
Version: external
OpenSSL (general-purpose cryptography library)
https://www.openssl.org/
Version: external
SFMT (SIMD-oriented Fast Mersenne Twister)
https://github.com/MersenneTwister-Lab/SFMT
Version: 73bcba2e483640b8d50c1275514326dd4c1b0ca4
rapidjson (A fast JSON parser/generator for C++ with both SAX/DOM style API http://rapidjson.org/)
https://github.com/Tencent/rapidjson
Version: 27c3a8dc0e2c9218fe94986d249a12b5ed838f1d
utf8-cpp (UTF-8 with C++ in a Portable Way)
http://utfcpp.sourceforge.net/
Version: 2.3.4
zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library)
http://www.zlib.net/
Version: 1.2.12
gSOAP (a portable development toolkit for C and C++ XML Web services and XML data bindings)
http://gsoap2.sourceforge.net/
Version: 2.8.117
readline (command line editing library)
https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
Version: external
recastnavigation (Recast is state of the art navigation mesh construction toolset for games)
https://github.com/recastnavigation/recastnavigation
@@ -59,19 +68,15 @@ recastnavigation (Recast is state of the art navigation mesh construction toolse
StormLib (a pack of modules, written in C++, which are able to read and also to write files from/to the MPQ archives)
http://www.zezula.net/en/mpq/stormlib.html
Version: 8.04
libzmq (ZeroMQ core engine in C++, implements ZMTP/3.1)
https://github.com/zeromq/libzmq
Version: 4.2.3 stable
utf8-cpp (UTF-8 with C++ in a Portable Way)
http://utfcpp.sourceforge.net/
Version: 2.3.4
zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library)
http://www.zlib.net/
Version: 1.2.12
zmqpp (C++ binding for 0mq/zmq is a 'high-level' library that hides most of the c-style interface core 0mq provides.)
https://github.com/zeromq/zmqpp
Version: 3.2.0 17e9f6afa98f56ecac1e3f3eecbfc112357a6732
rapidjson (A fast JSON parser/generator for C++ with both SAX/DOM style API http://rapidjson.org/)
https://github.com/Tencent/rapidjson
Version: 27c3a8dc0e2c9218fe94986d249a12b5ed838f1d
catch2
https://github.com/catchorg/Catch2
Version: v2.13.0
+1 -7
View File
@@ -18,15 +18,9 @@ target_include_directories(gsoap
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(gsoap
PUBLIC
-DWITH_OPENSSL)
target_link_libraries(gsoap
PRIVATE
trinity-dependency-interface
PUBLIC
openssl)
trinity-dependency-interface)
set_target_properties(gsoap
PROPERTIES
+1 -3
View File
@@ -11,9 +11,7 @@
# basic packagesearching and setup
# (further support will be needed, this is a preliminary release!)
set(OPENSSL_EXPECTED_VERSION 1.0.0)
find_package(OpenSSL REQUIRED COMPONENTS Crypto SSL)
find_package(OpenSSL 1.1 REQUIRED COMPONENTS Crypto SSL)
add_library(openssl INTERFACE)
+1 -1
View File
@@ -30,7 +30,7 @@ class TC_COMMON_API ConfigMgr
~ConfigMgr() = default;
public:
/// Method used only for loading main configuration files (authserver.conf and worldserver.conf)
/// Method used only for loading main configuration files (bnetserver.conf and worldserver.conf)
bool LoadInitial(std::string const& file, std::vector<std::string> args, std::string& error);
static ConfigMgr* instance();
+30 -13
View File
@@ -16,35 +16,52 @@
*/
#include "ARC4.h"
#include "Errors.h"
ARC4::ARC4(uint32 len) : m_ctx(EVP_CIPHER_CTX_new())
ARC4::ARC4(uint32 len) : _ctx(EVP_CIPHER_CTX_new())
{
EVP_CIPHER_CTX_init(m_ctx);
EVP_EncryptInit_ex(m_ctx, EVP_rc4(), nullptr, nullptr, nullptr);
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
_cipher = EVP_CIPHER_fetch(nullptr, "RC4", nullptr);
#else
EVP_CIPHER const *_cipher = EVP_rc4();
#endif
EVP_CIPHER_CTX_init(_ctx);
EVP_EncryptInit_ex(_ctx, EVP_rc4(), nullptr, nullptr, nullptr);
EVP_CIPHER_CTX_set_key_length(_ctx, len);
}
ARC4::ARC4(uint8* seed, uint32 len) : m_ctx(EVP_CIPHER_CTX_new())
ARC4::ARC4(uint8* seed, uint32 len) : _ctx(EVP_CIPHER_CTX_new())
{
EVP_CIPHER_CTX_init(m_ctx);
EVP_EncryptInit_ex(m_ctx, EVP_rc4(), nullptr, nullptr, nullptr);
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
EVP_EncryptInit_ex(m_ctx, nullptr, nullptr, seed, nullptr);
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
_cipher = EVP_CIPHER_fetch(nullptr, "RC4", nullptr);
#else
EVP_CIPHER const *_cipher = EVP_rc4();
#endif
EVP_CIPHER_CTX_init(_ctx);
EVP_EncryptInit_ex(_ctx, EVP_rc4(), nullptr, nullptr, nullptr);
EVP_CIPHER_CTX_set_key_length(_ctx, len);
EVP_EncryptInit_ex(_ctx, nullptr, nullptr, seed, nullptr);
}
ARC4::~ARC4()
{
EVP_CIPHER_CTX_free(m_ctx);
EVP_CIPHER_CTX_free(_ctx);
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
EVP_CIPHER_free(_cipher);
#endif
}
void ARC4::Init(uint8* seed)
{
EVP_EncryptInit_ex(m_ctx, nullptr, nullptr, seed, nullptr);
EVP_EncryptInit_ex(_ctx, nullptr, nullptr, seed, nullptr);
}
void ARC4::UpdateData(int len, uint8* data)
{
int outlen = 0;
EVP_EncryptUpdate(m_ctx, data, &outlen, data, len);
EVP_EncryptFinal_ex(m_ctx, data, &outlen);
EVP_EncryptUpdate(_ctx, data, &outlen, data, len);
EVP_EncryptFinal_ex(_ctx, data, &outlen);
}
+5 -1
View File
@@ -19,6 +19,7 @@
#define _AUTH_SARC4_H
#include "Define.h"
#include <array>
#include <openssl/evp.h>
class TC_COMMON_API ARC4
@@ -30,7 +31,10 @@ class TC_COMMON_API ARC4
void Init(uint8* seed);
void UpdateData(int len, uint8* data);
private:
EVP_CIPHER_CTX* m_ctx;
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
EVP_CIPHER *_cipher;
#endif
EVP_CIPHER_CTX* _ctx;
};
#endif
+18 -41
View File
@@ -18,51 +18,28 @@
#include "OpenSSLCrypto.h"
#include <openssl/crypto.h>
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL
#include <vector>
#include <thread>
#include <mutex>
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#include <openssl/provider.h>
OSSL_PROVIDER* LegacyProvider;
OSSL_PROVIDER* DefaultProvider;
#endif
std::vector<std::mutex*> cryptoLocks;
static void lockingCallback(int mode, int type, char const* /*file*/, int /*line*/)
void OpenSSLCrypto::threadsSetup([[maybe_unused]] boost::filesystem::path const &providerModulePath)
{
if (mode & CRYPTO_LOCK)
cryptoLocks[type]->lock();
else
cryptoLocks[type]->unlock();
}
static void threadIdCallback(CRYPTO_THREADID* id)
{
(void)id;
CRYPTO_THREADID_set_numeric(id, std::hash<std::thread::id>()(std::this_thread::get_id()));
}
void OpenSSLCrypto::threadsSetup()
{
cryptoLocks.resize(CRYPTO_num_locks());
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
{
cryptoLocks[i] = new std::mutex();
}
(void)&threadIdCallback;
CRYPTO_THREADID_set_callback(threadIdCallback);
(void)&lockingCallback;
CRYPTO_set_locking_callback(lockingCallback);
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
OSSL_PROVIDER_set_default_search_path(nullptr, providerModulePath.string().c_str());
#endif
LegacyProvider = OSSL_PROVIDER_load(nullptr, "legacy");
DefaultProvider = OSSL_PROVIDER_load(nullptr, "default");
#endif
}
void OpenSSLCrypto::threadsCleanup()
{
CRYPTO_set_locking_callback(nullptr);
CRYPTO_THREADID_set_callback(nullptr);
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
{
delete cryptoLocks[i];
}
cryptoLocks.resize(0);
}
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
OSSL_PROVIDER_unload(LegacyProvider);
OSSL_PROVIDER_unload(DefaultProvider);
OSSL_PROVIDER_set_default_search_path(nullptr, nullptr);
#endif
}
+2 -8
View File
@@ -19,7 +19,7 @@
#define TRINITY_OPENSSL_CRYPTO_H
#include "Define.h"
#include <openssl/opensslv.h>
#include <boost/filesystem/path.hpp>
/**
* A group of functions which setup openssl crypto module to work properly in multithreaded enviroment
@@ -27,16 +27,10 @@
*/
namespace OpenSSLCrypto
{
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL
/// Needs to be called before threads using openssl are spawned
TC_COMMON_API void threadsSetup();
TC_COMMON_API void threadsSetup(boost::filesystem::path const& providerModulePath);
/// Needs to be called after threads using openssl are despawned
TC_COMMON_API void threadsCleanup();
#else
void threadsSetup() { };
void threadsCleanup() { };
#endif
}
#endif
+30 -6
View File
@@ -23,18 +23,41 @@
SHA1Hash::SHA1Hash()
{
SHA1_Init(&mC);
memset(mDigest, 0, SHA_DIGEST_LENGTH * sizeof(uint8));
m_ctx = EVP_MD_CTX_new();
EVP_DigestInit_ex(m_ctx, EVP_sha1(), nullptr);
}
SHA1Hash::SHA1Hash(const SHA1Hash &other) : SHA1Hash() // copy
{
EVP_MD_CTX_copy_ex(m_ctx, other.m_ctx);
std::memcpy(m_digest, other.m_digest, SHA_DIGEST_LENGTH);
}
SHA1Hash::SHA1Hash(SHA1Hash &&other) : SHA1Hash() // move
{
Swap(other);
}
SHA1Hash &SHA1Hash::operator=(SHA1Hash other) // assign
{
Swap(other);
return *this;
}
SHA1Hash::~SHA1Hash()
{
SHA1_Init(&mC);
EVP_MD_CTX_free(m_ctx);
}
void SHA1Hash::Swap(SHA1Hash &other) throw()
{
std::swap(m_ctx, other.m_ctx);
std::swap(m_digest, other.m_digest);
}
void SHA1Hash::UpdateData(const uint8 *dta, int len)
{
SHA1_Update(&mC, dta, len);
EVP_DigestUpdate(m_ctx, dta, len);
}
void SHA1Hash::UpdateData(const std::string &str)
@@ -59,12 +82,13 @@ void SHA1Hash::UpdateBigNumbers(BigNumber* bn0, ...)
void SHA1Hash::Initialize()
{
SHA1_Init(&mC);
EVP_DigestInit(m_ctx, EVP_sha1());
}
void SHA1Hash::Finalize(void)
{
SHA1_Final(mDigest, &mC);
uint32 length = SHA_DIGEST_LENGTH;
EVP_DigestFinal_ex(m_ctx, m_digest, &length);
}
std::string CalculateSHA1Hash(std::string const& content)
+11 -4
View File
@@ -21,6 +21,7 @@
#include "Define.h"
#include <string>
#include <openssl/sha.h>
#include <openssl/evp.h>
class BigNumber;
@@ -28,8 +29,14 @@ class TC_COMMON_API SHA1Hash
{
public:
SHA1Hash();
SHA1Hash(SHA1Hash const &other); // copy
SHA1Hash(SHA1Hash &&other); // move
SHA1Hash &operator=(SHA1Hash other); // assign
~SHA1Hash();
void Swap(SHA1Hash &other) throw();
friend void Swap(SHA1Hash &left, SHA1Hash &right) { left.Swap(right); }
void UpdateBigNumbers(BigNumber* bn0, ...);
void UpdateData(const uint8 *dta, int len);
@@ -38,12 +45,12 @@ class TC_COMMON_API SHA1Hash
void Initialize();
void Finalize();
uint8 *GetDigest(void) { return mDigest; }
int GetLength(void) const { return SHA_DIGEST_LENGTH; }
uint8 *GetDigest(void) { return m_digest; }
int GetLength() const { return SHA_DIGEST_LENGTH; }
private:
SHA_CTX mC;
uint8 mDigest[SHA_DIGEST_LENGTH];
EVP_MD_CTX *m_ctx;
uint8 m_digest[SHA_DIGEST_LENGTH];
};
/// Returns the SHA1 hash of the given content as hex string.
+10 -1
View File
@@ -35,13 +35,18 @@
#include "IoContext.h"
#include "MySQLThreading.h"
#include "ModuleManager.h"
#include "OpenSSLCrypto.h"
#include "ProcessPriority.h"
#include "SessionManager.h"
#include "Util.h"
#include "ZmqContext.h"
#include <boost/asio/signal_set.hpp>
#include <boost/dll/runtime_symbol_info.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem/operations.hpp>
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
#include <openssl/provider.h>
#endif
#include <csignal>
#include <iostream>
@@ -119,11 +124,15 @@ int main(int argc, char** argv)
[]()
{
TC_LOG_INFO("server.bnetserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str());
TC_LOG_INFO("server.bnetserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
TC_LOG_INFO("server.bnetserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
TC_LOG_INFO("server.bnetserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
}
);
OpenSSLCrypto::threadsSetup(boost::dll::program_location().remove_filename());
std::shared_ptr<void> opensslHandle(nullptr, [](void*) { OpenSSLCrypto::threadsCleanup(); });
// Seed the OpenSSL's PRNG here.
// That way it won't auto-seed when calling BigNumber::SetRand and slow down the first world login
BigNumber seed;
@@ -108,7 +108,7 @@ void BNetRealmList::UpdateRealms(boost::system::error_code const& error)
if (error)
return;
TC_LOG_DEBUG("server.authserver", "Updating Realm List...");
TC_LOG_DEBUG("server.bnetserver", "Updating Realm List...");
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_REALMLIST);
PreparedQueryResult result = LoginDatabase.Query(stmt);
+1 -1
View File
@@ -180,7 +180,7 @@ void Battlenet::Session::HandleLogonRequest(Authentication::LogonRequest const&
else
logonResponse->SetAuthResult(AUTH_USE_GRUNT_LOGON);
TC_LOG_DEBUG("session", "[Battlenet::LogonRequest] %s is using unsupported component version %u!", GetClientInfo().c_str(), component.Build);
TC_LOG_DEBUG("session", "[Battlenet::LogonRequest] %s is using unsupported component %s version %u!", GetClientInfo().c_str(), component.Program.c_str(), component.Build);
}
AsyncWrite(logonResponse);
@@ -35,8 +35,15 @@
#include "MySQLWorkaround.h"
#include <mysqld_error.h>
#define MIN_MYSQL_SERVER_VERSION 50100u
#define MIN_MYSQL_CLIENT_VERSION 50100u
#define MIN_MYSQL_SERVER_VERSION 50700u
#define MIN_MYSQL_SERVER_VERSION_STRING "5.7"
#define MIN_MYSQL_CLIENT_VERSION 50700u
#define MIN_MYSQL_CLIENT_VERSION_STRING "5.7"
#define MIN_MARIADB_SERVER_VERSION 100209u
#define MIN_MARIADB_SERVER_VERSION_STRING "10.2.9"
#define MIN_MARIADB_CLIENT_VERSION 30003u
#define MIN_MARIADB_CLIENT_VERSION_STRING "3.0.3"
class PingOperation : public SQLOperation
{
@@ -54,9 +61,14 @@ DatabaseWorkerPool<T>::DatabaseWorkerPool()
_async_threads(0), _synch_threads(0)
{
WPFatal(mysql_thread_safe(), "Used MySQL library isn't thread-safe.");
WPFatal(mysql_get_client_version() >= MIN_MYSQL_CLIENT_VERSION, "TrinityCore does not support MySQL versions below 5.1");
WPFatal(mysql_get_client_version() == MYSQL_VERSION_ID, "Used MySQL library version (%s id %lu) does not match the version id used to compile TrinityCore (id %u). Search on forum for TCE00011.",
mysql_get_client_info(), mysql_get_client_version(), MYSQL_VERSION_ID);
#if defined(LIBMARIADB) && MARIADB_PACKAGE_VERSION_ID >= 30200
WPFatal(mysql_get_client_version() >= MIN_MARIADB_CLIENT_VERSION, "TrinityCore does not support MariaDB versions below " MIN_MARIADB_CLIENT_VERSION_STRING " (found %s id %lu, need id >= %u), please update your MariaDB client library", mysql_get_client_info(), mysql_get_client_version(), MIN_MARIADB_CLIENT_VERSION);
WPFatal(mysql_get_client_version() == MARIADB_PACKAGE_VERSION_ID, "Used MariaDB library version (%s id %lu) does not match the version id used to compile TrinityCore (id %u). Search on forum for TCE00011.", mysql_get_client_info(), mysql_get_client_version(), MARIADB_PACKAGE_VERSION_ID);
#else
WPFatal(mysql_get_client_version() >= MIN_MYSQL_CLIENT_VERSION, "TrinityCore does not support MySQL versions below " MIN_MYSQL_CLIENT_VERSION_STRING " (found %s id %lu, need id >= %u), please update your MySQL client library", mysql_get_client_info(), mysql_get_client_version(), MIN_MYSQL_CLIENT_VERSION);
WPFatal(mysql_get_client_version() == MYSQL_VERSION_ID, "Used MySQL library version (%s id %lu) does not match the version id used to compile TrinityCore (id %u). Search on forum for TCE00011.", mysql_get_client_info(), mysql_get_client_version(), MYSQL_VERSION_ID);
#endif
}
template <class T>
@@ -380,9 +392,17 @@ uint32 DatabaseWorkerPool<T>::OpenConnections(InternalIndex type, uint8 numConne
_connections[type].clear();
return error;
}
#ifndef LIBMARIADB
else if (connection->GetServerVersion() < MIN_MYSQL_SERVER_VERSION)
#else
else if (connection->GetServerVersion() < MIN_MARIADB_SERVER_VERSION)
#endif
{
TC_LOG_ERROR("sql.driver", "TrinityCore does not support MySQL versions below 5.1");
#ifndef LIBMARIADB
TC_LOG_ERROR("sql.driver", "TrinityCore does not support MySQL versions below " MIN_MYSQL_SERVER_VERSION_STRING " (found id %u, need id >= %u), please update your MySQL server", connection->GetServerVersion(), MIN_MYSQL_SERVER_VERSION);
#else
TC_LOG_ERROR("sql.driver", "TrinityCore does not support MariaDB versions below " MIN_MARIADB_SERVER_VERSION_STRING " (found id %u, need id >= %u), please update your MySQL server", connection->GetServerVersion(), MIN_MARIADB_SERVER_VERSION);
#endif
return 1;
}
else
+5 -4
View File
@@ -80,10 +80,11 @@ ClientWardenModule* WardenMac::GetModuleForClient()
memcpy(mod->Key, Module_0DBBF209A27B1E279A9FEC5C168A15F7_Key, 16);
// md5 hash
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, mod->CompressedData, len);
MD5_Final((uint8*)&mod->Id, &ctx);
EVP_MD_CTX *md5 = EVP_MD_CTX_new();
EVP_DigestInit_ex(md5, EVP_md5(), nullptr);
EVP_DigestUpdate(md5, mod->CompressedData, len);
EVP_DigestFinal_ex(md5, (uint8 *)&mod->Id, &len);
EVP_MD_CTX_free(md5);
return mod;
}
+5 -4
View File
@@ -76,10 +76,11 @@ ClientWardenModule* WardenWin::GetModuleForClient()
memcpy(mod->Key, Module.ModuleKey, 16);
// md5 hash
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, mod->CompressedData, length);
MD5_Final((uint8*)&mod->Id, &ctx);
EVP_MD_CTX *md5 = EVP_MD_CTX_new();
EVP_DigestInit_ex(md5, EVP_md5(), nullptr);
EVP_DigestUpdate(md5, mod->CompressedData, length);
EVP_DigestFinal_ex(md5, (uint8 *)&mod->Id, &length);
EVP_MD_CTX_free(md5);
return mod;
}
+7 -3
View File
@@ -53,8 +53,12 @@
#include "WorldSocket.h"
#include "WorldSocketMgr.h"
#include "ZmqContext.h"
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include <openssl/opensslv.h>
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
#include <openssl/provider.h>
#endif
#include <boost/dll/runtime_symbol_info.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/program_options.hpp>
@@ -207,12 +211,12 @@ extern int main(int argc, char** argv)
[]()
{
TC_LOG_INFO("server.worldserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str());
TC_LOG_INFO("server.worldserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
TC_LOG_INFO("server.worldserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
TC_LOG_INFO("server.worldserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
}
);
OpenSSLCrypto::threadsSetup();
OpenSSLCrypto::threadsSetup(boost::dll::program_location().remove_filename());
std::shared_ptr<void> opensslHandle(nullptr, [](void*) { OpenSSLCrypto::threadsCleanup(); });
+2
View File
@@ -258,6 +258,8 @@ int main(int argc, char** argv)
#ifdef _WIN32
wchar_t* commonAppData(nullptr);
SHGetKnownFolderPath(FOLDERID_ProgramData, 0, nullptr, &commonAppData);
#else
const wchar_t* commonAppData(L".");
#endif
std::cout << "Creating patched binary..." << std::endl;