summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2018-03-08 15:01:45 +0100
committerSimeon Simeonov2018-03-08 15:01:45 +0100
commit57944f6147f077ccf4d84b9d2659f4e8645e8858 (patch)
treeb5a4f7af257058fb602d36590568ffd06681f6cd
parent9bcc1f9650eb2d9dff7a78c632dcc14dfcfac9ee (diff)
Reastructure master password functionality
-rwxr-xr-xconfigure2
-rw-r--r--configure.ac2
-rw-r--r--libsylph/Makefile.am2
-rw-r--r--libsylph/Makefile.in7
-rw-r--r--libsylph/account.c49
-rw-r--r--libsylph/masterpassword.c100
-rw-r--r--libsylph/masterpassword.h38
-rw-r--r--libsylph/utils.c30
-rw-r--r--libsylph/utils.h7
-rw-r--r--src/inputdialog.c38
-rw-r--r--src/inputdialog.h3
-rw-r--r--src/main.c2
12 files changed, 233 insertions, 47 deletions
diff --git a/configure b/configure
index cc2b770..6984cce 100755
--- a/configure
+++ b/configure
@@ -2581,7 +2581,7 @@ MINOR_VERSION=7
2581MICRO_VERSION=0 2581MICRO_VERSION=0
2582INTERFACE_AGE=0 2582INTERFACE_AGE=0
2583BINARY_AGE=0 2583BINARY_AGE=0
2584EXTRA_VERSION=-sgs 2584EXTRA_VERSION=
2585BUILD_REVISION=1185 2585BUILD_REVISION=1185
2586VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION 2586VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
2587 2587
diff --git a/configure.ac b/configure.ac
index ae65343..090177d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,7 +9,7 @@ MINOR_VERSION=7
9MICRO_VERSION=0 9MICRO_VERSION=0
10INTERFACE_AGE=0 10INTERFACE_AGE=0
11BINARY_AGE=0 11BINARY_AGE=0
12EXTRA_VERSION=-sgs 12EXTRA_VERSION=
13BUILD_REVISION=1185 13BUILD_REVISION=1185
14VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION 14VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
15 15
diff --git a/libsylph/Makefile.am b/libsylph/Makefile.am
index 8f2b76b..40d26a9 100644
--- a/libsylph/Makefile.am
+++ b/libsylph/Makefile.am
@@ -19,6 +19,7 @@ libsylph_0_la_SOURCES = \
19 folder.c \ 19 folder.c \
20 html.c \ 20 html.c \
21 imap.c \ 21 imap.c \
22 masterpassword.c \
22 mbox.c \ 23 mbox.c \
23 md5.c \ 24 md5.c \
24 md5_hmac.c \ 25 md5_hmac.c \
@@ -62,6 +63,7 @@ libsylph_0include_HEADERS = \
62 folder.h \ 63 folder.h \
63 html.h \ 64 html.h \
64 imap.h \ 65 imap.h \
66 masterpassword.h \
65 mbox.h \ 67 mbox.h \
66 md5.h \ 68 md5.h \
67 md5_hmac.h \ 69 md5_hmac.h \
diff --git a/libsylph/Makefile.in b/libsylph/Makefile.in
index 6e3c999..ac8fefd 100644
--- a/libsylph/Makefile.in
+++ b/libsylph/Makefile.in
@@ -129,8 +129,8 @@ libsylph_0_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
129 $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) 129 $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
130am_libsylph_0_la_OBJECTS = account.lo base64.lo codeconv.lo \ 130am_libsylph_0_la_OBJECTS = account.lo base64.lo codeconv.lo \
131 customheader.lo displayheader.lo filter.lo folder.lo html.lo \ 131 customheader.lo displayheader.lo filter.lo folder.lo html.lo \
132 imap.lo mbox.lo md5.lo md5_hmac.lo mh.lo news.lo nntp.lo \ 132 imap.lo masterpassword.lo mbox.lo md5.lo md5_hmac.lo mh.lo news.lo \
133 pop.lo prefs.lo prefs_account.lo prefs_common.lo procheader.lo \ 133 nntp.lo pop.lo prefs.lo prefs_account.lo prefs_common.lo procheader.lo \
134 procmime.lo procmsg.lo quoted-printable.lo recv.lo session.lo \ 134 procmime.lo procmsg.lo quoted-printable.lo recv.lo session.lo \
135 smtp.lo socket.lo socks.lo ssl.lo ssl_hostname_validation.lo \ 135 smtp.lo socket.lo socks.lo ssl.lo ssl_hostname_validation.lo \
136 stringtable.lo sylmain.lo unmime.lo utils.lo uuencode.lo \ 136 stringtable.lo sylmain.lo unmime.lo utils.lo uuencode.lo \
@@ -402,6 +402,7 @@ libsylph_0_la_SOURCES = \
402 folder.c \ 402 folder.c \
403 html.c \ 403 html.c \
404 imap.c \ 404 imap.c \
405 masterpassword.c \
405 mbox.c \ 406 mbox.c \
406 md5.c \ 407 md5.c \
407 md5_hmac.c \ 408 md5_hmac.c \
@@ -445,6 +446,7 @@ libsylph_0include_HEADERS = \
445 folder.h \ 446 folder.h \
446 html.h \ 447 html.h \
447 imap.h \ 448 imap.h \
449 masterpassword.h \
448 mbox.h \ 450 mbox.h \
449 md5.h \ 451 md5.h \
450 md5_hmac.h \ 452 md5_hmac.h \
@@ -579,6 +581,7 @@ distclean-compile:
579@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/folder.Plo@am__quote@ 581@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/folder.Plo@am__quote@
580@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/html.Plo@am__quote@ 582@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/html.Plo@am__quote@
581@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap.Plo@am__quote@ 583@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imap.Plo@am__quote@
584@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/masterpassword.Plo@am__quote@
582@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbox.Plo@am__quote@ 585@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mbox.Plo@am__quote@
583@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Plo@am__quote@ 586@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5.Plo@am__quote@
584@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5_hmac.Plo@am__quote@ 587@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/md5_hmac.Plo@am__quote@
diff --git a/libsylph/account.c b/libsylph/account.c
index e4cb5cc..7440434 100644
--- a/libsylph/account.c
+++ b/libsylph/account.c
@@ -37,7 +37,7 @@
37#include "utils.h" 37#include "utils.h"
38#include "sylmain.h" 38#include "sylmain.h"
39#include "prefs_common.h" 39#include "prefs_common.h"
40#include "ssl.h" 40#include "masterpassword.h"
41 41
42 42
43PrefsAccount *cur_account; 43PrefsAccount *cur_account;
@@ -55,50 +55,17 @@ void account_read_config_all(void)
55 gchar buf[PREFSBUFSIZE]; 55 gchar buf[PREFSBUFSIZE];
56 PrefsAccount *ac_prefs; 56 PrefsAccount *ac_prefs;
57#if USE_SSL 57#if USE_SSL
58 guint cnt;
59 gchar *master_password, *master_password_confirm;
60 if (prefs_common.use_master_password) { 58 if (prefs_common.use_master_password) {
61 if (prefs_common.master_password_hash != NULL) { 59 if (prefs_common.master_password_hash != NULL) {
62 for (cnt = 0; cnt < 3; ++cnt) { 60 /* allow 3 attempts to enter the master password */
63 /* allow 3 attempts to enter the master password */ 61 if (check_master_password_interactively(3) != 0) {
64 master_password = input_query_password(_("Sylpheed"), 62 /* master password does not match the hash */
65 _("Master password")); 63 g_free(master_password);
66 if (check_password( 64 master_password = NULL;
67 master_password, 65 }
68 prefs_common.master_password_hash) == RC_OK) {
69 break;
70 }
71 debug_print(_("Wrong master password entered (%d)\n"), cnt);
72 g_free(master_password);
73 master_password = NULL;
74 }
75 } else { 66 } else {
76 /* No master password set (no master_password_hash) */ 67 /* No master password set (no master_password_hash) */
77 for (cnt = 0; cnt < 3; ++cnt) { 68 set_master_password_interactively(3);
78 master_password = input_query_password(_("Sylpheed"),
79 _("Master password"));
80 master_password_confirm = input_query_password(
81 _("Sylpheed"),
82 _("Master password confirmation"));
83 if (strcmp(master_password, master_password_confirm) == 0) {
84 /* The passwords match */
85 g_free(master_password_confirm);
86 if (generate_password_hash(
87 &prefs_common.master_password_hash,
88 master_password,
89 NULL) != RC_OK) {
90 debug_print(
91 _("Could not generate master password hash"));
92 g_free(master_password);
93 continue;
94 }
95 prefs_common_write_config();
96 break;
97 }
98 g_free(master_password);
99 g_free(master_password_confirm);
100 master_password = NULL;
101 }
102 } 69 }
103 /* TODO: Warning if password is NULL */ 70 /* TODO: Warning if password is NULL */
104 } else { 71 } else {
diff --git a/libsylph/masterpassword.c b/libsylph/masterpassword.c
new file mode 100644
index 0000000..ee443aa
--- /dev/null
+++ b/libsylph/masterpassword.c
@@ -0,0 +1,100 @@
1/*
2 * LibSylph -- E-Mail client library
3 * Copyright (C) 1999-2018 Hiroyuki Yamamoto
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include "prefs_common.h"
25#include "ssl.h"
26#include "utils.h"
27
28
29gchar *master_password;
30
31void set_master_password(const char *password) {
32 master_password = password;
33}
34
35gchar *get_master_password(void) {
36 return master_password;
37}
38
39#if USE_SSL
40
41gint set_master_password_interactively(guint max_attempts) {
42
43 if (master_password != NULL)
44 return 0; /* master_password already set */
45
46 master_password = input_set_new_password(max_attempts);
47
48 if (master_password == NULL)
49 return 1;
50
51 if (generate_password_hash(
52 &prefs_common.master_password_hash,
53 master_password,
54 NULL) != RC_OK) {
55 /* should not really happen unless buggy code / library */
56 g_free(prefs_common.master_password_hash);
57 prefs_common.master_password_hash = NULL;
58 debug_print(_("Could not generate master password hash"));
59 return 1;
60 }
61
62 prefs_common_write_config();
63 return 0;
64
65}
66
67gint check_master_password_interactively(guint max_attempts) {
68
69 guint cnt;
70
71 if (max_attempts < 1)
72 return 1;
73
74 if (prefs_common.master_password_hash != NULL) {
75 return 1;
76 }
77
78 if (master_password != NULL) {
79 /* password already cached */
80 return check_password(master_password,
81 prefs_common.master_password_hash);
82 }
83
84 for (cnt = 0; cnt < max_attempts; ++cnt) {
85 master_password = input_query_master_password();
86 if (check_password(master_password,
87 prefs_common.master_password_hash) == RC_OK) {
88 return RC_OK; /* match */
89 }
90 debug_print(_("Wrong master password entered (%d)\n"), cnt);
91 /* TODO: clear before free? */
92 g_free(master_password);
93 master_password = NULL;
94 }
95
96 return 1; /* no match */
97
98}
99
100#endif /* USE_SSL */
diff --git a/libsylph/masterpassword.h b/libsylph/masterpassword.h
new file mode 100644
index 0000000..b2798ce
--- /dev/null
+++ b/libsylph/masterpassword.h
@@ -0,0 +1,38 @@
1/*
2 * LibSylph -- E-Mail client library
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef __MASTERPASSWORD_H__
21#define __MASTERPASSWORD_H__
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27extern gchar *master_password;
28void set_master_password(const char *password);
29gchar *get_master_password(void);
30
31#if USE_SSL
32
33gint set_master_password_interactively(guint max_attempts);
34gint check_master_password_interactively(guint max_attempts);
35
36#endif /* USE_SSL */
37
38#endif /* __MASTERPASSWORD_H__ */
diff --git a/libsylph/utils.c b/libsylph/utils.c
index 6ecf328..3bbcbcf 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -4598,6 +4598,36 @@ gchar *input_query_password(const gchar *server, const gchar *user)
4598 return NULL; 4598 return NULL;
4599} 4599}
4600 4600
4601static QueryMasterPasswordFunc query_master_password_func = NULL;
4602
4603void set_input_query_master_password_func(QueryMasterPasswordFunc func)
4604{
4605 query_master_password_func = func;
4606}
4607
4608gchar *input_query_master_password(void)
4609{
4610 if (query_master_password_func)
4611 return query_master_password_func();
4612 else
4613 return NULL;
4614}
4615
4616static SetNewPasswordFunc set_new_password_func = NULL;
4617
4618void set_input_set_new_password_func(SetNewPasswordFunc func)
4619{
4620 set_new_password_func = func;
4621}
4622
4623gchar *input_set_new_password(guint max_attempts)
4624{
4625 if (set_new_password_func)
4626 return set_new_password_func(max_attempts);
4627 else
4628 return NULL;
4629}
4630
4601/* logging */ 4631/* logging */
4602 4632
4603static FILE *log_fp = NULL; 4633static FILE *log_fp = NULL;
diff --git a/libsylph/utils.h b/libsylph/utils.h
index 9ac65cf..ede55ff 100644
--- a/libsylph/utils.h
+++ b/libsylph/utils.h
@@ -202,6 +202,8 @@ typedef void (*ProgressFunc) (gint cur,
202 gint total); 202 gint total);
203typedef gchar * (*QueryPasswordFunc) (const gchar *server, 203typedef gchar * (*QueryPasswordFunc) (const gchar *server,
204 const gchar *user); 204 const gchar *user);
205typedef gchar * (*QueryMasterPasswordFunc) (void);
206typedef gchar * (*SetNewPasswordFunc) (guint max_attempts);
205typedef void (*LogFunc) (const gchar *str); 207typedef void (*LogFunc) (const gchar *str);
206typedef void (*LogFlushFunc) (void); 208typedef void (*LogFlushFunc) (void);
207 209
@@ -560,9 +562,12 @@ void progress_show (gint cur,
560 562
561/* user input */ 563/* user input */
562void set_input_query_password_func (QueryPasswordFunc func); 564void set_input_query_password_func (QueryPasswordFunc func);
563
564gchar *input_query_password (const gchar *server, 565gchar *input_query_password (const gchar *server,
565 const gchar *user); 566 const gchar *user);
567void set_input_query_master_password_func(QueryMasterPasswordFunc func);
568gchar *input_query_master_password(void);
569void set_input_set_new_password_func(SetNewPasswordFunc func);
570gchar *input_set_new_password(guint max_attempts);
566 571
567/* logging */ 572/* logging */
568void set_log_file (const gchar *filename); 573void set_log_file (const gchar *filename);
diff --git a/src/inputdialog.c b/src/inputdialog.c
index a601085..d17b852 100644
--- a/src/inputdialog.c
+++ b/src/inputdialog.c
@@ -156,6 +156,44 @@ gchar *input_dialog_query_password(const gchar *server, const gchar *user)
156 return pass; 156 return pass;
157} 157}
158 158
159gchar *input_dialog_query_master_password(void)
160{
161 return input_dialog_with_invisible(_("Input password"),
162 _("Master password"),
163 NULL);
164}
165
166gchar *input_dialog_set_new_password(guint max_attempts)
167{
168 guint cnt;
169 gchar *pass1, *pass2;
170
171 if (max_attempts < 1)
172 return NULL;
173
174 for (cnt = 0; cnt < max_attempts; ++cnt) {
175 pass1 = input_dialog_with_invisible(
176 _("Input password"),
177 _("New password"),
178 NULL);
179 pass2 = input_dialog_with_invisible(
180 _("Input password"),
181 _("Confirm new password"),
182 NULL);
183 if (strcmp(pass1, pass2) == 0) {
184 /* TODO: clear before free? */
185 g_free(pass2);
186 break;
187 }
188 /* TODO: clear before free? */
189 g_free(pass2);
190 g_free(pass1);
191 pass1 = NULL;
192 }
193
194 return pass1;
195}
196
159gchar *input_dialog_with_filesel(const gchar *title, const gchar *message, 197gchar *input_dialog_with_filesel(const gchar *title, const gchar *message,
160 const gchar *default_string, 198 const gchar *default_string,
161 GtkFileChooserAction action) 199 GtkFileChooserAction action)
diff --git a/src/inputdialog.h b/src/inputdialog.h
index 02bdda3..5364d1a 100644
--- a/src/inputdialog.h
+++ b/src/inputdialog.h
@@ -36,7 +36,8 @@ gchar *input_dialog_combo (const gchar *title,
36 gboolean case_sensitive); 36 gboolean case_sensitive);
37gchar *input_dialog_query_password (const gchar *server, 37gchar *input_dialog_query_password (const gchar *server,
38 const gchar *user); 38 const gchar *user);
39 39gchar *input_dialog_query_master_password(void);
40gchar *input_dialog_set_new_password(guint max_attempts);
40gchar *input_dialog_with_filesel (const gchar *title, 41gchar *input_dialog_with_filesel (const gchar *title,
41 const gchar *message, 42 const gchar *message,
42 const gchar *default_string, 43 const gchar *default_string,
diff --git a/src/main.c b/src/main.c
index 77d8192..be8ea54 100644
--- a/src/main.c
+++ b/src/main.c
@@ -265,9 +265,11 @@ int main(int argc, char *argv[])
265 set_ui_update_func(gtkut_events_flush); 265 set_ui_update_func(gtkut_events_flush);
266 set_progress_func(main_window_progress_show); 266 set_progress_func(main_window_progress_show);
267 set_input_query_password_func(input_dialog_query_password); 267 set_input_query_password_func(input_dialog_query_password);
268 set_input_set_new_password_func(input_dialog_set_new_password);
268#if USE_SSL 269#if USE_SSL
269 ssl_init(); 270 ssl_init();
270 ssl_set_verify_func(ssl_manager_verify_cert); 271 ssl_set_verify_func(ssl_manager_verify_cert);
272 set_input_query_master_password_func(input_dialog_query_master_password);
271#endif 273#endif
272 274
273 CHDIR_EXIT_IF_FAIL(get_home_dir(), 1); 275 CHDIR_EXIT_IF_FAIL(get_home_dir(), 1);