diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-05 20:05:31 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-12-05 20:05:31 +0000 |
commit | e770f8d983bc4eb674956ca365a70598615948f5 (patch) | |
tree | e5550447ecaf53dc7385bc48e4a71f6e3e390561 /src/modules | |
parent | e948507b19304625623f9bb150d3a0b0083b9a8d (diff) |
More tweakage
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5865 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_cloaking.cpp | 72 | ||||
-rw-r--r-- | src/modules/m_hash.h (renamed from src/modules/m_sha256.h) | 0 | ||||
-rw-r--r-- | src/modules/m_md5.cpp | 14 | ||||
-rw-r--r-- | src/modules/m_md5.h | 177 | ||||
-rw-r--r-- | src/modules/m_oper_hash.cpp | 51 | ||||
-rw-r--r-- | src/modules/m_sha256.cpp | 14 |
6 files changed, 72 insertions, 256 deletions
diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index 95b54b522..2eb078bf8 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -21,10 +21,10 @@ #include "channels.h" #include "modules.h" -#include "m_md5.h" +#include "m_hash.h" /* $ModDesc: Provides masking of user hostnames */ -/* $ModDep: m_md5.h */ +/* $ModDep: m_hash.h */ /* Used to vary the output a little more depending on the cloak keys */ static const char* xtab[] = {"F92E45D871BCA630", "A1B9D80C72E653F4", "1ABC078934DEF562", "ABCDEF5678901234"}; @@ -40,10 +40,10 @@ class CloakUser : public ModeHandler unsigned int key3; unsigned int key4; Module* Sender; - Module* MD5Provider; + Module* HashProvider; public: - CloakUser(InspIRCd* Instance, Module* Source, Module* MD5) : ModeHandler(Instance, 'x', 0, 0, false, MODETYPE_USER, false), Sender(Source), MD5Provider(MD5) + CloakUser(InspIRCd* Instance, Module* Source, Module* Hash) : ModeHandler(Instance, 'x', 0, 0, false, MODETYPE_USER, false), Sender(Source), HashProvider(Hash) { } @@ -90,13 +90,13 @@ class CloakUser : public ModeHandler std::string b; insp_inaddr testaddr; - /** Reset the MD5 module, and send it our IV and hex table */ - MD5ResetRequest(Sender, MD5Provider).Send(); - MD5KeyRequest(Sender, MD5Provider, iv).Send(); - MD5HexRequest(Sender, MD5Provider, xtab[0]); + /** Reset the Hash module, and send it our IV and hex table */ + HashResetRequest(Sender, HashProvider).Send(); + HashKeyRequest(Sender, HashProvider, iv).Send(); + HashHexRequest(Sender, HashProvider, xtab[0]); - /* Generate a cloak using specialized MD5 */ - std::string hostcloak = prefix + "-" + MD5SumRequest(Sender, MD5Provider, dest->host).Send() + a; + /* Generate a cloak using specialized Hash */ + std::string hostcloak = prefix + "-" + HashSumRequest(Sender, HashProvider, dest->host).Send() + a; /* Fix by brain - if the cloaked host is > the max length of a host (64 bytes * according to the DNS RFC) then tough titty, they get cloaked as an IP. @@ -154,22 +154,22 @@ class CloakUser : public ModeHandler octet3 = octet1 + "." + octet2 + "." + octet3; octet2 = octet1 + "." + octet2; - /* Reset the MD5 module and send it our IV */ - MD5ResetRequest(Sender, MD5Provider).Send(); - MD5KeyRequest(Sender, MD5Provider, iv).Send(); + /* Reset the Hash module and send it our IV */ + HashResetRequest(Sender, HashProvider).Send(); + HashKeyRequest(Sender, HashProvider, iv).Send(); - /* Send the MD5 module a different hex table for each octet group's MD5 sum */ - MD5HexRequest(Sender, MD5Provider, xtab[(key1+i1) % 4]).Send(); - ra1 = std::string(MD5SumRequest(Sender, MD5Provider, octet1).Send()).substr(0,6); + /* Send the Hash module a different hex table for each octet group's Hash sum */ + HashHexRequest(Sender, HashProvider, xtab[(key1+i1) % 4]).Send(); + ra1 = std::string(HashSumRequest(Sender, HashProvider, octet1).Send()).substr(0,6); - MD5HexRequest(Sender, MD5Provider, xtab[(key2+i2) % 4]).Send(); - ra2 = std::string(MD5SumRequest(Sender, MD5Provider, octet2).Send()).substr(0,6); + HashHexRequest(Sender, HashProvider, xtab[(key2+i2) % 4]).Send(); + ra2 = std::string(HashSumRequest(Sender, HashProvider, octet2).Send()).substr(0,6); - MD5HexRequest(Sender, MD5Provider, xtab[(key3+i3) % 4]).Send(); - ra3 = std::string(MD5SumRequest(Sender, MD5Provider, octet3).Send()).substr(0,6); + HashHexRequest(Sender, HashProvider, xtab[(key3+i3) % 4]).Send(); + ra3 = std::string(HashSumRequest(Sender, HashProvider, octet3).Send()).substr(0,6); - MD5HexRequest(Sender, MD5Provider, xtab[(key4+i4) % 4]).Send(); - ra4 = std::string(MD5SumRequest(Sender, MD5Provider, octet4).Send()).substr(0,6); + HashHexRequest(Sender, HashProvider, xtab[(key4+i4) % 4]).Send(); + ra4 = std::string(HashSumRequest(Sender, HashProvider, octet4).Send()).substr(0,6); /* Stick them all together */ return std::string().append(ra1).append(".").append(ra2).append(".").append(ra3).append(".").append(ra4); @@ -182,27 +182,27 @@ class CloakUser : public ModeHandler std::string item = ""; int rounds = 0; - /* Reset the MD5 module and send it our IV */ - MD5ResetRequest(Sender, MD5Provider).Send(); - MD5KeyRequest(Sender, MD5Provider, iv).Send(); + /* Reset the Hash module and send it our IV */ + HashResetRequest(Sender, HashProvider).Send(); + HashKeyRequest(Sender, HashProvider, iv).Send(); for (const char* input = ip; *input; input++) { item += *input; if (item.length() > 5) { - /* Send the MD5 module a different hex table for each octet group's MD5 sum */ - MD5HexRequest(Sender, MD5Provider, xtab[(key1+rounds) % 4]).Send(); - hashies.push_back(std::string(MD5SumRequest(Sender, MD5Provider, item).Send()).substr(0,10)); + /* Send the Hash module a different hex table for each octet group's Hash sum */ + HashHexRequest(Sender, HashProvider, xtab[(key1+rounds) % 4]).Send(); + hashies.push_back(std::string(HashSumRequest(Sender, HashProvider, item).Send()).substr(0,10)); item = ""; } rounds++; } if (!item.empty()) { - /* Send the MD5 module a different hex table for each octet group's MD5 sum */ - MD5HexRequest(Sender, MD5Provider, xtab[(key1+rounds) % 4]).Send(); - hashies.push_back(std::string(MD5SumRequest(Sender, MD5Provider, item).Send()).substr(0,10)); + /* Send the Hash module a different hex table for each octet group's Hash sum */ + HashHexRequest(Sender, HashProvider, xtab[(key1+rounds) % 4]).Send(); + hashies.push_back(std::string(HashSumRequest(Sender, HashProvider, item).Send()).substr(0,10)); item = ""; } /* Stick them all together */ @@ -236,19 +236,19 @@ class ModuleCloaking : public Module private: CloakUser* cu; - Module* MD5Module; + Module* HashModule; public: ModuleCloaking(InspIRCd* Me) : Module::Module(Me) { - /* Attempt to locate the MD5 service provider, bail if we can't find it */ - MD5Module = ServerInstance->FindModule("m_md5.so"); - if (!MD5Module) + /* Attempt to locate the Hash service provider, bail if we can't find it */ + HashModule = ServerInstance->FindModule("m_md5.so"); + if (!HashModule) throw ModuleException("Can't find m_md5.so. Please load m_md5.so before m_cloaking.so."); /* Create new mode handler object */ - cu = new CloakUser(ServerInstance, this, MD5Module); + cu = new CloakUser(ServerInstance, this, HashModule); /* Register it with the core */ ServerInstance->AddMode(cu, 'x'); diff --git a/src/modules/m_sha256.h b/src/modules/m_hash.h index 0c9eecdca..0c9eecdca 100644 --- a/src/modules/m_sha256.h +++ b/src/modules/m_hash.h diff --git a/src/modules/m_md5.cpp b/src/modules/m_md5.cpp index 55e462077..a753ef577 100644 --- a/src/modules/m_md5.cpp +++ b/src/modules/m_md5.cpp @@ -15,7 +15,7 @@ */ /* $ModDesc: Allows for MD5 encrypted oper passwords */ -/* $ModDep: m_md5.h */ +/* $ModDep: m_hash.h */ using namespace std; @@ -28,7 +28,7 @@ using namespace std; #include "modules.h" #include "inspircd.h" -#include "m_md5.h" +#include "m_hash.h" /* The four core functions - F1 is optimized somewhat */ #define F1(x, y, z) (z ^ (x & (y ^ z))) @@ -291,22 +291,22 @@ class ModuleMD5 : public Module virtual char* OnRequest(Request* request) { - MD5Request* MD5 = (MD5Request*)request; - if (strcmp("MD5_KEY", request->GetId()) == 0) + HashRequest* MD5 = (HashRequest*)request; + if (strcmp("KEY", request->GetId()) == 0) { this->key = (unsigned int*)MD5->GetKeyData(); } - else if (strcmp("MD5_HEX", request->GetId()) == 0) + else if (strcmp("HEX", request->GetId()) == 0) { this->chars = (char*)MD5->GetOutputs(); } - else if (strcmp("MD5_SUM", request->GetId()) == 0) + else if (strcmp("SUM", request->GetId()) == 0) { static char data[MAXBUF]; GenHash((const char*)MD5->GetHashData(), data, chars ? chars : "0123456789abcdef", key); return data; } - else if (strcmp("MD5_RESET", request->GetId()) == 0) + else if (strcmp("RESET", request->GetId()) == 0) { this->chars = NULL; this->key = NULL; diff --git a/src/modules/m_md5.h b/src/modules/m_md5.h deleted file mode 100644 index 448637359..000000000 --- a/src/modules/m_md5.h +++ /dev/null @@ -1,177 +0,0 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ - * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * <brain@chatspike.net> - * <Craig@chatspike.net> - * - * Written by Craig Edwards, Craig McLure, and others. - * This program is free but copyrighted software; see - * the file COPYING for details. - * - * --------------------------------------------------- - */ - -#ifndef __MD5_H__ -#define __MD5_H__ - -#include "modules.h" - -/** MD5Request is the base class used to send MD5 requests to m_md5.so. - * You should not instantiate classes of type MD5Request directly, instead - * you should instantiate classes of type MD5ResetRequest, MD5SumRequest, - * MD5KeyRequest and MD5HexRequest, shown below. - */ -class MD5Request : public Request -{ - /** The keys (IV) to use */ - unsigned int* keys; - /** The output characters (hex sequence) to use */ - const char* outputs; - /** The string to hash */ - std::string tohash; - public: - /** Initialize MD5Request as an MD5_RESET message */ - MD5Request(Module* Me, Module* Target) : Request(Me, Target, "MD5_RESET") - { - } - - /** Initialize MD5Request as an MD5_SUM message */ - MD5Request(Module* Me, Module* Target, const std::string &hashable) : Request(Me, Target, "MD5_SUM"), keys(NULL), outputs(NULL), tohash(hashable) - { - } - - /** Initialize MD5Request as an MD5_KEY message */ - MD5Request(Module* Me, Module* Target, unsigned int* k) : Request(Me, Target, "MD5_KEY"), keys(k), outputs(NULL), tohash("") - { - } - - /** Initialize MD5Request as an MD5_HEX message */ - MD5Request(Module* Me, Module* Target, const char* out) : Request(Me, Target, "MD5_HEX"), keys(NULL), outputs(out), tohash("") - { - } - - /** Get data to be hashed */ - const char* GetHashData() - { - return tohash.c_str(); - } - - /** Get keys (IVs) to be used */ - unsigned int* GetKeyData() - { - return keys; - } - - /** Get output characters (hex sequence) to be used */ - const char* GetOutputs() - { - return outputs; - } -}; - -/** Send this class to m_md5.so to reset the MD5 module to a known state. - * This will reset the IV to the defaults specified by the MD5 spec, - * and reset the hex sequence to "0123456789abcdef". It should be sent before - * ANY other Request types. - * - * Example: - * \code - * // Reset the MD5 module. - * MD5ResetRequest(this, MD5Module).Send(); - * \endcode - */ -class MD5ResetRequest : public MD5Request -{ - public: - /** Initialize MD5ResetRequest for sending. - * @param Me A pointer to the sending module - * @param Target A pointer to the m_md5.so module - */ - MD5ResetRequest(Module* Me, Module* Target) : MD5Request(Me, Target) - { - } -}; - -/** Send this class to m_md5.so to MD5SUM a std::string. - * You should make sure you know the state of the module before you send this - * class, e.g. by first sending an MD5ResetRequest class. The hash will be - * returned when you call Send(). - * - * Example: - * \code - * // ALWAYS ALWAYS reset first, or set your own IV and hex chars. - * MD5ResetRequest(this, MD5Module).Send(); - * // Get the MD5 sum of the string 'doodads'. - * std::string result = MD5SumRequest(this, MD5Module, "doodads").Send(); - * \endcode - */ -class MD5SumRequest : public MD5Request -{ - public: - /** Initialize MD5SumRequest for sending. - * @param Me A pointer to the sending module - * @param Target A pointer to the m_md5.so module - * @param data The data to be hashed - */ - MD5SumRequest(Module* Me, Module* Target, const std::string &data) : MD5Request(Me, Target, data) - { - } -}; - -/** Send this class to m_md5.so to change the IVs (keys) to use for hashing. - * You should make sure you know the state of the module before you send this - * class, e.g. by first sending an MD5ResetRequest class. The default values for - * the IV's are those specified in the MD5 specification. Only in very special - * circumstances should you need to change the IV's (see for example m_cloaking.cpp) - * - * Example: - * \code - * unsigned int iv[] = { 0xFFFFFFFF, 0x00000000, 0xAAAAAAAA, 0xCCCCCCCC }; - * MD5KeyRequest(this, MD5Module, iv); - * \endcode - */ -class MD5KeyRequest : public MD5Request -{ - public: - /** Initialize MD5KeyRequest for sending. - * @param Me A pointer to the sending module - * @param Target A pointer to the m_md5.so module - * @param data The new IV's. This should be an array of exactly four 32 bit values. - * On 64-bit architectures, the upper 32 bits of the values will be discarded. - */ - MD5KeyRequest(Module* Me, Module* Target, unsigned int* data) : MD5Request(Me, Target, data) - { - } -}; - -/** Send this class to m_md5.so to change the hex sequence to use for generating the returned value. - * You should make sure you know the state of the module before you send this - * class, e.g. by first sending an MD5ResetRequest class. The default value for - * the hex sequence is "0123456789abcdef". Only in very special circumstances should - * you need to change the hex sequence (see for example m_cloaking.cpp). - * - * Example: - * \code - * static const char tab[] = "fedcba9876543210"; - * MD5HexRequest(this, MD5Module, tab); - * \endcode - */ -class MD5HexRequest : public MD5Request -{ - public: - /** Initialize MD5HexRequest for sending. - * @param Me A pointer to the sending module - * @param Target A pointer to the m_md5.so module - * @param data The hex sequence to use. This should contain exactly 16 ASCII characters, - * terminated by a NULL char. - */ - MD5HexRequest(Module* Me, Module* Target, const char* data) : MD5Request(Me, Target, data) - { - } -}; - -#endif - diff --git a/src/modules/m_oper_hash.cpp b/src/modules/m_oper_hash.cpp index d74939a5d..e070bfc87 100644 --- a/src/modules/m_oper_hash.cpp +++ b/src/modules/m_oper_hash.cpp @@ -15,7 +15,7 @@ */ /* $ModDesc: Allows for hashed oper passwords */ -/* $ModDep: m_md5.h m_sha256.h */ +/* $ModDep: m_hash.h */ using namespace std; @@ -25,8 +25,7 @@ using namespace std; #include "modules.h" #include "inspircd.h" -#include "m_md5.h" -#include "m_sha256.h" +#include "m_hash.h" enum ProviderTypes { @@ -50,31 +49,21 @@ class cmd_mkpasswd : public command_t syntax = "<hashtype> <any-text>"; } + void MakeHash(userrec* user, Module* ProviderMod, const char* algo, const char* stuff) + { + HashResetRequest(Sender, ProviderMod); + user->WriteServ("NOTICE %s :%s hashed password for %s is %s",user->nick, algo, stuff, HashSumRequest(Sender, ProviderMod, stuff).Send() ); + } + CmdResult Handle (const char** parameters, int pcnt, userrec *user) { - if (!strcasecmp(parameters[0], "md5")) + if ((!strcasecmp(parameters[0], "MD5")) && ((Prov & PROV_MD5) > 0)) { - if ((Prov & PROV_MD5) > 0) - { - MD5ResetRequest(Sender, MD5Provider).Send(); - user->WriteServ("NOTICE %s :MD5 hashed password for %s is %s",user->nick, parameters[1], MD5SumRequest(Sender, MD5Provider, parameters[1]).Send() ); - } - else - { - user->WriteServ("NOTICE %s :MD5 hashing is not available (m_md5.so not loaded)"); - } + MakeHash(user, MD5Provider, "MD5", parameters[1]); } - else if (!strcasecmp(parameters[0], "sha256")) + else if ((!strcasecmp(parameters[0], "SHA256")) && ((Prov & PROV_SHA) > 0)) { - if ((Prov & PROV_SHA) > 0) - { - SHA256ResetRequest(Sender, SHAProvider).Send(); - user->WriteServ("NOTICE %s :SHA256 hashed password for %s is %s",user->nick, parameters[1], SHA256SumRequest(Sender, SHAProvider, parameters[1]).Send() ); - } - else - { - user->WriteServ("NOTICE %s :SHA256 hashing is not available (m_sha256.so not loaded)"); - } + MakeHash(user, SHAProvider, "SHA256", parameters[1]); } else { @@ -140,20 +129,24 @@ class ModuleOperHash : public Module virtual int OnOperCompare(const std::string &data, const std::string &input, int tagnumber) { std::string hashtype = Conf->ReadValue("oper", "hash", tagnumber); + Module* ModPtr = NULL; + if ((hashtype == "sha256") && (data.length() == SHA256_BLOCK_SIZE) && ((ID & PROV_SHA) > 0)) { - SHA256ResetRequest(this, SHAProvider).Send(); - if (!strcasecmp(data.c_str(), SHA256SumRequest(this, SHAProvider, input.c_str()).Send())) - return 1; - else return -1; + ModPtr = SHAProvider; } else if ((hashtype == "md5") && (data.length() == 32) && ((ID & PROV_MD5) > 0)) { - MD5ResetRequest(this, MD5Provider).Send(); - if (!strcasecmp(data.c_str(), MD5SumRequest(this, MD5Provider, input.c_str()).Send())) + ModPtr = MD5Provider; + } + if (ModPtr) + { + HashResetRequest(this, ModPtr).Send(); + if (!strcasecmp(data.c_str(), HashSumRequest(this, ModPtr, input.c_str()).Send())) return 1; else return -1; } + return 0; } diff --git a/src/modules/m_sha256.cpp b/src/modules/m_sha256.cpp index f446633b6..07bcab3ae 100644 --- a/src/modules/m_sha256.cpp +++ b/src/modules/m_sha256.cpp @@ -51,7 +51,7 @@ */ /* $ModDesc: Allows for SHA-256 encrypted oper passwords */ -/* $ModDep: m_sha256.h */ +/* $ModDep: m_hash.h */ #include "inspircd_config.h" #ifdef HAS_STDINT @@ -62,7 +62,7 @@ #include "modules.h" #include "inspircd.h" -#include "m_sha256.h" +#include "m_hash.h" #ifndef HAS_STDINT typedef unsigned int uint32_t; @@ -262,22 +262,22 @@ class ModuleSHA256 : public Module virtual char* OnRequest(Request* request) { - SHA256Request* SHA = (SHA256Request*)request; - if (strcmp("SHA256_KEY", request->GetId()) == 0) + HashRequest* SHA = (HashRequest*)request; + if (strcmp("KEY", request->GetId()) == 0) { this->key = (unsigned int*)SHA->GetKeyData(); } - else if (strcmp("SHA256_HEX", request->GetId()) == 0) + else if (strcmp("HEX", request->GetId()) == 0) { this->chars = (char*)SHA->GetOutputs(); } - else if (strcmp("SHA256_SUM", request->GetId()) == 0) + else if (strcmp("SUM", request->GetId()) == 0) { static char data[MAXBUF]; SHA256((const char*)SHA->GetHashData(), data, strlen(SHA->GetHashData()), chars ? chars : "0123456789abcdef", key); return data; } - else if (strcmp("SHA256_RESET", request->GetId()) == 0) + else if (strcmp("RESET", request->GetId()) == 0) { this->chars = NULL; this->key = NULL; |