2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2014 Adam <Adam@anope.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "modules/ssl.h"
22 #include "modules/cap.h"
31 class CommandStartTLS : public SplitCommand
33 dynamic_reference_nocheck<IOHookProvider>& ssl;
36 CommandStartTLS(Module* mod, dynamic_reference_nocheck<IOHookProvider>& s)
37 : SplitCommand(mod, "STARTTLS")
40 works_before_reg = true;
43 CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
47 user->WriteNumeric(ERR_STARTTLS, ":STARTTLS is not enabled");
51 if (user->registered == REG_ALL)
53 user->WriteNumeric(ERR_STARTTLS, ":STARTTLS is not permitted after client registration is complete");
57 if (user->eh.GetIOHook())
59 user->WriteNumeric(ERR_STARTTLS, ":STARTTLS failure");
63 user->WriteNumeric(RPL_STARTTLS, ":STARTTLS successful, go ahead with TLS handshake");
64 /* We need to flush the write buffer prior to adding the IOHook,
65 * otherwise we'll be sending this line inside the SSL session - which
66 * won't start its handshake until the client gets this line. Currently,
67 * we assume the write will not block here; this is usually safe, as
68 * STARTTLS is sent very early on in the registration phase, where the
69 * user hasn't built up much sendq. Handling a blocked write here would
74 ssl->OnAccept(&user->eh, NULL, NULL);
80 class ModuleStartTLS : public Module
82 CommandStartTLS starttls;
84 dynamic_reference_nocheck<IOHookProvider> ssl;
94 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
96 ConfigTag* conf = ServerInstance->Config->ConfValue("starttls");
98 std::string newprovider = conf->getString("provider");
99 if (newprovider.empty())
100 ssl.SetProvider("ssl");
102 ssl.SetProvider("ssl/" + newprovider);
105 Version GetVersion() CXX11_OVERRIDE
107 return Version("Provides support for the STARTTLS command", VF_VENDOR);
111 MODULE_INIT(ModuleStartTLS)