-
Notifications
You must be signed in to change notification settings - Fork 1
/
Proxy_Handlers.cpp
319 lines (264 loc) · 7.72 KB
/
Proxy_Handlers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* -*- C++ -*-
* Copyright (C) 2009 Trinity Core <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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @file
* @brief TBC specific opcode handlers for proxyd
* @author raczman <raczman@gmail.com>
* @date 2009-11-29
*
*/
#include <openssl/bn.h>
#include <openssl/sha.h>
#include "Update_Fields.h"
#include "dbc/DBC_Store.h"
#include "Proxy_Service.h"
#include "Proxy_Socket.h"
#include "Proxy_Crypto.h"
#include "Opcodes.h"
namespace Trinity
{
namespace Proxyd
{
void
Proxy_Socket::handle_cmsg_auth_session()
{
PROXY_TRACE;
uint32 tmp;
if(!this->in_packet->CheckSize(4 + 4+ 1 + 4 + 20))
return;
*this->in_packet >> tmp;
*this->in_packet >> tmp;
*this->in_packet >> this->login;
*this->in_packet >> this->client_seed;
this->client_digest = new uint8[20];
this->in_packet->read(this->client_digest, 20);
PROXY_LOG("User %s tries to authenticate (seed: 0x%X)\n",
this->login.c_str(),
this->client_seed);
sProxy->get_db()->get_account(this->ptr);
}
void
Proxy_Socket::account_retrieved(bool state)
{
PROXY_TRACE;
// The moment someone writes a hack that bypasses realmd
// and logs in somehow straight into game
// Call me so i can give a beer to that wonderful hacker.
// But still, we need to check if the account exists.
// Client doesn't even react to that opcode, but lets send it
// For sake of being...
// 0x15 is AUTH_STATE_ACCOUNT_UNKNOWN btw.
if(!state)
{
ServerPkt* pkt = new ServerPkt(SMSG_AUTH_RESPONSE, 1);
*pkt << uint8(0x15);
this->send(pkt);
this->die();
return;
}
//Prepare vars
BIGNUM* N = BN_new();
BIGNUM* g = BN_new();
BIGNUM* I = BN_new();
BIGNUM* s = BN_new();
BIGNUM* v = BN_new();
BIGNUM* x = BN_new();
BIGNUM* K = BN_new();
BN_CTX* ctx = BN_CTX_new();
uint8 pass_hash[SHA_DIGEST_LENGTH] = {0};
uint8 digest[SHA_DIGEST_LENGTH] = {0};
uint8* s_bin;
//Loading data
BN_hex2bn(&N, "894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
BN_set_word(g, 7);
BN_hex2bn(&I, this->acct.sha_pass_hash.c_str());
BN_hex2bn(&s, this->acct.s.c_str());
s_bin = new uint8[BN_num_bytes(s)];
BN_bn2bin(s, s_bin);
BN_bn2bin(I, pass_hash);
std::reverse(s_bin, (uint8*)s_bin + BN_num_bytes(s) );
// std::reverse(pass_hash, pass_hash + SHA_DIGEST_LENGTH);
SHA_CTX* sha = new SHA_CTX();
SHA1_Init(sha);
SHA1_Update(sha, s_bin, BN_num_bytes(s) );
SHA1_Update(sha, pass_hash, SHA_DIGEST_LENGTH);
SHA1_Final(digest, sha);
delete sha;
std::reverse(digest, digest + SHA_DIGEST_LENGTH);
BN_bin2bn(digest, SHA_DIGEST_LENGTH, x);
BN_mod_exp(v, g, x, N, ctx);
char* s_char = BN_bn2hex(s);
char* v_char = BN_bn2hex(v);
PROXY_LOG("s: %s \n\told v:%s\n\t v=%s\n", this->acct.s.c_str(),this->acct.v.c_str(),v_char);
if(ACE_OS::strcmp(v_char, this->acct.v.c_str()))
{
BN_free(K);
BN_free(N);
BN_free(g);
BN_free(I);
BN_free(s);
BN_free(v);
BN_free(x);
BN_CTX_free(ctx);
ACE_OS::free(s_char);
ACE_OS::free(v_char);
delete[] s_bin;
this->die();
return;
}
uint8 check_digest[SHA_DIGEST_LENGTH];
uint32 trailer = 0x00;
BN_hex2bn(&K, this->acct.sessionkey.c_str());
uint8* k_char = new uint8[BN_num_bytes(K)];
BN_bn2bin(K, k_char);
std::reverse(k_char, k_char + 40);
sha = new SHA_CTX();
SHA1_Init(sha);
SHA1_Update(sha, this->login.c_str(), this->login.length());
SHA1_Update(sha, &trailer, 4);
SHA1_Update(sha, &this->client_seed, 4);
SHA1_Update(sha, &this->seed, 4);
SHA1_Update(sha, k_char, BN_num_bytes(K));
SHA1_Final(check_digest, sha);
delete sha;
//std::reverse(check_digest, check_digest + SHA_DIGEST_LENGTH);
PROXY_LOG("memcmp %u\n",memcmp(check_digest, this->client_digest,20));
if(memcmp(check_digest, this->client_digest, 20))
{
BN_free(K);
BN_free(N);
BN_free(g);
BN_free(I);
BN_free(s);
BN_free(v);
BN_free(x);
BN_CTX_free(ctx);
ACE_OS::free(s_char);
ACE_OS::free(v_char);
this->die();
return;
}
this->crypto->set_key(K);
ServerPkt* pkt = new ServerPkt(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1);
*pkt << (uint8)0x0C; //AUTH_OK
*pkt << (uint32)0x00;
*pkt << (uint8)0x00;
*pkt << (uint32)0x00;
*pkt << (uint8)this->acct.expansion;
this->send(pkt);
BN_free(K);
BN_free(N);
BN_free(g);
BN_free(I);
BN_free(s);
BN_free(v);
BN_free(x);
BN_CTX_free(ctx);
ACE_OS::free(s_char);
ACE_OS::free(v_char);
}
void
Proxy_Socket::handle_cmsg_char_enum()
{
sProxy->get_db()->get_chars(this->ptr);
}
void
Proxy_Socket::characters_retrieved(bool state)
{
ServerPkt* pkt = new ServerPkt(SMSG_CHAR_ENUM, 1);
if(!state)
{
*pkt << uint8(0);
this->send(pkt);
return;
}
PROXY_LOG("%u characters\n", this->characters.size());
*pkt << (uint8)this->characters.size();
for(std::list<Character>::const_iterator iter = this->characters.begin();iter != this->characters.end(); iter++)
{
PROXY_LOG("%s \n", iter->name.c_str());
*pkt << uint64(uint64(iter->guid) | (uint64(0) <<24) | ( uint64(0) << 48) );
*pkt << iter->name;
*pkt << iter->race;
*pkt << iter->pclass;
*pkt << iter->gender;
*pkt << uint8(iter->bytes);
*pkt << uint8(iter->bytes >> 8);
*pkt << uint8(iter->bytes >> 16);
*pkt << uint8(iter->bytes >> 24);
*pkt << iter->bytes2;
*pkt << iter->level;
*pkt << iter->zone;
*pkt << iter->map;
*pkt << iter->x;
*pkt << iter->y;
*pkt << iter->z;
*pkt << iter->guild;
/** @todo player & atlogin flags; */
*pkt << uint32(0x00);//2002000); //iter->player_flags;
*pkt << (uint8)0x01; //UNK
/**
@todo Load dbc's and get pets family info...
*pkt << iter->pet.modelid;
*pkt << iter->pet.level;
*pkt << family;
*/
*pkt << (uint32)0;
*pkt << (uint32)0;
*pkt << (uint32)0;
for(uint8 slot = 0; slot < 19; slot++)
{
/**
* @todo
* *pkt << (uint32)enchant_id;
*/
uint32 item_base = PLAYER_VISIBLE_ITEM_1_0 + (slot * 16);
uint32 item_id = iter->update_fields[item_base];
if(sDBC->get_item_map()->find(item_id) != sDBC->get_item_map()->end())
{
const Trinity::DBC::ItemEntry& item = sDBC->get_item_map()->find(item_id)->second;
const Trinity::DBC::SpellItemEnchantmentEntry* spell = NULL;
*pkt << (uint32)item.display_id;
*pkt << (uint8)item.inventory_type;
for(uint8 i = 0; i <= 1; i++)
{
uint32 enchant_id = iter->update_fields[item_base + 1 + i];
if(sDBC->get_spell_item_ench_map()->find(enchant_id)
!=
sDBC->get_spell_item_ench_map()->end())
{
spell = &sDBC->get_spell_item_ench_map()->find(enchant_id)->second;
}
}
*pkt << (uint32)(spell? spell->aura_id :0);
}
else
{
*pkt << (uint32)0;
*pkt << (uint8)0;
*pkt << (uint32)0;
}
}
*pkt << (uint32)0;
*pkt << (uint8)0;
*pkt << (uint32)0;
}
this->send(pkt);
}
};
};