13870
|
1 /**
|
|
2 * The QQ2003C protocol plugin
|
|
3 *
|
|
4 * for gaim
|
|
5 *
|
|
6 * Copyright (C) 2004 Puzzlebird
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22
|
14021
|
23 #include "debug.h"
|
|
24 #include "internal.h"
|
|
25 #include "server.h"
|
13870
|
26
|
14021
|
27 #include "buddy_info.h"
|
|
28 #include "buddy_list.h"
|
|
29 #include "buddy_status.h"
|
|
30 #include "char_conv.h"
|
|
31 #include "crypt.h"
|
|
32 #include "group.h"
|
|
33 #include "header_info.h"
|
13870
|
34 #include "login_logout.h"
|
14021
|
35 #include "packet_parse.h"
|
|
36 #include "qq.h"
|
|
37 #include "qq_proxy.h"
|
|
38 #include "send_core.h"
|
|
39 #include "utils.h"
|
13870
|
40
|
14013
|
41 #define QQ_LOGIN_DATA_LENGTH 416
|
13870
|
42 #define QQ_LOGIN_REPLY_OK_PACKET_LEN 139
|
|
43 #define QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN 11
|
|
44
|
14013
|
45 #define QQ_REQUEST_LOGIN_TOKEN_REPLY_OK 0x00
|
13870
|
46
|
|
47 #define QQ_LOGIN_REPLY_OK 0x00
|
|
48 #define QQ_LOGIN_REPLY_REDIRECT 0x01
|
|
49 #define QQ_LOGIN_REPLY_PWD_ERROR 0x05
|
14021
|
50 #define QQ_LOGIN_REPLY_MISC_ERROR 0xff /* defined by myself */
|
13870
|
51
|
14021
|
52 /* for QQ 2003iii 0117, fixed value */
|
13870
|
53 /* static const guint8 login_23_51[29] = {
|
|
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
55 0x00, 0x00, 0x00, 0x00, 0xbf, 0x14, 0x11, 0x20,
|
|
56 0x03, 0x9d, 0xb2, 0xe6, 0xb3, 0x11, 0xb7, 0x13,
|
|
57 0x95, 0x67, 0xda, 0x2c, 0x01
|
|
58 }; */
|
|
59
|
14021
|
60 /* for QQ 2003iii 0304, fixed value */
|
13870
|
61 /*
|
|
62 static const guint8 login_23_51[29] = {
|
|
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
64 0x00, 0x00, 0x00, 0x00, 0x9a, 0x93, 0xfe, 0x85,
|
|
65 0xd3, 0xd9, 0x2a, 0x41, 0xc8, 0x0d, 0xff, 0xb6,
|
|
66 0x40, 0xb8, 0xac, 0x32, 0x01
|
|
67 };
|
|
68 */
|
|
69
|
14021
|
70 /* for QQ 2005? copy from lumaqq */
|
13870
|
71 static const gint8 login_23_51[29] = {
|
|
72 0, 0, 0,
|
|
73 0, 0, 0, 0, 0, 0, 0, 0, 0, -122,
|
|
74 -52, 76, 53, 44, -45, 115, 108, 20, -10, -10,
|
|
75 -81, -61, -6, 51, -92, 1
|
|
76 };
|
|
77
|
|
78 static const gint8 login_53_68[16] = {
|
|
79 -115, -117, -6, -20, -43, 82, 23, 74, -122, -7,
|
|
80 -89, 117, -26, 50, -47, 109
|
|
81 };
|
|
82
|
|
83 static const gint8 login_100_bytes[100] = {
|
|
84 64,
|
|
85 11, 4, 2, 0, 1, 0, 0, 0, 0, 0,
|
|
86 3, 9, 0, 0, 0, 0, 0, 0, 0, 1,
|
|
87 -23, 3, 1, 0, 0, 0, 0, 0, 1, -13,
|
|
88 3, 0, 0, 0, 0, 0, 0, 1, -19, 3,
|
|
89 0, 0, 0, 0, 0, 0, 1, -20, 3, 0,
|
|
90 0, 0, 0, 0, 0, 3, 5, 0, 0, 0,
|
|
91 0, 0, 0, 0, 3, 7, 0, 0, 0, 0,
|
|
92 0, 0, 0, 1, -18, 3, 0, 0, 0, 0,
|
|
93 0, 0, 1, -17, 3, 0, 0, 0, 0, 0,
|
|
94 0, 1, -21, 3, 0, 0, 0, 0, 0
|
|
95 };
|
|
96
|
14021
|
97 /* fixed value, not affected by version, or mac address */
|
13870
|
98 /*
|
|
99 static const guint8 login_53_68[16] = {
|
|
100 0x82, 0x2a, 0x91, 0xfd, 0xa5, 0xca, 0x67, 0x4c,
|
|
101 0xac, 0x81, 0x1f, 0x6f, 0x52, 0x05, 0xa7, 0xbf
|
|
102 };
|
|
103 */
|
|
104
|
|
105
|
|
106 typedef struct _qq_login_reply_ok qq_login_reply_ok_packet;
|
|
107 typedef struct _qq_login_reply_redirect qq_login_reply_redirect_packet;
|
|
108
|
|
109 struct _qq_login_reply_ok {
|
|
110 guint8 result;
|
|
111 guint8 *session_key;
|
|
112 guint32 uid;
|
14021
|
113 guint8 client_ip[4]; /* those detected by server */
|
13870
|
114 guint16 client_port;
|
|
115 guint8 server_ip[4];
|
|
116 guint16 server_port;
|
|
117 time_t login_time;
|
|
118 guint8 unknown1[26];
|
|
119 guint8 unknown_server1_ip[4];
|
|
120 guint16 unknown_server1_port;
|
|
121 guint8 unknown_server2_ip[4];
|
|
122 guint16 unknown_server2_port;
|
14021
|
123 guint16 unknown2; /* 0x0001 */
|
|
124 guint16 unknown3; /* 0x0000 */
|
13870
|
125 guint8 unknown4[32];
|
|
126 guint8 unknown5[12];
|
|
127 guint8 last_client_ip[4];
|
|
128 time_t last_login_time;
|
|
129 guint8 unknown6[8];
|
|
130 };
|
|
131
|
|
132 struct _qq_login_reply_redirect {
|
|
133 guint8 result;
|
|
134 guint32 uid;
|
|
135 guint8 new_server_ip[4];
|
|
136 guint16 new_server_port;
|
|
137 };
|
|
138
|
14021
|
139 extern gint /* defined in send_core.c */
|
|
140 _create_packet_head_seq(guint8 *buf,
|
|
141 guint8 **cursor, GaimConnection *gc, guint16 cmd, gboolean is_auto_seq, guint16 *seq);
|
|
142 extern gint /* defined in send_core.c */
|
|
143 _qq_send_packet(GaimConnection *gc, guint8 *buf, gint len, guint16 cmd);
|
13870
|
144
|
14021
|
145 /* It is fixed to 16 bytes 0x01 for QQ2003,
|
|
146 * Any value works (or a random 16 bytes string) */
|
14013
|
147 static guint8 *_gen_login_key(void)
|
13870
|
148 {
|
14013
|
149 return (guint8 *) g_strnfill(QQ_KEY_LENGTH, 0x01);
|
|
150 }
|
13870
|
151
|
14021
|
152 /* process login reply which says OK */
|
|
153 static gint _qq_process_login_ok(GaimConnection *gc, guint8 *data, gint len)
|
13870
|
154 {
|
|
155 gint bytes;
|
|
156 guint8 *cursor;
|
|
157 qq_data *qd;
|
|
158 qq_login_reply_ok_packet lrop;
|
|
159
|
|
160 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, QQ_LOGIN_REPLY_MISC_ERROR);
|
|
161
|
|
162 qd = (qq_data *) gc->proto_data;
|
|
163 cursor = data;
|
|
164 bytes = 0;
|
|
165
|
14021
|
166 /* 000-000: reply code */
|
13870
|
167 bytes += read_packet_b(data, &cursor, len, &lrop.result);
|
14021
|
168 /* 001-016: session key */
|
13870
|
169 lrop.session_key = g_memdup(cursor, QQ_KEY_LENGTH);
|
|
170 cursor += QQ_KEY_LENGTH;
|
|
171 bytes += QQ_KEY_LENGTH;
|
|
172 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Get session_key done\n");
|
14021
|
173 /* 017-020: login uid */
|
13870
|
174 bytes += read_packet_dw(data, &cursor, len, &lrop.uid);
|
14021
|
175 /* 021-024: server detected user public IP */
|
13870
|
176 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.client_ip, 4);
|
14021
|
177 /* 025-026: server detected user port */
|
13870
|
178 bytes += read_packet_w(data, &cursor, len, &lrop.client_port);
|
14021
|
179 /* 027-030: server detected itself ip 127.0.0.1 ? */
|
13870
|
180 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.server_ip, 4);
|
14021
|
181 /* 031-032: server listening port */
|
13870
|
182 bytes += read_packet_w(data, &cursor, len, &lrop.server_port);
|
14021
|
183 /* 033-036: login time for current session */
|
13870
|
184 bytes += read_packet_dw(data, &cursor, len, (guint32 *) & lrop.login_time);
|
14021
|
185 /* 037-062: 26 bytes, unknown */
|
13870
|
186 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown1, 26);
|
14021
|
187 /* 063-066: unknown server1 ip address */
|
13870
|
188 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown_server1_ip, 4);
|
14021
|
189 /* 067-068: unknown server1 port */
|
13870
|
190 bytes += read_packet_w(data, &cursor, len, &lrop.unknown_server1_port);
|
14021
|
191 /* 069-072: unknown server2 ip address */
|
13870
|
192 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown_server2_ip, 4);
|
14021
|
193 /* 073-074: unknown server2 port */
|
13870
|
194 bytes += read_packet_w(data, &cursor, len, &lrop.unknown_server2_port);
|
14021
|
195 /* 075-076: 2 bytes unknown */
|
13870
|
196 bytes += read_packet_w(data, &cursor, len, &lrop.unknown2);
|
14021
|
197 /* 077-078: 2 bytes unknown */
|
13870
|
198 bytes += read_packet_w(data, &cursor, len, &lrop.unknown3);
|
14021
|
199 /* 079-110: 32 bytes unknown */
|
13870
|
200 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown4, 32);
|
14021
|
201 /* 111-122: 12 bytes unknown */
|
13870
|
202 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown5, 12);
|
14021
|
203 /* 123-126: login IP of last session */
|
13870
|
204 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.last_client_ip, 4);
|
14021
|
205 /* 127-130: login time of last session */
|
13870
|
206 bytes += read_packet_dw(data, &cursor, len, (guint32 *) & lrop.last_login_time);
|
14021
|
207 /* 131-138: 8 bytes unknown */
|
13870
|
208 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown6, 8);
|
|
209
|
14021
|
210 if (bytes != QQ_LOGIN_REPLY_OK_PACKET_LEN) { /* fail parsing login info */
|
13870
|
211 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
212 "Fail parsing login info, expect %d bytes, read %d bytes\n",
|
|
213 QQ_LOGIN_REPLY_OK_PACKET_LEN, bytes);
|
14021
|
214 } /* but we still go on as login OK */
|
13870
|
215
|
|
216 qd->session_key = g_memdup(lrop.session_key, QQ_KEY_LENGTH);
|
|
217 qd->my_ip = gen_ip_str(lrop.client_ip);
|
|
218 qd->my_port = lrop.client_port;
|
|
219 qd->login_time = lrop.login_time;
|
|
220 qd->last_login_time = lrop.last_login_time;
|
|
221 qd->last_login_ip = gen_ip_str(lrop.last_client_ip);
|
|
222
|
|
223 g_free(lrop.session_key);
|
|
224
|
|
225 gaim_connection_set_state(gc, GAIM_CONNECTED);
|
14021
|
226 qd->logged_in = TRUE; /* must be defined after sev_finish_login */
|
13870
|
227
|
14021
|
228 /* now initiate QQ Qun, do it first as it may take longer to finish */
|
13870
|
229 qq_group_init(gc);
|
|
230
|
14021
|
231 /* Now goes on updating my icon/nickname, not showing info_window */
|
13870
|
232 qq_send_packet_get_info(gc, qd->uid, FALSE);
|
14021
|
233 /* change my status manually, even server may broadcast my online */
|
13870
|
234 qd->status = (qd->login_mode == QQ_LOGIN_MODE_HIDDEN) ? QQ_SELF_STATUS_INVISIBLE : QQ_SELF_STATUS_AVAILABLE;
|
|
235 qq_send_packet_change_status(gc);
|
14021
|
236 /* now refresh buddy list */
|
13870
|
237
|
14021
|
238 /* changed by gfhuang, using With Qun version, error, not working still */
|
13870
|
239 qq_send_packet_get_buddies_list(gc, QQ_FRIENDS_LIST_POSITION_START);
|
14021
|
240 /* qq_send_packet_get_all_list_with_group(gc, QQ_FRIENDS_LIST_POSITION_START); */
|
13870
|
241
|
|
242 return QQ_LOGIN_REPLY_OK;
|
14013
|
243 }
|
13870
|
244
|
14021
|
245 /* process login reply packet which includes redirected new server address */
|
|
246 static gint _qq_process_login_redirect(GaimConnection *gc, guint8 *data, gint len)
|
13870
|
247 {
|
|
248 gint bytes, ret;
|
|
249 guint8 *cursor;
|
|
250 gchar *new_server_str;
|
|
251 qq_data *qd;
|
|
252 qq_login_reply_redirect_packet lrrp;
|
|
253
|
|
254 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, QQ_LOGIN_REPLY_MISC_ERROR);
|
|
255
|
|
256 qd = (qq_data *) gc->proto_data;
|
|
257 cursor = data;
|
|
258 bytes = 0;
|
14021
|
259 /* 000-000: reply code */
|
13870
|
260 bytes += read_packet_b(data, &cursor, len, &lrrp.result);
|
14021
|
261 /* 001-004: login uid */
|
13870
|
262 bytes += read_packet_dw(data, &cursor, len, &lrrp.uid);
|
14021
|
263 /* 005-008: redirected new server IP */
|
13870
|
264 bytes += read_packet_data(data, &cursor, len, lrrp.new_server_ip, 4);
|
14021
|
265 /* 009-010: redirected new server port */
|
13870
|
266 bytes += read_packet_w(data, &cursor, len, &lrrp.new_server_port);
|
|
267
|
|
268 if (bytes != QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN) {
|
|
269 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
270 "Fail parsing login redirect packet, expect %d bytes, read %d bytes\n",
|
|
271 QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN, bytes);
|
|
272 ret = QQ_LOGIN_REPLY_MISC_ERROR;
|
14021
|
273 } else { /* start new connection */
|
13870
|
274 new_server_str = gen_ip_str(lrrp.new_server_ip);
|
|
275 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
276 "Redirected to new server: %s:%d\n", new_server_str, lrrp.new_server_port);
|
|
277 qq_connect(gc->account, new_server_str, lrrp.new_server_port, qd->use_tcp, TRUE);
|
|
278 g_free(new_server_str);
|
|
279 ret = QQ_LOGIN_REPLY_REDIRECT;
|
14013
|
280 }
|
13870
|
281
|
|
282 return ret;
|
14013
|
283 }
|
13870
|
284
|
14021
|
285 /* process login reply which says wrong password */
|
13870
|
286 static gint _qq_process_login_wrong_pwd(GaimConnection * gc, guint8 * data, gint len)
|
|
287 {
|
|
288 gchar *server_reply, *server_reply_utf8;
|
|
289 server_reply = g_new0(gchar, len);
|
|
290 g_memmove(server_reply, data + 1, len - 1);
|
|
291 server_reply_utf8 = qq_to_utf8(server_reply, QQ_CHARSET_DEFAULT);
|
|
292 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Wrong password, server msg in UTF8: %s\n", server_reply_utf8);
|
|
293 g_free(server_reply);
|
|
294 g_free(server_reply_utf8);
|
|
295
|
|
296 return QQ_LOGIN_REPLY_PWD_ERROR;
|
14013
|
297 }
|
13870
|
298
|
14021
|
299 /* request before login */
|
13870
|
300 void qq_send_packet_request_login_token(GaimConnection *gc)
|
|
301 {
|
|
302 qq_data *qd;
|
|
303 guint8 *buf, *cursor;
|
|
304 guint16 seq_ret;
|
|
305 gint bytes;
|
|
306
|
|
307 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
308
|
|
309 qd = (qq_data *) gc->proto_data;
|
|
310 buf = g_newa(guint8, MAX_PACKET_SIZE);
|
|
311
|
|
312 cursor = buf;
|
|
313 bytes = 0;
|
|
314 bytes += _create_packet_head_seq(buf, &cursor, gc, QQ_CMD_REQUEST_LOGIN_TOKEN, TRUE, &seq_ret);
|
|
315 bytes += create_packet_dw(buf, &cursor, qd->uid);
|
|
316 bytes += create_packet_b(buf, &cursor, 0);
|
|
317 bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAIL);
|
|
318
|
14021
|
319 if (bytes == (cursor - buf)) /* packet creation OK */
|
13870
|
320 _qq_send_packet(gc, buf, bytes, QQ_CMD_REQUEST_LOGIN_TOKEN);
|
|
321 else
|
|
322 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail create request login token packet\n");
|
|
323 }
|
|
324
|
14021
|
325 /* TODO: The login packet and its response have changed by QQ2006 Beta2. In that version,
|
|
326 * the login OK response packet does not appear to be decryptable with qd->pwkey or qd->inikey.
|
|
327 * Fortunately, this older system still works. */
|
14013
|
328
|
14021
|
329 /* send login packet to QQ server */
|
|
330 static void qq_send_packet_login(GaimConnection *gc, guint8 token_length, guint8 *token)
|
13870
|
331 {
|
|
332 qq_data *qd;
|
|
333 guint8 *buf, *cursor, *raw_data, *encrypted_data;
|
|
334 guint16 seq_ret;
|
|
335 gint encrypted_len, bytes;
|
|
336 gint pos;
|
|
337
|
|
338 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
339
|
|
340 qd = (qq_data *) gc->proto_data;
|
|
341 buf = g_newa(guint8, MAX_PACKET_SIZE);
|
|
342 raw_data = g_newa(guint8, QQ_LOGIN_DATA_LENGTH);
|
14021
|
343 encrypted_data = g_newa(guint8, QQ_LOGIN_DATA_LENGTH + 16); /* 16 bytes more */
|
13870
|
344 qd->inikey = _gen_login_key();
|
|
345
|
14021
|
346 /* now generate the encrypted data
|
|
347 * 000-015 use pwkey as key to encrypt empty string */
|
14013
|
348 qq_crypt(ENCRYPT, (guint8 *) "", 0, qd->pwkey, raw_data, &encrypted_len);
|
14021
|
349 /* 016-016 */
|
13870
|
350 raw_data[16] = 0x00;
|
14021
|
351 /* 017-020, used to be IP, now zero */
|
13870
|
352 *((guint32 *) (raw_data + 17)) = 0x00000000;
|
14021
|
353 /* 021-022, used to be port, now zero */
|
13870
|
354 *((guint16 *) (raw_data + 21)) = 0x0000;
|
14021
|
355 /* 023-051, fixed value, unknown */
|
13870
|
356 g_memmove(raw_data + 23, login_23_51, 29);
|
14021
|
357 /* 052-052, login mode */
|
13870
|
358 raw_data[52] = qd->login_mode;
|
14021
|
359 /* 053-068, fixed value, maybe related to per machine */
|
13870
|
360 g_memmove(raw_data + 53, login_53_68, 16);
|
|
361
|
14021
|
362 /* 069, login token length */
|
13870
|
363 raw_data[69] = token_length;
|
|
364 pos = 70;
|
14021
|
365 /* 070-093, login token, normally 24 bytes */
|
13870
|
366 g_memmove(raw_data + pos, token, token_length);
|
|
367 pos += token_length;
|
14021
|
368 /* 100 bytes unknown */
|
13870
|
369 g_memmove(raw_data + pos, login_100_bytes, 100);
|
|
370 pos += 100;
|
14021
|
371 /* all zero left */
|
13870
|
372 memset(raw_data+pos, 0, QQ_LOGIN_DATA_LENGTH - pos);
|
|
373
|
|
374 qq_crypt(ENCRYPT, raw_data, QQ_LOGIN_DATA_LENGTH, qd->inikey, encrypted_data, &encrypted_len);
|
|
375
|
|
376 cursor = buf;
|
|
377 bytes = 0;
|
|
378 bytes += _create_packet_head_seq(buf, &cursor, gc, QQ_CMD_LOGIN, TRUE, &seq_ret);
|
|
379 bytes += create_packet_dw(buf, &cursor, qd->uid);
|
|
380 bytes += create_packet_data(buf, &cursor, qd->inikey, QQ_KEY_LENGTH);
|
|
381 bytes += create_packet_data(buf, &cursor, encrypted_data, encrypted_len);
|
|
382 bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAIL);
|
|
383
|
14021
|
384 if (bytes == (cursor - buf)) /* packet creation OK */
|
13870
|
385 _qq_send_packet(gc, buf, bytes, QQ_CMD_LOGIN);
|
|
386 else
|
|
387 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail create login packet\n");
|
14013
|
388 }
|
13870
|
389
|
14021
|
390 void qq_process_request_login_token_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
|
13870
|
391 {
|
|
392 qq_data *qd;
|
|
393
|
|
394 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
395 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
396
|
|
397 qd = (qq_data *) gc->proto_data;
|
|
398
|
|
399 if (buf[0] == QQ_REQUEST_LOGIN_TOKEN_REPLY_OK) {
|
14013
|
400 if (buf[1] != buf_len-2) {
|
|
401 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
402 "Malformed login token reply packet. Packet specifies length of %d, actual length is %d\n", buf[1], buf_len-2);
|
|
403 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
|
404 "Attempting to proceed with the actual packet length.\n");
|
|
405 }
|
13870
|
406 gaim_debug(GAIM_DEBUG_INFO, "QQ",
|
14013
|
407 "<<< got a token with %d bytes -> [default] decrypt and dump\n%s",buf_len-2, hex_dump_to_str(buf+2, buf_len-2));
|
|
408 qq_send_packet_login(gc, buf_len-2, buf+2);
|
13870
|
409 } else {
|
|
410 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown request login token reply code : %d\n", buf[0]);
|
|
411 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
412 ">>> %d bytes -> [default] decrypt and dump\n%s",
|
|
413 buf_len, hex_dump_to_str(buf, buf_len));
|
|
414 try_dump_as_gbk(buf, buf_len);
|
|
415 gaim_connection_error(gc, _("Request login token error!"));
|
|
416 }
|
|
417 }
|
|
418
|
14021
|
419 /* send logout packets to QQ server */
|
|
420 void qq_send_packet_logout(GaimConnection *gc)
|
13870
|
421 {
|
|
422 gint i;
|
|
423 qq_data *qd;
|
|
424
|
|
425 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
426
|
|
427 qd = (qq_data *) gc->proto_data;
|
|
428 for (i = 0; i < 4; i++)
|
|
429 qq_send_cmd(gc, QQ_CMD_LOGOUT, FALSE, 0xffff, FALSE, qd->pwkey, QQ_KEY_LENGTH);
|
|
430
|
14021
|
431 qd->logged_in = FALSE; /* update login status AFTER sending logout packets */
|
|
432 }
|
13870
|
433
|
14021
|
434 /* process the login reply packet */
|
|
435 void qq_process_login_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
|
13870
|
436 {
|
|
437 gint len, ret, bytes;
|
|
438 guint8 *data;
|
|
439 qq_data *qd;
|
|
440
|
|
441 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
442 g_return_if_fail(buf != NULL && buf_len != 0);
|
|
443
|
|
444 qd = (qq_data *) gc->proto_data;
|
|
445 len = buf_len;
|
14021
|
446 data = g_newa(guint8, len);
|
13870
|
447
|
|
448 if (qq_crypt(DECRYPT, buf, buf_len, qd->pwkey, data, &len)) {
|
14021
|
449 /* should be able to decrypt with pwkey */
|
13870
|
450 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Decrypt login reply packet with pwkey, %d bytes\n", len);
|
|
451 if (data[0] == QQ_LOGIN_REPLY_OK) {
|
|
452 ret = _qq_process_login_ok(gc, data, len);
|
|
453 } else {
|
|
454 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown login reply code : %d\n", data[0]);
|
|
455 ret = QQ_LOGIN_REPLY_MISC_ERROR;
|
14021
|
456 }
|
|
457 } else { /* decrypt with pwkey error */
|
|
458 len = buf_len; /* reset len, decrypt will fail if len is too short */
|
13870
|
459 if (qq_crypt(DECRYPT, buf, buf_len, qd->inikey, data, &len)) {
|
14021
|
460 /* decrypt ok with inipwd, it might be password error */
|
|
461 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
462 "Decrypt login reply packet with inikey, %d bytes\n", len);
|
13870
|
463 bytes = 0;
|
|
464 switch (data[0]) {
|
|
465 case QQ_LOGIN_REPLY_REDIRECT:
|
|
466 ret = _qq_process_login_redirect(gc, data, len);
|
|
467 break;
|
|
468 case QQ_LOGIN_REPLY_PWD_ERROR:
|
|
469 ret = _qq_process_login_wrong_pwd(gc, data, len);
|
|
470 break;
|
|
471 default:
|
|
472 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown reply code: %d\n", data[0]);
|
|
473 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
474 ">>> %d bytes -> [default] decrypt and dump\n%s",
|
|
475 buf_len, hex_dump_to_str(data, len));
|
|
476 try_dump_as_gbk(data, len);
|
|
477
|
|
478 ret = QQ_LOGIN_REPLY_MISC_ERROR;
|
14021
|
479 }
|
|
480 } else { /* no idea how to decrypt */
|
13870
|
481 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "No idea how to decrypt login reply\n");
|
|
482 ret = QQ_LOGIN_REPLY_MISC_ERROR;
|
14021
|
483 }
|
|
484 }
|
13870
|
485
|
|
486 switch (ret) {
|
|
487 case QQ_LOGIN_REPLY_PWD_ERROR:
|
|
488 gc->wants_to_die = TRUE;
|
|
489 gaim_connection_error(gc, _("Wrong password!"));
|
|
490 break;
|
|
491 case QQ_LOGIN_REPLY_MISC_ERROR:
|
|
492 gaim_connection_error(gc, _("Unable to login, check debug log"));
|
|
493 break;
|
|
494 case QQ_LOGIN_REPLY_OK:
|
|
495 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login replys OK, everything is fine\n");
|
|
496 break;
|
|
497 case QQ_LOGIN_REPLY_REDIRECT:
|
14021
|
498 /* the redirect has been done in _qq_process_login_reply */
|
13870
|
499 break;
|
|
500 default:{;
|
|
501 }
|
14013
|
502 }
|
|
503 }
|