summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2018-03-14 12:18:31 +0100
committerSimeon Simeonov2018-03-14 12:18:31 +0100
commitc94746703a3e0b59372b3bbf9355112c6a85d2dc (patch)
treec1248351adf00fdee3b0be4c61c0eac83fffffe6
parent43cd0bb654ae0225388678aa09798fc94be7a135 (diff)
Implement master password encrypted string tags
-rw-r--r--libsylph/imap.c2
-rw-r--r--libsylph/masterpassword.c31
-rw-r--r--libsylph/masterpassword.h7
-rw-r--r--libsylph/news.c12
-rw-r--r--libsylph/pop.c12
-rw-r--r--src/send_message.c15
6 files changed, 41 insertions, 38 deletions
diff --git a/libsylph/imap.c b/libsylph/imap.c
index 9ee4b15..e773ad4 100644
--- a/libsylph/imap.c
+++ b/libsylph/imap.c
@@ -707,7 +707,7 @@ 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 710 /* TODO: check of the format is correct | possible memory leak */
711 pass = decrypt_with_master_password(account->passwd); 711 pass = decrypt_with_master_password(account->passwd);
712 if (!pass) 712 if (!pass)
713 pass = account->tmp_pass; 713 pass = account->tmp_pass;
diff --git a/libsylph/masterpassword.c b/libsylph/masterpassword.c
index d240a7a..23e8f2f 100644
--- a/libsylph/masterpassword.c
+++ b/libsylph/masterpassword.c
@@ -48,6 +48,15 @@ void unload_master_password(void) {
48 48
49} 49}
50 50
51gint mpes_string_prefix(const gchar *str) {
52
53 /* this function will be expanded in time as the format changes */
54 if (g_str_has_prefix(str, "mpes1:"))
55 return 6;
56 return 0;
57
58}
59
51gboolean master_password_active(void) { 60gboolean master_password_active(void) {
52 61
53#if USE_SSL 62#if USE_SSL
@@ -59,38 +68,40 @@ gboolean master_password_active(void) {
59 68
60} 69}
61 70
62gchar *decrypt_with_master_password(gchar *str) { 71gchar *decrypt_with_master_password(const gchar *str) {
63 72
64#if USE_SSL 73#if USE_SSL
65 gchar *new_str; 74 gchar *new_str;
75 gint str_prefix;
66 76
67 if ((!str) || (!master_password_active())) 77 if ((!str) || (!master_password_active()))
68 return str; /* do nothing */ 78 return g_strdup(str);
69 79
80 str_prefix = mpes_string_prefix(str);
70 if (decrypt_data(&new_str, 81 if (decrypt_data(&new_str,
71 str, 82 str + str_prefix,
72 master_password, 83 master_password,
73 strlen(str)) != RC_OK) { 84 strlen(str) - str_prefix) != RC_OK) {
74 OPENSSL_cleanse(new_str, strlen(new_str)); 85 OPENSSL_cleanse(new_str, strlen(new_str));
75 g_free(new_str); 86 g_free(new_str);
76 return str; 87 return g_strdup(str);
77 } 88 }
78 89
79 return new_str; 90 return new_str;
80#else 91#else
81 return str; /* do nothing */ 92 return g_strdup(str);
82#endif 93#endif
83 94
84} 95}
85 96
86gchar *encrypt_with_master_password(gchar *str) { 97gchar *encrypt_with_master_password(const gchar *str) {
87 98
88#if USE_SSL 99#if USE_SSL
89 gchar *new_str; 100 gchar *new_str;
90 gint length_encrypted; 101 gint length_encrypted;
91 102
92 if ((!str) || (!master_password_active())) 103 if ((!str) || (!master_password_active()))
93 return str; /* do nothing */ 104 return g_strdup(str);
94 105
95 if (encrypt_data(&new_str, 106 if (encrypt_data(&new_str,
96 &length_encrypted, 107 &length_encrypted,
@@ -101,12 +112,12 @@ gchar *encrypt_with_master_password(gchar *str) {
101 TRUE) != RC_OK) { 112 TRUE) != RC_OK) {
102 OPENSSL_cleanse(new_str, strlen(new_str)); 113 OPENSSL_cleanse(new_str, strlen(new_str));
103 g_free(new_str); 114 g_free(new_str);
104 return str; 115 return g_strdup(str);
105 } 116 }
106 117
107 return new_str; 118 return new_str;
108#else 119#else
109 return str; /* do nothing */ 120 return g_strdup(str);
110#endif 121#endif
111 122
112} 123}
diff --git a/libsylph/masterpassword.h b/libsylph/masterpassword.h
index 9d00384..91f3793 100644
--- a/libsylph/masterpassword.h
+++ b/libsylph/masterpassword.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * LibSylph -- E-Mail client library 2 * LibSylph -- E-Mail client library
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto 3 * Copyright (C) 1999-2018 Hiroyuki Yamamoto
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public 6 * modify it under the terms of the GNU Lesser General Public
@@ -28,9 +28,10 @@ extern gchar *master_password;
28void set_master_password(const char *password); 28void set_master_password(const char *password);
29gchar *get_master_password(void); 29gchar *get_master_password(void);
30void unload_master_password(void); 30void unload_master_password(void);
31gint mpes_string_prefix(const gchar *str);
31gboolean master_password_active(void); 32gboolean master_password_active(void);
32gchar *decrypt_with_master_password(gchar *str); 33gchar *decrypt_with_master_password(const gchar *str);
33gchar *encrypt_with_master_password(gchar *str); 34gchar *encrypt_with_master_password(const gchar *str);
34 35
35#if USE_SSL 36#if USE_SSL
36gint set_master_password_interactively(guint max_attempts); 37gint set_master_password_interactively(guint max_attempts);
diff --git a/libsylph/news.c b/libsylph/news.c
index b7a922a..e75976e 100644
--- a/libsylph/news.c
+++ b/libsylph/news.c
@@ -250,14 +250,12 @@ static Session *news_session_new_for_folder(Folder *folder)
250 ac = folder->account; 250 ac = folder->account;
251 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) { 251 if (ac->use_nntp_auth && ac->userid && ac->userid[0]) {
252 userid = ac->userid; 252 userid = ac->userid;
253 if (ac->passwd && ac->passwd[0]) 253 if (ac->passwd && ac->passwd[0]) {
254 if (master_password_active()) { 254 /* TODO: check if format is correct */
255 passwd = decrypt_with_master_password(ac->passwd); 255 passwd = decrypt_with_master_password(ac->passwd);
256 } else { 256 } else {
257 passwd = g_strdup(ac->passwd);
258 }
259 else
260 passwd = input_query_password(ac->nntp_server, userid); 257 passwd = input_query_password(ac->nntp_server, userid);
258 }
261 } 259 }
262 260
263 if (ac->use_socks && ac->use_socks_for_recv && ac->proxy_host) { 261 if (ac->use_socks && ac->use_socks_for_recv && ac->proxy_host) {
diff --git a/libsylph/pop.c b/libsylph/pop.c
index a387f5e..96f347e 100644
--- a/libsylph/pop.c
+++ b/libsylph/pop.c
@@ -438,14 +438,10 @@ Session *pop3_session_new(PrefsAccount *account)
438 session->error_msg = NULL; 438 session->error_msg = NULL;
439 439
440 session->user = g_strdup(account->userid); 440 session->user = g_strdup(account->userid);
441 if (master_password_active()) { 441 /* TODO: check format */
442 session->pass = account->passwd ? decrypt_with_master_password( 442 session->pass = account->passwd ? decrypt_with_master_password(
443 account->passwd) : account->tmp_pass ? g_strdup( 443 account->passwd) : account->tmp_pass ? g_strdup(
444 account->tmp_pass) : NULL; 444 account->tmp_pass) : NULL;
445 } else {
446 session->pass = account->passwd ? g_strdup(account->passwd) :
447 account->tmp_pass ? g_strdup(account->tmp_pass) : NULL;
448 }
449 445
450 SESSION(session)->server = g_strdup(account->recv_server); 446 SESSION(session)->server = g_strdup(account->recv_server);
451 447
diff --git a/src/send_message.c b/src/send_message.c
index d5fc6e8..c0a7f59 100644
--- a/src/send_message.c
+++ b/src/send_message.c
@@ -649,17 +649,14 @@ static gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp)
649 649
650 if (ac_prefs->smtp_userid) { 650 if (ac_prefs->smtp_userid) {
651 smtp_session->user = g_strdup(ac_prefs->smtp_userid); 651 smtp_session->user = g_strdup(ac_prefs->smtp_userid);
652 if (ac_prefs->smtp_passwd) 652 if (ac_prefs->smtp_passwd) {
653 if (master_password_active()) { 653 /* TODO: check if the format is correct */
654 smtp_session->pass = decrypt_with_master_password( 654 smtp_session->pass = decrypt_with_master_password(
655 ac_prefs->smtp_passwd); 655 ac_prefs->smtp_passwd);
656 } else { 656 } else if (ac_prefs->tmp_smtp_pass) {
657 smtp_session->pass = g_strdup(ac_prefs->smtp_passwd);
658 }
659 else if (ac_prefs->tmp_smtp_pass)
660 smtp_session->pass = 657 smtp_session->pass =
661 g_strdup(ac_prefs->tmp_smtp_pass); 658 g_strdup(ac_prefs->tmp_smtp_pass);
662 else { 659 } else {
663 smtp_session->pass = 660 smtp_session->pass =
664 input_query_password 661 input_query_password
665 (ac_prefs->smtp_server, 662 (ac_prefs->smtp_server,