1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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 "inspircd_config.h"
22 #include "transport.h"
25 /** Handle /FINGERPRINT
27 class cmd_fingerprint : public Command
30 cmd_fingerprint (InspIRCd* Instance) : Command(Instance,"FINGERPRINT", 0, 1)
32 this->source = "m_ssl_oper_cert.so";
33 syntax = "<nickname>";
36 CmdResult Handle (const char* const* parameters, int pcnt, User *user)
38 User* target = ServerInstance->FindNick(parameters[0]);
42 if (target->GetExt("ssl_cert",cert))
44 if (cert->GetFingerprint().length())
46 user->WriteServ("NOTICE %s :Certificate fingerprint for %s is %s",user->nick,target->nick,cert->GetFingerprint().c_str());
51 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick,target->nick);
57 user->WriteServ("NOTICE %s :Certificate fingerprint for %s does not exist!", user->nick, target->nick);
63 user->WriteNumeric(401, "%s %s :No such nickname", user->nick, parameters[0]);
71 class ModuleOperSSLCert : public Module
75 cmd_fingerprint* mycommand;
79 ModuleOperSSLCert(InspIRCd* Me)
82 mycommand = new cmd_fingerprint(ServerInstance);
83 ServerInstance->AddCommand(mycommand);
84 cf = new ConfigReader(ServerInstance);
85 Implementation eventlist[] = { I_OnPreCommand, I_OnRehash };
86 ServerInstance->Modules->Attach(eventlist, this, 2);
89 virtual ~ModuleOperSSLCert()
95 virtual void OnRehash(User* user, const std::string ¶meter)
98 cf = new ConfigReader(ServerInstance);
101 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
103 std::stringstream hl(hostlist);
107 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
115 virtual int OnPreCommand(const std::string &command, const char* const* parameters, int pcnt, User *user, bool validated, const std::string &original_line)
117 irc::string cmd = command.c_str();
119 if ((cmd == "OPER") && (validated))
121 char TheHost[MAXBUF];
123 std::string LoginName;
124 std::string Password;
125 std::string OperType;
126 std::string HostName;
127 std::string HashType;
128 std::string FingerPrint;
132 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
133 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
135 HasCert = user->GetExt("ssl_cert",cert);
137 for (int i = 0; i < cf->Enumerate("oper"); i++)
139 LoginName = cf->ReadValue("oper", "name", i);
140 Password = cf->ReadValue("oper", "password", i);
141 OperType = cf->ReadValue("oper", "type", i);
142 HostName = cf->ReadValue("oper", "host", i);
143 HashType = cf->ReadValue("oper", "hash", i);
144 FingerPrint = cf->ReadValue("oper", "fingerprint", i);
145 SSLOnly = cf->ReadFlag("oper", "sslonly", i);
147 if (SSLOnly || !FingerPrint.empty())
149 if ((!strcmp(LoginName.c_str(),parameters[0])) && (!ServerInstance->PassCompare(user, Password.c_str(),parameters[1], HashType.c_str())) && (OneOfMatches(TheHost,TheIP,HostName.c_str())))
151 if (SSLOnly && !user->GetExt("ssl", dummy))
153 user->WriteNumeric(491, "%s :This oper login name requires an SSL connection.", user->nick);
157 /* This oper would match */
158 if ((!cert) || (cert->GetFingerprint() != FingerPrint))
160 user->WriteNumeric(491, "%s :This oper login name requires a matching key fingerprint.",user->nick);
161 ServerInstance->SNO->WriteToSnoMask('o',"'%s' cannot oper, does not match fingerprint", user->nick);
162 ServerInstance->Logs->Log("m_ssl_oper_cert",DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but wrong fingerprint.",user->nick,user->ident,user->host);
172 virtual Version GetVersion()
174 return Version(1,2,0,0,VF_VENDOR,API_VERSION);
178 MODULE_INIT(ModuleOperSSLCert)