[balsa] Support GCR to display a certificate widget



commit ae37ff47d452a200b3bce1f2c29187e88bb58e4c
Author: Albrecht Dreß <albrecht dress arcor de>
Date:   Sun Oct 23 12:11:24 2016 -0400

    Support GCR to display a certificate widget
    
        * configure.ac: new option --with-gcr.
        * libbalsa/libbalsa.c (ask_cert_real): use gcr certificate API
        to display the certificate.
    
    Signed-off-by: Peter Bloomfield <PeterBloomfield bellsouth net>

 ChangeLog           |    8 +++++
 configure.ac        |   14 +++++++++
 libbalsa/libbalsa.c |   75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index af46146..587e98c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2016-10-23  Albrecht Dreß
 
+Support GCR to display a certificate widget
+
+       * configure.ac: new option --with-gcr.
+       * libbalsa/libbalsa.c (ask_cert_real): use gcr certificate API
+       to display the certificate.
+
+2016-10-23  Albrecht Dreß
+
 Disable header bars in the address book widgets if the
 environment variable BALSA_DIALOG_HEADERBAR is 0.
 
diff --git a/configure.ac b/configure.ac
index 5d2312a..7b74c11 100644
--- a/configure.ac
+++ b/configure.ac
@@ -155,6 +155,11 @@ AC_ARG_WITH(libsecret,
                   [Link to libsecret instead of gnome-keyring (default=no)]),
                   [with_libsecret=$withval],[with_libsecret=no])
 
+AC_ARG_WITH(gcr,
+   AC_HELP_STRING([--with-gcr],
+                  [Use libgcr-3 for dealing with TLS certificates (experimental, default=no)]),
+                  [with_gcr=$withval],[with_gcr=no])
+
 AC_ARG_ENABLE(more-warnings,
    AC_HELP_STRING([--enable-more-warnings],
                   [Enable maximum compiler warnings (default=yes)]),
@@ -599,6 +604,14 @@ if test x$with_libnotify != xno; then
     with_libnotify=" >= 0.$notifyver"
 fi
 
+# gcr configuration
+if test x$with_gcr != xno; then
+    PKG_CHECK_MODULES(GCR, [ gcr-3 ])
+    AC_DEFINE(HAVE_GCR,1,[Defined when gcr-3 can be used.])
+    BALSA_CFLAGS="$BALSA_CFLAGS $GCR_CFLAGS"
+    BALSA_LIBS="$BALSA_LIBS $GCR_LIBS"
+fi
+
 # Compface configuration
 #
 AC_MSG_CHECKING([whether to build Compface support])
@@ -880,6 +893,7 @@ echo "         Use GtkSourceView: $with_gtksourceview"
 echo "              Use Compface: $with_compface"
 echo "  Install extra MIME icons: $install_mimeicons"
 echo "             Use libsecret: $with_libsecret"
+echo "                   Use gcr: $with_gcr"
 dnl echo "                  Use SASL: $need_sasl"
 echo ""
 
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index ad92f80..b510a24 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -51,6 +51,11 @@
 #include <gtksourceview/gtksource.h>
 #endif
 
+#if HAVE_GCR
+#define GCR_API_SUBJECT_TO_CHANGE
+#include <gcr/gcr.h>
+#endif
+
 #include "misc.h"
 #include "missing.h"
 #include <glib/gi18n.h>
@@ -347,6 +352,9 @@ libbalsa_ask(gboolean (*cb)(void *arg), void *arg)
 
 static int libbalsa_ask_for_cert_acceptance(X509 *cert,
                                            const char *explanation);
+
+#ifndef HAVE_GCR
+
 static char*
 asn1time_to_string(ASN1_UTCTIME *tm)
 {
@@ -403,6 +411,8 @@ x509_fingerprint (char *s, unsigned len, X509 * cert)
     s[i] = '\0';
 }
 
+#endif  /* HAVE_GCR */
+
 static GList *accepted_certs = NULL; /* certs accepted for this session */
 static GMutex certificate_lock;
 
@@ -494,6 +504,69 @@ struct AskCertData {
     const char *explanation;
 };
 
+#if HAVE_GCR
+
+static int
+ask_cert_real(void *data)
+{
+    struct AskCertData *acd = (struct AskCertData*)data;
+    GtkWidget *dialog;
+    GtkWidget *cert_widget;
+    GString *str;
+    unsigned i;
+    unsigned char *der_buf = NULL;
+    int der_len;
+    GcrCertificate *gcr_cert;
+    GtkWidget *label;
+
+    dialog = gtk_dialog_new_with_buttons(_("SSL/TLS certificate"),
+                                         NULL, /* FIXME: NULL parent */
+                                         GTK_DIALOG_MODAL |
+                                         libbalsa_dialog_flags(),
+                                         _("_Accept Once"), 0,
+                                         _("Accept&_Save"), 1,
+                                         _("_Reject"), GTK_RESPONSE_CANCEL,
+                                         NULL);
+    gtk_window_set_role(GTK_WINDOW(dialog), "tls_cert_dialog");
+    der_len = i2d_X509(acd->certificate, &der_buf);
+    gcr_cert = gcr_simple_certificate_new(der_buf, der_len);
+    OPENSSL_free(der_buf);
+    cert_widget = GTK_WIDGET(gcr_certificate_widget_new(gcr_cert));
+    g_object_unref(G_OBJECT(gcr_cert));
+
+    str = g_string_new("");
+    g_string_printf(str, _("<big><b>Authenticity of this certificate "
+                           "could not be verified.</b></big>\n"
+                           "Reason: %s"),
+                    acd->explanation);
+    label = gtk_label_new(str->str);
+    g_string_free(str, TRUE);
+    gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
+    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
+                       label, FALSE, FALSE, 1);
+    gtk_widget_show(label);
+    gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
+                       cert_widget, TRUE, TRUE, 1);
+    gtk_widget_show(cert_widget);
+
+    switch(gtk_dialog_run(GTK_DIALOG(dialog))) {
+    case 0:
+       i = 1;
+       break;
+    case 1:
+       i = 2;
+       break;
+    case GTK_RESPONSE_CANCEL:
+    default:
+       i = 0;
+       break;
+    }
+    gtk_widget_destroy(dialog);
+    return i;
+}
+
+#else
+
 static int
 ask_cert_real(void *data)
 {
@@ -583,6 +656,8 @@ ask_cert_real(void *data)
     return i;
 }
 
+#endif /* HAVE_GCR */
+
 static int
 libbalsa_ask_for_cert_acceptance(X509 *cert, const char *explanation)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]