]> spindle.queued.net Git - midori/commitdiff
Render certificate, optionally with GCR
authorChristian Dywan <christian@twotoasts.de>
Mon, 16 Jul 2012 19:21:31 +0000 (21:21 +0200)
committerChristian Dywan <christian@twotoasts.de>
Mon, 16 Jul 2012 19:23:07 +0000 (21:23 +0200)
midori/main.c
midori/midori-locationaction.c
midori/wscript_build
wscript

index 11ffbb1d7331dd98a3047bc5c171874147c14e43..6a3e59a88476765de3320096fe1fa9b0ef89ca1d 100644 (file)
@@ -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);
 
index a76b1d88c03a7173e4eedc5526b69f3d46c0e7ec..154b989938eaf0e13de37338bdf56af234921dd4 100644 (file)
@@ -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)
index 4290505e3a2544bf648c7c845f4b33444322efe3..62ea67477bab2d41a06e9d65cad7c03f2b76ee97 100644 (file)
@@ -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 7123886478d94766a02a2f96a7f3e5683f819c14..bea428ca5e0ea9d03b02198f5aec22f24f088410 100644 (file)
--- 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')