aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Auth
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/Auth')
-rw-r--r--src/shared/Auth/AuthCrypt.cpp80
-rw-r--r--src/shared/Auth/AuthCrypt.h15
-rw-r--r--src/shared/Auth/CMakeLists.txt2
-rw-r--r--src/shared/Auth/Hmac.cpp22
-rw-r--r--src/shared/Auth/Hmac.h9
-rw-r--r--src/shared/Auth/Makefile.am2
-rw-r--r--src/shared/Auth/SARC4.cpp52
-rw-r--r--src/shared/Auth/SARC4.h36
8 files changed, 150 insertions, 68 deletions
diff --git a/src/shared/Auth/AuthCrypt.cpp b/src/shared/Auth/AuthCrypt.cpp
index 0b2a3f64338..e8126ad9f73 100644
--- a/src/shared/Auth/AuthCrypt.cpp
+++ b/src/shared/Auth/AuthCrypt.cpp
@@ -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;
- _initialized = true;
-}
-void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
-{
- if (!_initialized) return;
- if (len < CRYPTED_RECV_LEN) 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;
- }
}
-void AuthCrypt::EncryptSend(uint8 *data, size_t len)
+void AuthCrypt::Init(BigNumber *K)
{
- 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;
- }
-}
+ 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);
-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;
+ 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;
}
-AuthCrypt::~AuthCrypt()
+void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
{
+ if (!_initialized)
+ return;
+
+ _clientDecrypt.UpdateData(len, data);
}
-void AuthCrypt::GenerateKey(uint8 *key, BigNumber *bn)
+void AuthCrypt::EncryptSend(uint8 *data, size_t len)
{
- HmacHash hash;
- hash.UpdateBigNumber(bn);
- hash.Finalize();
- memcpy(key, hash.GetDigest(), SHA_DIGEST_LENGTH);
+ if (!_initialized)
+ return;
+
+ _serverEncrypt.UpdateData(len, data);
}
diff --git a/src/shared/Auth/AuthCrypt.h b/src/shared/Auth/AuthCrypt.h
index 5c35511ad9f..226fde018ae 100644
--- a/src/shared/Auth/AuthCrypt.h
+++ b/src/shared/Auth/AuthCrypt.h
@@ -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
diff --git a/src/shared/Auth/CMakeLists.txt b/src/shared/Auth/CMakeLists.txt
index f0714509e1d..536853e560e 100644
--- a/src/shared/Auth/CMakeLists.txt
+++ b/src/shared/Auth/CMakeLists.txt
@@ -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})
diff --git a/src/shared/Auth/Hmac.cpp b/src/shared/Auth/Hmac.cpp
index a8572f0e9f8..985b4fb9a56 100644
--- a/src/shared/Auth/Hmac.cpp
+++ b/src/shared/Auth/Hmac.cpp
@@ -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;
+}
diff --git a/src/shared/Auth/Hmac.h b/src/shared/Auth/Hmac.h
index fc80bdca4c4..76a302d68de 100644
--- a/src/shared/Auth/Hmac.h
+++ b/src/shared/Auth/Hmac.h
@@ -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
diff --git a/src/shared/Auth/Makefile.am b/src/shared/Auth/Makefile.am
index 7398e2f2fa7..bc1a39868f5 100644
--- a/src/shared/Auth/Makefile.am
+++ b/src/shared/Auth/Makefile.am
@@ -35,6 +35,8 @@ libmangosauth_a_SOURCES = \
BigNumber.h \
Hmac.cpp \
Hmac.h \
+ SARC4.cpp \
+ SARC4.h \
Sha1.cpp \
Sha1.h \
md5.c \
diff --git a/src/shared/Auth/SARC4.cpp b/src/shared/Auth/SARC4.cpp
new file mode 100644
index 00000000000..f59bb7f0c53
--- /dev/null
+++ b/src/shared/Auth/SARC4.cpp
@@ -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);
+}
diff --git a/src/shared/Auth/SARC4.h b/src/shared/Auth/SARC4.h
new file mode 100644
index 00000000000..3f15328d6cb
--- /dev/null
+++ b/src/shared/Auth/SARC4.h
@@ -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