mirror of
https://github.com/anope/anope.git
synced 2026-07-07 05:33:13 +02:00
Removed our RNG and just use the systems, it's not very widely used. Also made DNS query ids not random as they don't need to be.
This commit is contained in:
@@ -281,21 +281,6 @@ options
|
||||
*/
|
||||
passlen = 32
|
||||
|
||||
/*
|
||||
* These keys are used to initiate the random number generator. These numbers
|
||||
* MUST be random as you want your passcodes to be random. Don't give these
|
||||
* keys to anyone! Keep them private!
|
||||
*
|
||||
* NOTE: If you don't uncomment these or keep their default values, any talented
|
||||
* programmer would be able to easily "guess" random strings used to mask
|
||||
* information. Be safe, and come up with three different 7-digit numbers.
|
||||
*
|
||||
* These directives are optional, but highly recommended.
|
||||
*/
|
||||
#userkey1 = 9866235
|
||||
#userkey2 = 8362013
|
||||
#userkey3 = 2362899
|
||||
|
||||
/*
|
||||
* Allows Services to continue file write operations (i.e. database saving)
|
||||
* even if the original file cannot be backed up. Enabling this option may
|
||||
|
||||
@@ -625,11 +625,6 @@ class CoreExport ServerConfig
|
||||
/* List of modules to autoload */
|
||||
std::list<Anope::string> ModulesAutoLoad;
|
||||
|
||||
/* User keys to use for generating random hashes for pass codes etc */
|
||||
unsigned long UserKey1;
|
||||
unsigned long UserKey2;
|
||||
unsigned long UserKey3;
|
||||
|
||||
/* Numeric */
|
||||
Anope::string Numeric;
|
||||
/* Array of ulined servers */
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@ class CoreExport DNSManager : public Timer, public Socket
|
||||
sockaddrs addrs;
|
||||
public:
|
||||
std::deque<DNSPacket *> packets;
|
||||
std::map<short, DNSRequest *> requests;
|
||||
std::map<unsigned short, DNSRequest *> requests;
|
||||
|
||||
static const int DNSPort = 53;
|
||||
|
||||
|
||||
@@ -183,12 +183,6 @@ E Anope::string myStrGetTokenRemainder(const Anope::string &str, char dilim, int
|
||||
E int myNumToken(const Anope::string &str, char dilim);
|
||||
E bool nickIsServices(const Anope::string &nick, bool bot);
|
||||
|
||||
E void add_entropy_userkeys();
|
||||
E void rand_init();
|
||||
E unsigned char getrandom8();
|
||||
E uint16_t getrandom16();
|
||||
E uint32_t getrandom32();
|
||||
|
||||
E std::list<Anope::string> BuildStringList(const Anope::string &, char = ' ');
|
||||
E std::vector<Anope::string> BuildStringVector(const Anope::string &, char = ' ');
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ static bool SendRegmail(User *u, NickAlias *na, BotInfo *bi)
|
||||
};
|
||||
int idx, min = 1, max = 62;
|
||||
for (idx = 0; idx < 9; ++idx)
|
||||
codebuf += chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min];
|
||||
codebuf += chars[1 + static_cast<int>((static_cast<float>(max - min)) * static_cast<uint16_t>(rand()) / 65536.0) + min];
|
||||
na->nc->Extend("ns_register_passcode", new ExtensibleString(codebuf));
|
||||
}
|
||||
else
|
||||
|
||||
@@ -132,7 +132,7 @@ static bool SendResetEmail(User *u, NickAlias *na, BotInfo *bi)
|
||||
Anope::string passcode;
|
||||
int idx;
|
||||
for (idx = 0; idx < 20; ++idx)
|
||||
passcode += chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min];
|
||||
passcode += chars[1 + static_cast<int>((static_cast<float>(max - min)) * static_cast<uint16_t>(rand()) / 65536.0) + min];
|
||||
|
||||
Anope::string subject = translate(na->nc, Config->MailResetSubject.c_str());
|
||||
Anope::string message = translate(na->nc, Config->MailResetMessage.c_str());
|
||||
|
||||
@@ -25,7 +25,7 @@ static bool SendConfirmMail(User *u, BotInfo *bi)
|
||||
int idx, min = 1, max = 62;
|
||||
Anope::string code;
|
||||
for (idx = 0; idx < 9; ++idx)
|
||||
code += chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min];
|
||||
code += chars[1 + static_cast<int>((static_cast<float>(max - min)) * static_cast<uint16_t>(rand()) / 65536.0) + min];
|
||||
u->Account()->Extend("ns_set_email_passcode", new ExtensibleString(code));
|
||||
|
||||
Anope::string subject = Config->MailEmailchangeSubject;
|
||||
|
||||
@@ -128,7 +128,7 @@ class ESHA256 : public Module
|
||||
void NewRandomIV()
|
||||
{
|
||||
for (int i = 0; i < 8; ++i)
|
||||
iv[i] = getrandom32();
|
||||
iv[i] = static_cast<uint32_t>(rand());
|
||||
}
|
||||
|
||||
/* returns the IV as base64-encrypted string */
|
||||
|
||||
@@ -154,10 +154,6 @@ ServerConfig::ServerConfig() : config_data(), NSDefFlags(NickCoreFlagStrings), C
|
||||
this->SessionAutoKillExpiry = 1800; /* 30 minutes */
|
||||
}
|
||||
|
||||
/* Check the user keys */
|
||||
if (this->UserKey1 == this->UserKey2 || this->UserKey1 == this->UserKey3 || this->UserKey3 == this->UserKey2)
|
||||
Log() << "Every UserKey must be different. It's for YOUR safety! Remember that!";
|
||||
|
||||
SetDefaultMLock(this);
|
||||
|
||||
if (IsFile(this->NameServer))
|
||||
@@ -1132,9 +1128,6 @@ ConfigItems::ConfigItems(ServerConfig *conf)
|
||||
{"networkinfo", "userlen", "10", new ValueContainerUInt(&conf->UserLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
|
||||
{"networkinfo", "hostlen", "64", new ValueContainerUInt(&conf->HostLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
|
||||
{"options", "passlen", "32", new ValueContainerUInt(&conf->PassLen), DT_UINTEGER | DT_NORELOAD, NoValidation},
|
||||
{"options", "userkey1", "0", new ValueContainerLUInt(&conf->UserKey1), DT_LUINTEGER, NoValidation},
|
||||
{"options", "userkey2", "0", new ValueContainerLUInt(&conf->UserKey2), DT_LUINTEGER, NoValidation},
|
||||
{"options", "userkey3", "0", new ValueContainerLUInt(&conf->UserKey3), DT_LUINTEGER, NoValidation},
|
||||
{"options", "nobackupokay", "no", new ValueContainerBool(&conf->NoBackupOkay), DT_BOOLEAN, NoValidation},
|
||||
{"options", "strictpasswords", "no", new ValueContainerBool(&conf->StrictPasswords), DT_BOOLEAN, NoValidation},
|
||||
{"options", "badpasslimit", "0", new ValueContainerUInt(&conf->BadPassLimit), DT_UINTEGER, NoValidation},
|
||||
|
||||
+9
-6
@@ -52,8 +52,11 @@ DNSRequest::DNSRequest(const Anope::string &addr, QueryType qt, bool cache, Modu
|
||||
throw SocketException("DNS queue full");
|
||||
|
||||
do
|
||||
this->id = getrandom16();
|
||||
while (!this->id || DNSEngine->requests.count(this->id));
|
||||
{
|
||||
static unsigned short cur_id = 0;
|
||||
this->id = cur_id++;
|
||||
}
|
||||
while (DNSEngine->requests.count(this->id));
|
||||
|
||||
DNSEngine->requests[this->id] = this;
|
||||
}
|
||||
@@ -457,7 +460,7 @@ DNSManager::~DNSManager()
|
||||
delete this->packets[i - 1];
|
||||
this->packets.clear();
|
||||
|
||||
for (std::map<short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end; ++it)
|
||||
for (std::map<unsigned short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end; ++it)
|
||||
{
|
||||
DNSRequest *request = it->second;
|
||||
|
||||
@@ -504,7 +507,7 @@ bool DNSManager::ProcessRead()
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map<short, DNSRequest *>::iterator it = DNSEngine->requests.find(recv_packet.id);
|
||||
std::map<unsigned short, DNSRequest *>::iterator it = DNSEngine->requests.find(recv_packet.id);
|
||||
if (it == DNSEngine->requests.end())
|
||||
{
|
||||
Log(LOG_DEBUG_2) << "Resolver: Received an answer for something we didn't request";
|
||||
@@ -652,9 +655,9 @@ void DNSManager::Tick(time_t now)
|
||||
|
||||
void DNSManager::Cleanup(Module *mod)
|
||||
{
|
||||
for (std::map<short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end;)
|
||||
for (std::map<unsigned short, DNSRequest *>::iterator it = this->requests.begin(), it_end = this->requests.end(); it != it_end;)
|
||||
{
|
||||
short id = it->first;
|
||||
unsigned short id = it->first;
|
||||
DNSRequest *req = it->second;
|
||||
++it;
|
||||
|
||||
|
||||
+1
-2
@@ -459,8 +459,7 @@ void Init(int ac, char **av)
|
||||
InitLanguages();
|
||||
|
||||
/* Initialize random number generator */
|
||||
rand_init();
|
||||
add_entropy_userkeys();
|
||||
srand(time(NULL));
|
||||
|
||||
/* load modules */
|
||||
Log() << "Loading modules...";
|
||||
|
||||
-143
@@ -27,13 +27,6 @@ void ExtensibleItem::OnDelete()
|
||||
delete this;
|
||||
}
|
||||
|
||||
struct arc4_stream
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t j;
|
||||
uint8_t s[256];
|
||||
} rs;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/** Check if a file exists
|
||||
@@ -519,142 +512,6 @@ bool nickIsServices(const Anope::string &tempnick, bool bot)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* arc4 init
|
||||
* @return void
|
||||
*/
|
||||
static void arc4_init()
|
||||
{
|
||||
for (int n = 0; n < 256; ++n)
|
||||
rs.s[n] = n;
|
||||
rs.i = 0;
|
||||
rs.j = 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* arc4 addrandom
|
||||
* @param data
|
||||
* @param dalen Data Length
|
||||
* @return void
|
||||
*/
|
||||
static void arc4_addrandom(void *dat, int datlen)
|
||||
{
|
||||
--rs.i;
|
||||
for (int n = 0; n < 256; ++n)
|
||||
{
|
||||
++rs.i;
|
||||
uint8_t si = rs.s[rs.i];
|
||||
rs.j = rs.j + si + (static_cast<unsigned char *>(dat))[n % datlen];
|
||||
rs.s[rs.i] = rs.s[rs.j];
|
||||
rs.s[rs.j] = si;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* random init
|
||||
* @return void
|
||||
*/
|
||||
void rand_init()
|
||||
{
|
||||
struct
|
||||
{
|
||||
#ifndef _WIN32
|
||||
struct timeval nowt; /* time */
|
||||
char rnd[32]; /* /dev/urandom */
|
||||
#else
|
||||
MEMORYSTATUS mstat; /* memory status */
|
||||
struct _timeb nowt; /* time */
|
||||
#endif
|
||||
} rdat;
|
||||
|
||||
arc4_init();
|
||||
|
||||
/* Grab OS specific "random" data */
|
||||
#ifndef _WIN32
|
||||
/* unix/bsd: time */
|
||||
gettimeofday(&rdat.nowt, NULL);
|
||||
/* unix/bsd: /dev/urandom */
|
||||
int fd = open("/dev/urandom", O_RDONLY);
|
||||
if (fd)
|
||||
{
|
||||
read(fd, &rdat.rnd, sizeof(rdat.rnd));
|
||||
close(fd);
|
||||
}
|
||||
#else
|
||||
/* win32: time */
|
||||
_ftime(&rdat.nowt);
|
||||
/* win32: memory status */
|
||||
GlobalMemoryStatus(&rdat.mstat);
|
||||
#endif
|
||||
|
||||
arc4_addrandom(&rdat, sizeof(rdat));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Setup the random numbers
|
||||
* @return void
|
||||
*/
|
||||
void add_entropy_userkeys()
|
||||
{
|
||||
arc4_addrandom(&Config->UserKey1, sizeof(Config->UserKey1));
|
||||
arc4_addrandom(&Config->UserKey2, sizeof(Config->UserKey2));
|
||||
arc4_addrandom(&Config->UserKey3, sizeof(Config->UserKey3));
|
||||
/* UserKey3 is also used in mysql_rand() */
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the random numbers 8 byte deep
|
||||
* @return char
|
||||
*/
|
||||
unsigned char getrandom8()
|
||||
{
|
||||
++rs.i;
|
||||
unsigned char si = rs.s[rs.i];
|
||||
rs.j += si;
|
||||
unsigned char sj = rs.s[rs.j];
|
||||
rs.s[rs.i] = sj;
|
||||
rs.s[rs.j] = si;
|
||||
return rs.s[(si + sj) & 0xff];
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the random numbers 16 byte deep
|
||||
* @return char
|
||||
*/
|
||||
uint16_t getrandom16()
|
||||
{
|
||||
uint16_t val = getrandom8() << 8;
|
||||
val |= getrandom8();
|
||||
return val;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Get the random numbers 32 byte deep
|
||||
* @return char
|
||||
*/
|
||||
uint32_t getrandom32()
|
||||
{
|
||||
uint32_t val = getrandom8() << 24;
|
||||
val |= getrandom8() << 16;
|
||||
val |= getrandom8() << 8;
|
||||
val |= getrandom8();
|
||||
return val;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Number of tokens in a string
|
||||
* @param str String
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ Anope::string XLineManager::GenerateUID()
|
||||
{
|
||||
char c;
|
||||
do
|
||||
c = getrandom8();
|
||||
c = (random() % 75) + 48;
|
||||
while (!isupper(c) && !isdigit(c));
|
||||
id += c;
|
||||
}
|
||||
|
||||
+1
-1
@@ -321,7 +321,7 @@ void User::Collide(NickAlias *na)
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
guestnick = Config->NSGuestNickPrefix + stringify(getrandom16());
|
||||
guestnick = Config->NSGuestNickPrefix + stringify(static_cast<uint16_t>(rand()));
|
||||
} while (finduser(guestnick) && i++ < 10);
|
||||
|
||||
if (i == 11)
|
||||
|
||||
Reference in New Issue
Block a user