mirror of
https://github.com/alexkulya/pandaria_5.4.8.git
synced 2025-12-13 13:37:06 +00:00
Added Support Openssl 3.0.x
This commit is contained in:
parent
9339e072af
commit
df3ff87f65
10 changed files with 935 additions and 210 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -29,8 +29,9 @@
|
||||||
#include <ace/Sig_Handler.h>
|
#include <ace/Sig_Handler.h>
|
||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
|
#include "OpenSSLCrypto.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
#include <boost/dll/runtime_symbol_info.hpp>
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
#include "Configuration/Config.h"
|
#include "Configuration/Config.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
@ -40,6 +41,9 @@
|
||||||
#include "RealmList.h"
|
#include "RealmList.h"
|
||||||
#include "RealmAcceptor.h"
|
#include "RealmAcceptor.h"
|
||||||
#include "AppenderDB.h"
|
#include "AppenderDB.h"
|
||||||
|
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
|
||||||
|
#include <openssl/provider.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
|
@ -150,7 +154,7 @@ extern int main(int argc, char** argv)
|
||||||
|
|
||||||
TC_LOG_INFO("server.authserver", "Using configuration file %s.", configFile);
|
TC_LOG_INFO("server.authserver", "Using configuration file %s.", configFile);
|
||||||
|
|
||||||
TC_LOG_WARN("server.authserver", "%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
|
TC_LOG_WARN("server.authserver", "%s (Library: %s)", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
|
||||||
|
|
||||||
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
|
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
|
||||||
ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true);
|
ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true);
|
||||||
|
|
|
||||||
|
|
@ -17,35 +17,51 @@
|
||||||
|
|
||||||
#include "ARC4.h"
|
#include "ARC4.h"
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
#include "Errors.h"
|
||||||
|
|
||||||
ARC4::ARC4(uint8 len)
|
ARC4::ARC4(uint8 len) : _ctx(EVP_CIPHER_CTX_new())
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_init(m_ctx);
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||||
EVP_EncryptInit_ex(m_ctx, EVP_rc4(), NULL, NULL, NULL);
|
_cipher = EVP_CIPHER_fetch(nullptr, "RC4", nullptr);
|
||||||
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
|
#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 const* seed, size_t len)
|
ARC4::ARC4(uint8 const* seed, size_t len) : _ctx(EVP_CIPHER_CTX_new())
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_init(m_ctx);
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||||
EVP_EncryptInit_ex(m_ctx, EVP_rc4(), NULL, NULL, NULL);
|
_cipher = EVP_CIPHER_fetch(nullptr, "RC4", nullptr);
|
||||||
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
|
#else
|
||||||
EVP_EncryptInit_ex(m_ctx, NULL, NULL, seed, NULL);
|
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()
|
ARC4::~ARC4()
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_cleanup(m_ctx);
|
EVP_CIPHER_CTX_free(_ctx);
|
||||||
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||||
|
EVP_CIPHER_free(_cipher);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC4::Init(uint8 const* seed)
|
void ARC4::Init(uint8 const* seed)
|
||||||
{
|
{
|
||||||
EVP_EncryptInit_ex(m_ctx, NULL, NULL, seed, NULL);
|
EVP_EncryptInit_ex(_ctx, nullptr, nullptr, seed, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARC4::UpdateData(int len, uint8 *data)
|
void ARC4::UpdateData(int len, uint8 *data)
|
||||||
{
|
{
|
||||||
int outlen = 0;
|
int outlen = 0;
|
||||||
EVP_EncryptUpdate(m_ctx, data, &outlen, data, len);
|
EVP_EncryptUpdate(_ctx, data, &outlen, data, len);
|
||||||
EVP_EncryptFinal_ex(m_ctx, data, &outlen);
|
EVP_EncryptFinal_ex(_ctx, data, &outlen);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
class ARC4
|
class ARC4
|
||||||
{
|
{
|
||||||
|
|
@ -30,7 +31,10 @@ class ARC4
|
||||||
void Init(uint8 const* seed);
|
void Init(uint8 const* seed);
|
||||||
void UpdateData(int len, uint8 *data);
|
void UpdateData(int len, uint8 *data);
|
||||||
private:
|
private:
|
||||||
EVP_CIPHER_CTX * m_ctx = EVP_CIPHER_CTX_new();
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||||
|
EVP_CIPHER* _cipher;
|
||||||
|
#endif
|
||||||
|
EVP_CIPHER_CTX* _ctx;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,40 +20,29 @@
|
||||||
#include <ace/Thread_Mutex.h>
|
#include <ace/Thread_Mutex.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ace/Thread.h>
|
#include <ace/Thread.h>
|
||||||
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||||
|
#include <openssl/provider.h>
|
||||||
|
OSSL_PROVIDER* LegacyProvider;
|
||||||
|
OSSL_PROVIDER* DefaultProvider;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector<ACE_Thread_Mutex*> cryptoLocks;
|
|
||||||
|
|
||||||
static void lockingCallback(int mode, int type, const char* /*file*/, int /*line*/)
|
void OpenSSLCrypto::threadsSetup([[maybe_unused]] boost::filesystem::path const& providerModulePath)
|
||||||
{
|
{
|
||||||
if (mode & CRYPTO_LOCK)
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||||
cryptoLocks[type]->acquire();
|
#if PLATFORM == PLATFORM_WINDOWS
|
||||||
else
|
OSSL_PROVIDER_set_default_search_path(nullptr, providerModulePath.string().c_str());
|
||||||
cryptoLocks[type]->release();
|
#endif
|
||||||
}
|
LegacyProvider = OSSL_PROVIDER_load(nullptr, "legacy");
|
||||||
|
DefaultProvider = OSSL_PROVIDER_load(nullptr, "default");
|
||||||
static void threadIdCallback(CRYPTO_THREADID * id)
|
#endif
|
||||||
{
|
|
||||||
CRYPTO_THREADID_set_numeric(id, ACE_Thread::self());
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenSSLCrypto::threadsSetup()
|
|
||||||
{
|
|
||||||
cryptoLocks.resize(CRYPTO_num_locks());
|
|
||||||
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
|
|
||||||
{
|
|
||||||
cryptoLocks[i] = new ACE_Thread_Mutex();
|
|
||||||
}
|
|
||||||
CRYPTO_THREADID_set_callback(threadIdCallback);
|
|
||||||
CRYPTO_set_locking_callback(lockingCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenSSLCrypto::threadsCleanup()
|
void OpenSSLCrypto::threadsCleanup()
|
||||||
{
|
{
|
||||||
CRYPTO_set_locking_callback(NULL);
|
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
|
||||||
CRYPTO_THREADID_set_callback(NULL);
|
OSSL_PROVIDER_unload(LegacyProvider);
|
||||||
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
|
OSSL_PROVIDER_unload(DefaultProvider);
|
||||||
{
|
OSSL_PROVIDER_set_default_search_path(nullptr, nullptr);
|
||||||
delete cryptoLocks[i];
|
#endif
|
||||||
}
|
}
|
||||||
cryptoLocks.resize(0);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OPENSSL_CRYPTO_H
|
#ifndef PD_OPENSSL_CRYPTO_H
|
||||||
#define OPENSSL_CRYPTO_H
|
#define PD_OPENSSL_CRYPTO_H
|
||||||
|
#include <boost/filesystem/path.hpp>
|
||||||
/**
|
/**
|
||||||
* A group of functions which setup openssl crypto module to work properly in multithreaded enviroment
|
* A group of functions which setup openssl crypto module to work properly in multithreaded enviroment
|
||||||
* If not setup properly - it will crash
|
* If not setup properly - it will crash
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
namespace OpenSSLCrypto
|
namespace OpenSSLCrypto
|
||||||
{
|
{
|
||||||
/// Needs to be called before threads using openssl are spawned
|
/// Needs to be called before threads using openssl are spawned
|
||||||
void threadsSetup();
|
void threadsSetup(boost::filesystem::path const& providerModulePath);
|
||||||
/// Needs to be called after threads using openssl are despawned
|
/// Needs to be called after threads using openssl are despawned
|
||||||
void threadsCleanup();
|
void threadsCleanup();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,41 @@
|
||||||
|
|
||||||
SHA1Hash::SHA1Hash()
|
SHA1Hash::SHA1Hash()
|
||||||
{
|
{
|
||||||
SHA1_Init(&mC);
|
m_ctx = EVP_MD_CTX_new();
|
||||||
memset(mDigest, 0, SHA_DIGEST_LENGTH * sizeof(uint8));
|
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()
|
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)
|
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)
|
void SHA1Hash::UpdateData(const std::string &str)
|
||||||
|
|
@ -57,11 +80,12 @@ void SHA1Hash::UpdateBigNumbers(BigNumber* bn0, ...)
|
||||||
|
|
||||||
void SHA1Hash::Initialize()
|
void SHA1Hash::Initialize()
|
||||||
{
|
{
|
||||||
SHA1_Init(&mC);
|
EVP_DigestInit(m_ctx, EVP_sha1());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHA1Hash::Finalize(void)
|
void SHA1Hash::Finalize(void)
|
||||||
{
|
{
|
||||||
SHA1_Final(mDigest, &mC);
|
uint32 length = SHA_DIGEST_LENGTH;
|
||||||
|
EVP_DigestFinal_ex(m_ctx, m_digest, &length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
|
#include <openssl/evp.h>
|
||||||
|
|
||||||
class BigNumber;
|
class BigNumber;
|
||||||
|
|
||||||
|
|
@ -28,8 +29,13 @@ class SHA1Hash
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SHA1Hash();
|
SHA1Hash();
|
||||||
|
SHA1Hash(SHA1Hash const& other); // copy
|
||||||
|
SHA1Hash(SHA1Hash&& other); // move
|
||||||
|
SHA1Hash& operator=(SHA1Hash other); // assign
|
||||||
~SHA1Hash();
|
~SHA1Hash();
|
||||||
|
|
||||||
|
void Swap(SHA1Hash& other) throw();
|
||||||
|
friend void Swap(SHA1Hash& left, SHA1Hash& right) { left.Swap(right); }
|
||||||
void UpdateBigNumbers(BigNumber* bn0, ...);
|
void UpdateBigNumbers(BigNumber* bn0, ...);
|
||||||
|
|
||||||
void UpdateData(const uint8 *dta, int len);
|
void UpdateData(const uint8 *dta, int len);
|
||||||
|
|
@ -38,12 +44,12 @@ class SHA1Hash
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Finalize();
|
void Finalize();
|
||||||
|
|
||||||
uint8 *GetDigest(void) { return mDigest; };
|
uint8* GetDigest(void) { return m_digest; }
|
||||||
int GetLength(void) const { return SHA_DIGEST_LENGTH; };
|
int GetLength() const { return SHA_DIGEST_LENGTH; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SHA_CTX mC;
|
EVP_MD_CTX* m_ctx;
|
||||||
uint8 mDigest[SHA_DIGEST_LENGTH];
|
uint8 m_digest[SHA_DIGEST_LENGTH];
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,18 @@
|
||||||
|
|
||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
|
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
|
||||||
|
#include <openssl/provider.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <boost/dll/runtime_symbol_info.hpp>
|
||||||
#include <ace/Version.h>
|
#include <ace/Version.h>
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
#include "Configuration/Config.h"
|
#include "Configuration/Config.h"
|
||||||
|
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Master.h"
|
#include "Master.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
|
@ -139,7 +145,7 @@ extern int main(int argc, char** argv)
|
||||||
|
|
||||||
TC_LOG_INFO("server.worldserver", "Using configuration file %s.", cfg_file);
|
TC_LOG_INFO("server.worldserver", "Using configuration file %s.", cfg_file);
|
||||||
|
|
||||||
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 ACE version: %s", ACE_VERSION);
|
TC_LOG_INFO("server.worldserver", "Using ACE version: %s", ACE_VERSION);
|
||||||
|
|
||||||
///- and run the 'Master'
|
///- and run the 'Master'
|
||||||
|
|
@ -151,9 +157,6 @@ extern int main(int argc, char** argv)
|
||||||
// 1 - shutdown at error
|
// 1 - shutdown at error
|
||||||
// 2 - restart command used, this code can be used by restarter for restart Trinityd
|
// 2 - restart command used, this code can be used by restarter for restart Trinityd
|
||||||
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(20));
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,13 @@
|
||||||
#include "Database/DatabaseEnv.h"
|
#include "Database/DatabaseEnv.h"
|
||||||
#include "Database/DatabaseWorkerPool.h"
|
#include "Database/DatabaseWorkerPool.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 "CliRunnable.h"
|
#include "CliRunnable.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Master.h"
|
#include "Master.h"
|
||||||
|
|
@ -161,7 +168,7 @@ void RunAuthserverIfNeed()
|
||||||
/// Main function
|
/// Main function
|
||||||
int Master::Run()
|
int Master::Run()
|
||||||
{
|
{
|
||||||
OpenSSLCrypto::threadsSetup();
|
OpenSSLCrypto::threadsSetup(boost::dll::program_location().remove_filename());
|
||||||
BigNumber seed1;
|
BigNumber seed1;
|
||||||
seed1.SetRand(16 * 8);
|
seed1.SetRand(16 * 8);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue