[Xfce4-commits] <midori:master> Render certificate, optionally with GCR

Christian Dywan noreply at xfce.org
Mon Jul 16 21:24:03 CEST 2012


Updating branch refs/heads/master
         to 301bb89dd304d74daf7344df581e992304510802 (commit)
       from 19f291d2be6f18dda3b50fca2e98bf3deec75025 (commit)

commit 301bb89dd304d74daf7344df581e992304510802
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Jul 16 21:21:31 2012 +0200

    Render certificate, optionally with GCR

 midori/main.c                  |   19 ++++++++
 midori/midori-locationaction.c |   94 ++++++++++++++++++++++++++++++++++++++++
 midori/wscript_build           |    2 +-
 wscript                        |    3 +
 4 files changed, 117 insertions(+), 1 deletions(-)

diff --git a/midori/main.c b/midori/main.c
index 11ffbb1..6a3e59a 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -880,6 +880,21 @@ soup_session_settings_notify_first_party_cb (MidoriWebSettings* settings,
 }
 #endif
 
+#if defined (HAVE_LIBSOUP_2_34_0)
+/* Implemented in MidoriLocationAction */
+void
+midori_map_add_message (SoupMessage* message);
+
+static void
+midori_soup_session_request_started_cb (SoupSession* session,
+                                        SoupMessage* message,
+                                        SoupSocket*  socket,
+                                        gpointer     user_data)
+{
+    midori_map_add_message (message);
+}
+#endif
+
 static void
 midori_soup_session_settings_accept_language_cb (SoupSession*       session,
                                                  SoupMessage*       msg,
@@ -1021,6 +1036,10 @@ midori_load_soup_session (gpointer settings)
     g_free (cache);
     #endif
 
+    #if defined (HAVE_LIBSOUP_2_34_0)
+    g_signal_connect (session, "request-started",
+        G_CALLBACK (midori_soup_session_request_started_cb), session);
+    #endif
     g_signal_connect (session, "request-queued",
         G_CALLBACK (midori_soup_session_settings_accept_language_cb), settings);
 
diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index a76b1d8..154b989 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -1126,6 +1126,97 @@ midori_location_action_focus_out_event_cb (GtkWidget*   widget,
     return FALSE;
 }
 
+#if HAVE_GCR
+    #define GCR_API_SUBJECT_TO_CHANGE
+    #include <gcr/gcr.h>
+#endif
+
+#if defined (HAVE_LIBSOUP_2_34_0)
+static GHashTable* message_map = NULL;
+void
+midori_map_add_message (SoupMessage* message)
+{
+    SoupURI* uri = soup_message_get_uri (message);
+    if (message_map == NULL)
+        message_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+    g_return_if_fail (uri && uri->host);
+    g_hash_table_insert (message_map, g_strdup (uri->host), g_object_ref (message));
+}
+
+static SoupMessage*
+midori_map_get_message (SoupMessage* message)
+{
+    SoupURI* uri = soup_message_get_uri (message);
+    SoupMessage* full;
+    g_return_val_if_fail (uri && uri->host, message);
+    full = g_hash_table_lookup (message_map, uri->host);
+    g_return_val_if_fail (full, message);
+    return full;
+}
+
+void
+midori_location_action_show_page_info (GtkWidget* widget,
+                                       GtkBox*    box)
+{
+    MidoriBrowser* browser = midori_browser_get_for_widget (widget);
+    MidoriView* view = MIDORI_VIEW (midori_browser_get_current_tab (browser));
+    WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
+    WebKitWebFrame* web_frame = webkit_web_view_get_main_frame (web_view);
+    WebKitWebDataSource* source = webkit_web_frame_get_data_source (web_frame);
+    WebKitNetworkRequest* request = webkit_web_data_source_get_request (source);
+    SoupMessage* message = midori_map_get_message (webkit_network_request_get_message (request));
+    GTlsCertificate* tls_cert;
+    GTlsCertificateFlags tls_flags;
+
+    g_return_if_fail (message);
+    g_object_get (message, "tls-certificate", &tls_cert, "tls-errors", &tls_flags, NULL);
+
+    if (tls_cert == NULL)
+        return;
+
+    #if HAVE_GCR
+    GByteArray* der_cert;
+    GcrCertificate* gcr_cert;
+    GtkWidget* details;
+
+    g_object_get (tls_cert, "certificate", &der_cert, NULL);
+    gcr_cert = gcr_simple_certificate_new (
+        der_cert->data, der_cert->len);
+    g_byte_array_unref (der_cert);
+    g_object_unref (tls_cert);
+    details = (GtkWidget*)gcr_certificate_details_widget_new (gcr_cert);
+    gtk_widget_show (details);
+    gtk_container_add (GTK_CONTAINER (box), details);
+    #else
+    const gchar* tls_error;
+
+    if (!g_tls_certificate_get_issuer (tls_cert))
+        gtk_box_pack_start (box, gtk_label_new (_("Self-signed")), FALSE, FALSE, 0);
+
+    if (tls_flags & G_TLS_CERTIFICATE_UNKNOWN_CA)
+        tls_error = _("The signing certificate authority is not known.");
+    else if (tls_flags & G_TLS_CERTIFICATE_BAD_IDENTITY)
+        tls_error = _("The certificate does not match the expected identity of the site that it was retrieved from.");
+    else if(tls_flags & G_TLS_CERTIFICATE_NOT_ACTIVATED)
+        tls_error = _("The certificate's activation time is still in the future.");
+    else if (tls_flags & G_TLS_CERTIFICATE_EXPIRED)
+        tls_error = _("The certificate has expired");
+    else if (tls_flags & G_TLS_CERTIFICATE_REVOKED)
+        tls_error = _("The certificate has been revoked according to the GTlsConnection's certificate revocation list.");
+    else if (tls_flags & G_TLS_CERTIFICATE_INSECURE)
+        tls_error = _("The certificate's algorithm is considered insecure.");
+    else if (tls_flags & G_TLS_CERTIFICATE_GENERIC_ERROR)
+        tls_error = _("Some other error occurred validating the certificate.");
+    else
+        tls_error = "Unknown GTLSCertificateFlags value";
+
+    gtk_box_pack_start (box, gtk_label_new (tls_error), FALSE, FALSE, 0);
+    #endif
+
+    g_object_unref (tls_cert);
+}
+#endif
+
 static void
 midori_location_action_icon_released_cb (GtkWidget*           widget,
                                          GtkIconEntryPosition icon_pos,
@@ -1170,6 +1261,9 @@ midori_location_action_icon_released_cb (GtkWidget*           widget,
         gtk_box_pack_start (GTK_BOX (hbox),
             gtk_label_new (gtk_icon_entry_get_tooltip (GTK_ICON_ENTRY (widget), icon_pos)), FALSE, FALSE, 0);
         gtk_box_pack_start (GTK_BOX (content_area), hbox, FALSE, FALSE, 0);
+        #if defined (HAVE_LIBSOUP_2_34_0)
+        midori_location_action_show_page_info (widget, GTK_BOX (content_area));
+        #endif
         gtk_widget_show_all (dialog);
     }
     if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
diff --git a/midori/wscript_build b/midori/wscript_build
index 4290505..62ea674 100644
--- a/midori/wscript_build
+++ b/midori/wscript_build
@@ -8,7 +8,7 @@ import platform
 progressive = True
 libs = 'M UNIQUE LIBSOUP GMODULE GTHREAD LIBIDN GIO GTK SQLITE ' \
        'LIBNOTIFY WEBKIT JAVASCRIPTCOREGTK LIBXML X11 XSS WS2_32 HILDON' \
-       'HILDON_FM GRANITE'
+       'HILDON_FM GCR GRANITE'
 
 if progressive or Options.commands['check']:
     obj = bld.new_task_gen ('cc', 'staticlib')
diff --git a/wscript b/wscript
index 7123886..bea428c 100644
--- a/wscript
+++ b/wscript
@@ -265,8 +265,11 @@ def configure (conf):
         conf.define ('HAVE_LIBSOUP_2_29_91', 1)
     if check_version (conf.env['LIBSOUP_VERSION'], 2, 33, 4):
         conf.define ('HAVE_LIBSOUP_2_33_4', 1)
+    if check_version (conf.env['LIBSOUP_VERSION'], 2, 34, 0):
+        conf.define ('HAVE_LIBSOUP_2_34_0', 1)
     if check_version (conf.env['LIBSOUP_VERSION'], 2, 37, 1):
         conf.define ('HAVE_LIBSOUP_2_37_1', 1)
+    check_pkg ('gcr-3', '2.32', mandatory=False)
     check_pkg ('libxml-2.0', '2.6')
     check_pkg ('sqlite3', '3.6.19', True, var='SQLITE')
 


More information about the Xfce4-commits mailing list