diff --git a/telegram-adium/TelegramAccountView.xib b/telegram-adium/TelegramAccountView.xib index 76845c1..7d65ded 100644 --- a/telegram-adium/TelegramAccountView.xib +++ b/telegram-adium/TelegramAccountView.xib @@ -1,8 +1,8 @@ - + - + @@ -14,6 +14,7 @@ + @@ -21,11 +22,11 @@ - + - + @@ -33,26 +34,53 @@ - + + + + + + + + + - - + + + + + + + + + + + + + + + + + + NSAllRomanInputSourcesLocaleIdentifier + + + - + - + @@ -170,7 +198,7 @@ - + diff --git a/telegram-adium/TelegramAccountViewController.h b/telegram-adium/TelegramAccountViewController.h index 92c571c..594fed4 100644 --- a/telegram-adium/TelegramAccountViewController.h +++ b/telegram-adium/TelegramAccountViewController.h @@ -1,17 +1,19 @@ -/* - * Adium is the legal property of its developers, whose names are listed in the copyright file included - * with this source distribution. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the GNU - * General Public License as published by the Free Software Foundation; either version 2 of the License, - * or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; if not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + * + * Copyright Matthias Jentsch 2014-2015 */ #import @@ -24,6 +26,7 @@ IBOutlet NSTextField *textField_maxMsgSplitCount; IBOutlet NSTextField *textField_inactiveDaysOffline; IBOutlet NSTextField *textField_historyRetrieveDays; + IBOutlet NSSecureTextField *textField_passwordTwoFactor; IBOutlet NSMatrix *radio_Encryption; } diff --git a/telegram-adium/TelegramAccountViewController.m b/telegram-adium/TelegramAccountViewController.m index a9c6508..8743201 100644 --- a/telegram-adium/TelegramAccountViewController.m +++ b/telegram-adium/TelegramAccountViewController.m @@ -1,17 +1,19 @@ -/* - * Adium is the legal property of its developers, whose names are listed in the copyright file included - * with this source distribution. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the GNU - * General Public License as published by the Free Software Foundation; either version 2 of the License, - * or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; if not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + * + * Copyright Matthias Jentsch 2014-2015 */ #import "TelegramAccountViewController.h" @@ -46,6 +48,10 @@ } [radio_Encryption selectCellAtRow:row column:0]; + NSString *passwordTwoFactor = [account preferenceForKey:@"Telegram:"TGP_KEY_PASSWORD_TWO_FACTOR + group:GROUP_ACCOUNT_STATUS] ?: nil; + [textField_password setStringValue:passwordTwoFactor]; + id s = [account preferenceForKey:@"Telegram:"TGP_KEY_HISTORY_SYNC_ALL group:GROUP_ACCOUNT_STATUS]; [checkbox_historySyncAll setState:[s boolValue]]; @@ -69,6 +75,10 @@ NSArray *selections = @[@"ask", @"always", @"never"]; + [account setPreference:[textField_password stringValue] + forKey:@"Telegram:"TGP_KEY_PASSWORD_TWO_FACTOR + group:GROUP_ACCOUNT_STATUS]; + [account setPreference:selections[[radio_Encryption selectedRow]] forKey:@"Telegram:"TGP_KEY_ACCEPT_SECRET_CHATS group:GROUP_ACCOUNT_STATUS]; diff --git a/telegram-adium/TelegramJoinChatViewController.h b/telegram-adium/TelegramJoinChatViewController.h index 308377b..9b0e388 100644 --- a/telegram-adium/TelegramJoinChatViewController.h +++ b/telegram-adium/TelegramJoinChatViewController.h @@ -1,17 +1,19 @@ -/* - * Adium is the legal property of its developers, whose names are listed in the copyright file included - * with this source distribution. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the GNU - * General Public License as published by the Free Software Foundation; either version 2 of the License, - * or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; if not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + * + * Copyright Matthias Jentsch 2014-2015 */ #import @@ -19,7 +21,6 @@ @class AIAccount, AICompletingTextField; @interface TelegramJoinChatViewController : DCJoinChatViewController { - // IBOutlet NSTextField *textField_newChat; IBOutlet NSPopUpButton *popupButton_existingChat; } diff --git a/telegram-adium/TelegramJoinChatViewController.m b/telegram-adium/TelegramJoinChatViewController.m index d9e8db7..72baffc 100644 --- a/telegram-adium/TelegramJoinChatViewController.m +++ b/telegram-adium/TelegramJoinChatViewController.m @@ -1,17 +1,19 @@ -/* - * Adium is the legal property of its developers, whose names are listed in the copyright file included - * with this source distribution. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the GNU - * General Public License as published by the Free Software Foundation; either version 2 of the License, - * or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program; if not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + * + * Copyright Matthias Jentsch 2014-2015 */ #include diff --git a/telegram-base.c b/telegram-base.c index d2e0fbb..6cb26f1 100644 --- a/telegram-base.c +++ b/telegram-base.c @@ -467,25 +467,6 @@ static void request_code_canceled (gpointer data) { PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, "registration canceled"); } -static void request_name_code_entered (PurpleConnection* gc, PurpleRequestFields* fields) { - connection_data *conn = purple_connection_get_protocol_data(gc); - struct tgl_state *TLS = conn->TLS; - char const *username = purple_account_get_username(conn->pa); - - const char* first = purple_request_fields_get_string(fields, "first_name"); - const char* last = purple_request_fields_get_string(fields, "last_name"); - const char* code = purple_request_fields_get_string(fields, "code"); - if (!first || !last || !code) { - request_name_and_code (TLS); - return; - } - - tgl_do_send_code_result_auth(TLS, username, (int)strlen(username), conn->hash, - (int)strlen (conn->hash), code, (int)strlen (code), first, - (int)strlen (first), last, (int)strlen (last), - code_auth_receive_result, NULL); -} - static void request_code (struct tgl_state *TLS) { debug ("Client is not registered, registering..."); connection_data *conn = TLS->ev_base; @@ -507,6 +488,25 @@ static void request_code (struct tgl_state *TLS) { } } +static void request_name_code_entered (PurpleConnection* gc, PurpleRequestFields* fields) { + connection_data *conn = purple_connection_get_protocol_data(gc); + struct tgl_state *TLS = conn->TLS; + char const *username = purple_account_get_username(conn->pa); + + const char* first = purple_request_fields_get_string(fields, "first_name"); + const char* last = purple_request_fields_get_string(fields, "last_name"); + const char* code = purple_request_fields_get_string(fields, "code"); + if (!first || !last || !code) { + request_name_and_code (TLS); + return; + } + + tgl_do_send_code_result_auth(TLS, username, (int)strlen(username), conn->hash, + (int)strlen (conn->hash), code, (int)strlen (code), first, + (int)strlen (first), last, (int)strlen (last), + code_auth_receive_result, NULL); +} + static void request_name_and_code (struct tgl_state *TLS) { debug ("Phone is not registered, registering..."); @@ -536,6 +536,41 @@ static void request_name_and_code (struct tgl_state *TLS) { } } +static void request_password_entered (struct request_password_data *data, PurpleRequestFields* fields) { + const char* pass = purple_request_fields_get_string (fields, "password"); + data->callback (data->TLS, pass, data->arg); + free (data); +} + +void request_password (struct tgl_state *TLS, + void (*callback)(struct tgl_state *TLS, const char *string, void *arg), + void *arg) { + connection_data *conn = TLS->ev_base; + + struct request_password_data *data = malloc (sizeof(struct request_password_data)); + data->TLS = TLS; + data->arg = arg; + data->callback = callback; + + PurpleRequestFields* fields = purple_request_fields_new(); + PurpleRequestField* field = NULL; + + PurpleRequestFieldGroup* group = purple_request_field_group_new (""); + field = purple_request_field_string_new ("password", "Password", "", 0); + purple_request_field_string_set_masked (field, TRUE); + purple_request_field_group_add_field (group, field); + purple_request_fields_add_group (fields, group); + + if (!purple_request_fields (conn->gc, "Password needed", "Enter password for two factor authentication", + NULL, fields, "Ok", G_CALLBACK(request_password_entered), "Cancel", NULL, conn->pa, + NULL, NULL, data)) { + + const char *error = "No password for two factor authentication, enter it in extended settings."; + purple_connection_error_reason (conn->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, error); + purple_notify_error (_telegram_protocol, "Password invalid", "Password invalid", error); + } +} + void write_secret_chat_gw (struct tgl_state *TLS, void *extra, int success, struct tgl_secret_chat *E) { if (!success) { return; } write_secret_chat_file (TLS); diff --git a/telegram-base.h b/telegram-base.h index ff2dc43..53155ef 100644 --- a/telegram-base.h +++ b/telegram-base.h @@ -22,6 +22,12 @@ #include "telegram-purple.h" +struct request_password_data { + struct tgl_state *TLS; + void (*callback)(struct tgl_state *TLS, const char *string, void *arg); + void *arg; +}; + void read_state_file (struct tgl_state *TLS); void read_auth_file (struct tgl_state *TLS); void write_auth_file (struct tgl_state *TLS); @@ -33,6 +39,7 @@ void write_secret_chat_gw (struct tgl_state *TLS, void *extra, int success, stru void telegram_login (struct tgl_state *TLS); void request_code_entered (gpointer data, const gchar *code); +void request_password (struct tgl_state *TLS, void (*callback)(struct tgl_state *TLS, const char *string, void *arg), void *arg); void request_accept_secret_chat (struct tgl_state *TLS, struct tgl_secret_chat *U); diff --git a/telegram-purple.c b/telegram-purple.c index 727fd61..e547f6c 100755 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -72,6 +72,7 @@ #include "tgp-ft.h" #include "tgp-msg.h" +static void get_password (struct tgl_state *TLS, const char *prompt, int flags, void (*callback)(struct tgl_state *TLS, const char *string, void *arg), void *arg); static void update_message_received (struct tgl_state *TLS, struct tgl_message *M); static void update_user_handler (struct tgl_state *TLS, struct tgl_user *U, unsigned flags); static void update_user_status_handler (struct tgl_state *TLS, struct tgl_user *U); @@ -87,6 +88,7 @@ const char *pk_path = "/etc/telegram-purple/server.pub"; struct tgl_update_callback tgp_callback = { .logprintf = debug, + .get_string = get_password, .new_msg = update_message_received, .msg_receive = update_message_received, .user_update = update_user_handler, @@ -251,6 +253,19 @@ static char *format_print_name (struct tgl_state *TLS, tgl_peer_id_t id, const c return tgl_strdup (s); } +static void get_password (struct tgl_state *TLS, const char *prompt, int flags, + void (*callback)(struct tgl_state *TLS, const char *string, void *arg), void *arg) { + connection_data *conn = TLS->ev_base; + const char *P = purple_account_get_string (conn->pa, TGP_KEY_PASSWORD_TWO_FACTOR, NULL); + if (str_not_empty (P)) { + if (conn->password_retries++ < 1) { + callback (TLS, P, arg); + return; + } + } + request_password (TLS, callback, arg); +} + static void on_contact_added (struct tgl_state *TLS,void *callback_extra, int success, int size, struct tgl_user *users[]) { PurpleBuddy *buddy = callback_extra; @@ -762,10 +777,14 @@ static void tgprpl_init (PurplePlugin *plugin) { // Login + opt = purple_account_option_string_new ("Password (two factor authentication)", + TGP_KEY_PASSWORD_TWO_FACTOR, NULL); + prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt); + opt = purple_account_option_bool_new("Fallback SMS Verification", "compat-verification", 0); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt); - + // Messaging GList *verification_values = NULL; diff --git a/telegram-purple.h b/telegram-purple.h index 3fc4992..529018b 100644 --- a/telegram-purple.h +++ b/telegram-purple.h @@ -54,6 +54,8 @@ #define TGP_KEY_HISTORY_SYNC_ALL "history-sync-all" #define TGP_DEFAULT_HISTORY_SYNC_ALL FALSE +#define TGP_KEY_PASSWORD_TWO_FACTOR "password-two-factor" + void on_chat_get_info (struct tgl_state *TLS, void *extra, int success, struct tgl_chat *C); void on_ready (struct tgl_state *TLS); extern const char *pk_path;