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 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'libsylph/masterpassword.c') 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, -- cgit v1.3