#include <openssl/err.h>
#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 };
return ERR_error_string(ERR_get_error(), NULL);
}
-class issl_session
+class issl_session : public classbase
{
public:
SSL* sess;
class ModuleSSLOpenSSL : public Module
{
- Server* Srv;
- ServerConfig* SrvConf;
+
ConfigReader* Conf;
- CullList culllist;
+ CullList* culllist;
std::vector<int> listenports;
SSL_CTX* ctx;
+ char* dummy;
+
std::string keyfile;
std::string certfile;
std::string cafile;
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();
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();
{
// 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);
{
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)
{
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");
}
}
}
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]);
}
}
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
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];
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)
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);
}
}
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.
}
}
- 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");
}
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");
}
{
// 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<std::string>* metadata = new std::deque<std::string>;
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);
}
}
{
}
- virtual Module * CreateModule(Server* Me)
+ virtual Module * CreateModule(InspIRCd* Me)
{
return new ModuleSSLOpenSSL(Me);
}
{
return new ModuleSSLOpenSSLFactory;
}
-