TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WardenMac Class Reference

#include <WardenMac.h>

Public Member Functions

 WardenMac ()
 
 ~WardenMac ()
 
void Init (WorldSession *session, BigNumber *k) override
 
ClientWardenModuleGetModuleForClient () override
 
void InitializeModule () override
 
void RequestHash () override
 
void HandleHashResult (ByteBuffer &buff) override
 
void RequestData () override
 
void HandleData (ByteBuffer &buff) override
 
- Public Member Functions inherited from Warden
 Warden ()
 
virtual ~Warden ()
 
void SendModuleToClient ()
 
void RequestModule ()
 
void Update ()
 
void DecryptData (uint8 *buffer, uint32 length)
 
void EncryptData (uint8 *buffer, uint32 length)
 
std::string Penalty (WardenCheck *check=NULL)
 

Additional Inherited Members

- Static Public Member Functions inherited from Warden
static bool IsValidCheckSum (uint32 checksum, const uint8 *data, const uint16 length)
 
static uint32 BuildChecksum (const uint8 *data, uint32 length)
 

Constructor & Destructor Documentation

WardenMac::WardenMac ( )
35 : Warden() { }
Warden()
Definition: Warden.cpp:33
WardenMac::~WardenMac ( )
37 { }

Member Function Documentation

ClientWardenModule * WardenMac::GetModuleForClient ( )
overridevirtual

Implements Warden.

73 {
75 
77 
78  // data assign
79  mod->CompressedSize = len;
80  mod->CompressedData = new uint8[len];
83 
84  // md5 hash
85  MD5_CTX ctx;
86  MD5_Init(&ctx);
87  MD5_Update(&ctx, mod->CompressedData, len);
88  MD5_Final((uint8*)&mod->Id, &ctx);
89 
90  return mod;
91 }
uint8 Id[16]
Definition: Warden.h:87
uint32 CompressedSize
Definition: Warden.h:89
uint8 Key[16]
Definition: Warden.h:88
uint8 * CompressedData
Definition: Warden.h:90
uint32_t uint32
Definition: Define.h:150
uint8 Module_0DBBF209A27B1E279A9FEC5C168A15F7_Key[16]
Definition: WardenModuleMac.h:609
uint8_t uint8
Definition: Define.h:152
uint8 Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data[9318]
Definition: WardenModuleMac.h:22
Definition: Warden.h:85

+ Here is the caller graph for this function:

void WardenMac::HandleData ( ByteBuffer buff)
overridevirtual

Implements Warden.

217 {
218  TC_LOG_DEBUG("warden", "Handle data");
219 
220  _dataSent = false;
222 
223  //uint16 Length;
224  //buff >> Length;
225  //uint32 Checksum;
226  //buff >> Checksum;
227 
228  //if (!IsValidCheckSum(Checksum, buff.contents() + buff.rpos(), Length))
229  //{
230  // buff.rpos(buff.wpos());
231  // if (sWorld->getBoolConfig(CONFIG_BOOL_WARDEN_KICK))
232  // Client->KickPlayer();
233  // return;
234  //}
235 
236  //bool found = false;
237 
238  std::string str = "Test string!";
239 
240  SHA1Hash sha1;
241  sha1.UpdateData(str);
242  uint32 magic = 0xFEEDFACE; // unsure
243  sha1.UpdateData((uint8*)&magic, 4);
244  sha1.Finalize();
245 
246  uint8 sha1Hash[20];
247  buff.read(sha1Hash, 20);
248 
249  if (memcmp(sha1Hash, sha1.GetDigest(), 20) != 0)
250  {
251  TC_LOG_DEBUG("warden", "Handle data failed: SHA1 hash is wrong!");
252  //found = true;
253  }
254 
255  MD5_CTX ctx;
256  MD5_Init(&ctx);
257  MD5_Update(&ctx, str.c_str(), str.size());
258  uint8 ourMD5Hash[16];
259  MD5_Final(ourMD5Hash, &ctx);
260 
261  uint8 theirsMD5Hash[16];
262  buff.read(theirsMD5Hash, 16);
263 
264  if (memcmp(ourMD5Hash, theirsMD5Hash, 16) != 0)
265  {
266  TC_LOG_DEBUG("warden", "Handle data failed: MD5 hash is wrong!");
267  //found = true;
268  }
269 
270  _session->KickPlayer();
271 }
uint32 _clientResponseTimer
Definition: Warden.h:132
void Finalize()
Definition: SHA1.cpp:65
bool _dataSent
Definition: Warden.h:133
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
void KickPlayer()
Kick a player out of the World.
Definition: WorldSession.cpp:646
void UpdateData(const uint8 *dta, int len)
Definition: SHA1.cpp:35
uint32_t uint32
Definition: Define.h:150
WorldSession * _session
Definition: Warden.h:125
Definition: SHA1.h:29
uint8_t uint8
Definition: Define.h:152
uint8 * GetDigest(void)
Definition: SHA1.h:45
T read()
Definition: ByteBuffer.h:484

