1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "transport.h"
17 /* $ModDesc: Provides SSL metadata and /WHOIS information */
18 class ModuleSSLData : public Module
21 ModuleSSLData(InspIRCd* Me) : Module(Me)
23 Implementation eventlist[] = { I_OnSyncUserMetaData, I_OnDecodeMetaData, I_OnWhois };
24 ServerInstance->Modules->Attach(eventlist, this, 3);
27 virtual Version GetVersion()
29 return Version("$Id$", VF_VENDOR|VF_COMMON, API_VERSION);
33 // :kenny.chatspike.net 320 Om Epy|AFK :is a Secure Connection
34 virtual void OnWhois(User* source, User* dest)
36 if(dest->GetExt("ssl"))
38 ServerInstance->SendWhoisLine(source, dest, 320, "%s %s :is using a secure connection", source->nick.c_str(), dest->nick.c_str());
42 virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
44 // check if the linking module wants to know about OUR metadata
47 // check if this user has an ssl field to send
48 if (!user->GetExt(extname))
51 // call this function in the linking module, let it format the data how it
52 // sees fit, and send it on its way. We dont need or want to know how.
53 proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, displayable ? "Enabled" : "ON");
55 else if (extname == "ssl_cert")
58 if (!user->GetExt("ssl_cert", cert))
61 std::stringstream value;
62 bool hasError = cert->GetError().length();
63 value << (cert->IsInvalid() ? "v" : "V") << (cert->IsTrusted() ? "T" : "t") << (cert->IsRevoked() ? "R" : "r")
64 << (cert->IsUnknownSigner() ? "s" : "S") << (hasError ? "E" : "e") << " ";
66 value << cert->GetError();
68 value << cert->GetFingerprint() << " " << cert->GetDN() << " " << cert->GetIssuer();
70 proto->ProtoSendMetaData(opaque, TYPE_USER, user, extname, value.str().c_str());
74 virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata)
76 // check if its our metadata key, and its associated with a user
77 if ((target_type == TYPE_USER) && (extname == "ssl"))
79 User* dest = static_cast<User*>(target);
80 // if they dont already have an ssl flag, accept the remote server's
81 if (!dest->GetExt(extname))
83 dest->Extend(extname);
86 else if ((target_type == TYPE_USER) && (extname == "ssl_cert"))
88 User* dest = static_cast<User*>(target);
89 if (dest->GetExt(extname))
92 ssl_cert* cert = new ssl_cert;
93 dest->Extend(extname, cert);
95 std::stringstream s(extdata);
99 cert->data.insert(std::make_pair("invalid", ConvToStr(v.find('v') != std::string::npos)));
100 cert->data.insert(std::make_pair("trusted", ConvToStr(v.find('T') != std::string::npos)));
101 cert->data.insert(std::make_pair("revoked", ConvToStr(v.find('R') != std::string::npos)));
102 cert->data.insert(std::make_pair("unknownsigner", ConvToStr(v.find('s') != std::string::npos)));
103 if (v.find('E') != std::string::npos)
106 cert->data.insert(std::make_pair("error", v));
111 cert->data.insert(std::make_pair("fingerprint", v));
114 cert->data.insert(std::make_pair("dn", v));
117 cert->data.insert(std::make_pair("issuer", v));
123 MODULE_INIT(ModuleSSLData)