1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2016 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 #ifndef __PASSWORD_H
21 #define __PASSWORD_H
22 
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26 
27 #include <glib.h>
28 
29 #ifndef PASSWORD_CRYPTO_OLD
30 /* Returns a pointer to master passphrase, asking the user
31  * if necessary. Do not free the return value. */
32 const gchar *master_passphrase();
33 
34 /* Returns TRUE if there is a master passphrase set in preferences. */
35 gboolean master_passphrase_is_set();
36 /* Returns TRUE if input contains correct master passphrase, as set
37  * in preferences. */
38 gboolean master_passphrase_is_correct(const gchar *input);
39 /* Returns TRUE if master passphrase is entered (unlocked). */
40 gboolean master_passphrase_is_entered();
41 /* Removes (locks) master passphrase, if it was entered previously
42  * in current session. */
43 void master_passphrase_forget();
44 
45 /* Changes master passphrase. Also triggers reencryption of all stored
46  * passwords using the new master passphrase.
47  * oldp - old master passphrase; if NULL, it will be retrieved using
48  *        master_passphrase()
49  * newp - new master passphrase */
50 void master_passphrase_change(const gchar *oldp, const gchar *newp);
51 #endif
52 
53 /* Wrapper around the old, DES-CBC-broken implementation which
54  * returns a newly allocated string for the encrypt/decrypt result.
55  * This is for compatibility with with the rest of password-related
56  * functions.*/
57 gchar *password_encrypt_old(const gchar *password);
58 gchar *password_decrypt_old(const gchar *password);
59 
60 #ifdef PASSWORD_CRYPTO_GNUTLS
61 /* GNUTLS implementation */
62 gchar *password_encrypt_gnutls(const gchar *password,
63 		const gchar *encryption_passphrase);
64 gchar *password_decrypt_gnutls(const gchar *password,
65 		const gchar *decryption_passphrase);
66 #define password_encrypt_real(n, m) password_encrypt_gnutls(n, m)
67 #define password_decrypt_real(n, m) password_decrypt_gnutls(n, m)
68 #endif
69 
70 /* Wrapper function that will apply best encryption available,
71  * and return a string ready to be saved as-is in preferences. */
72 gchar *password_encrypt(const gchar *password,
73 		const gchar *encryption_passphrase);
74 
75 /* This is a wrapper function that looks at the whole string from
76  * prefs (e.g. including the leading '!' for old implementation),
77  * and tries to do the smart thing. */
78 gchar *password_decrypt(const gchar *password,
79 		const gchar *decryption_passphrase);
80 
81 #endif /* __PASSWORD_H */
82