+ Here is the call graph for this function:

void WardenMac::HandleHashResult ( ByteBuffer buff)
overridevirtual

Implements Warden.

131 {
132 
133  // test
134  int keyIn[4];
135 
136  keyData mod_seed = { { { { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE } } } };
137 
138  for (int i = 0; i < 4; ++i)
139  {
140  keyIn[i] = mod_seed.ints.ints[i];
141  }
142 
143  int keyOut[4];
144  int keyIn1, keyIn2;
145  keyOut[0] = keyIn[0];
146  keyIn[0] ^= 0xDEADBEEFu;
147  keyIn1 = keyIn[1];
148  keyIn[1] -= 0x35014542u;
149  keyIn2 = keyIn[2];
150  keyIn[2] += 0x5313F22u;
151  keyIn[3] *= 0x1337F00Du;
152  keyOut[1] = keyIn1 - 0x6A028A84;
153  keyOut[2] = keyIn2 + 0xA627E44;
154  keyOut[3] = 0x1337F00D * keyIn[3];
155  // end test
156 
157  buff.rpos(buff.wpos());
158 
159  SHA1Hash sha1;
160  sha1.UpdateData((uint8*)keyIn, 16);
161  sha1.Finalize();
162 
163  //const uint8 validHash[20] = { 0x56, 0x8C, 0x05, 0x4C, 0x78, 0x1A, 0x97, 0x2A, 0x60, 0x37, 0xA2, 0x29, 0x0C, 0x22, 0xB5, 0x25, 0x71, 0xA0, 0x6F, 0x4E };
164 
165  // Verify key
166  if (memcmp(buff.contents() + 1, sha1.GetDigest(), 20) != 0)
167  {
168  TC_LOG_WARN("warden", "%s failed hash reply. Action: %s", _session->GetPlayerInfo().c_str(), Penalty().c_str());
169  return;
170  }
171 
172  TC_LOG_DEBUG("warden", "Request hash reply: succeed");
173 
174  // client 7F96EEFDA5B63D20A4DF8E00CBF48304
175  //const uint8 client_key[16] = { 0x7F, 0x96, 0xEE, 0xFD, 0xA5, 0xB6, 0x3D, 0x20, 0xA4, 0xDF, 0x8E, 0x00, 0xCB, 0xF4, 0x83, 0x04 };
176 
177  // server C2B7ADEDFCCCA9C2BFB3F85602BA809B
178  //const uint8 server_key[16] = { 0xC2, 0xB7, 0xAD, 0xED, 0xFC, 0xCC, 0xA9, 0xC2, 0xBF, 0xB3, 0xF8, 0x56, 0x02, 0xBA, 0x80, 0x9B };
179 
180  // change keys here
181  memcpy(_inputKey, keyIn, 16);
182  memcpy(_outputKey, keyOut, 16);
183 
186 
187  _initialized = true;
188 
190 }
uint32 ints[5]
Definition: Warden.cpp:168
uint8 * contents()
Definition: ByteBuffer.h:573
uint32 _previousTimestamp
Definition: Warden.h:134
Definition: Warden.cpp:158
void Finalize()
Definition: SHA1.cpp:65
uint32 getMSTime()
Definition: Timer.h:24
std::string Penalty(WardenCheck *check=NULL)
Definition: Warden.cpp:184
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
void UpdateData(const uint8 *dta, int len)
Definition: SHA1.cpp:35
size_t wpos() const
Definition: ByteBuffer.h:454
void Init(uint8 *seed)
Definition: ARC4.cpp:42
WorldSession * _session
Definition: Warden.h:125
uint8 _outputKey[16]
Definition: Warden.h:127
Definition: SHA1.h:29
ARC4 _outputCrypto
Definition: Warden.h:130
ARC4 _inputCrypto
Definition: Warden.h:129
uint8 _inputKey[16]
Definition: Warden.h:126
bool _initialized
Definition: Warden.h:136
std::string GetPlayerInfo() const
Definition: WorldSession.cpp:195
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:204
uint8_t uint8
Definition: Define.h:152
uint8 * GetDigest(void)
Definition: SHA1.h:45
size_t rpos() const
Definition: ByteBuffer.h:441

+ Here is the call graph for this function:

void WardenMac::Init ( WorldSession session,
BigNumber k 
)
overridevirtual

Implements Warden.

