X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_ssl_openssl.cpp;h=a019d84abc5fafac667295582ae8b69e8b0886bc;hb=0b29e01eb5169f5e547b87c32de8e452ba3eff17;hp=880bbd1a3b7e0b7050848d12cd89c6eae94c70b4;hpb=366fea7aec3858bcaadfe1a66e7ae8afcde76ebc;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 880bbd1a3..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(); @@ -101,11 +107,11 @@ class ModuleSSLOpenSSL : public Module 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,12 +231,12 @@ 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"); } } } @@ -238,11 +246,11 @@ class ModuleSSLOpenSSL : public Module 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]); } } @@ -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) @@ -529,9 +531,9 @@ class ModuleSSLOpenSSL : public Module virtual void OnWhois(userrec* source, userrec* dest) { // Bugfix, only send this numeric for *our* SSL users - if(dest->GetExt("ssl") && isin(dest->port, listenports)) + if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->GetPort(), listenports))) { - WriteServ(source->fd, "320 %s %s :is using a secure connection", source->nick, dest->nick); + source->WriteServ("320 %s %s :is using a secure connection", source->nick, dest->nick); } } @@ -541,7 +543,7 @@ class ModuleSSLOpenSSL : public Module 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. @@ -550,14 +552,14 @@ class ModuleSSLOpenSSL : public Module } } - virtual void OnDecodeMetaData(int target_type, void* target, std::string extname, const 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"); } @@ -599,10 +601,10 @@ 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. - userrec* u = Srv->FindDescriptor(session->fd); + userrec* u = ServerInstance->FindDescriptor(session->fd); if (u) { - if (!u->GetExt("ssl")) + if (!u->GetExt("ssl", dummy)) u->Extend("ssl", "ON"); } @@ -618,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; @@ -626,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); } } @@ -668,7 +670,7 @@ class ModuleSSLOpenSSLFactory : public ModuleFactory { } - virtual Module * CreateModule(Server* Me) + virtual Module * CreateModule(InspIRCd* Me) { return new ModuleSSLOpenSSL(Me); } @@ -679,4 +681,3 @@ extern "C" void * init_module( void ) { return new ModuleSSLOpenSSLFactory; } -