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 * ---------------------------------------------------
14 /* $ModDesc: Allows for MD5 encrypted oper passwords */
15 /* $ModDep: transport.h */
18 #include "transport.h"
20 /** Handle /FINGERPRINT
22 class CommandFingerprint : public Command
25 CommandFingerprint (InspIRCd* Instance) : Command(Instance,"FINGERPRINT", 0, 1)
27 this->source = "m_ssl_oper_cert.so";
28 syntax = "<nickname>";
31 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
33 User* target = ServerInstance->FindNick(parameters[0]);
37 if (target->GetExt("ssl_cert",cert))
39 if (cert->GetFingerprint().length())
41 user->WriteServ("NOTICE %s :Certificate fingerprint for %s is %s",user->nick.c_str(),target->nick.c_str(),cert->GetFingerprint().c_str());
46 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick.c_str(),target->nick.c_str());
52 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick.c_str(), target->nick.c_str());
58 user->WriteNumeric(401, "%s %s :No such nickname", user->nick.c_str(), parameters[0].c_str());
66 class ModuleOperSSLCert : public Module
70 CommandFingerprint* mycommand;
74 ModuleOperSSLCert(InspIRCd* Me)
77 mycommand = new CommandFingerprint(ServerInstance);
78 ServerInstance->AddCommand(mycommand);
79 cf = new ConfigReader(ServerInstance);
80 Implementation eventlist[] = { I_OnPreCommand, I_OnRehash };
81 ServerInstance->Modules->Attach(eventlist, this, 2);
84 virtual ~ModuleOperSSLCert()
90 virtual void OnRehash(User* user, const std::string ¶meter)
93 cf = new ConfigReader(ServerInstance);
96 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
98 std::stringstream hl(hostlist);
102 if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
110 virtual int OnPreCommand(std::string &command, std::vector<std::string> ¶meters, User *user, bool validated, const std::string &original_line)
112 irc::string cmd = command.c_str();
114 if ((cmd == "OPER") && (validated))
116 char TheHost[MAXBUF];
118 std::string LoginName;
119 std::string Password;
120 std::string OperType;
121 std::string HostName;
122 std::string HashType;
123 std::string FingerPrint;
127 snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(),user->host.c_str());
128 snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(),user->GetIPString());
130 HasCert = user->GetExt("ssl_cert",cert);
132 for (int i = 0; i < cf->Enumerate("oper"); i++)
134 LoginName = cf->ReadValue("oper", "name", i);
135 Password = cf->ReadValue("oper", "password", i);
136 OperType = cf->ReadValue("oper", "type", i);
137 HostName = cf->ReadValue("oper", "host", i);
138 HashType = cf->ReadValue("oper", "hash", i);
139 FingerPrint = cf->ReadValue("oper", "fingerprint", i);
140 SSLOnly = cf->ReadFlag("oper", "sslonly", i);
142 if (FingerPrint.empty() && !SSLOnly)
145 if (LoginName != parameters[0])
148 if (!OneOfMatches(TheHost, TheIP, HostName.c_str()))
151 if (Password.length() && ServerInstance->PassCompare(user, Password.c_str(),parameters[1].c_str(), HashType.c_str()))
154 if (SSLOnly && !user->GetExt("ssl", dummy))
156 user->WriteNumeric(491, "%s :This oper login name requires an SSL connection.", user->nick.c_str());
161 * No cert found or the fingerprint doesn't match
163 if ((!cert) || (cert->GetFingerprint() != FingerPrint))
165 user->WriteNumeric(491, "%s :This oper login name requires a matching key fingerprint.",user->nick.c_str());
166 ServerInstance->SNO->WriteToSnoMask('o',"'%s' cannot oper, does not match fingerprint", user->nick.c_str());
167 ServerInstance->Logs->Log("m_ssl_oper_cert",DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but wrong fingerprint.", user->nick.c_str(), user->ident.c_str(), user->host.c_str());
173 // Let core handle it for extra stuff
177 virtual Version GetVersion()
179 return Version("$Id$", VF_VENDOR, API_VERSION);
183 MODULE_INIT(ModuleOperSSLCert)