From 98dfe80ca1e88f59ef81d16f5115791e3193ba28 Mon Sep 17 00:00:00 2001 From: vvaltman Date: Tue, 9 Sep 2014 20:50:07 +0400 Subject: [PATCH 1/2] Fixed rsa pad --- mtproto-client.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mtproto-client.c b/mtproto-client.c index e1e05ac..3027118 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -617,7 +617,12 @@ static int process_dh_answer (struct connection *c, char *packet, int len, int t l = BN_num_bytes (&auth_key_num); assert (l >= 250 && l <= 256); assert (BN_bn2bin (&auth_key_num, (unsigned char *)(temp_key ? D->temp_auth_key : D->auth_key))); - memset (temp_key ? D->temp_auth_key + l : D->auth_key + l, 0, 256 - l); + if (l < 256) { + char *key = temp_key ? D->temp_auth_key : D->auth_key; + memmove (key + 256 - l, key, l); + memset (key, 0, 256 - l); + } + BN_free (dh_power); BN_free (&auth_key_num); BN_free (&dh_g); From 4fe0014a66c372ee8d3dff84102122ca5373ff90 Mon Sep 17 00:00:00 2001 From: vvaltman Date: Tue, 9 Sep 2014 21:05:36 +0400 Subject: [PATCH 2/2] Added [-D] (disable output) key --- interface.c | 10 ++++++++-- loop.c | 6 ++++++ main.c | 37 ++++++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/interface.c b/interface.c index d8da3c8..cdd8c3d 100644 --- a/interface.c +++ b/interface.c @@ -94,6 +94,8 @@ int in_chat_mode; tgl_peer_id_t chat_mode_id; extern int readline_disabled; +extern int disable_output; + int is_same_word (const char *s, size_t l, const char *word) { return s && word && strlen (word) == l && !memcmp (s, word, l); } @@ -848,7 +850,7 @@ void mark_read_upd (int num, struct tgl_message *list[]) { } void type_notification_upd (struct tgl_user *U) { - if (log_level < 2) { return; } + if (log_level < 2 || disable_output) { return; } print_start (); push_color (COLOR_YELLOW); printf ("User "); @@ -859,7 +861,7 @@ void type_notification_upd (struct tgl_user *U) { } void type_in_chat_notification_upd (struct tgl_user *U, struct tgl_chat *C) { - if (log_level < 2) { return; } + if (log_level < 2 || disable_output) { return; } print_start (); push_color (COLOR_YELLOW); printf ("User "); @@ -876,6 +878,7 @@ void print_message_gw (struct tgl_message *M) { #ifdef USE_LUA lua_new_msg (M); #endif + if (disable_output) { return; } if (!binlog_read) { return; } print_start (); print_message (M); @@ -935,6 +938,7 @@ void user_update_gw (struct tgl_user *U, unsigned flags) { lua_user_update (U, flags); #endif + if (disable_output) { return; } if (!binlog_read) { return; } if (!(flags & TGL_UPDATE_CREATED)) { @@ -959,6 +963,7 @@ void chat_update_gw (struct tgl_chat *U, unsigned flags) { lua_chat_update (U, flags); #endif + if (disable_output) { return; } if (!binlog_read) { return; } if (!(flags & TGL_UPDATE_CREATED)) { @@ -983,6 +988,7 @@ void secret_chat_update_gw (struct tgl_secret_chat *U, unsigned flags) { lua_secret_chat_update (U, flags); #endif + if (disable_output) { return; } if (!binlog_read) { return; } if ((flags & TGL_UPDATE_WORKING) || (flags & TGL_UPDATE_DELETED)) { diff --git a/loop.c b/loop.c index f4b602e..4a503b9 100644 --- a/loop.c +++ b/loop.c @@ -72,6 +72,8 @@ int register_mode; extern int safe_quit; extern int sync_from_start; +extern int disable_output; + void got_it (char *line, int len); void write_state_file (void); @@ -613,6 +615,10 @@ int loop (void) { } if (!tgl_signed_dc (tgl_state.DC_working)) { + if (disable_output) { + fprintf (stderr, "Can not login without output\n"); + exit (2); + } if (!default_username) { size_t size = 0; char *user = 0; diff --git a/main.c b/main.c index f959954..25ef00c 100644 --- a/main.c +++ b/main.c @@ -94,6 +94,7 @@ int allow_weak_random; char *lua_file; int disable_colors; int readline_disabled; +int disable_output; void set_default_username (const char *s) { if (default_username) { @@ -218,7 +219,9 @@ void running_for_first_time (void) { //char *downloads_directory = get_downloads_directory (); if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) { - printf ("[%s] created\n", config_directory); + if (!disable_output) { + printf ("[%s] created\n", config_directory); + } } tfree_str (config_directory); @@ -351,15 +354,21 @@ void parse_config (void) { tgl_set_download_directory (downloads_directory); if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) { - printf ("[%s] created\n", config_directory); + if (!disable_output) { + printf ("[%s] created\n", config_directory); + } } if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) { - printf ("[%s] created\n", downloads_directory); + if (!disable_output) { + printf ("[%s] created\n", downloads_directory); + } } } #else void parse_config (void) { - printf ("libconfig not enabled\n"); + if (!disable_output) { + printf ("libconfig not enabled\n"); + } tasprintf (&downloads_directory, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, DOWNLOADS_DIRECTORY); if (binlog_enabled) { @@ -405,6 +414,7 @@ void usage (void) { printf (" -R disable readline\n"); printf (" -d daemon mode\n"); printf (" -L log file name\n"); + printf (" -D disable output\n"); exit (1); } @@ -462,7 +472,7 @@ static void sighup_handler (const int sig) { void args_parse (int argc, char **argv) { int opt = 0; - while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:" + while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:D" #ifdef HAVE_LIBCONFIG "c:p:" #else @@ -533,6 +543,9 @@ void args_parse (int argc, char **argv) { case 'L': logname = optarg; break; + case 'D': + disable_output ++; + break; case 'h': default: usage (); @@ -586,12 +599,14 @@ int main (int argc, char **argv) { signal (SIGUSR1, sigusr1_handler); reopen_logs (); } - printf ( - "Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n" - "Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n" - "This is free software, and you are welcome to redistribute it\n" - "under certain conditions; type `show_license' for details.\n" - ); + if (!disable_output) { + printf ( + "Telegram-cli version " TGL_VERSION ", Copyright (C) 2013-2014 Vitaly Valtman\n" + "Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.\n" + "This is free software, and you are welcome to redistribute it\n" + "under certain conditions; type `show_license' for details.\n" + ); + } running_for_first_time (); parse_config ();