aboutsummaryrefslogtreecommitdiffstats
path: root/smime/gui/certificate-viewer.c
blob: 4a0bc3327d4d0ea59a6cb21d811484cb89a6fcfe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 *  Authors: Chris Toshok <toshok@ximian.com>
 *
 *  Copyright (C) 2003 Ximian, Inc. (www.ximian.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.
 *
 */

#include "certificate-viewer.h"

#include <gtk/gtk.h>

#include <libgnome/gnome-i18n.h>
#include <glade/glade.h>

#define GLADE_FILE_NAME "smime-ui.glade"

typedef struct {
    GladeXML *gui;
    GtkWidget *dialog;
} CertificateViewerData;

static void
free_data (gpointer data, GObject *where_the_object_was)
{
    CertificateViewerData *cvm = data;

    g_object_unref (cvm->gui);
    g_free (cvm);
}


GtkWidget*
certificate_viewer_show (ECert *cert)
{
    CertificateViewerData *cvm_data;
    CERTCertificate *mcert;
    GtkWidget *label;
    const char *text;

    mcert = e_cert_get_internal_cert (cert);

    cvm_data = g_new0 (CertificateViewerData, 1);
    cvm_data->gui = glade_xml_new (EVOLUTION_GLADEDIR "/" GLADE_FILE_NAME, NULL, NULL);

    cvm_data->dialog = glade_xml_get_widget (cvm_data->gui, "certificate-viewer-dialog");

    /* issued to */
    if (e_cert_get_cn (cert)) {
        label = glade_xml_get_widget (cvm_data->gui, "issued-to-cn");
        gtk_label_set_text (GTK_LABEL (label), e_cert_get_cn (cert));
    }

    if (e_cert_get_org (cert)) {
        label = glade_xml_get_widget (cvm_data->gui, "issued-to-o");
        gtk_label_set_text (GTK_LABEL (label), e_cert_get_org (cert));
    }

    if (e_cert_get_org_unit (cert)) {
        label = glade_xml_get_widget (cvm_data->gui, "issued-to-ou");
        gtk_label_set_text (GTK_LABEL (label), e_cert_get_org_unit (cert));
    }

    text = e_cert_get_serial_number (cert);
    label = glade_xml_get_widget (cvm_data->gui, "issued-to-serial");
    gtk_label_set_text (GTK_LABEL (label), text);

    /* issued by */
    if (e_cert_get_issuer_cn (cert)) {
        label = glade_xml_get_widget (cvm_data->gui, "issued-by-cn");
        gtk_label_set_text (GTK_LABEL (label), e_cert_get_issuer_cn (cert));
    }

    if (e_cert_get_issuer_org (cert)) {
        label = glade_xml_get_widget (cvm_data->gui, "issued-by-o");
        gtk_label_set_text (GTK_LABEL (label), e_cert_get_issuer_org (cert));
    }

    if (e_cert_get_issuer_org_unit (cert)) {
        label = glade_xml_get_widget (cvm_data->gui, "issued-by-ou");
        gtk_label_set_text (GTK_LABEL (label), e_cert_get_issuer_org_unit (cert));
    }

    /* validity */
    if (e_cert_get_issued_on (cert)) {
        label = glade_xml_get_widget (cvm_data->gui, "validity-issued-on");
        gtk_label_set_text (GTK_LABEL (label), e_cert_get_issued_on (cert));
    }

    if (e_cert_get_expires_on (cert)) {
        label = glade_xml_get_widget (cvm_data->gui, "validity-expires-on");
        gtk_label_set_text (GTK_LABEL (label), e_cert_get_expires_on (cert));
    }

    /* fingerprints */
    text = e_cert_get_sha1_fingerprint (cert);
    label = glade_xml_get_widget (cvm_data->gui, "fingerprints-sha1");
    gtk_label_set_text (GTK_LABEL (label), text);

    text = e_cert_get_md5_fingerprint (cert);
    label = glade_xml_get_widget (cvm_data->gui, "fingerprints-md5");
    gtk_label_set_text (GTK_LABEL (label), text);

    g_object_weak_ref (G_OBJECT (cvm_data->dialog), free_data, cvm_data);

    g_signal_connect (cvm_data->dialog, "response",
              G_CALLBACK (gtk_widget_destroy), NULL);

    gtk_widget_show (cvm_data->dialog);
    return cvm_data->dialog;
}