| |
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 #include "debug.h" |
| |
24 #include "internal.h" |
| |
25 #include "server.h" |
| |
26 |
| |
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" |
| |
34 #include "login_logout.h" |
| |
35 #include "packet_parse.h" |
| |
36 #include "qq.h" |
| |
37 #include "qq_proxy.h" |
| |
38 #include "send_core.h" |
| |
39 #include "utils.h" |
| |
40 |
| |
41 #define QQ_LOGIN_DATA_LENGTH 416 |
| |
42 #define QQ_LOGIN_REPLY_OK_PACKET_LEN 139 |
| |
43 #define QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN 11 |
| |
44 |
| |
45 #define QQ_REQUEST_LOGIN_TOKEN_REPLY_OK 0x00 |
| |
46 |
| |
47 #define QQ_LOGIN_REPLY_OK 0x00 |
| |
48 #define QQ_LOGIN_REPLY_REDIRECT 0x01 |
| |
49 #define QQ_LOGIN_REPLY_PWD_ERROR 0x05 |
| |
50 #define QQ_LOGIN_REPLY_MISC_ERROR 0xff /* defined by myself */ |
| |
51 |
| |
52 /* for QQ 2003iii 0117, fixed value */ |
| |
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 |
| |
60 /* for QQ 2003iii 0304, fixed value */ |
| |
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 |
| |
70 /* for QQ 2005? copy from lumaqq */ |
| |
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 |
| |
97 /* fixed value, not affected by version, or mac address */ |
| |
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; |
| |
113 guint8 client_ip[4]; /* those detected by server */ |
| |
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; |
| |
123 guint16 unknown2; /* 0x0001 */ |
| |
124 guint16 unknown3; /* 0x0000 */ |
| |
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 |
| |
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); |
| |
144 |
| |
145 /* It is fixed to 16 bytes 0x01 for QQ2003, |
| |
146 * Any value works (or a random 16 bytes string) */ |
| |
147 static guint8 *_gen_login_key(void) |
| |
148 { |
| |
149 return (guint8 *) g_strnfill(QQ_KEY_LENGTH, 0x01); |
| |
150 } |
| |
151 |
| |
152 /* process login reply which says OK */ |
| |
153 static gint _qq_process_login_ok(GaimConnection *gc, guint8 *data, gint len) |
| |
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 |
| |
166 /* 000-000: reply code */ |
| |
167 bytes += read_packet_b(data, &cursor, len, &lrop.result); |
| |
168 /* 001-016: session key */ |
| |
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"); |
| |
173 /* 017-020: login uid */ |
| |
174 bytes += read_packet_dw(data, &cursor, len, &lrop.uid); |
| |
175 /* 021-024: server detected user public IP */ |
| |
176 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.client_ip, 4); |
| |
177 /* 025-026: server detected user port */ |
| |
178 bytes += read_packet_w(data, &cursor, len, &lrop.client_port); |
| |
179 /* 027-030: server detected itself ip 127.0.0.1 ? */ |
| |
180 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.server_ip, 4); |
| |
181 /* 031-032: server listening port */ |
| |
182 bytes += read_packet_w(data, &cursor, len, &lrop.server_port); |
| |
183 /* 033-036: login time for current session */ |
| |
184 bytes += read_packet_dw(data, &cursor, len, (guint32 *) & lrop.login_time); |
| |
185 /* 037-062: 26 bytes, unknown */ |
| |
186 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown1, 26); |
| |
187 /* 063-066: unknown server1 ip address */ |
| |
188 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown_server1_ip, 4); |
| |
189 /* 067-068: unknown server1 port */ |
| |
190 bytes += read_packet_w(data, &cursor, len, &lrop.unknown_server1_port); |
| |
191 /* 069-072: unknown server2 ip address */ |
| |
192 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown_server2_ip, 4); |
| |
193 /* 073-074: unknown server2 port */ |
| |
194 bytes += read_packet_w(data, &cursor, len, &lrop.unknown_server2_port); |
| |
195 /* 075-076: 2 bytes unknown */ |
| |
196 bytes += read_packet_w(data, &cursor, len, &lrop.unknown2); |
| |
197 /* 077-078: 2 bytes unknown */ |
| |
198 bytes += read_packet_w(data, &cursor, len, &lrop.unknown3); |
| |
199 /* 079-110: 32 bytes unknown */ |
| |
200 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown4, 32); |
| |
201 /* 111-122: 12 bytes unknown */ |
| |
202 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown5, 12); |
| |
203 /* 123-126: login IP of last session */ |
| |
204 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.last_client_ip, 4); |
| |
205 /* 127-130: login time of last session */ |
| |
206 bytes += read_packet_dw(data, &cursor, len, (guint32 *) & lrop.last_login_time); |
| |
207 /* 131-138: 8 bytes unknown */ |
| |
208 bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown6, 8); |
| |
209 |
| |
210 if (bytes != QQ_LOGIN_REPLY_OK_PACKET_LEN) { /* fail parsing login info */ |
| |
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); |
| |
214 } /* but we still go on as login OK */ |
| |
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); |
| |
226 qd->logged_in = TRUE; /* must be defined after sev_finish_login */ |
| |
227 |
| |
228 /* now initiate QQ Qun, do it first as it may take longer to finish */ |
| |
229 qq_group_init(gc); |
| |
230 |
| |
231 /* Now goes on updating my icon/nickname, not showing info_window */ |
| |
232 qq_send_packet_get_info(gc, qd->uid, FALSE); |
| |
233 /* change my status manually, even server may broadcast my online */ |
| |
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); |
| |
236 /* now refresh buddy list */ |
| |
237 |
| |
238 /* changed by gfhuang, using With Qun version, error, not working still */ |
| |
239 qq_send_packet_get_buddies_list(gc, QQ_FRIENDS_LIST_POSITION_START); |
| |
240 /* qq_send_packet_get_all_list_with_group(gc, QQ_FRIENDS_LIST_POSITION_START); */ |
| |
241 |
| |
242 return QQ_LOGIN_REPLY_OK; |
| |
243 } |
| |
244 |
| |
245 /* process login reply packet which includes redirected new server address */ |
| |
246 static gint _qq_process_login_redirect(GaimConnection *gc, guint8 *data, gint len) |
| |
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; |
| |
259 /* 000-000: reply code */ |
| |
260 bytes += read_packet_b(data, &cursor, len, &lrrp.result); |
| |
261 /* 001-004: login uid */ |
| |
262 bytes += read_packet_dw(data, &cursor, len, &lrrp.uid); |
| |
263 /* 005-008: redirected new server IP */ |
| |
264 bytes += read_packet_data(data, &cursor, len, lrrp.new_server_ip, 4); |
| |
265 /* 009-010: redirected new server port */ |
| |
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; |
| |
273 } else { /* start new connection */ |
| |
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; |
| |
280 } |
| |
281 |
| |
282 return ret; |
| |
283 } |
| |
284 |
| |
285 /* process login reply which says wrong password */ |
| |
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; |
| |
297 } |
| |
298 |
| |
299 /* request before login */ |
| |
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 |
| |
319 if (bytes == (cursor - buf)) /* packet creation OK */ |
| |
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 |
| |
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. */ |
| |
328 |
| |
329 /* send login packet to QQ server */ |
| |
330 static void qq_send_packet_login(GaimConnection *gc, guint8 token_length, guint8 *token) |
| |
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); |
| |
343 encrypted_data = g_newa(guint8, QQ_LOGIN_DATA_LENGTH + 16); /* 16 bytes more */ |
| |
344 qd->inikey = _gen_login_key(); |
| |
345 |
| |
346 /* now generate the encrypted data |
| |
347 * 000-015 use pwkey as key to encrypt empty string */ |
| |
348 qq_crypt(ENCRYPT, (guint8 *) "", 0, qd->pwkey, raw_data, &encrypted_len); |
| |
349 /* 016-016 */ |
| |
350 raw_data[16] = 0x00; |
| |
351 /* 017-020, used to be IP, now zero */ |
| |
352 *((guint32 *) (raw_data + 17)) = 0x00000000; |
| |
353 /* 021-022, used to be port, now zero */ |
| |
354 *((guint16 *) (raw_data + 21)) = 0x0000; |
| |
355 /* 023-051, fixed value, unknown */ |
| |
356 g_memmove(raw_data + 23, login_23_51, 29); |
| |
357 /* 052-052, login mode */ |
| |
358 raw_data[52] = qd->login_mode; |
| |
359 /* 053-068, fixed value, maybe related to per machine */ |
| |
360 g_memmove(raw_data + 53, login_53_68, 16); |
| |
361 |
| |
362 /* 069, login token length */ |
| |
363 raw_data[69] = token_length; |
| |
364 pos = 70; |
| |
365 /* 070-093, login token, normally 24 bytes */ |
| |
366 g_memmove(raw_data + pos, token, token_length); |
| |
367 pos += token_length; |
| |
368 /* 100 bytes unknown */ |
| |
369 g_memmove(raw_data + pos, login_100_bytes, 100); |
| |
370 pos += 100; |
| |
371 /* all zero left */ |
| |
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 |
| |
384 if (bytes == (cursor - buf)) /* packet creation OK */ |
| |
385 _qq_send_packet(gc, buf, bytes, QQ_CMD_LOGIN); |
| |
386 else |
| |
387 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail create login packet\n"); |
| |
388 } |
| |
389 |
| |
390 void qq_process_request_login_token_reply(guint8 *buf, gint buf_len, GaimConnection *gc) |
| |
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) { |
| |
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 } |
| |
406 gaim_debug(GAIM_DEBUG_INFO, "QQ", |
| |
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); |
| |
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 |
| |
419 /* send logout packets to QQ server */ |
| |
420 void qq_send_packet_logout(GaimConnection *gc) |
| |
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 |
| |
431 qd->logged_in = FALSE; /* update login status AFTER sending logout packets */ |
| |
432 } |
| |
433 |
| |
434 /* process the login reply packet */ |
| |
435 void qq_process_login_reply(guint8 *buf, gint buf_len, GaimConnection *gc) |
| |
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; |
| |
446 data = g_newa(guint8, len); |
| |
447 |
| |
448 if (qq_crypt(DECRYPT, buf, buf_len, qd->pwkey, data, &len)) { |
| |
449 /* should be able to decrypt with pwkey */ |
| |
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; |
| |
456 } |
| |
457 } else { /* decrypt with pwkey error */ |
| |
458 len = buf_len; /* reset len, decrypt will fail if len is too short */ |
| |
459 if (qq_crypt(DECRYPT, buf, buf_len, qd->inikey, data, &len)) { |
| |
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); |
| |
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; |
| |
479 } |
| |
480 } else { /* no idea how to decrypt */ |
| |
481 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "No idea how to decrypt login reply\n"); |
| |
482 ret = QQ_LOGIN_REPLY_MISC_ERROR; |
| |
483 } |
| |
484 } |
| |
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: |
| |
498 /* the redirect has been done in _qq_process_login_reply */ |
| |
499 break; |
| |
500 default:{; |
| |
501 } |
| |
502 } |
| |
503 } |