diff --git a/CHANGELOG b/CHANGELOG index c531adf..7726801 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +1.0.6 +* layer 18 support 1.0.5 * listening socket (tcp and unix) for commands 1.0.4 diff --git a/encrypted_scheme17.tl b/encrypted_scheme17.tl index 6418566..cc4a76d 100644 --- a/encrypted_scheme17.tl +++ b/encrypted_scheme17.tl @@ -1,10 +1,10 @@ ---types--- -decryptedMessageLayer#99a438cf layer:int message:DecryptedMessage = DecryptedMessageLayer; +decryptedMessageLayer#1be31789 layer:int message:DecryptedMessage = DecryptedMessageLayer; decryptedMessage_l16#1f814f1f random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage; decryptedMessageService_l16#aa48327d random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage; -decryptedMessage#20a6d4e2 in_seq_no:int out_seq_no:int ttl:int random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage; -decryptedMessageService#9bb84a4e in_seq_no:int out_seq_no:int random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage; +decryptedMessage#204d3878 in_seq_no:int out_seq_no:int ttl:int random_id:long random_bytes:bytes message:string media:DecryptedMessageMedia = DecryptedMessage; +decryptedMessageService#73164160 in_seq_no:int out_seq_no:int random_id:long random_bytes:bytes action:DecryptedMessageAction = DecryptedMessage; decryptedMessageMediaEmpty#89f5c4a = DecryptedMessageMedia; decryptedMessageMediaPhoto#32798a8c thumb:bytes thumb_w:int thumb_h:int w:int h:int size:int key:bytes iv:bytes = DecryptedMessageMedia; diff --git a/queries.c b/queries.c index dbc7d60..ebc10e1 100644 --- a/queries.c +++ b/queries.c @@ -896,14 +896,15 @@ void tgl_do_send_encr_msg_action (struct tgl_message *M, void (*callback)(void * out_int (CODE_decrypted_message_service_l16); } else { out_int (CODE_decrypted_message_layer); + out_random (15 + 4 * (lrand48 () % 3)); out_int (TGL_ENCRYPTED_LAYER); + out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id)); + out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id) - 2); out_int (CODE_decrypted_message_service); } out_long (M->id); - out_random (15 + 4 * (lrand48 () % 3)); - if (P->encr_chat.layer >= 17) { - out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id)); - out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id)); + if (P->encr_chat.layer < 17) { + out_random (15 + 4 * (lrand48 () % 3)); } switch (M->action.type) { @@ -945,17 +946,19 @@ void tgl_do_send_encr_msg (struct tgl_message *M, void (*callback)(void *callbac out_long (M->id); encr_start (); if (P->encr_chat.layer <= 16) { - out_int (CODE_decrypted_message_l16); + out_int (CODE_decrypted_message_service_l16); } else { out_int (CODE_decrypted_message_layer); + out_random (15 + 4 * (lrand48 () % 3)); out_int (TGL_ENCRYPTED_LAYER); + out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id)); + out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id) - 2); out_int (CODE_decrypted_message); } out_long (M->id); - out_random (15 + 4 * (lrand48 () % 3)); - if (P->encr_chat.layer >= 17) { - out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id)); - out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id)); + if (P->encr_chat.layer < 17) { + out_random (15 + 4 * (lrand48 () % 3)); + } else { out_int (0); } out_cstring ((void *)M->message, M->message_len); @@ -1692,17 +1695,19 @@ static void send_part (struct send_file *f, void *callback, void *callback_extra out_long (r); encr_start (); if (P->encr_chat.layer <= 16) { - out_int (CODE_decrypted_message_l16); + out_int (CODE_decrypted_message_service_l16); } else { out_int (CODE_decrypted_message_layer); + out_random (15 + 4 * (lrand48 () % 3)); out_int (TGL_ENCRYPTED_LAYER); + out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id)); + out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id)); out_int (CODE_decrypted_message); } out_long (r); - out_random (15 + 4 * (lrand48 () % 3)); - if (P->encr_chat.layer >= 17) { - out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id)); - out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id) + 2); + if (P->encr_chat.layer < 17) { + out_random (15 + 4 * (lrand48 () % 3)); + } else { out_int (0); } out_string (""); @@ -2146,17 +2151,19 @@ void tgl_do_send_location(tgl_peer_id_t id, double latitude, double longitude, v out_long (r); encr_start (); if (P->encr_chat.layer <= 16) { - out_int (CODE_decrypted_message_l16); + out_int (CODE_decrypted_message_service_l16); } else { out_int (CODE_decrypted_message_layer); + out_random (15 + 4 * (lrand48 () % 3)); out_int (TGL_ENCRYPTED_LAYER); + out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id)); + out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id)); out_int (CODE_decrypted_message); } out_long (r); - out_random (15 + 4 * (lrand48 () % 3)); - if (P->encr_chat.layer >= 17) { - out_int (2 * P->encr_chat.in_seq_no + (P->encr_chat.admin_id != tgl_state.our_id)); - out_int (2 * P->encr_chat.out_seq_no + (P->encr_chat.admin_id == tgl_state.our_id) + 2); + if (P->encr_chat.layer < 17) { + out_random (15 + 4 * (lrand48 () % 3)); + } else { out_int (0); } out_string (""); diff --git a/structures.c b/structures.c index c4b933d..3f0570b 100644 --- a/structures.c +++ b/structures.c @@ -1235,26 +1235,22 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) { in_end = in_ptr + ll; x = fetch_int (); if (x == CODE_decrypted_message_layer) { + ll = prefetch_strlen (); + fetch_str (ll); // random_bytes + int layer = fetch_int (); assert (layer >= 0); if (P && ((P->flags) & FLAG_CREATED)) { bl_do_encr_chat_set_layer ((void *)P, layer); } - x = fetch_int (); - } - assert (x == CODE_decrypted_message || x == CODE_decrypted_message_service || x == CODE_decrypted_message_l16 || x == CODE_decrypted_message_service_l16); - //assert (id == fetch_long ()); - long long new_id = fetch_long (); - if (P && P->encr_chat.layer >= 17) { - assert (new_id == id); - } - ll = prefetch_strlen (); - fetch_str (ll); // random_bytes - if (x == CODE_decrypted_message || x == CODE_decrypted_message_service) { + //x = fetch_int (); + //assert (x == CODE_decrypted_message || x == CODE_decrypted_message_service); + + out_seq_no = fetch_int (); in_seq_no = fetch_int (); - if (in_seq_no / 2 != P->encr_chat.in_seq_no + 1) { - vlogprintf (E_WARNING, "Hole in seq in secret chat. in_seq_no = %d, expect_seq_no = %d\n", in_seq_no / 2, P->encr_chat.in_seq_no + 1); + if (in_seq_no / 2 != P->encr_chat.in_seq_no) { + vlogprintf (E_WARNING, "Hole in seq in secret chat. in_seq_no = %d, expect_seq_no = %d\n", in_seq_no / 2, P->encr_chat.in_seq_no); drop = 1; } if ((in_seq_no & 1) != 1 - (P->encr_chat.admin_id == tgl_state.our_id) || @@ -1272,9 +1268,21 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) { } //vlogprintf (E_WARNING, "in = %d, out = %d\n", in_seq_no, out_seq_no); //P->encr_chat.in_seq_no = in_seq_no / 2; + x = fetch_int (); + } + assert (x == CODE_decrypted_message || x == CODE_decrypted_message_service || x == CODE_decrypted_message_l16 || x == CODE_decrypted_message_service_l16); + //assert (id == fetch_long ()); + long long new_id = fetch_long (); + if (P && P->encr_chat.layer >= 17) { + assert (new_id == id); + } + if (x == CODE_decrypted_message || x == CODE_decrypted_message_service) { if (x == CODE_decrypted_message) { fetch_int (); // ttl } + } else { + ll = prefetch_strlen (); + fetch_str (ll); // random_bytes } if (x == CODE_decrypted_message || x == CODE_decrypted_message_l16) { l = prefetch_strlen (); @@ -1285,8 +1293,8 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) { } else { start = in_ptr; if (skip_type_any (TYPE_TO_PARAM (decrypted_message_action)) < 0) { - vlogprintf (E_ERROR, "Skipped %ld int out of %ld. Magic = 0x%08x\n", (long)(in_ptr - start), (long)(in_end - start), *start); - assert (0); + vlogprintf (E_ERROR, "Can not decrypt: Skipped %ld int out of %ld. Magic = 0x%08x\n", (long)(in_ptr - start), (long)(in_end - start), *start); + drop = 1; } end = in_ptr; } @@ -1320,7 +1328,9 @@ void tglf_fetch_encrypted_message (struct tgl_message *M) { } } if (!drop) { - bl_do_encr_chat_update_seq ((void *)P, in_seq_no / 2, out_seq_no / 2); + if (in_seq_no >= 0 && out_seq_no >= 0) { + bl_do_encr_chat_update_seq ((void *)P, in_seq_no / 2 + 1, out_seq_no / 2); + } } }