From 690c372f6ef246b43b477e3685c8e716431427ad Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 18 Nov 2013 13:48:07 +0000 Subject: Use gnutls_rnd instead of gcry_randomize on newer GnuTLS versions. Also, fix a bug where eval() caused compile errors. --- src/modules/extra/m_ssl_gnutls.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/modules/extra') diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index 2924b0902..f894043b7 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -22,7 +22,6 @@ #include "inspircd.h" -#include #include #include #include "modules/ssl.h" @@ -33,6 +32,12 @@ #include #endif +#if (GNUTLS_VERSION_MAJOR > 2 || GNUTLS_VERSION_MAJOR == 2 && GNUTLS_VERSION_MINOR > 12) +# define GNUTLS_HAS_RND +#else +# include +#endif + #ifdef _WIN32 # pragma comment(lib, "libgnutls.lib") # pragma comment(lib, "libgcrypt.lib") @@ -44,8 +49,8 @@ # pragma comment(lib, "gdi32.lib") #endif -/* $CompileFlags: pkgconfincludes("gnutls","/gnutls/gnutls.h","") exec("libgcrypt-config --cflags") -Wno-pedantic */ -/* $LinkerFlags: rpath("pkg-config --libs gnutls") pkgconflibs("gnutls","/libgnutls.so","-lgnutls") exec("libgcrypt-config --libs") */ +/* $CompileFlags: pkgconfincludes("gnutls","/gnutls/gnutls.h","") eval("print `libgcrypt-config --cflags | tr -d \r` if `pkg-config --modversion gnutls 2>/dev/null | tr -d \r` lt '2.12'") -Wno-pedantic */ +/* $LinkerFlags: rpath("pkg-config --libs gnutls") pkgconflibs("gnutls","/libgnutls.so","-lgnutls") eval("print `libgcrypt-config --libs | tr -d \r` if `pkg-config --modversion gnutls 2>/dev/null | tr -d \r` lt '2.12'") */ #ifndef GNUTLS_VERSION_MAJOR #define GNUTLS_VERSION_MAJOR LIBGNUTLS_VERSION_MAJOR @@ -92,7 +97,11 @@ class RandGen : public HandlerBase2 RandGen() {} void Call(char* buffer, size_t len) { +#ifdef GNUTLS_HAS_RND + gnutls_rnd(GNUTLS_RND_RANDOM, buffer, len); +#else gcry_randomize(buffer, len, GCRY_STRONG_RANDOM); +#endif } }; @@ -610,7 +619,9 @@ class ModuleSSLGnuTLS : public Module ModuleSSLGnuTLS() : iohook(this), starttls(this, iohook), capHandler(this, "tls") { +#ifndef GNUTLS_HAS_RND gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); +#endif gnutls_global_init(); // This must be called once in the program gnutls_x509_privkey_init(&x509_key); -- cgit v1.2.3