2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
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 2 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <openssl/ssl.h>
29 #include "../common/intl.h"
30 #include "../ssl_certificate.h"
31 #include "../common/utils.h"
32 #include "../alertpanel.h"
34 GtkWidget *cert_presenter(SSLCertificate *cert)
36 GtkWidget *vbox = NULL;
37 GtkWidget *hbox = NULL;
38 GtkWidget *frame_owner = NULL;
39 GtkWidget *frame_signer = NULL;
40 GtkWidget *frame_status = NULL;
41 GtkTable *owner_table = NULL;
42 GtkTable *signer_table = NULL;
43 GtkTable *status_table = NULL;
44 GtkWidget *label = NULL;
46 char *issuer_commonname, *issuer_location, *issuer_organization;
47 char *subject_commonname, *subject_location, *subject_organization;
48 char *fingerprint, *sig_status;
50 unsigned char md[EVP_MAX_MD_SIZE];
53 if (X509_NAME_get_text_by_NID(X509_get_issuer_name(cert->x509_cert),
54 NID_commonName, buf, 100) >= 0)
55 issuer_commonname = g_strdup(buf);
57 issuer_commonname = g_strdup(_("<not in certificate>"));
58 if (X509_NAME_get_text_by_NID(X509_get_issuer_name(cert->x509_cert),
59 NID_localityName, buf, 100) >= 0) {
60 issuer_location = g_strdup(buf);
61 if (X509_NAME_get_text_by_NID(X509_get_issuer_name(cert->x509_cert),
62 NID_countryName, buf, 100) >= 0)
63 issuer_location = g_strconcat(issuer_location,", ",buf, NULL);
64 } else if (X509_NAME_get_text_by_NID(X509_get_issuer_name(cert->x509_cert),
65 NID_countryName, buf, 100) >= 0)
66 issuer_location = g_strdup(buf);
68 issuer_location = g_strdup(_("<not in certificate>"));
70 if (X509_NAME_get_text_by_NID(X509_get_issuer_name(cert->x509_cert),
71 NID_organizationName, buf, 100) >= 0)
72 issuer_organization = g_strdup(buf);
74 issuer_organization = g_strdup(_("<not in certificate>"));
77 if (X509_NAME_get_text_by_NID(X509_get_subject_name(cert->x509_cert),
78 NID_commonName, buf, 100) >= 0)
79 subject_commonname = g_strdup(buf);
81 subject_commonname = g_strdup(_("<not in certificate>"));
82 if (X509_NAME_get_text_by_NID(X509_get_subject_name(cert->x509_cert),
83 NID_localityName, buf, 100) >= 0) {
84 subject_location = g_strdup(buf);
85 if (X509_NAME_get_text_by_NID(X509_get_subject_name(cert->x509_cert),
86 NID_countryName, buf, 100) >= 0)
87 subject_location = g_strconcat(subject_location,", ",buf, NULL);
88 } else if (X509_NAME_get_text_by_NID(X509_get_subject_name(cert->x509_cert),
89 NID_countryName, buf, 100) >= 0)
90 subject_location = g_strdup(buf);
92 subject_location = g_strdup(_("<not in certificate>"));
94 if (X509_NAME_get_text_by_NID(X509_get_subject_name(cert->x509_cert),
95 NID_organizationName, buf, 100) >= 0)
96 subject_organization = g_strdup(buf);
98 subject_organization = g_strdup(_("<not in certificate>"));
101 X509_digest(cert->x509_cert, EVP_md5(), md, &n);
102 fingerprint = readable_fingerprint(md, (int)n);
105 sig_status = ssl_certificate_check_signer(cert->x509_cert);
107 if (sig_status==NULL)
108 sig_status = g_strdup(_("correct"));
110 vbox = gtk_vbox_new(FALSE, 5);
111 hbox = gtk_hbox_new(FALSE, 5);
113 frame_owner = gtk_frame_new(_("Owner"));
114 frame_signer = gtk_frame_new(_("Signer"));
115 frame_status = gtk_frame_new(_("Status"));
117 owner_table = GTK_TABLE(gtk_table_new(3, 2, FALSE));
118 signer_table = GTK_TABLE(gtk_table_new(3, 2, FALSE));
119 status_table = GTK_TABLE(gtk_table_new(2, 2, FALSE));
121 label = gtk_label_new(_("Name: "));
122 gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
123 gtk_table_attach(owner_table, label, 0, 1, 0, 1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
124 label = gtk_label_new(subject_commonname);
125 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
126 gtk_table_attach(owner_table, label, 1, 2, 0, 1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
128 label = gtk_label_new(_("Organization: "));
129 gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
130 gtk_table_attach(owner_table, label, 0, 1, 1, 2, GTK_EXPAND|GTK_FILL, 0, 0, 0);
131 label = gtk_label_new(subject_organization);
132 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
133 gtk_table_attach(owner_table, label, 1, 2, 1, 2, GTK_EXPAND|GTK_FILL, 0, 0, 0);
135 label = gtk_label_new(_("Location: "));
136 gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
137 gtk_table_attach(owner_table, label, 0, 1, 2, 3, GTK_EXPAND|GTK_FILL, 0, 0, 0);
138 label = gtk_label_new(subject_location);
139 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
140 gtk_table_attach(owner_table, label, 1, 2, 2, 3, GTK_EXPAND|GTK_FILL, 0, 0, 0);
142 label = gtk_label_new(_("Name: "));
143 gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
144 gtk_table_attach(signer_table, label, 0, 1, 0, 1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
145 label = gtk_label_new(issuer_commonname);
146 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
147 gtk_table_attach(signer_table, label, 1, 2, 0, 1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
149 label = gtk_label_new(_("Organization: "));
150 gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
151 gtk_table_attach(signer_table, label, 0, 1, 1, 2, GTK_EXPAND|GTK_FILL, 0, 0, 0);
152 label = gtk_label_new(issuer_organization);
153 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
154 gtk_table_attach(signer_table, label, 1, 2, 1, 2, GTK_EXPAND|GTK_FILL, 0, 0, 0);
156 label = gtk_label_new(_("Location: "));
157 gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
158 gtk_table_attach(signer_table, label, 0, 1, 2, 3, GTK_EXPAND|GTK_FILL, 0, 0, 0);
159 label = gtk_label_new(issuer_location);
160 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
161 gtk_table_attach(signer_table, label, 1, 2, 2, 3, GTK_EXPAND|GTK_FILL, 0, 0, 0);
163 label = gtk_label_new(_("Fingerprint: "));
164 gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
165 gtk_table_attach(status_table, label, 0, 1, 0, 1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
166 label = gtk_label_new(fingerprint);
167 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
168 gtk_table_attach(status_table, label, 1, 2, 0, 1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
169 label = gtk_label_new(_("Signature status: "));
170 gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
171 gtk_table_attach(status_table, label, 0, 1, 1, 2, GTK_EXPAND|GTK_FILL, 0, 0, 0);
172 label = gtk_label_new(sig_status);
173 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
174 gtk_table_attach(status_table, label, 1, 2, 1, 2, GTK_EXPAND|GTK_FILL, 0, 0, 0);
176 gtk_container_add(GTK_CONTAINER(frame_owner), GTK_WIDGET(owner_table));
177 gtk_container_add(GTK_CONTAINER(frame_signer), GTK_WIDGET(signer_table));
178 gtk_container_add(GTK_CONTAINER(frame_status), GTK_WIDGET(status_table));
180 gtk_box_pack_end(GTK_BOX(hbox), frame_signer, TRUE, TRUE, 0);
181 gtk_box_pack_end(GTK_BOX(hbox), frame_owner, TRUE, TRUE, 0);
182 gtk_box_pack_end(GTK_BOX(vbox), frame_status, TRUE, TRUE, 0);
183 gtk_box_pack_end(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
185 gtk_widget_show_all(vbox);
187 g_free(issuer_commonname);
188 g_free(issuer_location);
189 g_free(issuer_organization);
190 g_free(subject_commonname);
191 g_free(subject_location);
192 g_free(subject_organization);
199 void sslcertwindow_show_cert(SSLCertificate *cert)
201 GtkWidget *cert_widget = cert_presenter(cert);
204 buf = g_strdup_printf(_("SSL certificate for %s"), cert->host);
205 alertpanel_with_widget(buf, NULL, _("OK"), NULL, NULL, cert_widget);
209 gboolean sslcertwindow_ask_new_cert(SSLCertificate *cert)
211 GtkWidget *cert_widget = cert_presenter(cert);
214 buf = g_strdup_printf(_("Do you want to accept SSL certificate for %s?"), cert->host);
215 val = alertpanel_with_widget(_("Unknown SSL Certificate"), buf, _("Accept and save"), _("Cancel connection"), NULL, cert_widget);
217 return (val == G_ALERTDEFAULT);
220 gboolean sslcertwindow_ask_changed_cert(SSLCertificate *old_cert, SSLCertificate *new_cert)
222 GtkWidget *old_cert_widget = cert_presenter(old_cert);
223 GtkWidget *new_cert_widget = cert_presenter(new_cert);
229 vbox = gtk_vbox_new(FALSE, 5);
230 label = gtk_label_new(_("New certificate:"));
231 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
232 gtk_box_pack_end(GTK_BOX(vbox), new_cert_widget, TRUE, TRUE, 0);
233 gtk_box_pack_end(GTK_BOX(vbox), label, TRUE, TRUE, 0);
234 gtk_box_pack_end(GTK_BOX(vbox), gtk_hseparator_new(), TRUE, TRUE, 0);
235 label = gtk_label_new(_("Known certificate:"));
236 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
237 gtk_box_pack_end(GTK_BOX(vbox), old_cert_widget, TRUE, TRUE, 0);
238 gtk_box_pack_end(GTK_BOX(vbox), label, TRUE, TRUE, 0);
239 gtk_widget_show_all(vbox);
241 buf = g_strdup_printf(_("Do you want to accept new SSL certificate for %s?"), new_cert->host);
242 val = alertpanel_with_widget(_("Changed SSL Certificate"), buf, _("Accept and save"), _("Cancel connection"), NULL, vbox);
244 return (val == G_ALERTDEFAULT);