[gnome-online-accounts/gnome-3-8] Guard against invalid SSL certificates



commit a12bb2c494e9051bc552a13f88e78d4e6be054d0
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Feb 27 18:14:19 2013 +0100

    Guard against invalid SSL certificates
    
    For providers like ownCloud and Exchange which use libsoup to talk to
    a HTTPS server it is not enough to warn the user about an invalid
    certificate. We should make sure that we abort the connection before
    any credentials have been sent.
    
    Fixes: CVE-2013-1799

 src/goabackend/goaewsclient.c  |   40 +++++++++++++++++++++++++++-------------
 src/goabackend/goahttpclient.c |   38 ++++++++++++++++++++++++++------------
 2 files changed, 53 insertions(+), 25 deletions(-)
---
diff --git a/src/goabackend/goaewsclient.c b/src/goabackend/goaewsclient.c
index 8571770..f195b1c 100644
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -143,6 +143,25 @@ ews_client_authenticate (SoupSession *session,
 }
 
 static void
+ews_client_request_started (SoupSession *session, SoupMessage *msg, SoupSocket *socket, gpointer user_data)
+{
+  AutodiscoverData *data = user_data;
+  GError *error;
+  GTlsCertificateFlags cert_flags;
+
+  error = NULL;
+
+  if (!data->accept_ssl_errors
+      && soup_message_get_https_status (msg, NULL, &cert_flags)
+      && cert_flags != 0)
+    {
+      goa_utils_set_error_ssl (&error, cert_flags);
+      g_simple_async_result_take_error (data->res, error);
+      soup_session_abort (data->session);
+    }
+}
+
+static void
 ews_client_autodiscover_cancelled_cb (GCancellable *cancellable, gpointer user_data)
 {
   AutodiscoverData *data = user_data;
@@ -177,9 +196,7 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
 {
   GError *error;
   AutodiscoverData *data = user_data;
-  GTlsCertificateFlags cert_flags;
   gboolean op_res;
-  gboolean using_https;
   guint status;
   gint idx;
   gsize size;
@@ -204,6 +221,9 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
 
   data->msgs[idx] = NULL;
 
+  /* status == SOUP_STATUS_CANCELLED, if we are being aborted by the
+   * GCancellable or due to an SSL error.
+   */
   if (status == SOUP_STATUS_CANCELLED)
     goto out;
   else if (status != SOUP_STATUS_OK)
@@ -216,16 +236,6 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
       goto out;
     }
 
-  if (!data->accept_ssl_errors)
-    {
-      using_https = soup_message_get_https_status (msg, NULL, &cert_flags);
-      if (using_https && cert_flags != 0)
-        {
-          goa_utils_set_error_ssl (&error, cert_flags);
-          goto out;
-        }
-    }
-
   soup_buffer_free (soup_message_body_flatten (SOUP_MESSAGE (msg)->response_body));
   g_debug ("The response headers");
   g_debug ("===================");
@@ -310,7 +320,9 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
     }
 
  out:
-  /* error == NULL, if we are being aborted by the GCancellable */
+  /* error == NULL, if we are being aborted by the GCancellable or
+   * due to an SSL error.
+   */
   if (!op_res)
     {
       for (idx = 0; idx < size; idx++)
@@ -484,6 +496,8 @@ goa_ews_client_autodiscover (GoaEwsClient        *client,
                          ews_client_autodiscover_auth_data_free,
                          0);
 
+  g_signal_connect (data->session, "request-started", G_CALLBACK (ews_client_request_started), data);
+
   soup_session_queue_message (data->session, data->msgs[0], ews_client_autodiscover_response_cb, data);
   soup_session_queue_message (data->session, data->msgs[1], ews_client_autodiscover_response_cb, data);
 
diff --git a/src/goabackend/goahttpclient.c b/src/goabackend/goahttpclient.c
index 26cd493..c98f56c 100644
--- a/src/goabackend/goahttpclient.c
+++ b/src/goabackend/goahttpclient.c
@@ -127,6 +127,25 @@ http_client_authenticate (SoupSession *session,
 }
 
 static void
+http_client_request_started (SoupSession *session, SoupMessage *msg, SoupSocket *socket, gpointer user_data)
+{
+  CheckData *data = user_data;
+  GError *error;
+  GTlsCertificateFlags cert_flags;
+
+  error = NULL;
+
+  if (!data->accept_ssl_errors
+      && soup_message_get_https_status (msg, NULL, &cert_flags)
+      && cert_flags != 0)
+    {
+      goa_utils_set_error_ssl (&error, cert_flags);
+      g_simple_async_result_take_error (data->res, error);
+      soup_session_abort (data->session);
+    }
+}
+
+static void
 http_client_check_cancelled_cb (GCancellable *cancellable, gpointer user_data)
 {
   CheckData *data = user_data;
@@ -138,13 +157,14 @@ http_client_check_response_cb (SoupSession *session, SoupMessage *msg, gpointer
 {
   GError *error;
   CheckData *data = user_data;
-  GTlsCertificateFlags cert_flags;
   gboolean op_res;
-  gboolean using_https;
 
   error = NULL;
   op_res = FALSE;
 
+  /* status == SOUP_STATUS_CANCELLED, if we are being aborted by the
+   * GCancellable or due to an SSL error.
+   */
   if (msg->status_code == SOUP_STATUS_CANCELLED)
     goto out;
   else if (msg->status_code != SOUP_STATUS_OK)
@@ -157,19 +177,12 @@ http_client_check_response_cb (SoupSession *session, SoupMessage *msg, gpointer
       goto out;
     }
 
-  if (!data->accept_ssl_errors)
-    {
-      using_https = soup_message_get_https_status (msg, NULL, &cert_flags);
-      if (using_https && cert_flags != 0)
-        {
-          goa_utils_set_error_ssl (&error, cert_flags);
-          goto out;
-        }
-    }
-
   op_res = TRUE;
 
  out:
+  /* error == NULL, if we are being aborted by the GCancellable or
+   * due to an SSL error.
+   */
   g_simple_async_result_set_op_res_gboolean (data->res, op_res);
   if (error != NULL)
     g_simple_async_result_take_error (data->res, error);
@@ -248,6 +261,7 @@ goa_http_client_check (GoaHttpClient       *client,
                          http_client_check_auth_data_free,
                          0);
 
+  g_signal_connect (data->session, "request-started", G_CALLBACK (http_client_request_started), data);
   soup_session_queue_message (data->session, data->msg, http_client_check_response_cb, data);
 }
 


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