diff options
| author | Simeon Simeonov | 2018-03-07 09:20:45 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2018-03-07 09:20:45 +0100 |
| commit | 50ad277f9a7cbc3d2dc5b6b9ab80a49b88ea3d80 (patch) | |
| tree | 2a29abd12f5d5ca2e77087ed7aad0c085cf2ebbc | |
| parent | 8c56039d67bd910a334b2ddd009c6df4bb01cc8b (diff) | |
Master password hash (read and write) implemented
| -rw-r--r-- | libsylph/account.c | 46 | ||||
| -rw-r--r-- | libsylph/prefs_common.c | 2 | ||||
| -rw-r--r-- | libsylph/prefs_common.h | 1 | ||||
| -rw-r--r-- | libsylph/ssl.c | 8 |
4 files changed, 51 insertions, 6 deletions
diff --git a/libsylph/account.c b/libsylph/account.c index 95d19fc..05d5871 100644 --- a/libsylph/account.c +++ b/libsylph/account.c | |||
| @@ -37,6 +37,8 @@ | |||
| 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" | ||
| 41 | |||
| 40 | 42 | ||
| 41 | PrefsAccount *cur_account; | 43 | PrefsAccount *cur_account; |
| 42 | 44 | ||
| @@ -53,9 +55,49 @@ void account_read_config_all(void) | |||
| 53 | gchar buf[PREFSBUFSIZE]; | 55 | gchar buf[PREFSBUFSIZE]; |
| 54 | PrefsAccount *ac_prefs; | 56 | PrefsAccount *ac_prefs; |
| 55 | #if USE_SSL | 57 | #if USE_SSL |
| 56 | gchar *master_password; | 58 | guint cnt; |
| 59 | gchar *master_password, *master_password_confirm; | ||
| 57 | if (prefs_common.use_master_password) { | 60 | if (prefs_common.use_master_password) { |
| 58 | master_password = input_query_password("Sylpheed", "Master password"); | 61 | if (prefs_common.master_password_hash != NULL) { |
| 62 | for (cnt = 0; cnt < 3; ++cnt) { | ||
| 63 | /* allow 3 attempts to enter the master password */ | ||
| 64 | master_password = input_query_password(_("Sylpheed"), | ||
| 65 | _("Master password")); | ||
| 66 | if (check_password( | ||
| 67 | master_password, | ||
| 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 | /* TODO: Warning if password is NULL */ | ||
| 76 | } else { | ||
| 77 | /* No master password set (no master_password_hash) */ | ||
| 78 | for (cnt = 0; cnt < 3; ++cnt) { | ||
| 79 | master_password = input_query_password(_("Sylpheed"), | ||
| 80 | _("Master password")); | ||
| 81 | master_password_confirm = input_query_password( | ||
| 82 | _("Sylpheed"), | ||
| 83 | _("Master password confirmation")); | ||
| 84 | if (strcmp(master_password, master_password_confirm) == 0) { | ||
| 85 | /* The passwords match */ | ||
| 86 | g_free(master_password_confirm); | ||
| 87 | if (generate_password_hash( | ||
| 88 | &prefs_common.master_password_hash, | ||
| 89 | master_password, | ||
| 90 | NULL) != RC_OK) { | ||
| 91 | debug_print( | ||
| 92 | _("Could not generate master password hash")); | ||
| 93 | g_free(master_password); | ||
| 94 | continue; | ||
| 95 | } | ||
| 96 | prefs_common_write_config(); | ||
| 97 | break; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 59 | } else { | 101 | } else { |
| 60 | master_password = NULL; | 102 | master_password = NULL; |
| 61 | } | 103 | } |
diff --git a/libsylph/prefs_common.c b/libsylph/prefs_common.c index 1f1d3e2..6c20319 100644 --- a/libsylph/prefs_common.c +++ b/libsylph/prefs_common.c | |||
| @@ -421,6 +421,8 @@ static PrefParam param[] = { | |||
| 421 | /* Master password */ | 421 | /* Master password */ |
| 422 | {"use_master_password", "FALSE", &prefs_common.use_master_password, | 422 | {"use_master_password", "FALSE", &prefs_common.use_master_password, |
| 423 | P_BOOL}, | 423 | P_BOOL}, |
| 424 | {"master_password_hash", NULL, &prefs_common.master_password_hash, | ||
| 425 | P_STRING}, | ||
| 424 | 426 | ||
| 425 | /* Interface */ | 427 | /* Interface */ |
| 426 | {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL}, | 428 | {"separate_folder", "FALSE", &prefs_common.sep_folder, P_BOOL}, |
diff --git a/libsylph/prefs_common.h b/libsylph/prefs_common.h index ef5bb9b..bc1d2f3 100644 --- a/libsylph/prefs_common.h +++ b/libsylph/prefs_common.h | |||
| @@ -251,6 +251,7 @@ struct _PrefsCommon | |||
| 251 | 251 | ||
| 252 | /* Master password */ | 252 | /* Master password */ |
| 253 | gboolean use_master_password; | 253 | gboolean use_master_password; |
| 254 | gchar *master_password_hash; | ||
| 254 | 255 | ||
| 255 | /* Interface */ | 256 | /* Interface */ |
| 256 | gboolean sep_folder; | 257 | gboolean sep_folder; |
diff --git a/libsylph/ssl.c b/libsylph/ssl.c index 21686e1..5042f74 100644 --- a/libsylph/ssl.c +++ b/libsylph/ssl.c | |||
| @@ -794,7 +794,7 @@ gint generate_password_hash(gchar **password_hash, | |||
| 794 | 794 | ||
| 795 | if (salt == NULL) { | 795 | if (salt == NULL) { |
| 796 | if (RAND_bytes(lsalt, SALT_SIZE) != 1) { | 796 | if (RAND_bytes(lsalt, SALT_SIZE) != 1) { |
| 797 | g_fprintf(stderr, "Random problems...\n"); | 797 | debug_print("Random problems...\n"); |
| 798 | return RC_ERROR; | 798 | return RC_ERROR; |
| 799 | } | 799 | } |
| 800 | } else { | 800 | } else { |
| @@ -850,18 +850,18 @@ gint check_password(const gchar *password, const gchar *password_hash) { | |||
| 850 | } | 850 | } |
| 851 | 851 | ||
| 852 | if (token_counter != 4) { | 852 | if (token_counter != 4) { |
| 853 | g_fprintf(stderr, "Invalid password hash...\n"); | 853 | debug_print("Invalid password hash...\n"); |
| 854 | goto cleanup; | 854 | goto cleanup; |
| 855 | } | 855 | } |
| 856 | 856 | ||
| 857 | salt = g_base64_decode(*(tokens + 2), &salt_length); | 857 | salt = g_base64_decode(*(tokens + 2), &salt_length); |
| 858 | if (salt_length != SALT_SIZE) { | 858 | if (salt_length != SALT_SIZE) { |
| 859 | g_fprintf(stderr, "Salt size does not match\n"); | 859 | debug_print("Salt size does not match\n"); |
| 860 | goto cleanup; | 860 | goto cleanup; |
| 861 | } | 861 | } |
| 862 | 862 | ||
| 863 | if (generate_password_hash(&new_hash, password, salt) != RC_OK) { | 863 | if (generate_password_hash(&new_hash, password, salt) != RC_OK) { |
| 864 | g_fprintf(stderr, "Password hash generation failed\n"); | 864 | debug_print("Password hash generation failed\n"); |
| 865 | goto cleanup; | 865 | goto cleanup; |
| 866 | } | 866 | } |
| 867 | 867 | ||
