summaryrefslogtreecommitdiff
path: root/src/modules/extra
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-09 02:22:27 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-09 02:22:27 +0000
commitaab7998583ca16590a32c7bdb80955a18b090700 (patch)
treea2b7f6d82a523e683347b7489ab77f0e940bdede /src/modules/extra
parentdb790d9d1516c9c7cd48738340e5df1c8a2bebe3 (diff)
Add random number generation functions to InspIRCd class.
Default implementation uses libc random(), which can be better than rand(). If gnutls is loaded, gcrypt will be used to provide random numbers. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12404 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/extra')
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index a0804ddf9..c2dc4c878 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -14,6 +14,7 @@
#include "inspircd.h"
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
+#include <gcrypt.h>
#include "ssl.h"
#include "m_cap.h"
@@ -69,6 +70,16 @@ static ssize_t gnutls_push_wrapper(gnutls_transport_ptr_t user_wrap, const void*
return rv;
}
+class RandGen : public HandlerBase2<void, char*, size_t>
+{
+ public:
+ RandGen() {}
+ void Call(char* buffer, size_t len)
+ {
+ gcry_randomize(buffer, len, GCRY_STRONG_RANDOM);
+ }
+};
+
/** Represents an SSL user's extra data
*/
class issl_session
@@ -136,6 +147,7 @@ class ModuleSSLGnuTLS : public Module
bool cred_alloc;
+ RandGen randhandler;
CommandStartTLS starttls;
GenericCap capHandler;
@@ -159,6 +171,8 @@ class ModuleSSLGnuTLS : public Module
// Needs the flag as it ignores a plain /rehash
OnModuleRehash(NULL,"ssl");
+ ServerInstance->GenRandom = &randhandler;
+
// Void return, guess we assume success
gnutls_certificate_set_dh_params(x509_cred, dh_params);
Implementation eventlist[] = { I_On005Numeric, I_OnRehash, I_OnModuleRehash, I_OnUserConnect,
@@ -294,6 +308,7 @@ class ModuleSSLGnuTLS : public Module
}
gnutls_global_deinit();
delete[] sessions;
+ ServerInstance->GenRandom = &ServerInstance->HandleGenRandom;
}
void OnCleanup(int target_type, void* item)