From 46275eef3de4e025b5657e67e142fc58125779be Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Fri, 13 Apr 2018 15:24:01 +0200 Subject: Add support for auto-unloading av the master password --- libsylph/masterpassword.c | 23 +++++++++++++++++++++-- libsylph/prefs_account.c | 2 ++ libsylph/prefs_common.c | 3 +++ libsylph/prefs_common.h | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) (limited to 'libsylph') diff --git a/libsylph/masterpassword.c b/libsylph/masterpassword.c index 950b79a..8174def 100644 --- a/libsylph/masterpassword.c +++ b/libsylph/masterpassword.c @@ -26,6 +26,7 @@ #include "prefs_common.h" #include "ssl.h" #include "utils.h" +#include "masterpassword.h" gchar *master_password; @@ -84,9 +85,18 @@ gchar *decrypt_with_master_password(const gchar *str) { gchar *new_str; gint str_prefix; - if ((!str) || (!master_password_active())) + if ((!str) || (!prefs_common.use_master_password)) return g_strdup(str); + if (master_password == NULL) { + /* we have empty or auto unloaded master password */ + if ((!prefs_common.auto_unload_master_password) || + (check_master_password_interactively(3) != RC_OK)) { + return g_strdup(str); + } + debug_print("Reloaded master password\n"); + } + str_prefix = mpes_string_prefix(str); if (!str_prefix) return g_strdup(str); @@ -113,9 +123,18 @@ gchar *encrypt_with_master_password(const gchar *str) { gchar *new_str, *mpes1_str; gint length_encrypted; - if ((!str) || (!master_password_active())) + if ((!str) || (!prefs_common.use_master_password)) return g_strdup(str); + if (master_password == NULL) { + /* we have empty or auto unloaded master password */ + if ((!prefs_common.auto_unload_master_password) || + (check_master_password_interactively(3) != RC_OK)) { + return g_strdup(str); + } + debug_print("Reloaded master password\n"); + } + if (encrypt_data(&new_str, &length_encrypted, str, diff --git a/libsylph/prefs_account.c b/libsylph/prefs_account.c index fc4d8f1..54cbc89 100644 --- a/libsylph/prefs_account.c +++ b/libsylph/prefs_account.c @@ -239,6 +239,7 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label) label); tmp_str = ac_prefs->passwd; ac_prefs->passwd = encrypt_with_master_password(ac_prefs->passwd); + cleanse_buffer(tmp_str, strlen(tmp_str)); g_free(tmp_str); } @@ -251,6 +252,7 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label) tmp_str = ac_prefs->smtp_passwd; ac_prefs->smtp_passwd = encrypt_with_master_password( ac_prefs->smtp_passwd); + cleanse_buffer(tmp_str, strlen(tmp_str)); g_free(tmp_str); } diff --git a/libsylph/prefs_common.c b/libsylph/prefs_common.c index dda4a0f..192964e 100644 --- a/libsylph/prefs_common.c +++ b/libsylph/prefs_common.c @@ -425,6 +425,9 @@ static PrefParam param[] = { P_STRING}, {"encrypted_password_min_length", "32", &prefs_common.encrypted_password_min_length, P_INT}, + {"auto_unload_master_password", "FALSE", + &prefs_common.auto_unload_master_password, + P_BOOL}, /* Interface */ {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL}, diff --git a/libsylph/prefs_common.h b/libsylph/prefs_common.h index 92333aa..6f9c364 100644 --- a/libsylph/prefs_common.h +++ b/libsylph/prefs_common.h @@ -252,7 +252,8 @@ struct _PrefsCommon /* Master password */ gboolean use_master_password; gchar *master_password_hash; - guint encrypted_password_min_length; + guint encrypted_password_min_length; + gboolean auto_unload_master_password; /* Interface */ gboolean sep_folder; -- cgit v1.3