X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_ssl_openssl.cpp;h=fc0de61f4a8d55e7bcd9869b1c49b6c4b9be90b3;hb=c4cb1f9477b1fbf8662bedb1c36f84ff6f87e1f3;hp=20803e0829eda8995e6aad97a3db4b1a6c11d084;hpb=aab2a9bbcd817f58654a82d527750a13d66446f1;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 20803e082..fc0de61f4 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -152,15 +152,14 @@ class ModuleSSLOpenSSL : public Module OnModuleRehash(NULL,"ssl"); Implementation eventlist[] = { I_OnRawSocketConnect, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketRead, I_OnRawSocketWrite, I_OnCleanup, I_On005Numeric, - I_OnBufferFlushed, I_OnRequest, I_OnSyncUserMetaData, I_OnDecodeMetaData, - I_OnUnloadModule, I_OnRehash, I_OnModuleRehash, I_OnWhois, I_OnPostConnect, - I_OnHookUserIO }; - ServerInstance->Modules->Attach(eventlist, this, 17); + I_OnBufferFlushed, I_OnRequest, I_OnUnloadModule, I_OnRehash, I_OnModuleRehash, + I_OnPostConnect, I_OnHookIO }; + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } - virtual void OnHookUserIO(User* user, const std::string &targetip) + virtual void OnHookIO(EventHandler* user, ListenSocketBase* lsb) { - if (!user->GetIOHook() && isin(targetip,user->GetPort(), listenports)) + if (!user->GetIOHook() && isin(lsb->GetIP(),lsb->GetPort(),listenports)) { /* Hook the user with our module */ user->AddIOHook(this); @@ -425,7 +424,7 @@ class ModuleSSLOpenSSL : public Module } - virtual void OnRawSocketAccept(int fd, const std::string &ip, int localport) + virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) { /* Are there any possibilities of an out of range fd? Hope not, but lets be paranoid */ if ((fd < 0) || (fd > ServerInstance->SE->GetMaxFds() - 1)) @@ -709,48 +708,6 @@ class ModuleSSLOpenSSL : public Module } } - // :kenny.chatspike.net 320 Om Epy|AFK :is a Secure Connection - virtual void OnWhois(User* source, User* dest) - { - if (!clientactive) - return; - - // Bugfix, only send this numeric for *our* SSL users - if (dest->GetExt("ssl", dummy)) - { - ServerInstance->SendWhoisLine(source, dest, 320, "%s %s :is using a secure connection", source->nick.c_str(), dest->nick.c_str()); - } - } - - virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable) - { - // 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, 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. - proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, displayable ? "Enabled" : "ON"); - } - } - } - - 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")) - { - User* dest = (User*)target; - // if they dont already have an ssl flag, accept the remote server's - if (!dest->GetExt(extname, dummy)) - { - dest->Extend(extname, "ON"); - } - } - } - bool Handshake(issl_session* session) { int ret; @@ -791,8 +748,7 @@ class ModuleSSLOpenSSL : public Module EventHandler *u = ServerInstance->SE->GetRef(session->fd); if (u) { - if (!u->GetExt("ssl", dummy)) - u->Extend("ssl", "ON"); + u->Extend("ssl"); } session->status = ISSL_OPEN; @@ -816,12 +772,13 @@ class ModuleSSLOpenSSL : public Module // protocol module has propagated the NICK message. if ((user->GetIOHook() == this) && (IS_LOCAL(user))) { - // Tell whatever protocol module we're using that we need to inform other servers of this metadata NOW. - ServerInstance->PI->SendMetaData(user, TYPE_USER, "ssl", "on"); - - VerifyCertificate(&sessions[user->GetFd()], user); + ssl_cert* certdata = VerifyCertificate(&sessions[user->GetFd()], user); if (sessions[user->GetFd()].sess) user->WriteServ("NOTICE %s :*** You are connected using SSL cipher \"%s\"", user->nick.c_str(), SSL_get_cipher(sessions[user->GetFd()].sess)); + + ServerInstance->PI->SendMetaData(user, "ssl", "ON"); + if (certdata) + ServerInstance->PI->SendMetaData(user, "ssl_cert", certdata->GetMetaLine().c_str()); } } @@ -865,10 +822,10 @@ class ModuleSSLOpenSSL : public Module errno = EIO; } - void VerifyCertificate(issl_session* session, Extensible* user) + ssl_cert* VerifyCertificate(issl_session* session, Extensible* user) { if (!session->sess || !user) - return; + return NULL; X509* cert; ssl_cert* certinfo = new ssl_cert; @@ -882,41 +839,42 @@ class ModuleSSLOpenSSL : public Module if (!cert) { - certinfo->data.insert(std::make_pair("error","Could not get peer certificate: "+std::string(get_error()))); - return; + certinfo->error = "Could not get peer certificate: "+std::string(get_error()); + return certinfo; } - certinfo->data.insert(std::make_pair("invalid", SSL_get_verify_result(session->sess) != X509_V_OK ? ConvToStr(1) : ConvToStr(0))); + certinfo->invalid = (SSL_get_verify_result(session->sess) != X509_V_OK); if (SelfSigned) { - certinfo->data.insert(std::make_pair("unknownsigner",ConvToStr(0))); - certinfo->data.insert(std::make_pair("trusted",ConvToStr(1))); + certinfo->unknownsigner = false; + certinfo->trusted = true; } else { - certinfo->data.insert(std::make_pair("unknownsigner",ConvToStr(1))); - certinfo->data.insert(std::make_pair("trusted",ConvToStr(0))); + certinfo->unknownsigner = true; + certinfo->trusted = false; } - certinfo->data.insert(std::make_pair("dn",std::string(X509_NAME_oneline(X509_get_subject_name(cert),0,0)))); - certinfo->data.insert(std::make_pair("issuer",std::string(X509_NAME_oneline(X509_get_issuer_name(cert),0,0)))); + certinfo->dn = X509_NAME_oneline(X509_get_subject_name(cert),0,0); + certinfo->issuer = X509_NAME_oneline(X509_get_issuer_name(cert),0,0); if (!X509_digest(cert, digest, md, &n)) { - certinfo->data.insert(std::make_pair("error","Out of memory generating fingerprint")); + certinfo->error = "Out of memory generating fingerprint"; } else { - certinfo->data.insert(std::make_pair("fingerprint",irc::hex(md, n))); + certinfo->fingerprint = irc::hex(md, n); } if ((ASN1_UTCTIME_cmp_time_t(X509_get_notAfter(cert), ServerInstance->Time()) == -1) || (ASN1_UTCTIME_cmp_time_t(X509_get_notBefore(cert), ServerInstance->Time()) == 0)) { - certinfo->data.insert(std::make_pair("error","Not activated, or expired certificate")); + certinfo->error = "Not activated, or expired certificate"; } X509_free(cert); + return certinfo; } void Prioritize()