6cef02128cff31f11c5072abe5cdbe5c0485c6d7
[claws.git] / src / password.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2016 The Claws Mail Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #ifdef PASSWORD_CRYPTO_GNUTLS
26 # include <gnutls/gnutls.h>
27 # include <gnutls/crypto.h>
28 #endif
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32
33 #if defined G_OS_UNIX
34 #include <fcntl.h>
35 #include <unistd.h>
36 #elif defined G_OS_WIN32
37 #include <windows.h>
38 #include <wincrypt.h>
39 #endif
40
41 #include "common/passcrypt.h"
42 #include "common/plugin.h"
43 #include "common/pkcs5_pbkdf2.h"
44 #include "common/timing.h"
45 #include "common/utils.h"
46 #include "account.h"
47 #include "alertpanel.h"
48 #include "inputdialog.h"
49 #include "password.h"
50 #include "passwordstore.h"
51 #include "prefs_common.h"
52
53 #ifndef PASSWORD_CRYPTO_OLD
54 static gchar *_master_passphrase = NULL;
55
56 /* Length of stored key derivation, before base64. */
57 #define KD_LENGTH 64
58
59 /* Length of randomly generated and saved salt, used for key derivation.
60  * Also before base64. */
61 #define KD_SALT_LENGTH 64
62
63 static void _generate_salt()
64 {
65 #if defined G_OS_UNIX
66         int rnd;
67 #elif defined G_OS_WIN32
68         HCRYPTPROV rnd;
69 #endif
70         gint ret;
71         guchar salt[KD_SALT_LENGTH];
72
73         if (prefs_common_get_prefs()->master_passphrase_salt != NULL) {
74                 g_free(prefs_common_get_prefs()->master_passphrase_salt);
75         }
76
77         /* Prepare our source of random data. */
78 #if defined G_OS_UNIX
79         rnd = open("/dev/urandom", O_RDONLY);
80         if (rnd == -1) {
81                 perror("fopen on /dev/urandom");
82 #elif defined G_OS_WIN32
83         if (!CryptAcquireContext(&rnd, NULL, NULL, PROV_RSA_FULL, 0) &&
84                         !CryptAcquireContext(&rnd, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
85                 debug_print("Could not acquire a CSP handle.\n");
86 #endif
87                 return;
88         }
89
90 #if defined G_OS_UNIX
91         ret = read(rnd, salt, KD_SALT_LENGTH);
92         if (ret != KD_SALT_LENGTH) {
93                 perror("read into salt");
94                 close(rnd);
95 #elif defined G_OS_WIN32
96         if (!CryptGenRandom(rnd, KD_SALT_LENGTH, salt)) {
97                 debug_print("Could not read random data for salt\n");
98                 CryptReleaseContext(rnd, 0);
99 #endif
100                 return;
101         }
102
103 #if defined G_OS_UNIX
104         close(rnd);
105 #elif defined G_OS_WIN32
106         CryptReleaseContext(rnd, 0);
107 #endif
108
109         prefs_common_get_prefs()->master_passphrase_salt =
110                 g_base64_encode(salt, KD_SALT_LENGTH);
111 }
112
113 #undef KD_SALT_LENGTH
114
115 static guchar *_make_key_deriv(const gchar *passphrase, guint rounds)
116 {
117         guchar *kd, *salt;
118         gchar *saltpref = prefs_common_get_prefs()->master_passphrase_salt;
119         gsize saltlen;
120         gint ret;
121
122         /* Grab our salt, generating and saving a new random one if needed. */
123         if (saltpref == NULL || strlen(saltpref) == 0) {
124                 _generate_salt();
125                 saltpref = prefs_common_get_prefs()->master_passphrase_salt;
126         }
127         salt = g_base64_decode(saltpref, &saltlen);
128         kd = g_malloc0(KD_LENGTH);
129
130         START_TIMING("PBKDF2");
131         ret = pkcs5_pbkdf2(passphrase, strlen(passphrase), salt, saltlen,
132                         kd, KD_LENGTH, rounds);
133         END_TIMING();
134
135         g_free(salt);
136
137         if (ret == 0) {
138                 return kd;
139         }
140
141         g_free(kd);
142         return NULL;
143 }
144
145 static const gchar *master_passphrase()
146 {
147         gchar *input;
148         gboolean end = FALSE;
149
150         if (!prefs_common_get_prefs()->use_master_passphrase) {
151                 return PASSCRYPT_KEY;
152         }
153
154         if (_master_passphrase != NULL) {
155                 debug_print("Master passphrase is in memory, offering it.\n");
156                 return _master_passphrase;
157         }
158
159         while (!end) {
160                 input = input_dialog_with_invisible(_("Input master passphrase"),
161                                 _("Input master passphrase"), NULL);
162
163                 if (input == NULL) {
164                         debug_print("Cancel pressed at master passphrase dialog.\n");
165                         break;
166                 }
167
168                 if (master_passphrase_is_correct(input)) {
169                         debug_print("Entered master passphrase seems to be correct, remembering it.\n");
170                         _master_passphrase = input;
171                         end = TRUE;
172                 } else {
173                         alertpanel_error(_("Incorrect master passphrase."));
174                 }
175         }
176
177         return _master_passphrase;
178 }
179
180 const gboolean master_passphrase_is_set()
181 {
182         if (prefs_common_get_prefs()->master_passphrase == NULL
183                         || strlen(prefs_common_get_prefs()->master_passphrase) == 0)
184                 return FALSE;
185
186         return TRUE;
187 }
188
189 const gboolean master_passphrase_is_correct(const gchar *input)
190 {
191         guchar *kd, *input_kd;
192         gchar **tokens;
193         gchar *stored_kd = prefs_common_get_prefs()->master_passphrase;
194         gsize kd_len;
195         guint rounds = 0;
196         gint ret;
197
198         g_return_val_if_fail(stored_kd != NULL && strlen(stored_kd) > 0, FALSE);
199         g_return_val_if_fail(input != NULL, FALSE);
200
201         if (stored_kd == NULL)
202                 return FALSE;
203
204         tokens = g_strsplit_set(stored_kd, "{}", 3);
205         if (tokens[0] == NULL ||
206                         strlen(tokens[0]) != 0 || /* nothing before { */
207                         tokens[1] == NULL ||
208                         strncmp(tokens[1], "PBKDF2-HMAC-SHA1,", 17) || /* correct tag */
209                         strlen(tokens[1]) <= 17 || /* something after , */
210                         (rounds = atoi(tokens[1] + 17)) <= 0 || /* valid rounds # */
211                         tokens[2] == NULL ||
212                         strlen(tokens[2]) == 0) { /* string continues after } */
213                 debug_print("Mangled master_passphrase format in config, can not use it.\n");
214                 g_strfreev(tokens);
215                 return FALSE;
216         }
217
218         stored_kd = tokens[2];
219         kd = g_base64_decode(stored_kd, &kd_len); /* should be 64 */
220         g_strfreev(tokens);
221
222         if (kd_len != KD_LENGTH) {
223                 debug_print("master_passphrase is %ld bytes long, should be %d.\n",
224                                 kd_len, KD_LENGTH);
225                 g_free(kd);
226                 return FALSE;
227         }
228
229         input_kd = _make_key_deriv(input, rounds);
230         ret = memcmp(kd, input_kd, kd_len);
231
232         g_free(input_kd);
233         g_free(kd);
234
235         if (ret == 0)
236                 return TRUE;
237
238         return FALSE;
239 }
240
241 gboolean master_passphrase_is_entered()
242 {
243         return (_master_passphrase == NULL) ? FALSE : TRUE;
244 }
245
246 void master_passphrase_forget()
247 {
248         /* If master passphrase is currently in memory (entered by user),
249          * get rid of it. User will have to enter the new one again. */
250         if (_master_passphrase != NULL) {
251                 memset(_master_passphrase, 0, strlen(_master_passphrase));
252                 g_free(_master_passphrase);
253                 _master_passphrase = NULL;
254         }
255 }
256
257 void master_passphrase_change(const gchar *oldp, const gchar *newp)
258 {
259         guchar *kd;
260         gchar *base64_kd;
261         guint rounds = prefs_common_get_prefs()->master_passphrase_pbkdf2_rounds;
262
263         g_return_if_fail(rounds > 0);
264
265         if (oldp == NULL) {
266                 /* If oldp is NULL, make sure the user has to enter the
267                  * current master passphrase before being able to change it. */
268                 master_passphrase_forget();
269                 oldp = master_passphrase();
270         }
271         g_return_if_fail(oldp != NULL);
272
273         /* Update master passphrase hash in prefs */
274         if (prefs_common_get_prefs()->master_passphrase != NULL)
275                 g_free(prefs_common_get_prefs()->master_passphrase);
276
277         if (newp != NULL) {
278                 debug_print("Storing key derivation of new master passphrase\n");
279                 kd = _make_key_deriv(newp, rounds);
280                 base64_kd = g_base64_encode(kd, 64);
281                 prefs_common_get_prefs()->master_passphrase =
282                         g_strdup_printf("{PBKDF2-HMAC-SHA1,%d}%s", rounds, base64_kd);
283                 g_free(kd);
284                 g_free(base64_kd);
285         } else {
286                 debug_print("Setting master_passphrase to NULL\n");
287                 prefs_common_get_prefs()->master_passphrase = NULL;
288         }
289
290         /* Now go over all accounts, reencrypting their passwords using
291          * the new master passphrase. */
292
293         if (oldp == NULL)
294                 oldp = PASSCRYPT_KEY;
295         if (newp == NULL)
296                 newp = PASSCRYPT_KEY;
297
298         debug_print("Reencrypting all account passwords...\n");
299         passwd_store_reencrypt_all(oldp, newp);
300
301         /* Now reencrypt all plugins passwords fields 
302          * FIXME: Unloaded plugins won't be able to update their stored passwords
303          */
304         plugins_master_passphrase_change(oldp, newp);
305
306         master_passphrase_forget();
307 }
308 #endif
309
310 gchar *password_encrypt_old(const gchar *password)
311 {
312         if (!password || strlen(password) == 0) {
313                 return NULL;
314         }
315
316         gchar *encrypted = g_strdup(password);
317         gchar *encoded, *result;
318         gsize len = strlen(password);
319
320         passcrypt_encrypt(encrypted, len);
321         encoded = g_base64_encode(encrypted, len);
322         g_free(encrypted);
323         result = g_strconcat("!", encoded, NULL);
324         g_free(encoded);
325
326         return result;
327 }
328
329 gchar *password_decrypt_old(const gchar *password)
330 {
331         if (!password || strlen(password) == 0) {
332                 return NULL;
333         }
334
335         if (*password != '!' || strlen(password) < 2) {
336                 return NULL;
337         }
338
339         gsize len;
340         gchar *decrypted = g_base64_decode(password + 1, &len);
341
342         passcrypt_decrypt(decrypted, len);
343         return decrypted;
344 }
345
346 #ifdef PASSWORD_CRYPTO_GNUTLS
347 #define BUFSIZE 128
348
349 /* Since we can't count on having GnuTLS new enough to have
350  * gnutls_cipher_get_iv_size(), we hardcode the IV length for now. */
351 #define IVLEN 16
352
353 gchar *password_encrypt_gnutls(const gchar *password,
354                 const gchar *encryption_passphrase)
355 {
356         /* Another, slightly inferior combination is AES-128-CBC + SHA-256.
357          * Any block cipher in CBC mode with keysize N and a hash algo with
358          * digest length 2*N would do. */
359         gnutls_cipher_algorithm_t algo = GNUTLS_CIPHER_AES_256_CBC;
360         gnutls_digest_algorithm_t digest = GNUTLS_DIG_SHA512;
361         gnutls_cipher_hd_t handle;
362         gnutls_datum_t key, iv;
363         int keylen, digestlen, blocklen, ret, i;
364         unsigned char hashbuf[BUFSIZE], *buf, *encbuf, *base, *output;
365 #if defined G_OS_UNIX
366         int rnd;
367 #elif defined G_OS_WIN32
368         HCRYPTPROV rnd;
369 #endif
370
371         g_return_val_if_fail(password != NULL, NULL);
372         g_return_val_if_fail(encryption_passphrase != NULL, NULL);
373
374 /*      ivlen = gnutls_cipher_get_iv_size(algo);*/
375         keylen = gnutls_cipher_get_key_size(algo);
376         blocklen = gnutls_cipher_get_block_size(algo);
377         digestlen = gnutls_hash_get_len(digest);
378
379         /* Prepare key for cipher - first half of hash of passkey XORed with
380          * the second. */
381         memset(&hashbuf, 0, BUFSIZE);
382         if ((ret = gnutls_hash_fast(digest, encryption_passphrase,
383                                         strlen(encryption_passphrase), &hashbuf)) < 0) {
384                 debug_print("Hashing passkey failed: %s\n", gnutls_strerror(ret));
385                 return NULL;
386         }
387         for (i = 0; i < digestlen/2; i++) {
388                 hashbuf[i] = hashbuf[i] ^ hashbuf[i+digestlen/2];
389         }
390
391         key.data = malloc(keylen);
392         memcpy(key.data, &hashbuf, keylen);
393         key.size = keylen;
394
395         /* Prepare our source of random data. */
396 #if defined G_OS_UNIX
397         rnd = open("/dev/urandom", O_RDONLY);
398         if (rnd == -1) {
399                 perror("fopen on /dev/urandom");
400 #elif defined G_OS_WIN32
401         if (!CryptAcquireContext(&rnd, NULL, NULL, PROV_RSA_FULL, 0) &&
402                         !CryptAcquireContext(&rnd, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
403                 debug_print("Could not acquire a CSP handle.\n");
404 #endif
405                 g_free(key.data);
406                 return NULL;
407         }
408
409         /* Prepare random IV for cipher */
410         iv.data = malloc(IVLEN);
411         iv.size = IVLEN;
412 #if defined G_OS_UNIX
413         ret = read(rnd, iv.data, IVLEN);
414         if (ret != IVLEN) {
415                 perror("read into iv");
416                 close(rnd);
417 #elif defined G_OS_WIN32
418         if (!CryptGenRandom(rnd, IVLEN, iv.data)) {
419                 debug_print("Could not read random data for IV\n");
420                 CryptReleaseContext(rnd, 0);
421 #endif
422                 g_free(key.data);
423                 g_free(iv.data);
424                 return NULL;
425         }
426
427         /* Initialize the encryption */
428         ret = gnutls_cipher_init(&handle, algo, &key, &iv);
429         if (ret < 0) {
430                 g_free(key.data);
431                 g_free(iv.data);
432 #if defined G_OS_UNIX
433                 close(rnd);
434 #elif defined G_OS_WIN32
435                 CryptReleaseContext(rnd, 0);
436 #endif
437                 return NULL;
438         }
439
440         /* Fill buf with one block of random data, our password, pad the
441          * rest with zero bytes. */
442         buf = malloc(BUFSIZE + blocklen);
443         memset(buf, 0, BUFSIZE);
444 #if defined G_OS_UNIX
445         ret = read(rnd, buf, blocklen);
446         if (ret != blocklen) {
447                 perror("read into buffer");
448                 close(rnd);
449 #elif defined G_OS_WIN32
450         if (!CryptGenRandom(rnd, blocklen, buf)) {
451                 debug_print("Could not read random data for IV\n");
452                 CryptReleaseContext(rnd, 0);
453 #endif
454                 g_free(buf);
455                 g_free(key.data);
456                 g_free(iv.data);
457                 gnutls_cipher_deinit(handle);
458                 return NULL;
459         }
460
461         /* We don't need any more random data. */
462 #if defined G_OS_UNIX
463         close(rnd);
464 #elif defined G_OS_WIN32
465         CryptReleaseContext(rnd, 0);
466 #endif
467
468         memcpy(buf + blocklen, password, strlen(password));
469
470         /* Encrypt into encbuf */
471         encbuf = malloc(BUFSIZE + blocklen);
472         memset(encbuf, 0, BUFSIZE + blocklen);
473         ret = gnutls_cipher_encrypt2(handle, buf, BUFSIZE + blocklen,
474                         encbuf, BUFSIZE + blocklen);
475         if (ret < 0) {
476                 g_free(key.data);
477                 g_free(iv.data);
478                 g_free(buf);
479                 g_free(encbuf);
480                 gnutls_cipher_deinit(handle);
481                 return NULL;
482         }
483
484         /* Cleanup */
485         gnutls_cipher_deinit(handle);
486         g_free(key.data);
487         g_free(iv.data);
488         g_free(buf);
489
490         /* And finally prepare the resulting string:
491          * "{algorithm}base64encodedciphertext" */
492         base = g_base64_encode(encbuf, BUFSIZE);
493         g_free(encbuf);
494         output = g_strdup_printf("{%s}%s", gnutls_cipher_get_name(algo), base);
495         g_free(base);
496
497         return output;
498 }
499
500 gchar *password_decrypt_gnutls(const gchar *password,
501                 const gchar *decryption_passphrase)
502 {
503         gchar **tokens, *tmp;
504         gnutls_cipher_algorithm_t algo;
505         gnutls_digest_algorithm_t digest = GNUTLS_DIG_UNKNOWN;
506         gnutls_cipher_hd_t handle;
507         gnutls_datum_t key, iv;
508         int keylen, digestlen, blocklen, ret, i;
509         gsize len;
510         unsigned char hashbuf[BUFSIZE], *buf;
511 #if defined G_OS_UNIX
512         int rnd;
513 #elif defined G_OS_WIN32
514         HCRYPTPROV rnd;
515 #endif
516
517         g_return_val_if_fail(password != NULL, NULL);
518         g_return_val_if_fail(decryption_passphrase != NULL, NULL);
519
520         tokens = g_strsplit_set(password, "{}", 3);
521
522         /* Parse the string, retrieving algorithm and encrypted data.
523          * We expect "{algorithm}base64encodedciphertext". */
524         if (strlen(tokens[0]) != 0 ||
525                         (algo = gnutls_cipher_get_id(tokens[1])) == GNUTLS_CIPHER_UNKNOWN ||
526                         strlen(tokens[2]) == 0)
527                 return NULL;
528
529         /* Our hash algo needs to have digest length twice as long as our
530          * cipher algo's key length. */
531         if (algo == GNUTLS_CIPHER_AES_256_CBC) {
532                 debug_print("Using AES-256-CBC + SHA-512 for decryption\n");
533                 digest = GNUTLS_DIG_SHA512;
534         } else if (algo == GNUTLS_CIPHER_AES_128_CBC) {
535                 debug_print("Using AES-128-CBC + SHA-256 for decryption\n");
536                 digest = GNUTLS_DIG_SHA256;
537         }
538         if (digest == GNUTLS_DIG_UNKNOWN) {
539                 debug_print("Password is encrypted with unsupported cipher, giving up.\n");
540                 g_strfreev(tokens);
541                 return NULL;
542         }
543
544 /*      ivlen = gnutls_cipher_get_iv_size(algo); */
545         keylen = gnutls_cipher_get_key_size(algo);
546         blocklen = gnutls_cipher_get_block_size(algo);
547         digestlen = gnutls_hash_get_len(digest);
548
549         /* Prepare key for cipher - first half of hash of passkey XORed with
550          * the second. AES-256 has key length 32 and length of SHA-512 hash
551          * is exactly twice that, 64. */
552         memset(&hashbuf, 0, BUFSIZE);
553         if ((ret = gnutls_hash_fast(digest, decryption_passphrase,
554                                         strlen(decryption_passphrase), &hashbuf)) < 0) {
555                 debug_print("Hashing passkey failed: %s\n", gnutls_strerror(ret));
556                 g_strfreev(tokens);
557                 return NULL;
558         }
559         for (i = 0; i < digestlen/2; i++) {
560                 hashbuf[i] = hashbuf[i] ^ hashbuf[i+digestlen/2];
561         }
562
563         key.data = malloc(keylen);
564         memcpy(key.data, &hashbuf, keylen);
565         key.size = keylen;
566
567         /* Prepare our source of random data. */
568 #if defined G_OS_UNIX
569         rnd = open("/dev/urandom", O_RDONLY);
570         if (rnd == -1) {
571                 perror("fopen on /dev/urandom");
572 #elif defined G_OS_WIN32
573         if (!CryptAcquireContext(&rnd, NULL, NULL, PROV_RSA_FULL, 0) &&
574                         !CryptAcquireContext(&rnd, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
575                 debug_print("Could not acquire a CSP handle.\n");
576 #endif
577                 g_free(key.data);
578                 g_strfreev(tokens);
579                 return NULL;
580         }
581
582         /* Prepare random IV for cipher */
583         iv.data = malloc(IVLEN);
584         iv.size = IVLEN;
585 #if defined G_OS_UNIX
586         ret = read(rnd, iv.data, IVLEN);
587         if (ret != IVLEN) {
588                 perror("read into iv");
589                 close(rnd);
590 #elif defined G_OS_WIN32
591         if (!CryptGenRandom(rnd, IVLEN, iv.data)) {
592                 debug_print("Could not read random data for IV\n");
593                 CryptReleaseContext(rnd, 0);
594 #endif
595                 g_free(key.data);
596                 g_free(iv.data);
597                 g_strfreev(tokens);
598                 return NULL;
599         }
600
601         /* We don't need any more random data. */
602 #if defined G_OS_UNIX
603         close(rnd);
604 #elif defined G_OS_WIN32
605         CryptReleaseContext(rnd, 0);
606 #endif
607
608         /* Prepare encrypted password string for decryption. */
609         tmp = g_base64_decode(tokens[2], &len);
610         g_strfreev(tokens);
611
612         /* Initialize the decryption */
613         ret = gnutls_cipher_init(&handle, algo, &key, &iv);
614         if (ret < 0) {
615                 debug_print("Cipher init failed: %s\n", gnutls_strerror(ret));
616                 g_free(key.data);
617                 g_free(iv.data);
618                 return NULL;
619         }
620
621         buf = malloc(BUFSIZE + blocklen);
622         memset(buf, 0, BUFSIZE + blocklen);
623         ret = gnutls_cipher_decrypt2(handle, tmp, len,
624                         buf, BUFSIZE + blocklen);
625         if (ret < 0) {
626                 debug_print("Decryption failed: %s\n", gnutls_strerror(ret));
627                 g_free(key.data);
628                 g_free(iv.data);
629                 g_free(buf);
630                 gnutls_cipher_deinit(handle);
631                 return NULL;
632         }
633
634         /* Cleanup */
635         gnutls_cipher_deinit(handle);
636         g_free(key.data);
637         g_free(iv.data);
638
639         tmp = g_strndup(buf + blocklen, MIN(strlen(buf + blocklen), BUFSIZE));
640         g_free(buf);
641         return tmp;
642 }
643
644 #undef BUFSIZE
645
646 #endif
647
648 gchar *password_encrypt(const gchar *password,
649                 const gchar *encryption_passphrase)
650 {
651         if (password == NULL || strlen(password) == 0) {
652                 return NULL;
653         }
654
655 #ifndef PASSWORD_CRYPTO_OLD
656         if (encryption_passphrase == NULL)
657                 encryption_passphrase = master_passphrase();
658
659         return password_encrypt_real(password, encryption_passphrase);
660 #else
661         return password_encrypt_old(password);
662 #endif
663 }
664
665 gchar *password_decrypt(const gchar *password,
666                 const gchar *decryption_passphrase)
667 {
668         if (password == NULL || strlen(password) == 0) {
669                 return NULL;
670         }
671
672         /* First, check if the password was possibly decrypted using old,
673          * obsolete method */
674         if (*password == '!') {
675                 debug_print("Trying to decrypt password using the old method...\n");
676                 return password_decrypt_old(password);
677         }
678
679         /* Try available crypto backend */
680 #ifndef PASSWORD_CRYPTO_OLD
681         if (decryption_passphrase == NULL)
682                 decryption_passphrase = master_passphrase();
683
684         if (*password == '{') {
685                 debug_print("Trying to decrypt password...\n");
686                 return password_decrypt_real(password, decryption_passphrase);
687         }
688 #endif
689
690         /* Fallback, in case the configuration is really old and
691          * stored password in plaintext */
692         debug_print("Assuming password was stored plaintext, returning it unchanged\n");
693         return g_strdup(password);
694 }