evolution-3.6.4/smime/gui/cert-trust-dialog.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Chris Toshok <toshok@ximian.com>
 18  *      Michael Zucchi <notzed@ximian.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include "e-cert.h"
 29 #include "e-cert-trust.h"
 30 #include "e-cert-db.h"
 31 #include "cert-trust-dialog.h"
 32 #include "ca-trust-dialog.h"
 33 
 34 #include <gtk/gtk.h>
 35 
 36 #include <glib/gi18n.h>
 37 
 38 #include "e-util/e-util.h"
 39 #include "e-util/e-util-private.h"
 40 
 41 typedef struct {
 42 	GtkBuilder *builder;
 43 	GtkWidget *dialog;
 44 	GtkWidget *trust_button;
 45 	GtkWidget *notrust_button;
 46 	GtkWidget *label;
 47 
 48 	ECert *cert, *cacert;
 49 } CertTrustDialogData;
 50 
 51 static void
 52 free_data (gpointer data)
 53 {
 54 	CertTrustDialogData *ctd = data;
 55 
 56 	g_object_unref (ctd->cert);
 57 	g_object_unref (ctd->cacert);
 58 	g_object_unref (ctd->builder);
 59 	g_free (ctd);
 60 }
 61 
 62 static void
 63 ctd_response (GtkWidget *w,
 64               guint id,
 65               CertTrustDialogData *data)
 66 {
 67 	CERTCertTrust trust;
 68 	CERTCertificate *icert;
 69 
 70 	switch (id) {
 71 	case GTK_RESPONSE_OK:
 72 		icert = e_cert_get_internal_cert (data->cert);
 73 		e_cert_trust_init (&trust);
 74 		e_cert_trust_set_valid_peer (&trust);
 75 		e_cert_trust_add_peer_trust (
 76 			&trust, FALSE,
 77 			gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data->trust_button)),
 78 			FALSE);
 79 		e_cert_db_change_cert_trust (icert, &trust);
 80 		break;
 81 	case GTK_RESPONSE_ACCEPT: {
 82 		/* just *what on earth* was chris thinking here!?!?!  copied from certificate-manager.c */
 83 		GtkWidget *dialog = ca_trust_dialog_show (data->cacert, FALSE);
 84 		/* *icert is already declared earlier in this function? */
 85 		CERTCertificate *icert = e_cert_get_internal_cert (data->cacert);
 86 
 87 		g_signal_stop_emission_by_name (w, "response");
 88 
 89 		ca_trust_dialog_set_trust (
 90 			dialog,
 91 			e_cert_trust_has_trusted_ca (icert->trust, TRUE,  FALSE, FALSE),
 92 			e_cert_trust_has_trusted_ca (icert->trust, FALSE, TRUE,  FALSE),
 93 			e_cert_trust_has_trusted_ca (icert->trust, FALSE, FALSE, TRUE));
 94 
 95 		if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
 96 			gboolean trust_ssl, trust_email, trust_objsign;
 97 
 98 			ca_trust_dialog_get_trust (
 99 				dialog,
100 				&trust_ssl, &trust_email, &trust_objsign);
101 
102 			e_cert_trust_init (&trust);
103 			e_cert_trust_set_valid_ca (&trust);
104 			e_cert_trust_add_ca_trust (
105 				&trust,
106 				trust_ssl,
107 				trust_email,
108 				trust_objsign);
109 
110 			e_cert_db_change_cert_trust (icert, &trust);
111 		}
112 
113 		gtk_widget_destroy (dialog);
114 		break; }
115 	}
116 }
117 
118 GtkWidget *
119 cert_trust_dialog_show (ECert *cert)
120 {
121 	CertTrustDialogData *ctd_data;
122 	CERTCertificate *icert;
123 
124 	ctd_data = g_new0 (CertTrustDialogData, 1);
125 
126 	ctd_data->builder = gtk_builder_new ();
127 	e_load_ui_builder_definition (ctd_data->builder, "smime-ui.ui");
128 
129 	ctd_data->dialog = e_builder_get_widget (ctd_data->builder, "cert-trust-dialog");
130 	ctd_data->cert = g_object_ref (cert);
131 	ctd_data->cacert = e_cert_get_ca_cert (cert);
132 	ctd_data->trust_button = e_builder_get_widget (ctd_data->builder, "cert-trust");
133 	ctd_data->notrust_button = e_builder_get_widget (ctd_data->builder, "cert-notrust");
134 
135 	ctd_data->label = e_builder_get_widget (ctd_data->builder, "trust-label");
136 
137 	g_signal_connect (
138 		ctd_data->dialog, "response",
139 		G_CALLBACK (ctd_response), ctd_data);
140 
141 	g_object_set_data_full (G_OBJECT (ctd_data->dialog), "CertTrustDialogData", ctd_data, free_data);
142 
143 	icert = e_cert_get_internal_cert (cert);
144 	if (e_cert_trust_has_trusted_peer (icert->trust, FALSE, TRUE, FALSE))
145 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ctd_data->trust_button), TRUE);
146 	else
147 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ctd_data->notrust_button), TRUE);
148 
149 	icert = e_cert_get_internal_cert (ctd_data->cacert);
150 	if (e_cert_trust_has_trusted_ca (icert->trust, FALSE, TRUE, FALSE))
151 		gtk_label_set_text (
152 			(GtkLabel *) ctd_data->label,
153 			_("Because you trust the certificate authority that issued this certificate, "
154 			"then you trust the authenticity of this certificate unless otherwise indicated here"));
155 	else
156 		gtk_label_set_text (
157 			(GtkLabel *) ctd_data->label,
158 			_("Because you do not trust the certificate authority that issued this certificate, "
159 			"then you do not trust the authenticity of this certificate unless otherwise indicated here"));
160 
161 	return ctd_data->dialog;
162 }