1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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** 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->WriteServ("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()
94 void Implements(char* List)
96 List[I_OnPreCommand] = List[I_OnRehash] = 1;
99 virtual void OnRehash(User* user, const std::string ¶meter)
102 cf = new ConfigReader(ServerInstance);
105 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
107 std::stringstream hl(hostlist);
111 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
120 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, User *user, bool validated, const std::string &original_line)
122 irc::string cmd = command.c_str();
124 if ((cmd == "OPER") && (validated))
126 char TheHost[MAXBUF];
128 std::string LoginName;
129 std::string Password;
130 std::string OperType;
131 std::string HostName;
132 std::string FingerPrint;
136 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
137 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
139 HasCert = user->GetExt("ssl_cert",cert);
141 for (int i = 0; i < cf->Enumerate("oper"); i++)
143 LoginName = cf->ReadValue("oper", "name", i);
144 Password = cf->ReadValue("oper", "password", i);
145 OperType = cf->ReadValue("oper", "type", i);
146 HostName = cf->ReadValue("oper", "host", i);
147 FingerPrint = cf->ReadValue("oper", "fingerprint", i);
148 SSLOnly = cf->ReadFlag("oper", "sslonly", i);
150 if (SSLOnly || !FingerPrint.empty())
152 if ((!strcmp(LoginName.c_str(),parameters[0])) && (!ServerInstance->OperPassCompare(Password.c_str(),parameters[1],i)) && (OneOfMatches(TheHost,TheIP,HostName.c_str())))
154 if (SSLOnly && !user->GetExt("ssl", dummy))
156 user->WriteServ("491 %s :This oper login name requires an SSL connection.", user->nick);
160 /* This oper would match */
161 if ((!cert) || (cert->GetFingerprint() != FingerPrint))
163 user->WriteServ("491 %s :This oper login name requires a matching key fingerprint.",user->nick);
164 ServerInstance->SNO->WriteToSnoMask('o',"'%s' cannot oper, does not match fingerprint", user->nick);
165 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but wrong fingerprint.",user->nick,user->ident,user->host);
175 virtual Version GetVersion()
177 return Version(1,1,0,0,VF_VENDOR,API_VERSION);
181 MODULE_INIT(ModuleOperSSLCert)