summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2013-11-18 08:05:29 -0800
committerAttila Molnar <attilamolnar@hush.com>2013-11-18 08:05:29 -0800
commit2eed59bea6f6e42c77ffd7e6061570c13f172e21 (patch)
treed6c6b97a3267e81236cadd5bb6617ca92001f435 /src
parentcada37c7b51c0f1bee8117caa0123412b2e48081 (diff)
parent690c372f6ef246b43b477e3685c8e716431427ad (diff)
Merge pull request #685 from SaberUK/master+gnutls-rng
Use gnutls_rnd instead of gcry_randomize on newer GnuTLS versions.
Diffstat (limited to 'src')
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp17
1 files changed, 14 insertions, 3 deletions
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 <gcrypt.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include "modules/ssl.h"
@@ -33,6 +32,12 @@
#include <gnutls/crypto.h>
#endif
+#if (GNUTLS_VERSION_MAJOR > 2 || GNUTLS_VERSION_MAJOR == 2 && GNUTLS_VERSION_MINOR > 12)
+# define GNUTLS_HAS_RND
+#else
+# include <gcrypt.h>
+#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<void, char*, size_t>
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);