1 /*
2  * This program is free software; you can redistribute it and/or modify it
3  * under the terms of the GNU Lesser General Public License as published by
4  * the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful, but
7  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9  * for more details.
10  *
11  * You should have received a copy of the GNU Lesser General Public License
12  * along with this program; if not, see <http://www.gnu.org/licenses/>.
13  *
14  *
15  * Authors:
16  *		Chris Toshok <toshok@ximian.com>
17  *
18  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
19  *
20  */
21 
22 #include "evolution-config.h"
23 
24 #include "component.h"
25 
26 #include <gtk/gtk.h>
27 
28 #include <glib/gi18n.h>
29 
30 #include "e-util/e-util.h"
31 
32 #include "ca-trust-dialog.h"
33 #include "e-cert-db.h"
34 #include "pk11func.h"
35 
36 static gboolean
smime_pk11_passwd(ECertDB * db,PK11SlotInfo * slot,gboolean retry,gchar ** passwd,gpointer arg)37 smime_pk11_passwd (ECertDB *db,
38                    PK11SlotInfo *slot,
39                    gboolean retry,
40                    gchar **passwd,
41                    gpointer arg)
42 {
43 	gchar *prompt;
44 	gchar *slot_name = g_strdup (PK11_GetSlotName (slot));
45 	gchar *token_name = g_strdup (PK11_GetTokenName (slot));
46 
47 	g_strchomp (slot_name);
48 
49 	if (token_name)
50 		g_strchomp (token_name);
51 
52 	if (token_name && *token_name && g_ascii_strcasecmp (slot_name, token_name) != 0)
53 		prompt = g_strdup_printf (_("Enter the password for “%s”, token “%s”"), slot_name, token_name);
54 	else
55 		prompt = g_strdup_printf (_("Enter the password for “%s”"), slot_name);
56 
57 	g_free (slot_name);
58 	g_free (token_name);
59 
60 	*passwd = e_passwords_ask_password (
61 		_("Enter password"), "", prompt,
62 		E_PASSWORDS_REMEMBER_NEVER | E_PASSWORDS_SECRET,
63 		NULL, NULL);
64 
65 	g_free (prompt);
66 
67 	/* this should return FALSE if they canceled. */
68 	return TRUE;
69 }
70 
71 static gboolean
smime_pk11_change_passwd(ECertDB * db,gchar ** old_passwd,gchar ** passwd,gpointer arg)72 smime_pk11_change_passwd (ECertDB *db,
73                           gchar **old_passwd,
74                           gchar **passwd,
75                           gpointer arg)
76 {
77 	gchar *prompt;
78 
79 	/* XXX need better strings here, just copy mozilla's? */
80 
81 	if (!old_passwd) {
82 		/* we're setting the password initially */
83 		prompt = _("Enter new password for certificate database");
84 
85 		*passwd = e_passwords_ask_password (
86 			_("Enter new password"), "", prompt,
87 			E_PASSWORDS_REMEMBER_NEVER | E_PASSWORDS_SECRET,
88 			NULL, NULL);
89 	}
90 	else {
91 		/* we're changing the password */
92 		/* XXX implement this... */
93 	}
94 
95 	/* this should return FALSE if they canceled. */
96 	return TRUE;
97 }
98 
99 static gboolean
smime_confirm_ca_cert_import(ECertDB * db,ECert * cert,gboolean * trust_ssl,gboolean * trust_email,gboolean * trust_objsign,gpointer arg)100 smime_confirm_ca_cert_import (ECertDB *db,
101                               ECert *cert,
102                               gboolean *trust_ssl,
103                               gboolean *trust_email,
104                               gboolean *trust_objsign,
105                               gpointer arg)
106 {
107 	GtkWidget *dialog = ca_trust_dialog_show (cert, TRUE);
108 	gint response;
109 
110 	response = gtk_dialog_run (GTK_DIALOG (dialog));
111 
112 	ca_trust_dialog_get_trust (dialog, trust_ssl, trust_email, trust_objsign);
113 
114 	gtk_widget_destroy (dialog);
115 
116 	return response != GTK_RESPONSE_CANCEL;
117 }
118 
119 void
smime_component_init(void)120 smime_component_init (void)
121 {
122 	static gboolean init_done = FALSE;
123 	if (init_done)
124 		return;
125 
126 	init_done = TRUE;
127 	g_signal_connect (
128 		e_cert_db_peek (), "pk11_passwd",
129 		G_CALLBACK (smime_pk11_passwd), NULL);
130 
131 	g_signal_connect (
132 		e_cert_db_peek (), "pk11_change_passwd",
133 		G_CALLBACK (smime_pk11_change_passwd), NULL);
134 
135 	g_signal_connect (
136 		e_cert_db_peek (), "confirm_ca_cert_import",
137 		G_CALLBACK (smime_confirm_ca_cert_import), NULL);
138 }
139