40 {
41  _session = pClient;
42  // Generate Warden Key
43  SessionKeyGenerator<SHA1Hash> WK(K->AsByteArray().get(), K->GetNumBytes());
44  WK.Generate(_inputKey, 16);
45  WK.Generate(_outputKey, 16);
46  /*
47  Seed: 4D808D2C77D905C41A6380EC08586AFE (0x05 packet)
48  Hash: <?> (0x04 packet)
49  Module MD5: 0DBBF209A27B1E279A9FEC5C168A15F7
50  New Client Key: <?>
51  New Cerver Key: <?>
52  */
53  uint8 mod_seed[16] = { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE };
54 
55  memcpy(_seed, mod_seed, 16);
56 
59  TC_LOG_DEBUG("warden", "Server side warden for client %u initializing...", pClient->GetAccountId());
60  TC_LOG_DEBUG("warden", "C->S Key: %s", ByteArrayToHexStr(_inputKey, 16).c_str());
61  TC_LOG_DEBUG("warden", "S->C Key: %s", ByteArrayToHexStr(_outputKey, 16).c_str());
62  TC_LOG_DEBUG("warden", " Seed: %s", ByteArrayToHexStr(_seed, 16).c_str());
63  TC_LOG_DEBUG("warden", "Loading Module...");
64 
66 
67  TC_LOG_DEBUG("warden", "Module Key: %s", ByteArrayToHexStr(_module->Key, 16).c_str());
68  TC_LOG_DEBUG("warden", "Module ID: %s", ByteArrayToHexStr(_module->Id, 16).c_str());
69  RequestModule();
70 }
void Generate(uint8 *buf, uint32 sz)
Definition: SessionKeyGeneration.h:49
ClientWardenModule * _module
Definition: Warden.h:135
uint8 Id[16]
Definition: Warden.h:87
uint8 Key[16]
Definition: Warden.h:88
Definition: SessionKeyGeneration.h:25
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint8 _seed[16]
Definition: Warden.h:128
ClientWardenModule * GetModuleForClient() override
Definition: WardenMac.cpp:72
void Init(uint8 *seed)
Definition: ARC4.cpp:42
WorldSession * _session
Definition: Warden.h:125
void RequestModule()
Definition: Warden.cpp:75
uint8 _outputKey[16]
Definition: Warden.h:127
ARC4 _outputCrypto
Definition: Warden.h:130
ARC4 _inputCrypto
Definition: Warden.h:129
std::string ByteArrayToHexStr(uint8 const *bytes, uint32 arrayLen, bool reverse)
Definition: Util.cpp:509
uint8 _inputKey[16]
Definition: Warden.h:126
uint8_t uint8
Definition: Define.h:152

+ Here is the call graph for this function:

void WardenMac::InitializeModule ( )
overridevirtual

Implements Warden.

94 {
95  TC_LOG_DEBUG("warden", "Initialize module");
96 }
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
void WardenMac::RequestData ( )
overridevirtual

Implements Warden.

193 {
194  TC_LOG_DEBUG("warden", "Request data");
195 
196  ByteBuffer buff;
198 
199  std::string str = "Test string!";
200 
201  buff << uint8(str.size());
202  buff.append(str.c_str(), str.size());
203 
204  buff.hexlike();
205 
206  // Encrypt with warden RC4 key.
207  EncryptData(buff.contents(), buff.size());
208 
209  WorldPacket pkt(SMSG_WARDEN_DATA, buff.size());
210  pkt.append(buff);
211  _session->SendPacket(&pkt);
212 
213  _dataSent = true;
214 }
uint8 * contents()
Definition: ByteBuffer.h:573
Definition: ByteBuffer.h:70
bool _dataSent
Definition: Warden.h:133
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
Definition: Warden.h:41
size_t size() const
Definition: ByteBuffer.h:587
void EncryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:137
WorldSession * _session
Definition: Warden.h:125
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211
void hexlike() const
Definition: ByteBuffer.cpp:82
void append(T value)
Definition: ByteBuffer.h:143
uint8_t uint8
Definition: g3dmath.h:164
Definition: Opcodes.h:1623
Definition: WorldPacket.h:26

+ Here is the call graph for this function:

void WardenMac::RequestHash ( )
overridevirtual

Implements Warden.

99 {
100  TC_LOG_DEBUG("warden", "Request hash");
101 
102  // Create packet structure
103  WardenHashRequest Request;
105  memcpy(Request.Seed, _seed, 16);
106 
107  // Encrypt with warden RC4 key.
108  EncryptData((uint8*)&Request, sizeof(WardenHashRequest));
109 
111  pkt.append((uint8*)&Request, sizeof(WardenHashRequest));
112  _session->SendPacket(&pkt);
113 }
Definition: Warden.h:44
Definition: Warden.h:77
uint8 Seed[16]
Definition: Warden.h:80
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint8 _seed[16]
Definition: Warden.h:128
void EncryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:137
WorldSession * _session
Definition: Warden.h:125
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211
uint8 Command
Definition: Warden.h:79
uint8_t uint8
Definition: Define.h:152
Definition: Opcodes.h:1623
Definition: WorldPacket.h:26

+ Here is the call graph for this function:


The documentation for this class was generated from the following files: