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