refactor(Core): remove ace_autoptr, cleanup (#3276)
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ace/Auto_Ptr.h>
|
|
||||||
|
|
||||||
BigNumber::BigNumber()
|
BigNumber::BigNumber()
|
||||||
: _bn(BN_new())
|
: _bn(BN_new())
|
||||||
@@ -158,23 +157,24 @@ bool BigNumber::isZero() const
|
|||||||
return BN_is_zero(_bn);
|
return BN_is_zero(_bn);
|
||||||
}
|
}
|
||||||
|
|
||||||
ACE_Auto_Array_Ptr<uint8> BigNumber::AsByteArray(int32 minSize, bool littleEndian)
|
std::unique_ptr<uint8[]> BigNumber::AsByteArray(int32 minSize, bool littleEndian)
|
||||||
{
|
{
|
||||||
int length = (minSize >= GetNumBytes()) ? minSize : GetNumBytes();
|
int numBytes = GetNumBytes();
|
||||||
|
int length = (minSize >= numBytes) ? minSize : numBytes;
|
||||||
|
|
||||||
uint8* array = new uint8[length];
|
uint8* array = new uint8[length];
|
||||||
|
|
||||||
// If we need more bytes than length of BigNumber set the rest to 0
|
// If we need more bytes than length of BigNumber set the rest to 0
|
||||||
if (length > GetNumBytes())
|
if (length > numBytes)
|
||||||
memset((void*)array, 0, length);
|
memset((void*)array, 0, length);
|
||||||
|
|
||||||
BN_bn2bin(_bn, (unsigned char *)array);
|
BN_bn2bin(_bn, (unsigned char*)array);
|
||||||
|
|
||||||
// openssl's BN stores data internally in big endian format, reverse if little endian desired
|
// openssl's BN stores data internally in big endian format, reverse if little endian desired
|
||||||
if (littleEndian)
|
if (littleEndian)
|
||||||
std::reverse(array, array + length);
|
std::reverse(array, array + length);
|
||||||
|
|
||||||
ACE_Auto_Array_Ptr<uint8> ret(array);
|
std::unique_ptr<uint8[]> ret(array);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,10 @@
|
|||||||
#define _AUTH_BIGNUMBER_H
|
#define _AUTH_BIGNUMBER_H
|
||||||
|
|
||||||
#include "Define.h"
|
#include "Define.h"
|
||||||
#include <ace/Auto_Ptr.h>
|
#include "Errors.h"
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
struct bignum_st;
|
struct bignum_st;
|
||||||
|
|
||||||
@@ -75,7 +78,7 @@ class BigNumber
|
|||||||
|
|
||||||
uint32 AsDword();
|
uint32 AsDword();
|
||||||
|
|
||||||
ACE_Auto_Array_Ptr<uint8> AsByteArray(int32 minSize = 0, bool littleEndian = true);
|
std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true);
|
||||||
|
|
||||||
char * AsHexStr() const;
|
char * AsHexStr() const;
|
||||||
char * AsDecStr() const;
|
char * AsDecStr() const;
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
#include "HMACSHA1.h"
|
#include "HMACSHA1.h"
|
||||||
#include "BigNumber.h"
|
#include "BigNumber.h"
|
||||||
#include "Common.h"
|
#include "Errors.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||||
HMAC_CTX* HMAC_CTX_new()
|
HMAC_CTX* HMAC_CTX_new()
|
||||||
@@ -23,8 +24,7 @@ void HMAC_CTX_free(HMAC_CTX* ctx)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
HmacHash::HmacHash(uint32 len, uint8* seed)
|
||||||
HmacHash::HmacHash(uint32 len, uint8 *seed)
|
|
||||||
{
|
{
|
||||||
m_ctx = HMAC_CTX_new();
|
m_ctx = HMAC_CTX_new();
|
||||||
HMAC_Init_ex(m_ctx, seed, len, EVP_sha1(), nullptr);
|
HMAC_Init_ex(m_ctx, seed, len, EVP_sha1(), nullptr);
|
||||||
@@ -36,14 +36,14 @@ HmacHash::~HmacHash()
|
|||||||
HMAC_CTX_free(m_ctx);
|
HMAC_CTX_free(m_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HmacHash::UpdateData(const std::string &str)
|
void HmacHash::UpdateData(std::string const& str)
|
||||||
{
|
{
|
||||||
HMAC_Update(m_ctx, reinterpret_cast<uint8 const*>(str.c_str()), str.length());
|
HMAC_Update(m_ctx, reinterpret_cast<uint8 const*>(str.c_str()), str.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HmacHash::UpdateData(const uint8* data, size_t len)
|
void HmacHash::UpdateData(uint8 const* data, size_t len)
|
||||||
{
|
{
|
||||||
HMAC_Update(m_ctx, data, len);
|
HMAC_Update(m_ctx, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HmacHash::Finalize()
|
void HmacHash::Finalize()
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ class BigNumber;
|
|||||||
class HmacHash
|
class HmacHash
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HmacHash(uint32 len, uint8 *seed);
|
HmacHash(uint32 len, uint8* seed);
|
||||||
~HmacHash();
|
~HmacHash();
|
||||||
void UpdateData(const std::string &str);
|
void UpdateData(std::string const& str);
|
||||||
void UpdateData(const uint8* data, size_t len);
|
void UpdateData(uint8 const* data, size_t len);
|
||||||
void Finalize();
|
void Finalize();
|
||||||
uint8* ComputeHash(BigNumber* bn);
|
uint8* ComputeHash(BigNumber* bn);
|
||||||
uint8* GetDigest() { return m_digest; }
|
uint8* GetDigest() { return m_digest; }
|
||||||
|
|||||||
@@ -6,52 +6,44 @@
|
|||||||
|
|
||||||
#include <OpenSSLCrypto.h>
|
#include <OpenSSLCrypto.h>
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
#include <ace/Thread_Mutex.h>
|
|
||||||
|
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ace/Thread.h>
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
std::vector<ACE_Thread_Mutex*> cryptoLocks;
|
std::vector<std::mutex*> cryptoLocks;
|
||||||
|
static void lockingCallback(int mode, int type, char const* /*file*/, int /*line*/)
|
||||||
static void lockingCallback(int mode, int type, const char* /*file*/, int /*line*/)
|
|
||||||
{
|
{
|
||||||
if (mode & CRYPTO_LOCK)
|
if (mode & CRYPTO_LOCK)
|
||||||
cryptoLocks[type]->acquire();
|
cryptoLocks[type]->lock();
|
||||||
else
|
else
|
||||||
cryptoLocks[type]->release();
|
cryptoLocks[type]->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void threadIdCallback(CRYPTO_THREADID * id)
|
static void threadIdCallback(CRYPTO_THREADID * id)
|
||||||
{
|
{
|
||||||
(void)id;
|
(void)id;
|
||||||
/// ACE_thread_t turns out to be a struct under Mac OS.
|
CRYPTO_THREADID_set_numeric(id, std::hash<std::thread::id>()(std::this_thread::get_id()));
|
||||||
#ifndef __APPLE__
|
|
||||||
CRYPTO_THREADID_set_numeric(id, ACE_Thread::self());
|
|
||||||
#else
|
|
||||||
CRYPTO_THREADID_set_pointer(id, ACE_Thread::self());
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenSSLCrypto::threadsSetup()
|
void OpenSSLCrypto::threadsSetup()
|
||||||
{
|
{
|
||||||
cryptoLocks.resize(CRYPTO_num_locks());
|
cryptoLocks.resize(CRYPTO_num_locks());
|
||||||
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
|
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
|
||||||
{
|
{
|
||||||
cryptoLocks[i] = new ACE_Thread_Mutex();
|
cryptoLocks[i] = new std::mutex();
|
||||||
}
|
}
|
||||||
(void)&threadIdCallback;
|
(void)&threadIdCallback;
|
||||||
CRYPTO_THREADID_set_callback(threadIdCallback);
|
CRYPTO_THREADID_set_callback(threadIdCallback);
|
||||||
|
|
||||||
(void)&lockingCallback;
|
(void)&lockingCallback;
|
||||||
CRYPTO_set_locking_callback(lockingCallback);
|
CRYPTO_set_locking_callback(lockingCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenSSLCrypto::threadsCleanup()
|
void OpenSSLCrypto::threadsCleanup()
|
||||||
{
|
{
|
||||||
CRYPTO_set_locking_callback(NULL);
|
CRYPTO_set_locking_callback(nullptr);
|
||||||
CRYPTO_THREADID_set_callback(NULL);
|
CRYPTO_THREADID_set_callback(nullptr);
|
||||||
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
|
for(int i = 0 ; i < CRYPTO_num_locks(); ++i)
|
||||||
{
|
{
|
||||||
delete cryptoLocks[i];
|
delete cryptoLocks[i];
|
||||||
}
|
}
|
||||||
cryptoLocks.resize(0);
|
cryptoLocks.resize(0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -7,16 +7,26 @@
|
|||||||
#ifndef OPENSSL_CRYPTO_H
|
#ifndef OPENSSL_CRYPTO_H
|
||||||
#define OPENSSL_CRYPTO_H
|
#define OPENSSL_CRYPTO_H
|
||||||
|
|
||||||
|
#include "Define.h"
|
||||||
|
#include <openssl/opensslv.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
namespace OpenSSLCrypto
|
namespace OpenSSLCrypto
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL
|
||||||
/// Needs to be called before threads using openssl are spawned
|
/// Needs to be called before threads using openssl are spawned
|
||||||
void threadsSetup();
|
void threadsSetup();
|
||||||
/// Needs to be called after threads using openssl are despawned
|
/// Needs to be called after threads using openssl are despawned
|
||||||
void threadsCleanup();
|
void threadsCleanup();
|
||||||
|
#else
|
||||||
|
void threadsSetup() { };
|
||||||
|
void threadsCleanup() { };
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
#include <ace/os_include/sys/os_socket.h>
|
#include <ace/os_include/sys/os_socket.h>
|
||||||
#include <ace/OS_NS_string.h>
|
#include <ace/OS_NS_string.h>
|
||||||
#include <ace/Reactor.h>
|
#include <ace/Reactor.h>
|
||||||
#include <ace/Auto_Ptr.h>
|
|
||||||
|
|
||||||
#include "WorldSocket.h"
|
#include "WorldSocket.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
@@ -660,7 +659,7 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
|
|||||||
ACE_ASSERT (new_pct);
|
ACE_ASSERT (new_pct);
|
||||||
|
|
||||||
// manage memory ;)
|
// manage memory ;)
|
||||||
ACE_Auto_Ptr<WorldPacket> aptr (new_pct);
|
std::unique_ptr<WorldPacket> aptr (new_pct);
|
||||||
|
|
||||||
const uint16 opcode = new_pct->GetOpcode();
|
const uint16 opcode = new_pct->GetOpcode();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user