Commit cce98419 authored by vysheng's avatar vysheng

Many improvements in encrypted chats. Can not send/download encrypted messages, for example

parent e4dc0e08
...@@ -78,12 +78,12 @@ char *next_token (int *l) { ...@@ -78,12 +78,12 @@ char *next_token (int *l) {
#define NOT_FOUND (int)0x80000000 #define NOT_FOUND (int)0x80000000
peer_id_t PEER_NOT_FOUND = {.id = NOT_FOUND}; peer_id_t PEER_NOT_FOUND = {.id = NOT_FOUND};
int next_token_int (void) { long long next_token_int (void) {
int l; int l;
char *s = next_token (&l); char *s = next_token (&l);
if (!s) { return NOT_FOUND; } if (!s) { return NOT_FOUND; }
char *r; char *r;
int x = strtod (s, &r); long long x = strtoll (s, &r, 10);
if (r == s + l) { if (r == s + l) {
return x; return x;
} else { } else {
...@@ -139,6 +139,22 @@ peer_id_t next_token_chat (void) { ...@@ -139,6 +139,22 @@ peer_id_t next_token_chat (void) {
} }
} }
peer_id_t next_token_encr_chat (void) {
int l;
char *s = next_token (&l);
if (!s) { return PEER_NOT_FOUND; }
int index = 0;
while (index < peer_num && (!is_same_word (s, l, Peers[index]->print_name) || get_peer_type (Peers[index]->id) != PEER_ENCR_CHAT)) {
index ++;
}
if (index < peer_num) {
return Peers[index]->id;
} else {
return PEER_NOT_FOUND;
}
}
peer_id_t next_token_peer (void) { peer_id_t next_token_peer (void) {
int l; int l;
char *s = next_token (&l); char *s = next_token (&l);
...@@ -232,6 +248,7 @@ char *commands[] = { ...@@ -232,6 +248,7 @@ char *commands[] = {
"show_license", "show_license",
"search", "search",
"mark_read", "mark_read",
"visualize_key",
0 }; 0 };
int commands_flags[] = { int commands_flags[] = {
...@@ -259,6 +276,7 @@ int commands_flags[] = { ...@@ -259,6 +276,7 @@ int commands_flags[] = {
07, 07,
072, 072,
072, 072,
075,
}; };
int get_complete_mode (void) { int get_complete_mode (void) {
...@@ -322,6 +340,19 @@ int complete_chat_list (int index, const char *text, int len, char **R) { ...@@ -322,6 +340,19 @@ int complete_chat_list (int index, const char *text, int len, char **R) {
} }
} }
int complete_encr_chat_list (int index, const char *text, int len, char **R) {
index ++;
while (index < peer_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len) || get_peer_type (Peers[index]->id) != PEER_ENCR_CHAT)) {
index ++;
}
if (index < peer_num) {
*R = strdup (Peers[index]->print_name);
return index;
} else {
return -1;
}
}
int complete_user_chat_list (int index, const char *text, int len, char **R) { int complete_user_chat_list (int index, const char *text, int len, char **R) {
index ++; index ++;
while (index < peer_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) { while (index < peer_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) {
...@@ -390,6 +421,10 @@ char *command_generator (const char *text, int state) { ...@@ -390,6 +421,10 @@ char *command_generator (const char *text, int state) {
index = complete_chat_list (index, text, len, &R); index = complete_chat_list (index, text, len, &R);
if (c) { rl_line_buffer[rl_point] = c; } if (c) { rl_line_buffer[rl_point] = c; }
return R; return R;
case 5:
index = complete_encr_chat_list (index, text, len, &R);
if (c) { rl_line_buffer[rl_point] = c; }
return R;
default: default:
if (c) { rl_line_buffer[rl_point] = c; } if (c) { rl_line_buffer[rl_point] = c; }
return 0; return 0;
...@@ -446,7 +481,13 @@ void interpreter (char *line UU) { ...@@ -446,7 +481,13 @@ void interpreter (char *line UU) {
#define GET_PEER_CHAT \ #define GET_PEER_CHAT \
id = next_token_chat (); \ id = next_token_chat (); \
if (!cmp_peer_id (id, PEER_NOT_FOUND)) { \ if (!cmp_peer_id (id, PEER_NOT_FOUND)) { \
printf ("Bad char id\n"); \ printf ("Bad chat id\n"); \
RET; \
}
#define GET_PEER_ENCR_CHAT \
id = next_token_encr_chat (); \
if (!cmp_peer_id (id, PEER_NOT_FOUND)) { \
printf ("Bad encr_chat id\n"); \
RET; \ RET; \
} }
...@@ -512,34 +553,38 @@ void interpreter (char *line UU) { ...@@ -512,34 +553,38 @@ void interpreter (char *line UU) {
} }
do_forward_message (id, num); do_forward_message (id, num);
} else if (IS_WORD ("load_photo")) { } else if (IS_WORD ("load_photo")) {
int num = next_token_int (); long long num = next_token_int ();
if (num == NOT_FOUND || num <= 0) { if (num == NOT_FOUND) {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_photo) { if (M && !M->service && M->media.type == (int)CODE_message_media_photo) {
do_load_photo (&M->media.photo, 1); do_load_photo (&M->media.photo, 1);
} else if (M && !M->service && M->media.type == (int)CODE_decrypted_message_media_photo) {
do_load_encr_video (&M->media.encr_video, 1); // this is not a bug.
} else { } else {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
} else if (IS_WORD ("view_photo")) { } else if (IS_WORD ("view_photo")) {
int num = next_token_int (); long long num = next_token_int ();
if (num == NOT_FOUND || num <= 0) { if (num == NOT_FOUND) {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_photo) { if (M && !M->service && M->media.type == (int)CODE_message_media_photo) {
do_load_photo (&M->media.photo, 2); do_load_photo (&M->media.photo, 2);
} else if (M && !M->service && M->media.type == (int)CODE_decrypted_message_media_photo) {
do_load_encr_video (&M->media.encr_video, 2); // this is not a bug.
} else { } else {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
} else if (IS_WORD ("load_video_thumb")) { } else if (IS_WORD ("load_video_thumb")) {
int num = next_token_int (); long long num = next_token_int ();
if (num == NOT_FOUND || num <= 0) { if (num == NOT_FOUND) {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
...@@ -551,8 +596,8 @@ void interpreter (char *line UU) { ...@@ -551,8 +596,8 @@ void interpreter (char *line UU) {
RET; RET;
} }
} else if (IS_WORD ("view_video_thumb")) { } else if (IS_WORD ("view_video_thumb")) {
int num = next_token_int (); long long num = next_token_int ();
if (num == NOT_FOUND || num <= 0) { if (num == NOT_FOUND) {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
...@@ -564,27 +609,31 @@ void interpreter (char *line UU) { ...@@ -564,27 +609,31 @@ void interpreter (char *line UU) {
RET; RET;
} }
} else if (IS_WORD ("load_video")) { } else if (IS_WORD ("load_video")) {
int num = next_token_int (); long long num = next_token_int ();
if (num == NOT_FOUND || num <= 0) { if (num == NOT_FOUND) {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_video) { if (M && !M->service && M->media.type == (int)CODE_message_media_video) {
do_load_video (&M->media.video, 1); do_load_video (&M->media.video, 1);
} else if (M && !M->service && M->media.type == (int)CODE_decrypted_message_media_video) {
do_load_encr_video (&M->media.encr_video, 1);
} else { } else {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
} else if (IS_WORD ("view_video")) { } else if (IS_WORD ("view_video")) {
int num = next_token_int (); long long num = next_token_int ();
if (num == NOT_FOUND || num <= 0) { if (num == NOT_FOUND) {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
} }
struct message *M = message_get (num); struct message *M = message_get (num);
if (M && !M->service && M->media.type == (int)CODE_message_media_video) { if (M && !M->service && M->media.type == (int)CODE_message_media_video) {
do_load_video (&M->media.video, 2); do_load_video (&M->media.video, 2);
} else if (M && !M->service && M->media.type == (int)CODE_decrypted_message_media_video) {
do_load_encr_video (&M->media.encr_video, 2);
} else { } else {
printf ("Bad msg id\n"); printf ("Bad msg id\n");
RET; RET;
...@@ -691,6 +740,9 @@ void interpreter (char *line UU) { ...@@ -691,6 +740,9 @@ void interpreter (char *line UU) {
} else if (IS_WORD ("mark_read")) { } else if (IS_WORD ("mark_read")) {
GET_PEER; GET_PEER;
do_mark_read (id); do_mark_read (id);
} else if (IS_WORD ("visualize_key")) {
GET_PEER_ENCR_CHAT;
do_visualize_key (id);
} }
#undef IS_WORD #undef IS_WORD
#undef RET #undef RET
......
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
#define COLOR_BLUE "\033[34;1m" #define COLOR_BLUE "\033[34;1m"
#define COLOR_MAGENTA "\033[35;1m" #define COLOR_MAGENTA "\033[35;1m"
#define COLOR_CYAN "\033[36;1m" #define COLOR_CYAN "\033[36;1m"
#define COLOR_LCYAN "\033[0;36m"
#define COLOR_INVERSE "\033[7m"
char *get_default_prompt (void); char *get_default_prompt (void);
char *complete_none (const char *text, int state); char *complete_none (const char *text, int state);
......
...@@ -1050,11 +1050,24 @@ void work_update (struct connection *c UU, long long msg_id UU) { ...@@ -1050,11 +1050,24 @@ void work_update (struct connection *c UU, long long msg_id UU) {
peer_id_t id = MK_ENCR_CHAT (fetch_int ()); // chat_id peer_id_t id = MK_ENCR_CHAT (fetch_int ()); // chat_id
fetch_int (); // max_date fetch_int (); // max_date
fetch_int (); // date fetch_int (); // date
peer_t *P = user_chat_get (id);
int x = -1;
if (P && P->last) {
x = 0;
struct message *M = P->last;
while (M && (!M->out || M->unread)) {
if (M->out) {
M->unread = 0;
x ++;
}
M = M->next;
}
}
print_start (); print_start ();
push_color (COLOR_YELLOW); push_color (COLOR_YELLOW);
printf ("Messages in encrypted chat "); printf ("Encrypted chat ");
print_encr_chat_name_full (id, user_chat_get (id)); print_encr_chat_name_full (id, user_chat_get (id));
printf (" marked read \n"); printf (": %d messages marked read \n", x);
pop_color (); pop_color ();
print_end (); print_end ();
} }
......
int thumb_file_size = (82 * 6 - 2) * 4;
int thumb_file [] = {
0xe0ffd8ff, 0x464a1000, 0x01004649, 0x64000101, 0x00006400, 0xa002e2ff,
0x5f434349, 0x464f5250, 0x00454c49, 0x00000101, 0x636c9002, 0x3004736d,
0x6e6d0000, 0x47527274, 0x59582042, 0xdd07205a, 0x04000b00, 0x1b001600,
0x63612400, 0x50417073, 0x00004c50, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x0100d6f6, 0x00000000, 0x636c2dd3,
0x0000736d, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x65640b00, 0x00006373, 0x00000801, 0x70633800, 0x00007472, 0x00004001,
0x74774e00, 0x00007470, 0x00009001, 0x68631400, 0x00006461, 0x0000a401,
0x58722c00, 0x00005a59, 0x0000d001, 0x58621400, 0x00005a59, 0x0000e401,
0x58671400, 0x00005a59, 0x0000f801, 0x54721400, 0x00004352, 0x00000c02,
0x54672000, 0x00004352, 0x00002c02, 0x54622000, 0x00004352, 0x00004c02,
0x68632000, 0x00006d72, 0x00006c02, 0x6c6d2400, 0x00006375, 0x00000000,
0x00000100, 0x6e650c00, 0x00005355, 0x00001c00, 0x73001c00, 0x47005200,
0x20004200, 0x75006200, 0x6c006900, 0x2d007400, 0x6e006900, 0x6c6d0000,
0x00006375, 0x00000000, 0x00000100, 0x6e650c00, 0x00005355, 0x00003200,
0x4e001c00, 0x20006f00, 0x6f006300, 0x79007000, 0x69007200, 0x68006700,
0x2c007400, 0x75002000, 0x65007300, 0x66002000, 0x65007200, 0x6c006500,
0x00007900, 0x59580000, 0x0000205a, 0x00000000, 0x0100d6f6, 0x00000000,
0x66732dd3, 0x00003233, 0x01000000, 0x00004a0c, 0xffffe305, 0x00002af3,
0x00009b07, 0xffff87fd, 0xffffa2fb, 0x0000a3fd, 0x0000d803, 0x595894c0,
0x0000205a, 0x00000000, 0x0000946f, 0x0000ee38, 0x59589003, 0x0000205a,
0x00000000, 0x00009d24, 0x0000830f, 0x5958beb6, 0x0000205a, 0x00000000,
0x0000a562, 0x000090b7, 0x6170de18, 0x00006172, 0x03000000, 0x02000000,
0x00006666, 0x0000a7f2, 0x0000590d, 0x0000d013, 0x61705b0a, 0x00006172,
0x03000000, 0x02000000, 0x00006666, 0x0000a7f2, 0x0000590d, 0x0000d013,
0x61705b0a, 0x00006172, 0x03000000, 0x02000000, 0x00006666, 0x0000a7f2,
0x0000590d, 0x0000d013, 0x68635b0a, 0x00006d72, 0x03000000, 0x00000000,
0x0000d7a3, 0x00007b54, 0x0000cd4c, 0x00009a99, 0x00006626, 0xdbff5c0f,
0x14004300, 0x0f120f0e, 0x1112140d, 0x14161712, 0x21331f18, 0x1f1c1c1f,
0x252f2d3f, 0x4e414a33, 0x4841494d, 0x765c5246, 0x6f575264, 0x66484658,
0x7a6f688c, 0x8485847d, 0x9b91634f, 0x769a808f, 0xff7f8481, 0x014300db,
0x1f171716, 0x213c1f1b, 0x547f3c21, 0x7f7f5448, 0x7f7f7f7f, 0x7f7f7f7f,
0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f,
0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x7f7f7f7f, 0x1100c0ff, 0x005a0008,
0x2201035a, 0x01110200, 0xff011103, 0x001900c4, 0x01010101, 0x00000101,
0x00000000, 0x00000000, 0x02030400, 0xc4ff0605, 0x00103600, 0x02010401,
0x06050304, 0x00000306, 0x01000000, 0x11030200, 0x05211204, 0x13514131,
0x32146122, 0x23918171, 0x72423424, 0x432515a1, 0xa2827444, 0xc4fff0b3,
0x01011400, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x1400c4ff,
0x00000111, 0x00000000, 0x00000000, 0x00000000, 0xdaff0000, 0x01030c00,
0x03110200, 0x003f0011, 0x404434fb, 0xbcb4875c, 0x006b38b0, 0x03dcdb12,
0xf4637f74, 0xe519f153, 0x09d7c5c7, 0x47d29160, 0x20692f18, 0xd06d786a,
0x53f7f922, 0x17b3e260, 0x2fe8668c, 0x1786a473, 0x9775efbd, 0xe917e43a,
0x1d0a1bb0, 0x114d0f82, 0x14651110, 0x35f299ed, 0xe9b09680, 0xf5a4fc2f,
0xe975bd03, 0xb506737b, 0x04444440, 0x5c444044, 0x8e8dedbd, 0xc61adc7b,
0x689c738b, 0x92a0dc01, 0x58e2b77f, 0x7bfb37d1, 0xb5b5e79d, 0xdbf968cc,
0xead3f48d, 0x38ed1313, 0xdea77c86, 0xae089963, 0xc743435a, 0x403fe4ce,
0x392ee1b9, 0xed39e718, 0xd6517e2d, 0x7fc4aa03, 0xb7ad7590, 0x77e7e6ab,
0x34bf705d, 0x7c77ca53, 0x3dea1299, 0x7fb0bcf4, 0x241fadc5, 0x95a7a816,
0x13fbe6f3, 0x3182b135, 0xd1b4b224, 0x1b0d48a2, 0xbf9d26d8, 0x82dc3640,
0x63569a2a, 0xbbd224c3, 0xb9b4714c, 0x1680aec6, 0x3d311856, 0x9b59be91,
0x09876ca6, 0x61d86564, 0x5a9f06d2, 0x36f51b0d, 0x8682e476, 0xacb1b131,
0xd1584363, 0x00456b4d, 0x22d2053b, 0x22202202, 0xf3f30222, 0xe3e513e5,
0xf1e6e1f0, 0x2380496e, 0x5fdcdb68, 0x549b3a27, 0x825e6a6c, 0x6522028b,
0xaf91ccc8, 0x341cf26b, 0x58dbc4b5, 0xf2289add, 0x0854ddbd, 0x0b9247d5,
0xf02b5c54, 0x3f917f92, 0xaf56affd, 0xe3760637, 0x05cebde0, 0xed4c76ce,
0x3cef1b63, 0x7fd8aff8, 0xa0c902ea, 0x7e730d0a, 0x435834f3, 0x26edbb76,
0xd3ec00fd, 0x76d48efa, 0xa8560f2d, 0x0e766331, 0xd319993c, 0x20243209,
0x61b7e6c8, 0x998331d0, 0x640ee802, 0x47a3d493, 0xfab99413, 0x4fd871f1,
0xe9443792, 0x627e051c, 0xd8f3051c, 0x2f28f558, 0x64b51745, 0x1b2bfee3,
0xb8783953, 0x9900fff6, 0xd8176a65, 0x5a3bf56a, 0x1b331fdb, 0x64b3572f,
0xd59a3643, 0xaf3abce1, 0x11dd20bd, 0x01111110, 0x5c141011, 0xb3e3083f,
0xd9b19cc4, 0x17edb20e, 0xa78e9aa1, 0x4ef4de06, 0x00c0bfe7, 0x7e1e442d,
0x9221fe38, 0xedb5c7dc, 0x6338078a, 0x62495b8d, 0xc11d9b8c, 0x49e81b16,
0x51d02bea, 0x3eb86d70, 0xc8bc4f13, 0xa10ec758, 0xd40751c0, 0x5ac94710,
0xc4c8b080, 0x95492b83, 0x975ee696, 0xb7bd96b4, 0x17379cce, 0x82e856e8,
0xe4c2c82a, 0x398e935f, 0x632437ea, 0x7c9c87d2, 0xdc1ddb7c, 0x65a80a48,
0x2309f164, 0x51fab475, 0x081dc11d, 0xda45573b, 0x6622f3f3, 0x48f1b214,
0x676c4edb, 0x243468c7, 0x00ffde60, 0xf1630350, 0xa0076c1d, 0x8f2c0c8b,
0x2383c26b, 0x361a8f4e, 0xaceea6c9, 0x01dd5a5d, 0x11111011, 0xc3780c04,
0xbf093ee2, 0xc7972c0b, 0x00d99040, 0xc0c20eb7, 0x659d3bd4, 0x269ab85e,
0x468e114f, 0x11ad4fdb, 0x83d083d8, 0x8c52f4bd, 0x3c9664bf, 0xa4f9c77c,
0x22a68876, 0xadb18784, 0xf480be83, 0x885a00ea, 0x220e0a88, 0xc303e4f6,
0xc866e058, 0xdddbd661, 0xdf395db1, 0xbad64343, 0xe6e65b03, 0x668e81c3,
0xad619e98, 0xeeb94563, 0xd4d19a3c, 0x3316ce95, 0x9d65f1e1, 0x3bf324fe,
0x0e468f53, 0xc386068c, 0xa89e24f7, 0xf0c7c73b, 0xb60e391f, 0x1b8827cb,
0x58601954, 0xc54f90f9, 0x80886ec5, 0x88088888, 0x1b7bb980, 0xb4c71c23,
0xe6148e39, 0xb12358b8, 0xbd08225d, 0x0ffef085, 0x72b4f025, 0x635ce389,
0xb90277e4, 0x0d05e000, 0x9bf9dbb9, 0x8e749fbc, 0x7ee6abbf, 0x4ddbf4af,
0x728df7f3, 0x10b59adf, 0xe3c38f49, 0xb23c638a, 0xdb3d9349, 0x66899a64,
0x00004dd5, 0xf51b5adf, 0x2220a255, 0xd9ff0f22};
This diff is collapsed.
...@@ -80,6 +80,7 @@ void do_get_user_list_info_silent (int num, int *list); ...@@ -80,6 +80,7 @@ void do_get_user_list_info_silent (int num, int *list);
void do_get_user_info (peer_id_t id); void do_get_user_info (peer_id_t id);
void do_forward_message (peer_id_t id, int n); void do_forward_message (peer_id_t id, int n);
void do_rename_chat (peer_id_t id, char *name); void do_rename_chat (peer_id_t id, char *name);
void do_load_encr_video (struct encr_video *V, int next);
struct photo; struct photo;
struct video; struct video;
...@@ -97,5 +98,6 @@ void do_msg_search (peer_id_t id, int from, int to, int limit, const char *s); ...@@ -97,5 +98,6 @@ void do_msg_search (peer_id_t id, int from, int to, int limit, const char *s);
void do_accept_encr_chat_request (struct secret_chat *E); void do_accept_encr_chat_request (struct secret_chat *E);
void do_get_difference (void); void do_get_difference (void);
void do_mark_read (peer_id_t id); void do_mark_read (peer_id_t id);
void do_visualize_key (peer_id_t id);
#endif #endif
...@@ -818,6 +818,8 @@ void fetch_encrypted_message (struct message *M) { ...@@ -818,6 +818,8 @@ void fetch_encrypted_message (struct message *M) {
peer_id_t chat = MK_ENCR_CHAT (fetch_int ()); peer_id_t chat = MK_ENCR_CHAT (fetch_int ());
M->to_id = chat; M->to_id = chat;
peer_t *P = user_chat_get (chat); peer_t *P = user_chat_get (chat);
M->flags &= ~(FLAG_EMPTY | FLAG_DELETED);
M->flags |= FLAG_ENCRYPTED;
if (!P) { if (!P) {
logprintf ("Encrypted message to unknown chat. Dropping\n"); logprintf ("Encrypted message to unknown chat. Dropping\n");
M->flags |= FLAG_EMPTY; M->flags |= FLAG_EMPTY;
......
...@@ -91,9 +91,9 @@ struct encr_video { ...@@ -91,9 +91,9 @@ struct encr_video {
int w; int w;
int h; int h;
int duration;
unsigned char *key; unsigned char *key;
unsigned char *iv; unsigned char *iv;
int duration;
}; };
struct encr_file { struct encr_file {
......
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