2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Robby <robby@chatbelgie.be>
5 * Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2014 Adam <Adam@anope.org>
7 * Copyright (C) 2013, 2015-2016 Attila Molnar <attilamolnar@hush.com>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "modules/ssl.h"
25 #include "modules/cap.h"
34 class CommandStartTLS : public SplitCommand
36 dynamic_reference_nocheck<IOHookProvider>& ssl;
39 CommandStartTLS(Module* mod, dynamic_reference_nocheck<IOHookProvider>& s)
40 : SplitCommand(mod, "STARTTLS")
43 works_before_reg = true;
46 CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
50 user->WriteNumeric(ERR_STARTTLS, "STARTTLS is not enabled");
54 if (user->registered == REG_ALL)
56 user->WriteNumeric(ERR_STARTTLS, "STARTTLS is not permitted after client registration is complete");
60 if (user->eh.GetIOHook())
62 user->WriteNumeric(ERR_STARTTLS, "STARTTLS failure");
66 user->WriteNumeric(RPL_STARTTLS, "STARTTLS successful, go ahead with TLS handshake");
67 /* We need to flush the write buffer prior to adding the IOHook,
68 * otherwise we'll be sending this line inside the SSL session - which
69 * won't start its handshake until the client gets this line. Currently,
70 * we assume the write will not block here; this is usually safe, as
71 * STARTTLS is sent very early on in the registration phase, where the
72 * user hasn't built up much sendq. Handling a blocked write here would
77 ssl->OnAccept(&user->eh, NULL, NULL);
83 class ModuleStartTLS : public Module
85 CommandStartTLS starttls;
87 dynamic_reference_nocheck<IOHookProvider> ssl;
97 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
99 ConfigTag* conf = ServerInstance->Config->ConfValue("starttls");
101 std::string newprovider = conf->getString("provider");
102 if (newprovider.empty())
103 ssl.SetProvider("ssl");
105 ssl.SetProvider("ssl/" + newprovider);
108 Version GetVersion() CXX11_OVERRIDE
110 return Version("Provides the STARTTLS command", VF_VENDOR);
114 MODULE_INIT(ModuleStartTLS)