2 * Copyright (c) 2012 William Pitcock <nenolod@dereferenced.org>.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice is present in all copies.
8 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18 * POSSIBILITY OF SUCH DAMAGE.
35 static const char starttls_desc
[] = "Provides the tls CAP and STARTTLS command";
37 static void mr_starttls(struct MsgBuf
*, struct Client
*, struct Client
*, int, const char **);
39 struct Message starttls_msgtab
= {
40 "STARTTLS", 0, 0, 0, 0,
41 {{mr_starttls
, 0}, mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
}
44 mapi_clist_av1 starttls_clist
[] = { &starttls_msgtab
, NULL
};
46 unsigned int CLICAP_TLS
= 0;
49 mapi_cap_list_av2 starttls_cap_list
[] = {
50 { MAPI_CAP_CLIENT
, "tls", NULL
, &CLICAP_TLS
},
51 { 0, NULL
, NULL
, NULL
}
53 #else /* HAVE_LIBCRYPTO */
55 mapi_cap_list_av2 starttls_cap_list
[] = { { 0, NULL
, NULL
, NULL
} };
57 #endif /* HAVE_LIBCRYPTO */
59 DECLARE_MODULE_AV2(starttls
, NULL
, NULL
, starttls_clist
, NULL
, NULL
, starttls_cap_list
, NULL
, starttls_desc
);
62 mr_starttls(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
68 if (!MyConnect(client_p
))
73 sendto_one_numeric(client_p
, ERR_STARTTLS
, form_str(ERR_STARTTLS
), "Nested TLS handshake not allowed");
77 if (!ircd_ssl_ok
|| !get_ssld_count())
79 sendto_one_numeric(client_p
, ERR_STARTTLS
, form_str(ERR_STARTTLS
), "TLS is not configured");
83 if (rb_socketpair(AF_UNIX
, SOCK_STREAM
, 0, &F
[0], &F
[1], "STARTTLS ssld session") == -1)
85 ilog_error("error creating SSL/TLS socketpair for ssld slave");
86 sendto_one_numeric(client_p
, ERR_STARTTLS
, form_str(ERR_STARTTLS
), "Unable to create SSL/TLS socketpair for ssld offload slave");
90 s_assert(client_p
->localClient
!= NULL
);
92 /* clear out any remaining plaintext lines */
93 rb_linebuf_donebuf(&client_p
->localClient
->buf_recvq
);
95 sendto_one_numeric(client_p
, RPL_STARTTLS
, form_str(RPL_STARTTLS
));
96 send_queued(client_p
);
98 ctl
= start_ssld_accept(client_p
->localClient
->F
, F
[1], connid_get(client_p
));
101 client_p
->localClient
->F
= F
[0];
102 client_p
->localClient
->ssl_ctl
= ctl
;
105 #else /* HAVE_LIBCRYPTO */
106 sendto_one_numeric(client_p
, ERR_STARTTLS
, form_str(ERR_STARTTLS
), "TLS is not configured");
107 #endif /* HAVE_LIBCRYPTO */