Updated to new client build

This commit is contained in:
tomrus88 2009-03-04 14:58:11 +03:00
parent 2197da6407
commit e6a66cdc54
18 changed files with 360 additions and 188 deletions

View file

@ -24,57 +24,46 @@ AuthCrypt::AuthCrypt()
_initialized = false;
}
void AuthCrypt::Init()
AuthCrypt::~AuthCrypt()
{
_send_i = _send_j = _recv_i = _recv_j = 0;
}
void AuthCrypt::Init(BigNumber *K)
{
uint8 recvSeed[SEED_KEY_SIZE] = { 0x22, 0xBE, 0xE5, 0xCF, 0xBB, 0x07, 0x64, 0xD9, 0x00, 0x45, 0x1B, 0xD0, 0x24, 0xB8, 0xD5, 0x45 };
HmacHash recvHash(SEED_KEY_SIZE, (uint8*)recvSeed);
recvHash.UpdateBigNumber(K);
recvHash.Finalize();
_recvCrypt.Init(SHA_DIGEST_LENGTH, recvHash.GetDigest());
uint8 sendSeed[SEED_KEY_SIZE] = { 0xF4, 0x66, 0x31, 0x59, 0xFC, 0x83, 0x6E, 0x31, 0x31, 0x02, 0x51, 0xD5, 0x44, 0x31, 0x67, 0x98 };
HmacHash sendHash(SEED_KEY_SIZE, (uint8*)sendSeed);
sendHash.UpdateBigNumber(K);
sendHash.Finalize();
_sendCrypt.Init(SHA_DIGEST_LENGTH, sendHash.GetDigest());
uint8 emptyBuf[1000];
memset(emptyBuf, 0, 1000);
_sendCrypt.Process(1000, (uint8*)emptyBuf, (uint8*)emptyBuf);
_recvCrypt.Process(1000, (uint8*)emptyBuf, (uint8*)emptyBuf);
_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;
}
_recvCrypt.Process(len, data, 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);
_sendCrypt.Process(len, data, data);
}

View file

@ -21,6 +21,7 @@
#include <Common.h>
#include <vector>
#include "SARC4.h"
class BigNumber;
@ -30,22 +31,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 _sendCrypt;
SARC4 _recvCrypt;
bool _initialized;
};
#endif

View file

@ -19,10 +19,11 @@
#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);
memcpy(&m_key, seed, len);
HMAC_CTX_init(&m_ctx);
HMAC_Init_ex(&m_ctx, &m_key, SEED_KEY_SIZE, EVP_sha1(), NULL);
}

View file

@ -30,7 +30,7 @@ class BigNumber;
class HmacHash
{
public:
HmacHash();
HmacHash(uint32 len, uint8 *seed);
~HmacHash();
void UpdateBigNumber(BigNumber *bn);
void UpdateData(const uint8 *data, int length);

View file

@ -33,6 +33,8 @@ libmangosauth_a_SOURCES = \
BigNumber.h \
Hmac.cpp \
Hmac.h \
SARC4.cpp \
SARC4.h \
Sha1.cpp \
Sha1.h \
md5.c \

30
src/shared/Auth/SARC4.cpp Normal file
View file

@ -0,0 +1,30 @@
/*
* 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 "BigNumber.h"
void SARC4::Init(uint32 len, uint8 *seed)
{
RC4_set_key(&m_rc4_key, len, seed);
}
void SARC4::Process(uint32 len, uint8 *indata, uint8 *outdata)
{
RC4(&m_rc4_key, len, indata, outdata);
}

38
src/shared/Auth/SARC4.h Normal file
View file

@ -0,0 +1,38 @@
/*
* 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/rc4.h>
#include <openssl/sha.h>
class BigNumber;
#define SEED_KEY_SIZE 16
class SARC4
{
public:
void Init(uint32 len, uint8 *seed);
void Process(uint32 len, uint8 *indata, uint8 *outdata);
private:
RC4_KEY m_rc4_key;
};
#endif