diff options
author | StormBytePP <stormbyte@gmail.com> | 2015-08-24 02:17:32 +0200 |
---|---|---|
committer | StormBytePP <stormbyte@gmail.com> | 2015-08-24 03:35:19 +0200 |
commit | ba2e9fbe95e1adc3cf4ac163581bf95332ee5ac3 (patch) | |
tree | a1dd6c34b9aef17846e13244d5d7598ee27b8c30 /src/common/Cryptography/Authentication | |
parent | cdfa9afceb224a6b0a34889f06c720f6bc982c61 (diff) |
Core/BuildSystem: Merged crypto into common, cleaned include directory lists (to mimic 3.x buildsystem)
Diffstat (limited to 'src/common/Cryptography/Authentication')
4 files changed, 175 insertions, 0 deletions
diff --git a/src/common/Cryptography/Authentication/PacketCrypt.cpp b/src/common/Cryptography/Authentication/PacketCrypt.cpp new file mode 100644 index 00000000000..c38bd844327 --- /dev/null +++ b/src/common/Cryptography/Authentication/PacketCrypt.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include "PacketCrypt.h" + +PacketCrypt::PacketCrypt(uint32 rc4InitSize) + : _clientDecrypt(rc4InitSize), _serverEncrypt(rc4InitSize), _initialized(false) +{ +} + +void PacketCrypt::DecryptRecv(uint8* data, size_t len) +{ + if (!_initialized) + return; + + _clientDecrypt.UpdateData(len, data); +} + +void PacketCrypt::EncryptSend(uint8* data, size_t len) +{ + if (!_initialized) + return; + + _serverEncrypt.UpdateData(len, data); +} diff --git a/src/common/Cryptography/Authentication/PacketCrypt.h b/src/common/Cryptography/Authentication/PacketCrypt.h new file mode 100644 index 00000000000..d43cac77e66 --- /dev/null +++ b/src/common/Cryptography/Authentication/PacketCrypt.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _PACKETCRYPT_H +#define _PACKETCRYPT_H + +#include "Cryptography/ARC4.h" + +class BigNumber; + +class PacketCrypt +{ + public: + PacketCrypt(uint32 rc4InitSize); + virtual ~PacketCrypt() { } + + virtual void Init(BigNumber* K) = 0; + void DecryptRecv(uint8* data, size_t length); + void EncryptSend(uint8* data, size_t length); + + bool IsInitialized() const { return _initialized; } + + protected: + ARC4 _clientDecrypt; + ARC4 _serverEncrypt; + bool _initialized; +}; + +#endif // _PACKETCRYPT_H diff --git a/src/common/Cryptography/Authentication/WorldPacketCrypt.cpp b/src/common/Cryptography/Authentication/WorldPacketCrypt.cpp new file mode 100644 index 00000000000..55c9f01908d --- /dev/null +++ b/src/common/Cryptography/Authentication/WorldPacketCrypt.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include "WorldPacketCrypt.h" +#include "Cryptography/HmacHash.h" +#include "Cryptography/BigNumber.h" + +#include <cstring> + +WorldPacketCrypt::WorldPacketCrypt() : PacketCrypt(SHA_DIGEST_LENGTH) +{ +} + +void WorldPacketCrypt::Init(BigNumber* K) +{ + uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0x08, 0xF1, 0x95, 0x9F, 0x47, 0xE5, 0xD2, 0xDB, 0xA1, 0x3D, 0x77, 0x8F, 0x3F, 0x3E, 0xE7, 0x00 }; + uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0x40, 0xAA, 0xD3, 0x92, 0x26, 0x71, 0x43, 0x47, 0x3A, 0x31, 0x08, 0xA6, 0xE7, 0xDC, 0x98, 0x2A }; + Init(K, ServerEncryptionKey, ServerDecryptionKey); +} + +void WorldPacketCrypt::Init(BigNumber* k, uint8 const* serverKey, uint8 const* clientKey) +{ + HmacSha1 serverEncryptHmac(SEED_KEY_SIZE, (uint8*)serverKey); + uint8 *encryptHash = serverEncryptHmac.ComputeHash(k); + + HmacSha1 clientDecryptHmac(SEED_KEY_SIZE, (uint8*)clientKey); + uint8 *decryptHash = clientDecryptHmac.ComputeHash(k); + + _clientDecrypt.Init(decryptHash); + _serverEncrypt.Init(encryptHash); + + // Drop first 1024 bytes, as WoW uses ARC4-drop1024. + uint8 syncBuf[1024]; + memset(syncBuf, 0, 1024); + + _serverEncrypt.UpdateData(1024, syncBuf); + + memset(syncBuf, 0, 1024); + + _clientDecrypt.UpdateData(1024, syncBuf); + + _initialized = true; +} diff --git a/src/common/Cryptography/Authentication/WorldPacketCrypt.h b/src/common/Cryptography/Authentication/WorldPacketCrypt.h new file mode 100644 index 00000000000..dfa54182059 --- /dev/null +++ b/src/common/Cryptography/Authentication/WorldPacketCrypt.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _WORLDPACKETCRYPT_H +#define _WORLDPACKETCRYPT_H + +#include "PacketCrypt.h" + +class BigNumber; + +class WorldPacketCrypt : public PacketCrypt +{ + public: + WorldPacketCrypt(); + + void Init(BigNumber* K) override; + void Init(BigNumber* k, uint8 const* serverKey, uint8 const* clientKey); +}; + +#endif // _WORLDPACKETCRYPT_H |