summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2018-03-18 17:07:51 +0100
committerSimeon Simeonov2018-03-18 17:07:51 +0100
commit0a708b4e41e80263f8c8e4a5a399c69cec1608c6 (patch)
tree12017f84acb912e4410c31f2b4c75b8fd11a9898
parentc94746703a3e0b59372b3bbf9355112c6a85d2dc (diff)
Use the mpes1: - tag for passwords encrypted with master password
-rw-r--r--libsylph/imap.c19
-rw-r--r--libsylph/masterpassword.c15
-rw-r--r--libsylph/prefs_account.c29
-rw-r--r--src/inputdialog.c7
4 files changed, 60 insertions, 10 deletions
diff --git a/libsylph/imap.c b/libsylph/imap.c
index e773ad4..e1c7cfd 100644
--- a/libsylph/imap.c
+++ b/libsylph/imap.c
@@ -707,8 +707,12 @@ static gint imap_session_connect(IMAPSession *session)
707 707
708 log_message(_("creating IMAP4 connection to %s:%d ...\n"), 708 log_message(_("creating IMAP4 connection to %s:%d ...\n"),
709 SESSION(session)->server, SESSION(session)->port); 709 SESSION(session)->server, SESSION(session)->port);
710 /* TODO: check of the format is correct | possible memory leak */ 710 if (master_password_active()) {
711 pass = decrypt_with_master_password(account->passwd); 711 pass = decrypt_with_master_password(account->passwd);
712 /* a new string is allocated. To be removed ... */
713 } else {
714 pass = account->passwd;
715 }
712 if (!pass) 716 if (!pass)
713 pass = account->tmp_pass; 717 pass = account->tmp_pass;
714 if (!pass) { 718 if (!pass) {
@@ -771,8 +775,11 @@ static gint imap_session_connect(IMAPSession *session)
771#endif 775#endif
772 776
773 if (!session->authenticated && 777 if (!session->authenticated &&
774 imap_auth(session, account->userid, pass, account->imap_auth_type) 778 imap_auth(session, account->userid, pass, account->imap_auth_type)
775 != IMAP_SUCCESS) { 779 != IMAP_SUCCESS) {
780 if (master_password_active()) {
781 g_free(pass); /* remove the decrypted password */
782 }
776 if (account->tmp_pass) { 783 if (account->tmp_pass) {
777 g_free(account->tmp_pass); 784 g_free(account->tmp_pass);
778 account->tmp_pass = NULL; 785 account->tmp_pass = NULL;
@@ -781,6 +788,10 @@ static gint imap_session_connect(IMAPSession *session)
781 return IMAP_AUTHFAIL; 788 return IMAP_AUTHFAIL;
782 } 789 }
783 790
791 if (master_password_active()) {
792 g_free(pass); /* remove the decrypted password */
793 }
794
784 return IMAP_SUCCESS; 795 return IMAP_SUCCESS;
785} 796}
786 797
diff --git a/libsylph/masterpassword.c b/libsylph/masterpassword.c
index 23e8f2f..77ff281 100644
--- a/libsylph/masterpassword.c
+++ b/libsylph/masterpassword.c
@@ -78,6 +78,9 @@ gchar *decrypt_with_master_password(const gchar *str) {
78 return g_strdup(str); 78 return g_strdup(str);
79 79
80 str_prefix = mpes_string_prefix(str); 80 str_prefix = mpes_string_prefix(str);
81 if (!str_prefix)
82 return g_strdup(str);
83
81 if (decrypt_data(&new_str, 84 if (decrypt_data(&new_str,
82 str + str_prefix, 85 str + str_prefix,
83 master_password, 86 master_password,
@@ -97,7 +100,7 @@ gchar *decrypt_with_master_password(const gchar *str) {
97gchar *encrypt_with_master_password(const gchar *str) { 100gchar *encrypt_with_master_password(const gchar *str) {
98 101
99#if USE_SSL 102#if USE_SSL
100 gchar *new_str; 103 gchar *new_str, *mpes1_str;
101 gint length_encrypted; 104 gint length_encrypted;
102 105
103 if ((!str) || (!master_password_active())) 106 if ((!str) || (!master_password_active()))
@@ -115,7 +118,11 @@ gchar *encrypt_with_master_password(const gchar *str) {
115 return g_strdup(str); 118 return g_strdup(str);
116 } 119 }
117 120
118 return new_str; 121 mpes1_str = g_strdup_printf("mpes1:%s", new_str);
122 OPENSSL_cleanse(new_str, strlen(new_str));
123 g_free(new_str);
124
125 return mpes1_str;
119#else 126#else
120 return g_strdup(str); 127 return g_strdup(str);
121#endif 128#endif
@@ -163,6 +170,10 @@ gint check_master_password_interactively(guint max_attempts) {
163 170
164 for (cnt = 0; cnt < max_attempts; ++cnt) { 171 for (cnt = 0; cnt < max_attempts; ++cnt) {
165 master_password = input_query_master_password(); 172 master_password = input_query_master_password();
173 if (master_password == NULL) {
174 /* input canceled or query_master_password_func not set */
175 continue;
176 }
166 if (check_password(master_password, 177 if (check_password(master_password,
167 prefs_common.master_password_hash) == RC_OK) { 178 prefs_common.master_password_hash) == RC_OK) {
168 return RC_OK; /* match */ 179 return RC_OK; /* match */
diff --git a/libsylph/prefs_account.c b/libsylph/prefs_account.c
index 1aecba9..fc4d8f1 100644
--- a/libsylph/prefs_account.c
+++ b/libsylph/prefs_account.c
@@ -34,6 +34,7 @@
34#include "customheader.h" 34#include "customheader.h"
35#include "account.h" 35#include "account.h"
36#include "utils.h" 36#include "utils.h"
37#include "masterpassword.h"
37 38
38static PrefsAccount tmp_ac_prefs; 39static PrefsAccount tmp_ac_prefs;
39 40
@@ -205,7 +206,7 @@ PrefsAccount *prefs_account_new(void)
205void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label) 206void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
206{ 207{
207 const gchar *p = label; 208 const gchar *p = label;
208 gchar *rcpath; 209 gchar *rcpath, *tmp_str;
209 gint id; 210 gint id;
210 211
211 g_return_if_fail(ac_prefs != NULL); 212 g_return_if_fail(ac_prefs != NULL);
@@ -229,6 +230,32 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
229 ac_prefs->use_apop_auth = TRUE; 230 ac_prefs->use_apop_auth = TRUE;
230 } 231 }
231 232
233 if (master_password_active()) {
234 if ((ac_prefs->passwd != NULL) &&
235 !mpes_string_prefix(ac_prefs->passwd)) {
236 /* TODO: Perhaps some prompt? */
237 debug_print(
238 "%s -> converting passwd cleartext to encrypted\n",
239 label);
240 tmp_str = ac_prefs->passwd;
241 ac_prefs->passwd = encrypt_with_master_password(ac_prefs->passwd);
242 g_free(tmp_str);
243 }
244
245 if ((ac_prefs->smtp_passwd != NULL) &&
246 !mpes_string_prefix(ac_prefs->smtp_passwd)) {
247 /* TODO: Perhaps some prompt? */
248 debug_print(
249 "%s -> converting smtp_passwd from cleartext to encrypted\n",
250 label);
251 tmp_str = ac_prefs->smtp_passwd;
252 ac_prefs->smtp_passwd = encrypt_with_master_password(
253 ac_prefs->smtp_passwd);
254 g_free(tmp_str);
255 }
256
257 }
258
232 custom_header_read_config(ac_prefs); 259 custom_header_read_config(ac_prefs);
233} 260}
234 261
diff --git a/src/inputdialog.c b/src/inputdialog.c
index d17b852..340e488 100644
--- a/src/inputdialog.c
+++ b/src/inputdialog.c
@@ -180,12 +180,13 @@ gchar *input_dialog_set_new_password(guint max_attempts)
180 _("Input password"), 180 _("Input password"),
181 _("Confirm new password"), 181 _("Confirm new password"),
182 NULL); 182 NULL);
183 if (strcmp(pass1, pass2) == 0) { 183
184 /* TODO: clear before free? */ 184 if (pass1 != NULL && pass2 != NULL && strcmp(pass1, pass2) == 0) {
185 /* TODO: clear before free? */
185 g_free(pass2); 186 g_free(pass2);
186 break; 187 break;
187 } 188 }
188 /* TODO: clear before free? */ 189 /* TODO: clear before free? */
189 g_free(pass2); 190 g_free(pass2);
190 g_free(pass1); 191 g_free(pass1);
191 pass1 = NULL; 192 pass1 = NULL;