From 1dc76861d81c012c80871738ae6d18ed4fc881fe Mon Sep 17 00:00:00 2001 From: Not Zed Date: Fri, 28 May 2004 07:52:37 +0000 Subject: ** See bugs #52061 & #52669. 2004-05-28 Not Zed ** See bugs #52061 & #52669. * gui/smime-ui.glade: added cert-trust-dialog and tweaked the ca-trust-dialog. * gui/ca-trust-dialog.c (ca_trust_dialog_show): Fix the %s in the label. Slack. (ca_trust_dialog_show): slight rearrangement. * gui/certificate-manager.c (add_contact_cert): fill out fields. * lib/e-cert.c (e_cert_get_usage): helper to get the usage of a cert. * gui/certificate-manager.c (edit_ca): use the right certdb, not the e-one. (add_user_cert): fill out missing columns. * lib/e-cert.c (e_cert_get_ca_cert): new method to find the ca cert of a cert. * gui/cert-trust-dialog.[ch]: peer cert trust editor. * gui/certificate-manager.c (edit_contact): implement. svn path=/trunk/; revision=26119 --- smime/gui/Makefile.am | 2 + smime/gui/ca-trust-dialog.c | 39 +++--- smime/gui/cert-trust-dialog.c | 153 +++++++++++++++++++++++ smime/gui/cert-trust-dialog.h | 32 +++++ smime/gui/certificate-manager.c | 39 +++++- smime/gui/smime-ui.glade | 270 +++++++++++++++++++++++++++------------- 6 files changed, 427 insertions(+), 108 deletions(-) create mode 100644 smime/gui/cert-trust-dialog.c create mode 100644 smime/gui/cert-trust-dialog.h (limited to 'smime/gui') diff --git a/smime/gui/Makefile.am b/smime/gui/Makefile.am index 3a18b30784..6a3dff3503 100644 --- a/smime/gui/Makefile.am +++ b/smime/gui/Makefile.am @@ -21,6 +21,8 @@ noinst_LTLIBRARIES = libevolution-smime.la libevolution_smime_la_SOURCES = \ ca-trust-dialog.c \ ca-trust-dialog.h \ + cert-trust-dialog.c \ + cert-trust-dialog.h \ certificate-manager.c \ certificate-manager.h \ certificate-viewer.c \ diff --git a/smime/gui/ca-trust-dialog.c b/smime/gui/ca-trust-dialog.c index b59e189b9e..b0dc07001e 100644 --- a/smime/gui/ca-trust-dialog.c +++ b/smime/gui/ca-trust-dialog.c @@ -41,13 +41,12 @@ typedef struct { GtkWidget *ssl_checkbutton; GtkWidget *email_checkbutton; GtkWidget *objsign_checkbutton; - GtkWidget *view_cert_button; ECert *cert; } CATrustDialogData; static void -free_data (gpointer data, GObject *where_the_object_was) +free_data (gpointer data) { CATrustDialogData *ctd = data; @@ -57,21 +56,26 @@ free_data (gpointer data, GObject *where_the_object_was) } static void -view_cert (GtkWidget *button, CATrustDialogData *data) +catd_response(GtkWidget *w, guint id, CATrustDialogData *data) { - GtkWidget *dialog = certificate_viewer_show (data->cert); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (data->dialog)); - - gtk_dialog_run (GTK_DIALOG (dialog)); - - gtk_widget_destroy (dialog); + switch (id) { + case GTK_RESPONSE_ACCEPT: { + GtkWidget *dialog = certificate_viewer_show (data->cert); + + g_signal_stop_emission_by_name(w, "response"); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (data->dialog)); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + break; } + } } GtkWidget* ca_trust_dialog_show (ECert *cert, gboolean importing) { CATrustDialogData *ctd_data; + GtkWidget *w; + char *txt; ctd_data = g_new0 (CATrustDialogData, 1); ctd_data->gui = glade_xml_new (EVOLUTION_GLADEDIR "/" GLADE_FILE_NAME, NULL, NULL); @@ -82,18 +86,15 @@ ca_trust_dialog_show (ECert *cert, gboolean importing) ctd_data->ssl_checkbutton = glade_xml_get_widget (ctd_data->gui, "ssl_trust_checkbutton"); ctd_data->email_checkbutton = glade_xml_get_widget (ctd_data->gui, "email_trust_checkbutton"); ctd_data->objsign_checkbutton = glade_xml_get_widget (ctd_data->gui, "objsign_trust_checkbutton"); - ctd_data->view_cert_button = glade_xml_get_widget (ctd_data->gui, "view_certificate_button"); - - g_signal_connect (ctd_data->view_cert_button, - "clicked", G_CALLBACK (view_cert), - ctd_data); - gtk_widget_realize (ctd_data->dialog); - gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (ctd_data->dialog)->action_area), 12); + w = glade_xml_get_widget(ctd_data->gui, "ca-trust-label"); + txt = g_strdup_printf(_("Certificate '%s' is a CA certificate.\n\nEdit trust settings:"), e_cert_get_cn(cert)); + gtk_label_set_text((GtkLabel *)w, txt); + g_free(txt); - g_object_weak_ref (G_OBJECT (ctd_data->dialog), free_data, ctd_data); + g_signal_connect (ctd_data->dialog, "response", G_CALLBACK (catd_response), ctd_data); - g_object_set_data (G_OBJECT (ctd_data->dialog), "CATrustDialogData", ctd_data); + g_object_set_data_full (G_OBJECT (ctd_data->dialog), "CATrustDialogData", ctd_data, free_data); return ctd_data->dialog; } diff --git a/smime/gui/cert-trust-dialog.c b/smime/gui/cert-trust-dialog.c new file mode 100644 index 0000000000..3148adfaa9 --- /dev/null +++ b/smime/gui/cert-trust-dialog.c @@ -0,0 +1,153 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Chris Toshok + * Michael Zucchi + * + * Copyright (C) 2004 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "e-cert.h" +#include "e-cert-trust.h" +#include "e-cert-db.h" +#include "cert-trust-dialog.h" +#include "ca-trust-dialog.h" + +#include +#include +#include +#include + +#include +#include + +#define GLADE_FILE_NAME "smime-ui.glade" + +typedef struct { + GladeXML *gui; + GtkWidget *dialog; + GtkWidget *trust_button; + GtkWidget *notrust_button; + GtkWidget *label; + + ECert *cert, *cacert; +} CertTrustDialogData; + +static void +free_data (void *data) +{ + CertTrustDialogData *ctd = data; + + g_object_unref (ctd->cert); + g_object_unref (ctd->cacert); + g_object_unref (ctd->gui); + g_free (ctd); +} + +static void +ctd_response(GtkWidget *w, guint id, CertTrustDialogData *data) +{ + CERTCertTrust trust; + CERTCertificate *icert; + + switch (id) { + case GTK_RESPONSE_OK: + icert = e_cert_get_internal_cert(data->cert); + e_cert_trust_init(&trust); + e_cert_trust_set_valid_peer(&trust); + e_cert_trust_add_peer_trust (&trust, FALSE, + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (data->trust_button)), + FALSE); + CERT_ChangeCertTrust (CERT_GetDefaultCertDB(), icert, &trust); + break; + case GTK_RESPONSE_ACCEPT: { + g_signal_stop_emission_by_name(w, "response"); + + /* just *what on earth* was chris thinking here!?!?! copied from certificate-manager.c */ + GtkWidget *dialog = ca_trust_dialog_show (data->cacert, FALSE); + CERTCertificate *icert = e_cert_get_internal_cert (data->cacert); + + ca_trust_dialog_set_trust (dialog, + e_cert_trust_has_trusted_ca (icert->trust, TRUE, FALSE, FALSE), + e_cert_trust_has_trusted_ca (icert->trust, FALSE, TRUE, FALSE), + e_cert_trust_has_trusted_ca (icert->trust, FALSE, FALSE, TRUE)); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { + gboolean trust_ssl, trust_email, trust_objsign; + + ca_trust_dialog_get_trust (dialog, + &trust_ssl, &trust_email, &trust_objsign); + + e_cert_trust_init (&trust); + e_cert_trust_set_valid_ca (&trust); + e_cert_trust_add_ca_trust (&trust, + trust_ssl, + trust_email, + trust_objsign); + + CERT_ChangeCertTrust(CERT_GetDefaultCertDB(), icert, &trust); + } + + gtk_widget_destroy (dialog); + break; } + } +} + +GtkWidget* +cert_trust_dialog_show (ECert *cert) +{ + CertTrustDialogData *ctd_data; + CERTCertificate *icert; + + ctd_data = g_new0 (CertTrustDialogData, 1); + ctd_data->gui = glade_xml_new (EVOLUTION_GLADEDIR "/" GLADE_FILE_NAME, NULL, NULL); + + ctd_data->dialog = glade_xml_get_widget (ctd_data->gui, "cert-trust-dialog"); + ctd_data->cert = g_object_ref (cert); + ctd_data->cacert = e_cert_get_ca_cert(cert); + ctd_data->trust_button = glade_xml_get_widget(ctd_data->gui, "cert-trust"); + ctd_data->notrust_button = glade_xml_get_widget(ctd_data->gui, "cert-notrust"); + + ctd_data->label = glade_xml_get_widget(ctd_data->gui, "trust-label"); + + g_signal_connect(ctd_data->dialog, "response", G_CALLBACK(ctd_response), ctd_data); + + g_object_set_data_full (G_OBJECT (ctd_data->dialog), "CertTrustDialogData", ctd_data, free_data); + + icert = e_cert_get_internal_cert(cert); + if (e_cert_trust_has_trusted_peer(icert->trust, FALSE, TRUE, FALSE)) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (ctd_data->trust_button), TRUE); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (ctd_data->notrust_button), TRUE); + + + icert = e_cert_get_internal_cert(ctd_data->cacert); + if (e_cert_trust_has_trusted_ca(icert->trust, FALSE, TRUE, FALSE)) + gtk_label_set_text((GtkLabel *)ctd_data->label, + _("Because you trust the certificate authority that issued this certificate, " + "then you trust the authenticity of this certificate unless otherwise indicated here")); + else + gtk_label_set_text((GtkLabel *)ctd_data->label, + _("Because you do not trust the certificate authority that issued this certificate, " + "then you do not trust the authenticity of this certificate unless otherwise indicated here")); + + return ctd_data->dialog; +} diff --git a/smime/gui/cert-trust-dialog.h b/smime/gui/cert-trust-dialog.h new file mode 100644 index 0000000000..fe71c6a1b5 --- /dev/null +++ b/smime/gui/cert-trust-dialog.h @@ -0,0 +1,32 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Authors: Chris Toshok + * Michael Zucchi + * + * Copyright (C) 2004 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef _CERT_TRUST_DIALOG_H_ +#define _CERT_TRUST_DIALOG_H + +struct _GtkWidget; +struct _ECert; + +struct _GtkWidget* cert_trust_dialog_show (struct _ECert *cert); + +#endif /* _CERT_TRUST_DIALOG_H_ */ diff --git a/smime/gui/certificate-manager.c b/smime/gui/certificate-manager.c index f291fffea4..81a392f463 100644 --- a/smime/gui/certificate-manager.c +++ b/smime/gui/certificate-manager.c @@ -34,10 +34,12 @@ #include #include "evolution-config-control.h" #include "ca-trust-dialog.h" +#include "cert-trust-dialog.h" #include "certificate-manager.h" #include "certificate-viewer.h" #include "e-cert.h" +#include "e-cert-trust.h" #include "e-cert-db.h" #include "nss.h" @@ -319,6 +321,30 @@ view_contact (GtkWidget *widget, CertificateManagerData *cfm) } } +static void +edit_contact (GtkWidget *widget, CertificateManagerData *cfm) +{ + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW(cfm->contactcerts_treeview)), + NULL, + &iter)) { + ECert *cert; + + gtk_tree_model_get (GTK_TREE_MODEL (cfm->contactcerts_streemodel), + &iter, + 3, &cert, + -1); + + if (cert) { + GtkWidget *dialog = cert_trust_dialog_show (cert); + g_signal_connect (dialog, "response", + G_CALLBACK (gtk_widget_destroy), NULL); + gtk_widget_show (dialog); + } + } +} + static void import_contact (GtkWidget *widget, CertificateManagerData *cfm) { @@ -438,6 +464,9 @@ initialize_contactcerts_ui (CertificateManagerData *cfm) if (cfm->view_contact_button) g_signal_connect (cfm->view_contact_button, "clicked", G_CALLBACK (view_contact), cfm); + if (cfm->edit_contact_button) + g_signal_connect (cfm->edit_contact_button, "clicked", G_CALLBACK (edit_contact), cfm); + if (cfm->import_contact_button) g_signal_connect (cfm->import_contact_button, "clicked", G_CALLBACK (import_contact), cfm); @@ -508,7 +537,7 @@ edit_ca (GtkWidget *widget, CertificateManagerData *cfm) trust_email, trust_objsign); - CERT_ChangeCertTrust (e_cert_db_peek (), icert, &trust); + CERT_ChangeCertTrust (CERT_GetDefaultCertDB(), icert, &trust); } gtk_widget_destroy (dialog); @@ -654,11 +683,17 @@ add_user_cert (CertificateManagerData *cfm, ECert *cert) if (e_cert_get_cn (cert)) gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 0, e_cert_get_cn (cert), + 1, e_cert_get_usage(cert), + 2, e_cert_get_serial_number(cert), + 3, e_cert_get_expires_on(cert), 4, cert, -1); else gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 0, e_cert_get_nickname (cert), + 1, e_cert_get_usage(cert), + 2, e_cert_get_serial_number(cert), + 3, e_cert_get_expires_on(cert), 4, cert, -1); } @@ -693,12 +728,14 @@ add_contact_cert (CertificateManagerData *cfm, ECert *cert) gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 0, e_cert_get_cn (cert), 1, e_cert_get_email (cert), + 2, e_cert_get_usage(cert), 3, cert, -1); else gtk_tree_store_set (GTK_TREE_STORE (model), &iter, 0, e_cert_get_nickname (cert), 1, e_cert_get_email (cert), + 2, e_cert_get_usage(cert), 3, cert, -1); } diff --git a/smime/gui/smime-ui.glade b/smime/gui/smime-ui.glade index 5682522b8d..cda60ed349 100644 --- a/smime/gui/smime-ui.glade +++ b/smime/gui/smime-ui.glade @@ -1782,7 +1782,19 @@ GTK_BUTTONBOX_END - + + True + True + True + _View Certificate + True + GTK_RELIEF_NORMAL + -3 + + + + + True True True @@ -1794,7 +1806,7 @@ - + True True True @@ -1814,53 +1826,33 @@ - - True - You have been asked to trust a new Certificate Authority (CA). - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - Do you want to trust "%s" for the following purposes? - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - + + 12 True False 0 + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + False + False + + + True @@ -1914,57 +1906,32 @@ False - - - 0 - False - False - - - - - - True - Before trusting this CA for any purpose, you should examine its certificate and its policy and procedures (if available). - False - False - GTK_JUSTIFY_LEFT - True - False - 0 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - 0 - 0.5 - 0 - 1 - + True - True - View Certificate - True - GTK_RELIEF_NORMAL + Before trusting this CA for any purpose, you should examine its certificate and its policy and procedures (if available). + False + False + GTK_JUSTIFY_LEFT + True + False + 0 + 0.5 + 0 + 0 + + 0 + False + False + 0 - False - False + True + True @@ -2099,4 +2066,131 @@ + + Email Certificate Trust Settings + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + _Edit CA Trust + True + GTK_RELIEF_NORMAL + -3 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_LEFT + True + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + True + Trust the authenticity of this certificate + True + GTK_RELIEF_NORMAL + False + False + True + + + 0 + False + False + + + + + + True + True + Do not trust the authenticity of this certificate + True + GTK_RELIEF_NORMAL + False + False + True + cert-trust + + + 0 + False + False + + + + + 0 + False + True + + + + + + -- cgit v1.2.3