comparison libpurple/protocols/qq/file_trans.c @ 23695:5f454b975a99

2008.08.10 - csyfek <csyfek(at)gmail.com> * Commit to Pidgin 2008.08.06 - ccpaging <ecc_hy(at)hotmail.com> * Rename names of variables, Group, to Room * Functions of group_network merged into qq_network and qq_process * Canceled managing glist of group packet, add sub_cmdd and room_id to transaction * Fixed error of demo group: If 'room list' and 'room infor' are not setup, response received from server will emits 'room_id = 0' packet. 2008.08.04 - ccpaging <ecc_hy(at)hotmail.com> * Use new crypt/decrypt functions * Rename crypt.c/h to qq_crypt.c/h * Clean code of decrypt functions * Fixed decryption failure 2008.08.04 - csyfek <csyfek(at)gmail.com> * Update AUTHORS
author SHiNE CsyFeK <csyfek@gmail.com>
date Sun, 10 Aug 2008 04:32:14 +0000
parents 1c50f12b1c52
children 967344bc404d
comparison
equal deleted inserted replaced
23690:107166bb2a64 23695:5f454b975a99
30 30
31 #include "debug.h" 31 #include "debug.h"
32 #include "ft.h" 32 #include "ft.h"
33 #include "cipher.h" 33 #include "cipher.h"
34 34
35 #include "crypt.h" 35 #include "qq_crypt.h"
36 #include "file_trans.h" 36 #include "file_trans.h"
37 #include "header_info.h" 37 #include "header_info.h"
38 #include "im.h" 38 #include "im.h"
39 #include "packet_parse.h" 39 #include "packet_parse.h"
40 #include "proxy.h" 40 #include "proxy.h"
336 336
337 qq_hex_dump(PURPLE_DEBUG_INFO, "QQ", 337 qq_hex_dump(PURPLE_DEBUG_INFO, "QQ",
338 raw_data, bytes, 338 raw_data, bytes,
339 "sending packet[%s]:", qq_get_file_cmd_desc(packet_type)); 339 "sending packet[%s]:", qq_get_file_cmd_desc(packet_type));
340 340
341 encrypted_len = bytes + 16; 341 encrypted_data = g_newa(guint8, bytes + 16);
342 encrypted_data = g_newa(guint8, encrypted_len); 342 encrypted_len = qq_encrypt(encrypted_data, raw_data, bytes, info->file_session_key);
343 qq_encrypt(raw_data, bytes, info->file_session_key, encrypted_data, &encrypted_len);
344 /*debug: try to decrypt it */ 343 /*debug: try to decrypt it */
345 /* 344
346 if (QQ_DEBUG) { 345 #if 0
347 guint8 *buf; 346 guint8 *buf;
348 int buflen; 347 int buflen;
349 hex_dump = hex_dump_to_str(encrypted_data, encrypted_len); 348 hex_dump = hex_dump_to_str(encrypted_data, encrypted_len);
350 purple_debug(PURPLE_DEBUG_INFO, "QQ", "encrypted packet: \n%s", hex_dump); 349 purple_debug(PURPLE_DEBUG_INFO, "QQ", "encrypted packet: \n%s", hex_dump);
351 g_free(hex_dump); 350 g_free(hex_dump);
352 buf = g_newa(guint8, MAX_PACKET_SIZE); 351 buf = g_newa(guint8, MAX_PACKET_SIZE);
353 buflen = encrypted_len; 352 buflen = encrypted_len;
354 if (qq_crypt(DECRYPT, encrypted_data, encrypted_len, info->file_session_key, buf, &buflen)) { 353 if (qq_crypt(DECRYPT, encrypted_data, encrypted_len, info->file_session_key, buf, &buflen)) {
355 purple_debug(PURPLE_DEBUG_INFO, "QQ", "decrypt success\n"); 354 purple_debug(PURPLE_DEBUG_INFO, "QQ", "decrypt success\n");
356 if (buflen == bytes && memcmp(raw_data, buf, buflen) == 0) 355 if (buflen == bytes && memcmp(raw_data, buf, buflen) == 0)
357 purple_debug(PURPLE_DEBUG_INFO, "QQ", "checksum ok\n"); 356 purple_debug(PURPLE_DEBUG_INFO, "QQ", "checksum ok\n");
358 hex_dump = hex_dump_to_str(buf, buflen); 357
359 purple_debug(PURPLE_DEBUG_INFO, "QQ", "decrypted packet: \n%s", hex_dump); 358 hex_dump = hex_dump_to_str(buf, buflen);
360 g_free(hex_dump); 359 purple_debug(PURPLE_DEBUG_INFO, "QQ", "decrypted packet: \n%s", hex_dump);
361 } else { 360 g_free(hex_dump);
362 purple_debug(PURPLE_DEBUG_INFO, "QQ", "decrypt fail\n"); 361 } else {
363 } 362 purple_debug(PURPLE_DEBUG_INFO, "QQ", "decrypt fail\n");
364 } 363 }
365 */ 364 #endif
366 365
367 purple_debug(PURPLE_DEBUG_INFO, "QQ", "<== send %s packet\n", qq_get_file_cmd_desc(packet_type)); 366 purple_debug(PURPLE_DEBUG_INFO, "QQ", "<== send %s packet\n", qq_get_file_cmd_desc(packet_type));
368 _qq_send_file(gc, encrypted_data, encrypted_len, QQ_FILE_CONTROL_PACKET_TAG, info->to_uid); 367 _qq_send_file(gc, encrypted_data, encrypted_len, QQ_FILE_CONTROL_PACKET_TAG, info->to_uid);
369 } 368 }
370 369
496 * Sender ==> Receiver [QQ_FILE_CMD_FILE_OP, QQ_FILE_EOF] 495 * Sender ==> Receiver [QQ_FILE_CMD_FILE_OP, QQ_FILE_EOF]
497 * Sender <== Receiver [QQ_FILE_CMD_FILE_OP_ACK, QQ_FILE_EOF] 496 * Sender <== Receiver [QQ_FILE_CMD_FILE_OP_ACK, QQ_FILE_EOF]
498 */ 497 */
499 498
500 499
501 static void _qq_process_recv_file_ctl_packet(PurpleConnection *gc, guint8 *data, gint len) 500 static void _qq_process_recv_file_ctl_packet(PurpleConnection *gc, guint8 *data, gint data_len)
502 { 501 {
503 gint bytes ; 502 gint bytes ;
504 gint decryped_bytes; 503 gint decryped_bytes;
505 qq_file_header fh; 504 qq_file_header fh;
506 guint8 *decrypted_data; 505 guint8 *decrypted_data;
512 ft_info *info = (ft_info *) qd->xfer->data; 511 ft_info *info = (ft_info *) qd->xfer->data;
513 512
514 bytes = 0; 513 bytes = 0;
515 bytes += _qq_get_file_header(&fh, data + bytes); 514 bytes += _qq_get_file_header(&fh, data + bytes);
516 515
517 decrypted_data = g_newa(guint8, len); 516 decrypted_data = g_newa(guint8, data_len);
518 decrypted_len = len; 517 decrypted_len = qq_decrypt(decrypted_data, data, data_len, qd->session_md5);
519 518 if ( decrypted_len <= 0 ) {
520 if ( !qq_decrypt(data, len, qd->session_md5, decrypted_data, &decrypted_len) ) {
521 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt rcv file ctrl packet\n"); 519 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt rcv file ctrl packet\n");
522 return; 520 return;
523 } 521 }
524 522
525 /* only for debug info */ 523 /* only for debug info */