*Switch to support client version 3.1.3
*I strongly recommend you not to use this until you get the 313 db. Now all destructible buildings cause client crash. Source: Mangos Thanks to TOM_RUS for most work to make this switch possible ;) --HG-- branch : trunk
This commit is contained in:
@@ -20,64 +20,62 @@
|
||||
|
||||
#include "AuthCrypt.h"
|
||||
#include "Hmac.h"
|
||||
#include "Log.h"
|
||||
#include "BigNumber.h"
|
||||
|
||||
AuthCrypt::AuthCrypt()
|
||||
{
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
void AuthCrypt::Init()
|
||||
AuthCrypt::~AuthCrypt()
|
||||
{
|
||||
_send_i = _send_j = _recv_i = _recv_j = 0;
|
||||
|
||||
}
|
||||
|
||||
void AuthCrypt::Init(BigNumber *K)
|
||||
{
|
||||
uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0x22, 0xBE, 0xE5, 0xCF, 0xBB, 0x07, 0x64, 0xD9, 0x00, 0x45, 0x1B, 0xD0, 0x24, 0xB8, 0xD5, 0x45 };
|
||||
HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
|
||||
uint8 *encryptHash = serverEncryptHmac.ComputeHash(K);
|
||||
|
||||
uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xF4, 0x66, 0x31, 0x59, 0xFC, 0x83, 0x6E, 0x31, 0x31, 0x02, 0x51, 0xD5, 0x44, 0x31, 0x67, 0x98 };
|
||||
HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
|
||||
uint8 *decryptHash = clientDecryptHmac.ComputeHash(K);
|
||||
|
||||
//SARC4 _serverDecrypt(encryptHash);
|
||||
_clientDecrypt.Init(decryptHash);
|
||||
_serverEncrypt.Init(encryptHash);
|
||||
//SARC4 _clientEncrypt(decryptHash);
|
||||
|
||||
uint8 syncBuf[1024];
|
||||
|
||||
memset(syncBuf, 0, 1024);
|
||||
|
||||
_serverEncrypt.UpdateData(1024, syncBuf);
|
||||
//_clientEncrypt.UpdateData(1024, syncBuf);
|
||||
|
||||
memset(syncBuf, 0, 1024);
|
||||
|
||||
//_serverDecrypt.UpdateData(1024, syncBuf);
|
||||
_clientDecrypt.UpdateData(1024, syncBuf);
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
|
||||
{
|
||||
if (!_initialized) return;
|
||||
if (len < CRYPTED_RECV_LEN) return;
|
||||
if (!_initialized)
|
||||
return;
|
||||
|
||||
for (size_t t = 0; t < CRYPTED_RECV_LEN; t++)
|
||||
{
|
||||
_recv_i %= _key.size();
|
||||
uint8 x = (data[t] - _recv_j) ^ _key[_recv_i];
|
||||
++_recv_i;
|
||||
_recv_j = data[t];
|
||||
data[t] = x;
|
||||
}
|
||||
_clientDecrypt.UpdateData(len, data);
|
||||
}
|
||||
|
||||
void AuthCrypt::EncryptSend(uint8 *data, size_t len)
|
||||
{
|
||||
if (!_initialized) return;
|
||||
if (!_initialized)
|
||||
return;
|
||||
|
||||
for (size_t t = 0; t < len; t++)
|
||||
{
|
||||
_send_i %= _key.size();
|
||||
uint8 x = (data[t] ^ _key[_send_i]) + _send_j;
|
||||
++_send_i;
|
||||
data[t] = _send_j = x;
|
||||
}
|
||||
}
|
||||
|
||||
void AuthCrypt::SetKey(BigNumber *bn)
|
||||
{
|
||||
uint8 *key = new uint8[SHA_DIGEST_LENGTH];
|
||||
GenerateKey(key, bn);
|
||||
_key.resize(SHA_DIGEST_LENGTH);
|
||||
std::copy(key, key + SHA_DIGEST_LENGTH, _key.begin());
|
||||
delete[] key;
|
||||
}
|
||||
|
||||
AuthCrypt::~AuthCrypt()
|
||||
{
|
||||
}
|
||||
|
||||
void AuthCrypt::GenerateKey(uint8 *key, BigNumber *bn)
|
||||
{
|
||||
HmacHash hash;
|
||||
hash.UpdateBigNumber(bn);
|
||||
hash.Finalize();
|
||||
memcpy(key, hash.GetDigest(), SHA_DIGEST_LENGTH);
|
||||
_serverEncrypt.UpdateData(len, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define _AUTHCRYPT_H
|
||||
|
||||
#include <Common.h>
|
||||
#include <vector>
|
||||
#include "SARC4.h"
|
||||
|
||||
class BigNumber;
|
||||
|
||||
@@ -32,22 +32,15 @@ class AuthCrypt
|
||||
AuthCrypt();
|
||||
~AuthCrypt();
|
||||
|
||||
const static size_t CRYPTED_RECV_LEN = 6;
|
||||
|
||||
void Init();
|
||||
|
||||
void SetKey(BigNumber *);
|
||||
|
||||
void Init(BigNumber *K);
|
||||
void DecryptRecv(uint8 *, size_t);
|
||||
void EncryptSend(uint8 *, size_t);
|
||||
|
||||
bool IsInitialized() { return _initialized; }
|
||||
|
||||
static void GenerateKey(uint8 *, BigNumber *);
|
||||
|
||||
private:
|
||||
std::vector<uint8> _key;
|
||||
uint8 _send_i, _send_j, _recv_i, _recv_j;
|
||||
SARC4 _clientDecrypt;
|
||||
SARC4 _serverEncrypt;
|
||||
bool _initialized;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,8 @@ SET(trinityauth_STAT_SRCS
|
||||
Sha1.h
|
||||
md5.c
|
||||
md5.h
|
||||
SARC4.cpp
|
||||
SARC4.h
|
||||
)
|
||||
|
||||
add_library(trinityauth STATIC ${trinityauth_STAT_SRCS})
|
||||
|
||||
+11
-11
@@ -21,17 +21,16 @@
|
||||
#include "Auth/Hmac.h"
|
||||
#include "BigNumber.h"
|
||||
|
||||
HmacHash::HmacHash()
|
||||
HmacHash::HmacHash(uint32 len, uint8 *seed)
|
||||
{
|
||||
uint8 temp[SEED_KEY_SIZE] = { 0x38, 0xA7, 0x83, 0x15, 0xF8, 0x92, 0x25, 0x30, 0x71, 0x98, 0x67, 0xB1, 0x8C, 0x4, 0xE2, 0xAA };
|
||||
memcpy(&m_key, &temp, SEED_KEY_SIZE);
|
||||
ASSERT(len == SEED_KEY_SIZE);
|
||||
|
||||
HMAC_CTX_init(&m_ctx);
|
||||
HMAC_Init_ex(&m_ctx, &m_key, SEED_KEY_SIZE, EVP_sha1(), NULL);
|
||||
HMAC_Init_ex(&m_ctx, seed, SEED_KEY_SIZE, EVP_sha1(), NULL);
|
||||
}
|
||||
|
||||
HmacHash::~HmacHash()
|
||||
{
|
||||
memset(&m_key, 0x00, SEED_KEY_SIZE);
|
||||
HMAC_CTX_cleanup(&m_ctx);
|
||||
}
|
||||
|
||||
@@ -45,15 +44,16 @@ void HmacHash::UpdateData(const uint8 *data, int length)
|
||||
HMAC_Update(&m_ctx, data, length);
|
||||
}
|
||||
|
||||
void HmacHash::Initialize()
|
||||
{
|
||||
HMAC_Init_ex(&m_ctx, &m_key, SEED_KEY_SIZE, EVP_sha1(), NULL);
|
||||
}
|
||||
|
||||
void HmacHash::Finalize()
|
||||
{
|
||||
uint32 length = 0;
|
||||
HMAC_Final(&m_ctx, m_digest, &length);
|
||||
HMAC_Final(&m_ctx, (uint8*)m_digest, &length);
|
||||
ASSERT(length == SHA_DIGEST_LENGTH)
|
||||
}
|
||||
|
||||
uint8 *HmacHash::ComputeHash(BigNumber *bn)
|
||||
{
|
||||
HMAC_Update(&m_ctx, bn->AsByteArray(), bn->GetNumBytes());
|
||||
Finalize();
|
||||
return (uint8*)m_digest;
|
||||
}
|
||||
|
||||
@@ -32,17 +32,16 @@ class BigNumber;
|
||||
class HmacHash
|
||||
{
|
||||
public:
|
||||
HmacHash();
|
||||
HmacHash(uint32 len, uint8 *seed);
|
||||
~HmacHash();
|
||||
void UpdateBigNumber(BigNumber *bn);
|
||||
void UpdateData(const uint8 *data, int length);
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
uint8 *GetDigest() { return m_digest; };
|
||||
int GetLength() { return SHA_DIGEST_LENGTH; };
|
||||
uint8 *ComputeHash(BigNumber *bn);
|
||||
uint8 *GetDigest() { return (uint8*)m_digest; }
|
||||
int GetLength() { return SHA_DIGEST_LENGTH; }
|
||||
private:
|
||||
HMAC_CTX m_ctx;
|
||||
uint8 m_key[SEED_KEY_SIZE];
|
||||
uint8 m_digest[SHA_DIGEST_LENGTH];
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -35,6 +35,8 @@ libmangosauth_a_SOURCES = \
|
||||
BigNumber.h \
|
||||
Hmac.cpp \
|
||||
Hmac.h \
|
||||
SARC4.cpp \
|
||||
SARC4.h \
|
||||
Sha1.cpp \
|
||||
Sha1.h \
|
||||
md5.c \
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "Auth/SARC4.h"
|
||||
#include <openssl/sha.h>
|
||||
|
||||
SARC4::SARC4()
|
||||
{
|
||||
EVP_CIPHER_CTX_init(&m_ctx);
|
||||
EVP_EncryptInit_ex(&m_ctx, EVP_rc4(), NULL, NULL, NULL);
|
||||
EVP_CIPHER_CTX_set_key_length(&m_ctx, SHA_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
SARC4::SARC4(uint8 *seed)
|
||||
{
|
||||
EVP_CIPHER_CTX_init(&m_ctx);
|
||||
EVP_EncryptInit_ex(&m_ctx, EVP_rc4(), NULL, NULL, NULL);
|
||||
EVP_CIPHER_CTX_set_key_length(&m_ctx, SHA_DIGEST_LENGTH);
|
||||
EVP_EncryptInit_ex(&m_ctx, NULL, NULL, seed, NULL);
|
||||
}
|
||||
|
||||
SARC4::~SARC4()
|
||||
{
|
||||
EVP_CIPHER_CTX_cleanup(&m_ctx);
|
||||
}
|
||||
|
||||
void SARC4::Init(uint8 *seed)
|
||||
{
|
||||
EVP_EncryptInit_ex(&m_ctx, NULL, NULL, seed, NULL);
|
||||
}
|
||||
|
||||
void SARC4::UpdateData(int len, uint8 *data)
|
||||
{
|
||||
int outlen = 0;
|
||||
EVP_EncryptUpdate(&m_ctx, data, &outlen, data, len);
|
||||
EVP_EncryptFinal_ex(&m_ctx, data, &outlen);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _AUTH_SARC4_H
|
||||
#define _AUTH_SARC4_H
|
||||
|
||||
#include "Common.h"
|
||||
#include <openssl/evp.h>
|
||||
|
||||
class SARC4
|
||||
{
|
||||
public:
|
||||
SARC4();
|
||||
SARC4(uint8 *seed);
|
||||
~SARC4();
|
||||
void Init(uint8 *seed);
|
||||
void UpdateData(int len, uint8 *data);
|
||||
private:
|
||||
EVP_CIPHER_CTX m_ctx;
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user