[glib-networking] gnutls: Make the GTlsDatabase implementations cancellable



commit 6cda90ef7594c50bb8aeaa2c6acaedcebed24b11
Author: Stef Walter <stefw collabora co uk>
Date:   Sat Aug 13 14:39:21 2011 +0200

    gnutls: Make the GTlsDatabase implementations cancellable
    
    * Actually respect the cancellable paramater where possible
       in GTlsDatabaseGnutls and GTlsFileDatabaseGnutls
    
    https://bugzilla.gnome.org/show_bug.cgi?id=656454

 tls/gnutls/gtlsdatabase-gnutls.c     |    8 +++++++
 tls/gnutls/gtlsfiledatabase-gnutls.c |   37 ++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/tls/gnutls/gtlsdatabase-gnutls.c b/tls/gnutls/gtlsdatabase-gnutls.c
index 3e21052..ed82435 100644
--- a/tls/gnutls/gtlsdatabase-gnutls.c
+++ b/tls/gnutls/gtlsdatabase-gnutls.c
@@ -99,6 +99,9 @@ build_certificate_chain (GTlsDatabaseGnutls      *self,
 
   for (;;)
     {
+      if (g_cancellable_set_error_if_cancelled (cancellable, error))
+        return STATUS_FAILURE;
+
       /* Was the last certificate self-signed? */
       if (is_self_signed (certificate))
         {
@@ -240,6 +243,9 @@ g_tls_database_gnutls_verify_chain (GTlsDatabase           *database,
   if (status == STATUS_PINNED)
       return 0;
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return G_TLS_CERTIFICATE_GENERIC_ERROR;
+
   convert_certificate_chain_to_gnutls (G_TLS_CERTIFICATE_GNUTLS (chain),
                                        &certs, &certs_length);
 
@@ -265,6 +271,8 @@ g_tls_database_gnutls_verify_chain (GTlsDatabase           *database,
 
   if (gerr != 0)
       return G_TLS_CERTIFICATE_GENERIC_ERROR;
+  else if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return G_TLS_CERTIFICATE_GENERIC_ERROR;
 
   result = g_tls_certificate_gnutls_convert_flags (gnutls_result);
 
diff --git a/tls/gnutls/gtlsfiledatabase-gnutls.c b/tls/gnutls/gtlsfiledatabase-gnutls.c
index 22abfa4..c215dd5 100644
--- a/tls/gnutls/gtlsfiledatabase-gnutls.c
+++ b/tls/gnutls/gtlsfiledatabase-gnutls.c
@@ -401,6 +401,9 @@ g_tls_file_database_gnutls_lookup_certificate_for_handle (GTlsDatabase
   GByteArray *der;
   gnutls_datum_t datum;
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return NULL;
+
   if (!handle)
     return NULL;
 
@@ -421,6 +424,9 @@ g_tls_file_database_gnutls_lookup_certificate_for_handle (GTlsDatabase
   datum.data = der->data;
   datum.size = der->len;
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return NULL;
+
   return g_tls_certificate_gnutls_new (&datum, NULL);
 }
 
@@ -437,6 +443,9 @@ g_tls_file_database_gnutls_lookup_assertion (GTlsDatabaseGnutls          *databa
   GByteArray *der = NULL;
   gboolean contains;
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return FALSE;
+
   /* We only have anchored certificate assertions here */
   if (assertion != G_TLS_DATABASE_GNUTLS_ANCHORED_CERTIFICATE)
     return FALSE;
@@ -455,6 +464,9 @@ g_tls_file_database_gnutls_lookup_assertion (GTlsDatabaseGnutls          *databa
 
   g_byte_array_unref (der);
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return FALSE;
+
   /* All certificates in our file are anchored certificates */
   return contains;
 }
@@ -477,6 +489,9 @@ g_tls_file_database_gnutls_lookup_certificate_issuer (GTlsDatabase           *da
 
   g_return_val_if_fail (G_IS_TLS_CERTIFICATE_GNUTLS (certificate), NULL);
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return NULL;
+
   if (flags & G_TLS_DATABASE_LOOKUP_KEYPAIR)
     return NULL;
 
@@ -500,6 +515,9 @@ g_tls_file_database_gnutls_lookup_certificate_issuer (GTlsDatabase           *da
 
   g_byte_array_unref (subject);
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return NULL;
+
   if (der != NULL)
     {
       datum.data = der->data;
@@ -523,8 +541,12 @@ g_tls_file_database_gnutls_lookup_certificates_issued_by (GTlsDatabase
   gnutls_datum_t datum;
   GList *issued = NULL;
   GPtrArray *ders;
+  GList *l;
   guint i;
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return NULL;
+
   /* We don't have any private keys here */
   if (flags & G_TLS_DATABASE_LOOKUP_KEYPAIR)
     return NULL;
@@ -536,6 +558,15 @@ g_tls_file_database_gnutls_lookup_certificates_issued_by (GTlsDatabase
 
   for (i = 0; ders && i < ders->len; i++)
     {
+      if (g_cancellable_set_error_if_cancelled (cancellable, error))
+        {
+          for (l = issued; l != NULL; l = g_list_next (l))
+            g_object_unref (l->data);
+          g_list_free (issued);
+          issued = NULL;
+          break;
+        }
+
       der = ders->pdata[i];
       datum.data = der->data;
       datum.size = der->len;
@@ -582,6 +613,9 @@ g_tls_file_database_gnutls_initable_init (GInitable    *initable,
   GHashTable *subjects, *issuers, *complete;
   gboolean result;
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return FALSE;
+
   subjects = multi_byte_array_hash_new ();
   issuers = multi_byte_array_hash_new ();
 
@@ -592,6 +626,9 @@ g_tls_file_database_gnutls_initable_init (GInitable    *initable,
   result = load_anchor_file (self->priv->anchor_filename, subjects, issuers,
                              complete, error);
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    result = FALSE;
+
   if (result)
     {
       g_mutex_lock (self->priv->mutex);



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