From f1babd48f5259186cd1233288992f942d4b5b0bb Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Fri, 9 Mar 2018 14:02:34 +0100 Subject: Complete rewrite of the master password implementation --- src/main.c | 28 ++++++++++++++++++++++++++++ src/send_message.c | 22 ++++++++-------------- 2 files changed, 36 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index be8ea54..7c1cd7b 100644 --- a/src/main.c +++ b/src/main.c @@ -87,6 +87,7 @@ #include "foldersel.h" #include "update_check.h" #include "colorlabel.h" +#include "masterpassword.h" #if USE_GPGME # include "rfc2015.h" @@ -275,6 +276,32 @@ int main(int argc, char *argv[]) CHDIR_EXIT_IF_FAIL(get_home_dir(), 1); prefs_common_read_config(); + set_master_password(NULL); +#if USE_SSL + if (prefs_common.use_master_password) { + if (prefs_common.master_password_hash != NULL) { + if (check_master_password_interactively(3)) { + if (alertpanel(_("Master password"), + _("Unable to set master password"), + GTK_STOCK_DISCARD, + GTK_STOCK_QUIT, + NULL) != G_ALERTDEFAULT) { + exit(1); + } + } + } else { + if (set_master_password_interactively(3) != 0) { + if (alertpanel(_("Master password"), + _("Unable to set master password"), + GTK_STOCK_DISCARD, + GTK_STOCK_QUIT, + NULL) != G_ALERTDEFAULT) { + exit(1); + } + } + } + } +#endif filter_set_addressbook_func(addressbook_has_address); filter_read_config(); prefs_actions_read_config(); @@ -995,6 +1022,7 @@ void app_will_exit(gboolean force) /* remove temporary files, close log file, socket cleanup */ #if USE_SSL + unload_master_password(); ssl_done(); #endif syl_cleanup(); diff --git a/src/send_message.c b/src/send_message.c index 7b66423..d5fc6e8 100644 --- a/src/send_message.c +++ b/src/send_message.c @@ -58,6 +58,7 @@ #include "inc.h" #include "mainwindow.h" #include "summaryview.h" +#include "masterpassword.h" #define SMTP_PORT 25 #if USE_SSL @@ -648,24 +649,17 @@ static gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp) if (ac_prefs->smtp_userid) { smtp_session->user = g_strdup(ac_prefs->smtp_userid); - if (ac_prefs->smtp_passwd) { - if(prefs_common.use_master_password && - ac_prefs->master_password != NULL) { - if (decrypt_data(&(smtp_session->pass), - ac_prefs->smtp_passwd, - ac_prefs->master_password, - strlen(ac_prefs->smtp_passwd) + 1) != RC_OK) { - session_destroy(session); - return -1; - } + if (ac_prefs->smtp_passwd) + if (master_password_active()) { + smtp_session->pass = decrypt_with_master_password( + ac_prefs->smtp_passwd); } else { - smtp_session->pass = - g_strdup(ac_prefs->smtp_passwd); + smtp_session->pass = g_strdup(ac_prefs->smtp_passwd); } - } else if (ac_prefs->tmp_smtp_pass) { + else if (ac_prefs->tmp_smtp_pass) smtp_session->pass = g_strdup(ac_prefs->tmp_smtp_pass); - } else { + else { smtp_session->pass = input_query_password (ac_prefs->smtp_server, -- cgit v1.3