[glib-networking] Remove explicit gcrypt references
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking] Remove explicit gcrypt references
- Date: Sat, 3 Dec 2011 11:48:47 +0000 (UTC)
commit deb4bf3245fdd54de420b2ce2c3e1e1a588f184f
Author: Dan Winship <danw gnome org>
Date: Sat Dec 3 12:41:23 2011 +0100
Remove explicit gcrypt references
gnutls 2.11 allows using nettle instead of gcrypt for crypto, and
gnutls 3.0 only supports nettle. But our gnutls code was making
explicit gcrypt calls to initialize gnutls thread-safety, which meant
we required gcrypt even if gnutls didn't.
Fortunately, gnutls 2.11 fixed this situation by initializing gcrypt
thread-safety by default (when using gcrypt), so we can just remove
all the explicit references to gcrypt from glib-networking (since we
already depend on gnutls 2.11 or later), and it all just works.
https://bugzilla.gnome.org/show_bug.cgi?id=657306
configure.ac | 3 +-
tls/gnutls/Makefile.am | 2 -
tls/gnutls/gtlsbackend-gnutls.c | 89 +++++----------------------------------
3 files changed, 12 insertions(+), 82 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4f8a19f..a408a54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,8 +93,7 @@ if test "x$with_gnutls" != "xno"; then
PKG_CHECK_MODULES(GNUTLS,
[gnutls >= $GNUTLS_MIN_REQUIRED],
[with_gnutls=yes
- tls_support="${tls_support}gnutls "
- AM_PATH_LIBGCRYPT([])],
+ tls_support="${tls_support}gnutls "],
[AS_IF([test "x$with_gnutls" = "xyes"],
[AC_MSG_FAILURE("$GNUTLS_PKG_ERRORS")])])
fi
diff --git a/tls/gnutls/Makefile.am b/tls/gnutls/Makefile.am
index 1d86c84..fd83f4f 100644
--- a/tls/gnutls/Makefile.am
+++ b/tls/gnutls/Makefile.am
@@ -50,7 +50,6 @@ libgiognutls_la_SOURCES = \
INCLUDES += \
$(P11_CFLAGS) \
$(LIBGNUTLS_CFLAGS) \
- $(LIBGCRYPT_CFLAGS) \
$(NULL)
libgiognutls_la_LDFLAGS = $(module_flags)
@@ -58,5 +57,4 @@ libgiognutls_la_LIBADD = \
$(P11_LIBADD) \
$(GLIB_LIBS) \
$(GNUTLS_LIBS) \
- $(LIBGCRYPT_LIBS) \
$(NULL)
diff --git a/tls/gnutls/gtlsbackend-gnutls.c b/tls/gnutls/gtlsbackend-gnutls.c
index 66a0a9e..6db3fec 100644
--- a/tls/gnutls/gtlsbackend-gnutls.c
+++ b/tls/gnutls/gtlsbackend-gnutls.c
@@ -21,12 +21,9 @@
#include "glib.h"
#include <errno.h>
+#include <string.h>
#include <gnutls/gnutls.h>
-#include <gcrypt.h>
-#ifndef G_OS_WIN32
-#include <pthread.h>
-#endif
#include "gtlsbackend-gnutls.h"
#include "gtlscertificate-gnutls.h"
@@ -40,63 +37,14 @@ struct _GTlsBackendGnutlsPrivate
GTlsDatabase *default_database;
};
+static void gtls_gnutls_init (void);
static void g_tls_backend_gnutls_interface_init (GTlsBackendInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GTlsBackendGnutls, g_tls_backend_gnutls, G_TYPE_OBJECT, 0,
G_IMPLEMENT_INTERFACE_DYNAMIC (G_TYPE_TLS_BACKEND,
- g_tls_backend_gnutls_interface_init);)
-
-#if defined(GCRY_THREAD_OPTION_PTHREAD_IMPL) && !defined(G_OS_WIN32)
-GCRY_THREAD_OPTION_PTHREAD_IMPL;
-#endif
-
-#ifdef G_OS_WIN32
-
-static int
-gtls_gcry_win32_mutex_init (void **priv)
-{
- int err = 0;
- CRITICAL_SECTION *lock = (CRITICAL_SECTION*)malloc (sizeof (CRITICAL_SECTION));
-
- if (!lock)
- err = ENOMEM;
- if (!err) {
- InitializeCriticalSection (lock);
- *priv = lock;
- }
- return err;
-}
-
-static int
-gtls_gcry_win32_mutex_destroy (void **lock)
-{
- DeleteCriticalSection ((CRITICAL_SECTION*)*lock);
- free (*lock);
- return 0;
-}
-
-static int
-gtls_gcry_win32_mutex_lock (void **lock)
-{
- EnterCriticalSection ((CRITICAL_SECTION*)*lock);
- return 0;
-}
-
-static int
-gtls_gcry_win32_mutex_unlock (void **lock)
-{
- LeaveCriticalSection ((CRITICAL_SECTION*)*lock);
- return 0;
-}
-
-
-static struct gcry_thread_cbs gtls_gcry_threads_win32 = { \
- (GCRY_THREAD_OPTION_USER | (GCRY_THREAD_OPTION_VERSION << 8)), \
- NULL, gtls_gcry_win32_mutex_init, gtls_gcry_win32_mutex_destroy, \
- gtls_gcry_win32_mutex_lock, gtls_gcry_win32_mutex_unlock, \
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
-
-#endif
+ g_tls_backend_gnutls_interface_init);
+ gtls_gnutls_init ();
+ )
#ifdef GTLS_GNUTLS_DEBUG
static void
@@ -106,40 +54,25 @@ gtls_log_func (int level, const char *msg)
}
#endif
-static gpointer
-gtls_gnutls_init (gpointer data)
+static void
+gtls_gnutls_init (void)
{
-#if defined(GCRY_THREAD_OPTION_PTHREAD_IMPL) && !defined(G_OS_WIN32)
- gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
-#elif defined(G_OS_WIN32)
- gcry_control (GCRYCTL_SET_THREAD_CBS, >ls_gcry_threads_win32);
-#endif
gnutls_global_init ();
#ifdef GTLS_GNUTLS_DEBUG
gnutls_global_set_log_function (gtls_log_func);
gnutls_global_set_log_level (9);
-#endif
- /* Leak the module to keep it from being unloaded. */
+ /* Leak the module to keep it from being unloaded and breaking
+ * the pointer to gtls_log_func().
+ */
g_type_plugin_use (g_type_get_plugin (G_TYPE_TLS_BACKEND_GNUTLS));
- return NULL;
+#endif
}
-static GOnce gnutls_inited = G_ONCE_INIT;
-
static void
g_tls_backend_gnutls_init (GTlsBackendGnutls *backend)
{
- /* Once we call gtls_gnutls_init(), we can't allow the module to be
- * unloaded, since that would break the pointers to the mutex
- * functions we set for gcrypt. So we initialize it from here rather
- * than at class init time so that it doesn't happen unless the app
- * is actually using TLS (as opposed to just calling
- * g_io_modules_scan_all_in_directory()).
- */
- g_once (&gnutls_inited, gtls_gnutls_init, NULL);
-
backend->priv = G_TYPE_INSTANCE_GET_PRIVATE (backend, G_TYPE_TLS_BACKEND_GNUTLS, GTlsBackendGnutlsPrivate);
g_mutex_init (&backend->priv->mutex);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]