Commit 0754212e authored by vysheng's avatar vysheng

Some fixes with download/upload in encrypted chats

parent cce98419
...@@ -1160,7 +1160,8 @@ int send_encr_file_on_answer (struct query *q UU) { ...@@ -1160,7 +1160,8 @@ int send_encr_file_on_answer (struct query *q UU) {
assert (fetch_int () == CODE_encrypted_file); assert (fetch_int () == CODE_encrypted_file);
M->media.encr_photo.id = fetch_long (); M->media.encr_photo.id = fetch_long ();
M->media.encr_photo.access_hash = fetch_long (); M->media.encr_photo.access_hash = fetch_long ();
M->media.encr_photo.size = fetch_int (); //M->media.encr_photo.size = fetch_int ();
fetch_int ();
M->media.encr_photo.dc_id = fetch_int (); M->media.encr_photo.dc_id = fetch_int ();
assert (fetch_int () == M->media.encr_photo.key_fingerprint); assert (fetch_int () == M->media.encr_photo.key_fingerprint);
print_message (M); print_message (M);
...@@ -1292,7 +1293,7 @@ void send_part (struct send_file *f) { ...@@ -1292,7 +1293,7 @@ void send_part (struct send_file *f) {
M->media.encr_photo.key = f->key; M->media.encr_photo.key = f->key;
M->media.encr_photo.iv = f->init_iv; M->media.encr_photo.iv = f->init_iv;
M->media.encr_photo.key_fingerprint = (*(int *)md5) ^ (*(int *)(md5 + 4)); M->media.encr_photo.key_fingerprint = (*(int *)md5) ^ (*(int *)(md5 + 4));
M->media.encr_photo.size = f->size;
M->flags = FLAG_ENCRYPTED; M->flags = FLAG_ENCRYPTED;
M->from_id = MK_USER (our_id); M->from_id = MK_USER (our_id);
...@@ -1640,6 +1641,9 @@ int download_on_answer (struct query *q) { ...@@ -1640,6 +1641,9 @@ int download_on_answer (struct query *q) {
AES_KEY aes_key; AES_KEY aes_key;
AES_set_decrypt_key (D->key, 256, &aes_key); AES_set_decrypt_key (D->key, 256, &aes_key);
AES_ige_encrypt (ptr, ptr, len, &aes_key, D->iv, 0); AES_ige_encrypt (ptr, ptr, len, &aes_key, D->iv, 0);
if (len > D->size - D->offset) {
len = D->size - D->offset;
}
assert (write (D->fd, ptr, len) == len); assert (write (D->fd, ptr, len) == len);
} else { } else {
assert (write (D->fd, fetch_str (len), len) == len); assert (write (D->fd, fetch_str (len), len) == len);
......
...@@ -893,8 +893,9 @@ void fetch_encrypted_message_file (struct message_media *M) { ...@@ -893,8 +893,9 @@ void fetch_encrypted_message_file (struct message_media *M) {
assert (M->type == CODE_decrypted_message_media_photo || M->type == CODE_decrypted_message_media_video); assert (M->type == CODE_decrypted_message_media_photo || M->type == CODE_decrypted_message_media_video);
M->encr_photo.id = fetch_long (); M->encr_photo.id = fetch_long ();
M->encr_photo.access_hash = fetch_long (); M->encr_photo.access_hash = fetch_long ();
fetch_int ();
//assert (M->encr_photo.size == fetch_int ()); //assert (M->encr_photo.size == fetch_int ());
M->encr_photo.size = fetch_int (); // Why it is not the same? //M->encr_photo.size = fetch_int (); // Why it is not the same?
M->encr_photo.dc_id = fetch_int (); M->encr_photo.dc_id = fetch_int ();
M->encr_photo.key_fingerprint = fetch_int (); M->encr_photo.key_fingerprint = fetch_int ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment