X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_ssl_openssl.cpp;h=a019d84abc5fafac667295582ae8b69e8b0886bc;hb=0b29e01eb5169f5e547b87c32de8e452ba3eff17;hp=9b0e52a7b1babf6ca1c38f43d1690442674c9f76;hpb=94d1d02c4c43ad3a77529cfef15a18a576a4d0f2;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index 9b0e52a7b..a019d84ab 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -5,17 +5,21 @@ #include #include "inspircd_config.h" +#include "configreader.h" #include "users.h" #include "channels.h" #include "modules.h" #include "helperfuncs.h" #include "socket.h" #include "hashcomp.h" +#include "inspircd.h" /* $ModDesc: Provides SSL support for clients */ /* $CompileFlags: -I/usr/include -I/usr/local/include */ /* $LinkerFlags: -L/usr/local/lib -Wl,--rpath -Wl,/usr/local/lib -L/usr/lib -Wl,--rpath -Wl,/usr/lib -lssl */ + + enum issl_status { ISSL_NONE, ISSL_HANDSHAKING, ISSL_OPEN }; enum issl_io_status { ISSL_WRITE, ISSL_READ }; @@ -33,7 +37,7 @@ char* get_error() return ERR_error_string(ERR_get_error(), NULL); } -class issl_session +class issl_session : public classbase { public: SSL* sess; @@ -55,11 +59,10 @@ public: class ModuleSSLOpenSSL : public Module { - Server* Srv; - ServerConfig* SrvConf; + ConfigReader* Conf; - CullList culllist; + CullList* culllist; std::vector listenports; @@ -68,6 +71,8 @@ class ModuleSSLOpenSSL : public Module SSL_CTX* ctx; + char* dummy; + std::string keyfile; std::string certfile; std::string cafile; @@ -76,14 +81,15 @@ class ModuleSSLOpenSSL : public Module public: - ModuleSSLOpenSSL(Server* Me) + ModuleSSLOpenSSL(InspIRCd* Me) : Module::Module(Me) { - Srv = Me; - SrvConf = Srv->GetConfig(); + + + culllist = new CullList(ServerInstance); // Not rehashable...because I cba to reduce all the sizes of existing buffers. - inbufsize = SrvConf->NetBufferSize; + inbufsize = ServerInstance->Config->NetBufferSize; /* Global SSL library initialization*/ SSL_library_init(); @@ -96,16 +102,16 @@ class ModuleSSLOpenSSL : public Module OnRehash("ssl"); } - virtual void OnRehash(std::string param) + virtual void OnRehash(const std::string ¶m) { if(param != "ssl") return; - Conf = new ConfigReader; + Conf = new ConfigReader(ServerInstance); for(unsigned int i = 0; i < listenports.size(); i++) { - SrvConf->DelIOHook(listenports[i]); + ServerInstance->Config->DelIOHook(listenports[i]); } listenports.clear(); @@ -117,7 +123,7 @@ class ModuleSSLOpenSSL : public Module { // Get the port we're meant to be listening on with SSL unsigned int port = Conf->ReadInteger("bind", "port", i, true); - if(SrvConf->AddIOHook(port, this)) + if (ServerInstance->Config->AddIOHook(port, this)) { // We keep a record of which ports we're listening on with SSL listenports.push_back(port); @@ -189,32 +195,34 @@ class ModuleSSLOpenSSL : public Module { log(DEFAULT, "m_ssl_openssl.so: Can't read CA list from ", cafile.c_str()); } - + FILE* dhpfile = fopen(dhfile.c_str(), "r"); DH* ret; if(dhpfile == NULL) { log(DEFAULT, "m_ssl_openssl.so Couldn't open DH file %s: %s", dhfile.c_str(), strerror(errno)); + throw ModuleException(); } else { ret = PEM_read_DHparams(dhpfile, NULL, NULL, NULL); + + if(SSL_CTX_set_tmp_dh(ctx, ret) < 0) + { + log(DEFAULT, "m_ssl_openssl.so: Couldn't set DH parameters"); + } } fclose(dhpfile); - - if(SSL_CTX_set_tmp_dh(ctx, ret) < 0) - { - log(DEFAULT, "m_ssl_openssl.so: Couldn't set DH parameters"); - } - delete Conf; + DELETE(Conf); } virtual ~ModuleSSLOpenSSL() { SSL_CTX_free(ctx); + delete culllist; } virtual void OnCleanup(int target_type, void* item) @@ -223,26 +231,26 @@ class ModuleSSLOpenSSL : public Module { userrec* user = (userrec*)item; - if(user->GetExt("ssl") && IS_LOCAL(user) && isin(user->port, listenports)) + if(user->GetExt("ssl", dummy) && IS_LOCAL(user) && isin(user->GetPort(), listenports)) { // User is using SSL, they're a local user, and they're using one of *our* SSL ports. // Potentially there could be multiple SSL modules loaded at once on different ports. log(DEBUG, "m_ssl_openssl.so: Adding user %s to cull list", user->nick); - culllist.AddItem(user, "SSL module unloading"); + culllist->AddItem(user, "SSL module unloading"); } } } - virtual void OnUnloadModule(Module* mod, std::string name) + virtual void OnUnloadModule(Module* mod, const std::string &name) { if(mod == this) { // We're being unloaded, kill all the users added to the cull list in OnCleanup - int numusers = culllist.Apply(); + int numusers = culllist->Apply(); log(DEBUG, "m_ssl_openssl.so: Killed %d users for unload of OpenSSL SSL module", numusers); for(unsigned int i = 0; i < listenports.size(); i++) - SrvConf->DelIOHook(listenports[i]); + ServerInstance->Config->DelIOHook(listenports[i]); } } @@ -257,7 +265,7 @@ class ModuleSSLOpenSSL : public Module List[I_OnSyncUserMetaData] = List[I_OnDecodeMetaData] = List[I_OnUnloadModule] = List[I_OnRehash] = List[I_OnWhois] = List[I_OnGlobalConnect] = 1; } - virtual void OnRawSocketAccept(int fd, std::string ip, int localport) + virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport) { issl_session* session = &sessions[fd]; @@ -362,9 +370,6 @@ class ModuleSSLOpenSSL : public Module session->inbufoffset = 0; } - log(DEBUG, "m_ssl_openssl.so: OnRawSocketRead: Passing %d bytes up to insp:"); - Srv->Log(DEBUG, std::string(buffer, readresult)); - return 1; } else @@ -377,7 +382,7 @@ class ModuleSSLOpenSSL : public Module return -1; } - virtual int OnRawSocketWrite(int fd, char* buffer, int count) + virtual int OnRawSocketWrite(int fd, const char* buffer, int count) { issl_session* session = &sessions[fd]; @@ -431,9 +436,6 @@ class ModuleSSLOpenSSL : public Module int DoWrite(issl_session* session) { - log(DEBUG, "m_ssl_openssl.so: DoWrite: Trying to write %d bytes:", session->outbuf.size()); - Srv->Log(DEBUG, session->outbuf); - int ret = SSL_write(session->sess, session->outbuf.data(), session->outbuf.size()); if(ret == 0) @@ -528,19 +530,20 @@ class ModuleSSLOpenSSL : public Module // :kenny.chatspike.net 320 Om Epy|AFK :is a Secure Connection virtual void OnWhois(userrec* source, userrec* dest) { - if(dest->GetExt("ssl")) + // Bugfix, only send this numeric for *our* SSL users + if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->GetPort(), listenports))) { - WriteServ(source->fd, "320 %s %s :is a secure connection", source->nick, dest->nick); + source->WriteServ("320 %s %s :is using a secure connection", source->nick, dest->nick); } } - virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, std::string extname) + virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname) { // check if the linking module wants to know about OUR metadata if(extname == "ssl") { // check if this user has an swhois field to send - if(user->GetExt(extname)) + if(user->GetExt(extname, dummy)) { // call this function in the linking module, let it format the data how it // sees fit, and send it on its way. We dont need or want to know how. @@ -549,14 +552,14 @@ class ModuleSSLOpenSSL : public Module } } - virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, std::string extdata) + virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata) { // check if its our metadata key, and its associated with a user if ((target_type == TYPE_USER) && (extname == "ssl")) { userrec* dest = (userrec*)target; // if they dont already have an ssl flag, accept the remote server's - if (!dest->GetExt(extname)) + if (!dest->GetExt(extname, dummy)) { dest->Extend(extname, "ON"); } @@ -598,7 +601,12 @@ class ModuleSSLOpenSSL : public Module log(DEBUG, "m_ssl_openssl.so: Handshake completed"); // This will do for setting the ssl flag...it could be done earlier if it's needed. But this seems neater. - Srv->FindDescriptor(session->fd)->Extend("ssl", "ON"); + userrec* u = ServerInstance->FindDescriptor(session->fd); + if (u) + { + if (!u->GetExt("ssl", dummy)) + u->Extend("ssl", "ON"); + } session->status = ISSL_OPEN; @@ -612,7 +620,7 @@ class ModuleSSLOpenSSL : public Module { // This occurs AFTER OnUserConnect so we can be sure the // protocol module has propogated the NICK message. - if ((user->GetExt("ssl")) && (IS_LOCAL(user))) + if ((user->GetExt("ssl", dummy)) && (IS_LOCAL(user))) { // Tell whatever protocol module we're using that we need to inform other servers of this metadata NOW. std::deque* metadata = new std::deque; @@ -620,9 +628,9 @@ class ModuleSSLOpenSSL : public Module metadata->push_back("ssl"); // The metadata id metadata->push_back("ON"); // The value to send Event* event = new Event((char*)metadata,(Module*)this,"send_metadata"); - event->Send(); // Trigger the event. We don't care what module picks it up. - delete event; - delete metadata; + event->Send(ServerInstance); // Trigger the event. We don't care what module picks it up. + DELETE(event); + DELETE(metadata); } } @@ -662,7 +670,7 @@ class ModuleSSLOpenSSLFactory : public ModuleFactory { } - virtual Module * CreateModule(Server* Me) + virtual Module * CreateModule(InspIRCd* Me) { return new ModuleSSLOpenSSL(Me); } @@ -673,4 +681,3 @@ extern "C" void * init_module( void ) { return new ModuleSSLOpenSSLFactory; } -