2012-09-22 23:30:01 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 William Pitcock <nenolod@dereferenced.org>.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice is present in all copies.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-07 09:05:28 +01:00
|
|
|
static const char starttls_desc[] = "Provides the tls CAP and STARTTLS command";
|
2012-09-22 23:30:01 +02:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void mr_starttls(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
2016-03-09 08:29:41 +01:00
|
|
|
|
2012-09-22 23:30:01 +02:00
|
|
|
struct Message starttls_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"STARTTLS", 0, 0, 0, 0,
|
2012-09-22 23:30:01 +02:00
|
|
|
{{mr_starttls, 0}, mg_ignore, mg_ignore, mg_ignore, mg_ignore, mg_ignore}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 starttls_clist[] = { &starttls_msgtab, NULL };
|
|
|
|
|
2016-02-27 08:45:40 +01:00
|
|
|
unsigned int CLICAP_TLS = 0;
|
|
|
|
|
2016-03-07 10:14:02 +01:00
|
|
|
mapi_cap_list_av2 starttls_cap_list[] = {
|
|
|
|
{ MAPI_CAP_CLIENT, "tls", NULL, &CLICAP_TLS },
|
|
|
|
{ 0, NULL, NULL, NULL }
|
|
|
|
};
|
2016-02-27 08:45:40 +01:00
|
|
|
|
2016-03-07 10:15:50 +01:00
|
|
|
DECLARE_MODULE_AV2(starttls, NULL, NULL, starttls_clist, NULL, NULL, starttls_cap_list, NULL, starttls_desc);
|
2012-09-22 23:30:01 +02:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
mr_starttls(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2012-09-22 23:30:01 +02:00
|
|
|
{
|
|
|
|
ssl_ctl_t *ctl;
|
|
|
|
rb_fde_t *F[2];
|
|
|
|
|
|
|
|
if (!MyConnect(client_p))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2012-09-22 23:30:01 +02:00
|
|
|
|
2015-12-30 08:28:53 +01:00
|
|
|
if (IsSSL(client_p))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(client_p, ERR_STARTTLS, form_str(ERR_STARTTLS), "Nested TLS handshake not allowed");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2015-12-30 08:28:53 +01:00
|
|
|
}
|
|
|
|
|
2016-03-19 06:57:32 +01:00
|
|
|
if (!ircd_ssl_ok || !get_ssld_count())
|
2012-11-03 15:50:43 +01:00
|
|
|
{
|
|
|
|
sendto_one_numeric(client_p, ERR_STARTTLS, form_str(ERR_STARTTLS), "TLS is not configured");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2012-11-03 15:50:43 +01:00
|
|
|
}
|
|
|
|
|
2012-09-22 23:30:01 +02:00
|
|
|
if (rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &F[0], &F[1], "STARTTLS ssld session") == -1)
|
|
|
|
{
|
|
|
|
ilog_error("error creating SSL/TLS socketpair for ssld slave");
|
2012-09-23 02:31:55 +02:00
|
|
|
sendto_one_numeric(client_p, ERR_STARTTLS, form_str(ERR_STARTTLS), "Unable to create SSL/TLS socketpair for ssld offload slave");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2012-09-22 23:30:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s_assert(client_p->localClient != NULL);
|
|
|
|
|
|
|
|
/* clear out any remaining plaintext lines */
|
|
|
|
rb_linebuf_donebuf(&client_p->localClient->buf_recvq);
|
|
|
|
|
|
|
|
sendto_one_numeric(client_p, RPL_STARTTLS, form_str(RPL_STARTTLS));
|
|
|
|
send_queued(client_p);
|
|
|
|
|
2016-04-24 12:48:35 +02:00
|
|
|
/* TODO: set localClient->ssl_callback and handle success/failure */
|
|
|
|
|
2016-03-26 01:49:01 +01:00
|
|
|
ctl = start_ssld_accept(client_p->localClient->F, F[1], connid_get(client_p));
|
2012-09-22 23:30:01 +02:00
|
|
|
if (ctl != NULL)
|
|
|
|
{
|
|
|
|
client_p->localClient->F = F[0];
|
|
|
|
client_p->localClient->ssl_ctl = ctl;
|
|
|
|
SetSSL(client_p);
|
|
|
|
}
|
|
|
|
}
|