summaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree
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/m_spanningtree
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/m_spanningtree')
-rw-r--r--src/modules/m_spanningtree/capab.cpp2
-rw-r--r--src/modules/m_spanningtree/hmac.cpp30
-rw-r--r--src/modules/m_spanningtree/treesocket.h4
3 files changed, 1 insertions, 35 deletions
diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp
index 80236c37e..ba34d67b4 100644
--- a/src/modules/m_spanningtree/capab.cpp
+++ b/src/modules/m_spanningtree/capab.cpp
@@ -129,7 +129,7 @@ void TreeSocket::SendCapabilities(int phase)
/* Do we have sha256 available? If so, we send a challenge */
if (Utils->ChallengeResponse && (ServerInstance->Modules->Find("m_sha256.so")))
{
- this->SetOurChallenge(RandString(20));
+ SetOurChallenge(ServerInstance->GenRandomStr(20));
extra = " CHALLENGE=" + this->GetOurChallenge();
}
diff --git a/src/modules/m_spanningtree/hmac.cpp b/src/modules/m_spanningtree/hmac.cpp
index c08ac1522..52128b17b 100644
--- a/src/modules/m_spanningtree/hmac.cpp
+++ b/src/modules/m_spanningtree/hmac.cpp
@@ -96,36 +96,6 @@ std::string TreeSocket::MakePass(const std::string &password, const std::string
return password;
}
-std::string TreeSocket::RandString(unsigned int ilength)
-{
- char* randombuf = new char[ilength+1];
- std::string out;
-#ifndef WINDOWS
- int f = open("/dev/urandom", O_RDONLY, 0);
-
- if (f >= 0)
- {
- if (read(f, randombuf, ilength) < (int)ilength)
- ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Entropy source has gone predictable (did not return enough data)");
- close(f);
- }
- else
-#endif
- {
- for (unsigned int i = 0; i < ilength; i++)
- randombuf[i] = rand();
- }
-
- for (unsigned int i = 0; i < ilength; i++)
- {
- char randchar = static_cast<char>(0x3F + (randombuf[i] & 0x3F));
- out += randchar;
- }
-
- delete[] randombuf;
- return out;
-}
-
bool TreeSocket::ComparePass(const Link& link, const std::string &theirs)
{
capab->auth_fingerprint = !link.Fingerprint.empty();
diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h
index 4438b473d..1eefc500e 100644
--- a/src/modules/m_spanningtree/treesocket.h
+++ b/src/modules/m_spanningtree/treesocket.h
@@ -146,10 +146,6 @@ class TreeSocket : public BufferedSocket
*/
~TreeSocket();
- /** Generate random string used for challenge-response auth
- */
- std::string RandString(unsigned int length);
-
/** Construct a password, optionally hashed with the other side's
* challenge string
*/