mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 13:37:00 +00:00
Just a commit
This commit is contained in:
parent
8f9849969b
commit
2626d8c243
7 changed files with 77 additions and 53 deletions
|
|
@ -187,7 +187,7 @@ int WorldSocket::SendPacket (const WorldPacket& pct)
|
|||
}
|
||||
|
||||
ServerPktHeader header(pct.size()+2, pct.GetOpcode());
|
||||
m_Crypt.EncryptSend ( header.header, header.getHeaderLength());
|
||||
m_Crypt.EncryptSend ((uint8*)header.header, header.getHeaderLength());
|
||||
|
||||
if (m_OutBuffer->space () >= pct.size () + header.getHeaderLength() && msg_queue()->is_empty())
|
||||
{
|
||||
|
|
@ -480,7 +480,7 @@ int WorldSocket::handle_input_header (void)
|
|||
|
||||
ACE_ASSERT (m_Header.length () == sizeof (ClientPktHeader));
|
||||
|
||||
m_Crypt.DecryptRecv ((ACE_UINT8*) m_Header.rd_ptr (), sizeof (ClientPktHeader));
|
||||
m_Crypt.DecryptRecv ((uint8*) m_Header.rd_ptr (), sizeof (ClientPktHeader));
|
||||
|
||||
ClientPktHeader& header = *((ClientPktHeader*) m_Header.rd_ptr ());
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include "AuthCrypt.h"
|
||||
#include "Hmac.h"
|
||||
#include "Log.h"
|
||||
#include "BigNumber.h"
|
||||
|
||||
AuthCrypt::AuthCrypt()
|
||||
{
|
||||
|
|
@ -31,32 +33,51 @@ AuthCrypt::~AuthCrypt()
|
|||
|
||||
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();
|
||||
sLog.outDebug("SessionKey: %s", K->AsHexStr());
|
||||
|
||||
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();
|
||||
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);
|
||||
|
||||
_recvCrypt.Init(recvHash.GetDigest(), sendHash.GetDigest());
|
||||
_sendCrypt.Init(recvHash.GetDigest(), sendHash.GetDigest());
|
||||
BigNumber eh;
|
||||
eh.SetBinary(encryptHash, SHA_DIGEST_LENGTH);
|
||||
sLog.outDebug("EncryptHash: %s", eh.AsHexStr());
|
||||
|
||||
uint8 emptyBuf1[1024];
|
||||
memset(emptyBuf1, 0, 1024);
|
||||
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);
|
||||
|
||||
_sendCrypt.Encrypt(1024, (uint8*)emptyBuf1);
|
||||
_sendCrypt.Decrypt(1024, (uint8*)emptyBuf1);
|
||||
BigNumber dh;
|
||||
dh.SetBinary(decryptHash, SHA_DIGEST_LENGTH);
|
||||
sLog.outDebug("DecryptHash: %s", dh.AsHexStr());
|
||||
|
||||
uint8 emptyBuf2[1024];
|
||||
memset(emptyBuf2, 0, 1024);
|
||||
SARC4 _serverDecrypt(encryptHash);
|
||||
_clientDecrypt.Init(decryptHash);
|
||||
_serverEncrypt.Init(encryptHash);
|
||||
SARC4 _clientEncrypt(decryptHash);
|
||||
|
||||
_recvCrypt.Encrypt(1024, (uint8*)emptyBuf2);
|
||||
_recvCrypt.Decrypt(1024, (uint8*)emptyBuf2);
|
||||
uint8 *syncBuf = new uint8[1024];
|
||||
memset(syncBuf, 0, 1024);
|
||||
|
||||
_serverEncrypt.UpdateData(1024, syncBuf);
|
||||
_clientEncrypt.UpdateData(1024, syncBuf);
|
||||
|
||||
BigNumber b1;
|
||||
b1.SetBinary(syncBuf, 16);
|
||||
sLog.outDebug("buf1: %s", b1.AsHexStr());
|
||||
|
||||
memset(syncBuf, 0, 1024);
|
||||
|
||||
_serverDecrypt.UpdateData(1024, syncBuf);
|
||||
_clientDecrypt.UpdateData(1024, syncBuf);
|
||||
|
||||
BigNumber b2;
|
||||
b2.SetBinary(syncBuf, 16);
|
||||
sLog.outDebug("buf2: %s", b2.AsHexStr());
|
||||
|
||||
_initialized = true;
|
||||
|
||||
delete[] syncBuf;
|
||||
}
|
||||
|
||||
void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
|
||||
|
|
@ -64,7 +85,7 @@ void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
|
|||
if (!_initialized)
|
||||
return;
|
||||
|
||||
_recvCrypt.Decrypt(len, data);
|
||||
_clientDecrypt.UpdateData(len, data);
|
||||
}
|
||||
|
||||
void AuthCrypt::EncryptSend(uint8 *data, size_t len)
|
||||
|
|
@ -72,5 +93,5 @@ void AuthCrypt::EncryptSend(uint8 *data, size_t len)
|
|||
if (!_initialized)
|
||||
return;
|
||||
|
||||
_sendCrypt.Encrypt(len, data);
|
||||
_serverEncrypt.UpdateData(len, data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ class AuthCrypt
|
|||
bool IsInitialized() { return _initialized; }
|
||||
|
||||
private:
|
||||
SARC4 _recvCrypt;
|
||||
SARC4 _sendCrypt;
|
||||
SARC4 _clientDecrypt;
|
||||
SARC4 _serverEncrypt;
|
||||
bool _initialized;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -45,6 +45,13 @@ void HmacHash::UpdateData(const uint8 *data, int length)
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,9 @@ class HmacHash
|
|||
void UpdateBigNumber(BigNumber *bn);
|
||||
void UpdateData(const uint8 *data, int length);
|
||||
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_digest[SHA_DIGEST_LENGTH];
|
||||
|
|
|
|||
|
|
@ -21,36 +21,32 @@
|
|||
|
||||
SARC4::SARC4()
|
||||
{
|
||||
EVP_CIPHER_CTX_init(&m_encryptctx);
|
||||
EVP_EncryptInit_ex(&m_encryptctx, EVP_rc4(), NULL, NULL, NULL);
|
||||
EVP_CIPHER_CTX_set_key_length(&m_encryptctx, SHA_DIGEST_LENGTH);
|
||||
EVP_CIPHER_CTX_init(&m_decryptctx);
|
||||
EVP_DecryptInit_ex(&m_decryptctx, EVP_rc4(), NULL, NULL, NULL);
|
||||
EVP_CIPHER_CTX_set_key_length(&m_decryptctx, SHA_DIGEST_LENGTH);
|
||||
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_encryptctx);
|
||||
EVP_CIPHER_CTX_cleanup(&m_decryptctx);
|
||||
EVP_CIPHER_CTX_cleanup(&m_ctx);
|
||||
}
|
||||
|
||||
void SARC4::Init(uint8 *seed1, uint8 *seed2)
|
||||
void SARC4::Init(uint8 *seed)
|
||||
{
|
||||
EVP_EncryptInit_ex(&m_encryptctx, NULL, NULL, seed1, NULL);
|
||||
EVP_DecryptInit_ex(&m_decryptctx, NULL, NULL, seed2, NULL);
|
||||
EVP_EncryptInit_ex(&m_ctx, NULL, NULL, seed, NULL);
|
||||
}
|
||||
|
||||
void SARC4::Encrypt(uint32 len, uint8 *data)
|
||||
void SARC4::UpdateData(int len, uint8 *data)
|
||||
{
|
||||
int outlen = 0;
|
||||
EVP_EncryptUpdate(&m_encryptctx, data, &outlen, data, len);
|
||||
EVP_EncryptFinal_ex(&m_encryptctx, data, &outlen);
|
||||
}
|
||||
|
||||
void SARC4::Decrypt(uint32 len, uint8 *data)
|
||||
{
|
||||
int outlen = 0;
|
||||
EVP_DecryptUpdate(&m_decryptctx, data, &outlen, data, len);
|
||||
EVP_DecryptFinal_ex(&m_decryptctx, data, &outlen);
|
||||
EVP_EncryptUpdate(&m_ctx, data, &outlen, data, len);
|
||||
EVP_EncryptFinal_ex(&m_ctx, data, &outlen);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,11 @@ class SARC4
|
|||
{
|
||||
public:
|
||||
SARC4();
|
||||
SARC4(uint8 *seed);
|
||||
~SARC4();
|
||||
void Init(uint8 *seed1, uint8 *seed2);
|
||||
void Encrypt(uint32 len, uint8 *data);
|
||||
void Decrypt(uint32 len, uint8 *data);
|
||||
void Init(uint8 *seed);
|
||||
void UpdateData(int len, uint8 *data);
|
||||
private:
|
||||
EVP_CIPHER_CTX m_encryptctx;
|
||||
EVP_CIPHER_CTX m_decryptctx;
|
||||
EVP_CIPHER_CTX m_ctx;
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue