2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2020 Matt Schatz <genius3000@g3k.solutions>
5 * Copyright (C) 2019 Robby <robby@chatbelgie.be>
6 * Copyright (C) 2018 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2014 Adam <Adam@anope.org>
8 * Copyright (C) 2013, 2015-2016 Attila Molnar <attilamolnar@hush.com>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "modules/ssl.h"
26 #include "modules/cap.h"
35 class CommandStartTLS : public SplitCommand
37 dynamic_reference_nocheck<IOHookProvider>& ssl;
40 CommandStartTLS(Module* mod, dynamic_reference_nocheck<IOHookProvider>& s)
41 : SplitCommand(mod, "STARTTLS")
44 works_before_reg = true;
47 CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
51 user->WriteNumeric(ERR_STARTTLS, "STARTTLS is not enabled");
55 if (user->registered == REG_ALL)
57 user->WriteNumeric(ERR_STARTTLS, "STARTTLS is not permitted after client registration is complete");
61 if (user->eh.GetIOHook())
63 user->WriteNumeric(ERR_STARTTLS, "STARTTLS failure");
67 user->WriteNumeric(RPL_STARTTLS, "STARTTLS successful, go ahead with TLS handshake");
68 /* We need to flush the write buffer prior to adding the IOHook,
69 * otherwise we'll be sending this line inside the TLS (SSL) session - which
70 * won't start its handshake until the client gets this line. Currently,
71 * we assume the write will not block here; this is usually safe, as
72 * STARTTLS is sent very early on in the registration phase, where the
73 * user hasn't built up much sendq. Handling a blocked write here would
78 ssl->OnAccept(&user->eh, NULL, NULL);
84 class ModuleStartTLS : public Module
86 CommandStartTLS starttls;
88 dynamic_reference_nocheck<IOHookProvider> ssl;
98 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
100 ConfigTag* conf = ServerInstance->Config->ConfValue("starttls");
102 std::string newprovider = conf->getString("provider");
103 if (newprovider.empty())
104 ssl.SetProvider("ssl");
106 ssl.SetProvider("ssl/" + newprovider);
109 Version GetVersion() CXX11_OVERRIDE
111 return Version("Provides the IRCv3 tls client capability.", VF_VENDOR);
115 MODULE_INIT(ModuleStartTLS)