diff options
Diffstat (limited to 'libsylph/masterpassword.c')
| -rw-r--r-- | libsylph/masterpassword.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/libsylph/masterpassword.c b/libsylph/masterpassword.c index 8174def..bac49c4 100644 --- a/libsylph/masterpassword.c +++ b/libsylph/masterpassword.c | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | * | 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, | 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. | 13 | * Lesser General Public License for more details. |
| 14 | * | 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public | 15 | * You should have received a copy of the GNU Lesser General Public |
| @@ -30,6 +30,7 @@ | |||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | gchar *master_password; | 32 | gchar *master_password; |
| 33 | gboolean master_password_enabled_on_init; | ||
| 33 | 34 | ||
| 34 | void set_master_password(const char *password) { | 35 | void set_master_password(const char *password) { |
| 35 | master_password = password; | 36 | master_password = password; |
| @@ -91,7 +92,7 @@ gchar *decrypt_with_master_password(const gchar *str) { | |||
| 91 | if (master_password == NULL) { | 92 | if (master_password == NULL) { |
| 92 | /* we have empty or auto unloaded master password */ | 93 | /* we have empty or auto unloaded master password */ |
| 93 | if ((!prefs_common.auto_unload_master_password) || | 94 | if ((!prefs_common.auto_unload_master_password) || |
| 94 | (check_master_password_interactively(3) != RC_OK)) { | 95 | (check_master_password_interactively(3) != MP_RC_OK)) { |
| 95 | return g_strdup(str); | 96 | return g_strdup(str); |
| 96 | } | 97 | } |
| 97 | debug_print("Reloaded master password\n"); | 98 | debug_print("Reloaded master password\n"); |
| @@ -104,7 +105,7 @@ gchar *decrypt_with_master_password(const gchar *str) { | |||
| 104 | if (decrypt_data(&new_str, | 105 | if (decrypt_data(&new_str, |
| 105 | str + str_prefix, | 106 | str + str_prefix, |
| 106 | master_password, | 107 | master_password, |
| 107 | strlen(str) - str_prefix) != RC_OK) { | 108 | strlen(str) - str_prefix) != MP_RC_OK) { |
| 108 | OPENSSL_cleanse(new_str, strlen(new_str)); | 109 | OPENSSL_cleanse(new_str, strlen(new_str)); |
| 109 | g_free(new_str); | 110 | g_free(new_str); |
| 110 | return g_strdup(str); | 111 | return g_strdup(str); |
| @@ -123,17 +124,13 @@ gchar *encrypt_with_master_password(const gchar *str) { | |||
| 123 | gchar *new_str, *mpes1_str; | 124 | gchar *new_str, *mpes1_str; |
| 124 | gint length_encrypted; | 125 | gint length_encrypted; |
| 125 | 126 | ||
| 126 | if ((!str) || (!prefs_common.use_master_password)) | 127 | if ((!str) || (!master_password_active())) |
| 127 | return g_strdup(str); | 128 | return NULL; |
| 128 | 129 | ||
| 129 | if (master_password == NULL) { | 130 | /* |
| 130 | /* we have empty or auto unloaded master password */ | 131 | * unlike the decrypt function, here it is up to the caller |
| 131 | if ((!prefs_common.auto_unload_master_password) || | 132 | * to make sure that auto unloaded master password is handled properly |
| 132 | (check_master_password_interactively(3) != RC_OK)) { | 133 | */ |
| 133 | return g_strdup(str); | ||
| 134 | } | ||
| 135 | debug_print("Reloaded master password\n"); | ||
| 136 | } | ||
| 137 | 134 | ||
| 138 | if (encrypt_data(&new_str, | 135 | if (encrypt_data(&new_str, |
| 139 | &length_encrypted, | 136 | &length_encrypted, |
| @@ -141,19 +138,17 @@ gchar *encrypt_with_master_password(const gchar *str) { | |||
| 141 | master_password, | 138 | master_password, |
| 142 | strlen(str), | 139 | strlen(str), |
| 143 | prefs_common.encrypted_password_min_length, | 140 | prefs_common.encrypted_password_min_length, |
| 144 | TRUE) != RC_OK) { | 141 | TRUE) != MP_RC_OK) { |
| 145 | OPENSSL_cleanse(new_str, strlen(new_str)); | ||
| 146 | g_free(new_str); | 142 | g_free(new_str); |
| 147 | return g_strdup(str); | 143 | return NULL; |
| 148 | } | 144 | } |
| 149 | 145 | ||
| 150 | mpes1_str = g_strdup_printf("mpes1:%s", new_str); | 146 | mpes1_str = g_strdup_printf("mpes1:%s", new_str); |
| 151 | OPENSSL_cleanse(new_str, strlen(new_str)); | ||
| 152 | g_free(new_str); | 147 | g_free(new_str); |
| 153 | 148 | ||
| 154 | return mpes1_str; | 149 | return mpes1_str; |
| 155 | #else | 150 | #else |
| 156 | return g_strdup(str); | 151 | return NULL; |
| 157 | #endif | 152 | #endif |
| 158 | 153 | ||
| 159 | } | 154 | } |
| @@ -170,7 +165,7 @@ gint set_master_password_interactively(guint max_attempts) { | |||
| 170 | if (generate_password_hash( | 165 | if (generate_password_hash( |
| 171 | &prefs_common.master_password_hash, | 166 | &prefs_common.master_password_hash, |
| 172 | master_password, | 167 | master_password, |
| 173 | NULL) != RC_OK) { | 168 | NULL) != MP_RC_OK) { |
| 174 | /* should not really happen unless buggy code / library */ | 169 | /* should not really happen unless buggy code / library */ |
| 175 | g_free(prefs_common.master_password_hash); | 170 | g_free(prefs_common.master_password_hash); |
| 176 | prefs_common.master_password_hash = NULL; | 171 | prefs_common.master_password_hash = NULL; |
| @@ -204,8 +199,8 @@ gint check_master_password_interactively(guint max_attempts) { | |||
| 204 | continue; | 199 | continue; |
| 205 | } | 200 | } |
| 206 | if (check_password(master_password, | 201 | if (check_password(master_password, |
| 207 | prefs_common.master_password_hash) == RC_OK) { | 202 | prefs_common.master_password_hash) == MP_RC_OK) { |
| 208 | return RC_OK; /* match */ | 203 | return MP_RC_OK; /* match */ |
| 209 | } | 204 | } |
| 210 | debug_print(_("Wrong master password entered (%d)\n"), cnt); | 205 | debug_print(_("Wrong master password entered (%d)\n"), cnt); |
| 211 | OPENSSL_cleanse(master_password, strlen(master_password)); | 206 | OPENSSL_cleanse(master_password, strlen(master_password)); |
