Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Server/Crypto: Some crypto cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AriDEV3 committed Dec 29, 2023
1 parent 51bbda7 commit 0b3501e
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/server/game/Warden/Warden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "Warden.h"
#include "AccountMgr.h"

Warden::Warden() : _inputCrypto(16), _outputCrypto(16), _checkTimer(10000/*10 sec*/), _clientResponseTimer(0), _dataSent(false), _initialized(false) { }
Warden::Warden() : _inputCrypto(), _outputCrypto(), _checkTimer(10000/*10 sec*/), _clientResponseTimer(0), _dataSent(false), _initialized(false) { }

Warden::~Warden()
{
Expand Down
8 changes: 4 additions & 4 deletions src/server/game/Warden/WardenMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void WardenMac::Init(WorldSession* pClient, BigNumber* K)

memcpy(_seed, mod_seed, 16);

_inputCrypto.Init(_inputKey);
_outputCrypto.Init(_outputKey);
_inputCrypto.Init(_inputKey, 16);
_outputCrypto.Init(_outputKey, 16);
SF_LOG_DEBUG("warden", "Server side warden for client %u initializing...", pClient->GetAccountId());
SF_LOG_DEBUG("warden", "C->S Key: %s", ByteArrayToHexStr(_inputKey, 16).c_str());
SF_LOG_DEBUG("warden", "S->C Key: %s", ByteArrayToHexStr(_outputKey, 16).c_str());
Expand Down Expand Up @@ -165,8 +165,8 @@ void WardenMac::HandleHashResult(ByteBuffer &buff)
memcpy(_inputKey, keyIn, 16);
memcpy(_outputKey, keyOut, 16);

_inputCrypto.Init(_inputKey);
_outputCrypto.Init(_outputKey);
_inputCrypto.Init(_inputKey, 16);
_outputCrypto.Init(_outputKey, 16);

_initialized = true;

Expand Down
8 changes: 4 additions & 4 deletions src/server/game/Warden/WardenWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void WardenWin::Init(WorldSession* session, BigNumber* k)

memcpy(_seed, Module.Seed, 16);

_inputCrypto.Init(_inputKey);
_outputCrypto.Init(_outputKey);
_inputCrypto.Init(_inputKey, 16);
_outputCrypto.Init(_outputKey, 16);
SF_LOG_DEBUG("warden", "Server side warden for client %u initializing...", session->GetAccountId());
SF_LOG_DEBUG("warden", "C->S Key: %s", ByteArrayToHexStr(_inputKey, 16).c_str());
SF_LOG_DEBUG("warden", "S->C Key: %s", ByteArrayToHexStr(_outputKey, 16).c_str());
Expand Down Expand Up @@ -149,8 +149,8 @@ void WardenWin::HandleHashResult(ByteBuffer &buff)
memcpy(_inputKey, Module.ClientKeySeed, 16);
memcpy(_outputKey, Module.ServerKeySeed, 16);

_inputCrypto.Init(_inputKey);
_outputCrypto.Init(_outputKey);
_inputCrypto.Init(_inputKey, 16);
_outputCrypto.Init(_outputKey, 16);

_initialized = true;

Expand Down
14 changes: 3 additions & 11 deletions src/server/shared/Cryptography/ARC4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,20 @@
#include "ARC4.h"
#include <openssl/sha.h>

ARC4::ARC4(uint32 len) : m_ctx(EVP_CIPHER_CTX_new())
ARC4::ARC4() : m_ctx(EVP_CIPHER_CTX_new())
{
EVP_CIPHER_CTX_init(m_ctx);
EVP_EncryptInit_ex(m_ctx, EVP_rc4(), NULL, NULL, NULL);
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
}

ARC4::ARC4(uint8 *seed, uint32 len) : m_ctx(EVP_CIPHER_CTX_new())
{
EVP_CIPHER_CTX_init(m_ctx);
EVP_EncryptInit_ex(m_ctx, EVP_rc4(), NULL, NULL, NULL);
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
EVP_EncryptInit_ex(m_ctx, NULL, NULL, seed, NULL);
}

ARC4::~ARC4()
{
EVP_CIPHER_CTX_cleanup(m_ctx);
}

void ARC4::Init(uint8 *seed)
void ARC4::Init(uint8* seed, uint32 len)
{
EVP_CIPHER_CTX_set_key_length(m_ctx, len);
EVP_EncryptInit_ex(m_ctx, NULL, NULL, seed, NULL);
}

Expand Down
5 changes: 2 additions & 3 deletions src/server/shared/Cryptography/ARC4.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
class ARC4
{
public:
ARC4(uint32 len);
ARC4(uint8 *seed, uint32 len);
ARC4();
~ARC4();
void Init(uint8 *seed);
void Init(uint8 *seed, uint32 len);
void UpdateData(int len, uint8 *data);
private:
EVP_CIPHER_CTX *m_ctx;
Expand Down
6 changes: 3 additions & 3 deletions src/server/shared/Cryptography/Authentication/AuthCrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "Cryptography/BigNumber.h"

AuthCrypt::AuthCrypt() :
_clientDecrypt(SHA_DIGEST_LENGTH), _serverEncrypt(SHA_DIGEST_LENGTH),
_clientDecrypt(), _serverEncrypt(),
_initialized(false)
{ }

Expand All @@ -23,8 +23,8 @@ void AuthCrypt::Init(BigNumber* K)
uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);

//ARC4 _serverDecrypt(encryptHash);
_clientDecrypt.Init(decryptHash);
_serverEncrypt.Init(encryptHash);
_clientDecrypt.Init(decryptHash, 20);
_serverEncrypt.Init(encryptHash, 20);
//ARC4 _clientEncrypt(decryptHash);

// Drop first 1024 bytes, as WoW uses ARC4-drop1024.
Expand Down
47 changes: 0 additions & 47 deletions src/server/shared/Cryptography/OpenSSLCrypto.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions src/server/shared/Cryptography/OpenSSLCrypto.h

This file was deleted.

3 changes: 0 additions & 3 deletions src/server/worldserver/Master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "RealmList.h"

#include "BigNumber.h"
#include "OpenSSLCrypto.h"

#ifdef _WIN32
#include "ServiceWin32.h"
Expand Down Expand Up @@ -110,7 +109,6 @@ class FreezeDetectorRunnable : public ACE_Based::Runnable
/// Main function
int Master::Run()
{
OpenSSLCrypto::threadsSetup();
BigNumber seed1;
seed1.SetRand(16 * 8);

Expand Down Expand Up @@ -368,7 +366,6 @@ int Master::Run()
// fixes a memory leak related to detaching threads from the module
//UnloadScriptingModule();

OpenSSLCrypto::threadsCleanup();
// Exit the process with specified return value
return World::GetExitCode();
}
Expand Down

0 comments on commit 0b3501e

Please sign in to comment.