mirror of
https://github.com/irssi/irssi.git
synced 2026-08-09 20:00:23 +02:00
Merge pull request #1170 from ailin-nemui/starttls
use starttls / enable tls_verify
This commit is contained in:
commit
4432b0bf0d
25 changed files with 643 additions and 234 deletions
|
|
@ -101,6 +101,7 @@ static SERVER_SETUP_REC *create_server_setup(GHashTable *optlist)
|
|||
|
||||
server = rec->create_server_setup();
|
||||
server->chat_type = rec->id;
|
||||
server->tls_verify = TRUE;
|
||||
return server;
|
||||
}
|
||||
|
||||
|
|
@ -110,6 +111,7 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||
SERVER_SETUP_REC *rec;
|
||||
char *addr, *portstr, *password, *value, *chatnet;
|
||||
void *free_arg;
|
||||
gboolean newrec;
|
||||
int port;
|
||||
|
||||
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
||||
|
|
@ -135,6 +137,7 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||
rec = server_setup_find(addr, port, chatnet);
|
||||
|
||||
if (rec == NULL) {
|
||||
newrec = TRUE;
|
||||
if (add == FALSE) {
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
TXT_SETUPSERVER_NOT_FOUND, addr, port);
|
||||
|
|
@ -150,6 +153,7 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||
rec->address = g_strdup(addr);
|
||||
rec->port = port;
|
||||
} else {
|
||||
newrec = FALSE;
|
||||
if (*portstr != '\0' || g_hash_table_lookup(optlist, "port"))
|
||||
rec->port = port;
|
||||
|
||||
|
|
@ -165,20 +169,17 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||
else if (g_hash_table_lookup(optlist, "4"))
|
||||
rec->family = AF_INET;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "tls") || g_hash_table_lookup(optlist, "ssl")) {
|
||||
rec->use_tls = TRUE;
|
||||
}
|
||||
else if (g_hash_table_lookup(optlist, "notls") || g_hash_table_lookup(optlist, "nossl")) {
|
||||
rec->use_tls = FALSE;
|
||||
/* tls_verify implies use_tls, disable it explicitly */
|
||||
rec->tls_verify = FALSE;
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup(optlist, "tls_cert");
|
||||
if (value == NULL)
|
||||
value = g_hash_table_lookup(optlist, "ssl_cert");
|
||||
if (value != NULL && *value != '\0')
|
||||
if (value != NULL && *value != '\0') {
|
||||
rec->tls_cert = g_strdup(value);
|
||||
if (newrec) {
|
||||
/* convenience and backward compatibility, turn on tls if tls_cert is given
|
||||
*/
|
||||
rec->use_tls = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup(optlist, "tls_pkey");
|
||||
if (value == NULL)
|
||||
|
|
@ -192,11 +193,6 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||
if (value != NULL && *value != '\0')
|
||||
rec->tls_pass = g_strdup(value);
|
||||
|
||||
if (g_hash_table_lookup(optlist, "tls_verify") || g_hash_table_lookup(optlist, "ssl_verify"))
|
||||
rec->tls_verify = TRUE;
|
||||
else if (g_hash_table_lookup(optlist, "notls_verify") || g_hash_table_lookup(optlist, "nossl_verify"))
|
||||
rec->tls_verify = FALSE;
|
||||
|
||||
value = g_hash_table_lookup(optlist, "tls_cafile");
|
||||
if (value == NULL)
|
||||
value = g_hash_table_lookup(optlist, "ssl_cafile");
|
||||
|
|
@ -231,8 +227,23 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||
|| (rec->tls_capath != NULL && rec->tls_capath[0] != '\0'))
|
||||
rec->tls_verify = TRUE;
|
||||
|
||||
if ((rec->tls_cert != NULL && rec->tls_cert[0] != '\0') || rec->tls_verify == TRUE)
|
||||
if (g_hash_table_lookup(optlist, "tls_verify") ||
|
||||
g_hash_table_lookup(optlist, "ssl_verify")) {
|
||||
rec->tls_verify = TRUE;
|
||||
if (newrec) {
|
||||
/* convenience and backward compatibility, turn on tls if tls_verify is
|
||||
* given */
|
||||
rec->use_tls = TRUE;
|
||||
}
|
||||
} else if (g_hash_table_lookup(optlist, "notls_verify") ||
|
||||
g_hash_table_lookup(optlist, "nossl_verify")) {
|
||||
rec->tls_verify = FALSE;
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup(optlist, "tls") || g_hash_table_lookup(optlist, "ssl"))
|
||||
rec->use_tls = TRUE;
|
||||
else if (g_hash_table_lookup(optlist, "notls") || g_hash_table_lookup(optlist, "nossl"))
|
||||
rec->use_tls = FALSE;
|
||||
|
||||
if (g_hash_table_lookup(optlist, "auto")) rec->autoconnect = TRUE;
|
||||
if (g_hash_table_lookup(optlist, "noauto")) rec->autoconnect = FALSE;
|
||||
|
|
@ -246,7 +257,7 @@ static void cmd_server_add_modify(const char *data, gboolean add)
|
|||
rec->own_ip4 = rec->own_ip6 = NULL;
|
||||
}
|
||||
|
||||
signal_emit("server add fill", 2, rec, optlist);
|
||||
signal_emit("server add fill", 3, rec, optlist, GINT_TO_POINTER(add));
|
||||
|
||||
server_setup_add(rec);
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
|
|
|
|||
|
|
@ -51,12 +51,13 @@ const char *get_visible_target(IRC_SERVER_REC *server, const char *target)
|
|||
return target;
|
||||
}
|
||||
|
||||
/* SYNTAX: SERVER ADD|MODIFY [-4 | -6] [-tls] [-tls_cert <cert>] [-tls_pkey <pkey>] [-tls_pass <password>]
|
||||
[-tls_verify] [-tls_cafile <cafile>] [-tls_capath <capath>]
|
||||
[-tls_ciphers <list>]
|
||||
/* SYNTAX: SERVER ADD|MODIFY [-4 | -6] [-tls_cert <cert>] [-tls_pkey <pkey>]
|
||||
[-tls_pass <password>] [-tls_verify] [-tls_cafile <cafile>]
|
||||
[-tls_capath <capath>] [-tls_ciphers <list>] [-tls | -notls]
|
||||
[-starttls | -nostarttls | -disallow_starttls | -nodisallow_starttls]
|
||||
[-auto | -noauto] [-network <network>] [-host <hostname>]
|
||||
[-cmdspeed <ms>] [-cmdmax <count>] [-port <port>]
|
||||
<address> [<port> [<password>]] */
|
||||
[-cmdspeed <ms>] [-cmdmax <count>] [-port <port>] <address> [<port>
|
||||
[<password>]] */
|
||||
/* NOTE: -network replaces the old -ircnet flag. */
|
||||
static void sig_server_add_fill(IRC_SERVER_SETUP_REC *rec,
|
||||
GHashTable *optlist)
|
||||
|
|
@ -85,6 +86,28 @@ static void sig_server_add_fill(IRC_SERVER_SETUP_REC *rec,
|
|||
if (value != NULL && *value != '\0') rec->max_cmds_at_once = atoi(value);
|
||||
value = g_hash_table_lookup(optlist, "querychans");
|
||||
if (value != NULL && *value != '\0') rec->max_query_chans = atoi(value);
|
||||
if (g_hash_table_lookup(optlist, "nodisallow_starttls") ||
|
||||
g_hash_table_lookup(optlist, "nostarttls"))
|
||||
rec->starttls = STARTTLS_NOTSET;
|
||||
if (g_hash_table_lookup(optlist, "disallow_starttls"))
|
||||
rec->starttls = STARTTLS_DISALLOW;
|
||||
if (g_hash_table_lookup(optlist, "starttls")) {
|
||||
rec->starttls = STARTTLS_ENABLED;
|
||||
rec->use_tls = 0;
|
||||
}
|
||||
if (g_hash_table_lookup(optlist, "nocap"))
|
||||
rec->no_cap = 1;
|
||||
if (g_hash_table_lookup(optlist, "cap"))
|
||||
rec->no_cap = 0;
|
||||
}
|
||||
|
||||
static void sig_server_waiting_info(IRC_SERVER_REC *server, const char *version)
|
||||
{
|
||||
if (!IS_IRC_SERVER(server))
|
||||
return;
|
||||
|
||||
printformat(server, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_SERVER_WAITING_CAP_LS, server,
|
||||
version);
|
||||
}
|
||||
|
||||
/* SYNTAX: SERVER LIST */
|
||||
|
|
@ -108,29 +131,35 @@ static void cmd_server_list(const char *data)
|
|||
g_string_append(str, "autoconnect, ");
|
||||
if (rec->no_proxy)
|
||||
g_string_append(str, "noproxy, ");
|
||||
if (rec->use_tls) {
|
||||
if (rec->no_cap)
|
||||
g_string_append(str, "nocap, ");
|
||||
if (rec->starttls == STARTTLS_DISALLOW)
|
||||
g_string_append(str, "disallow_starttls, ");
|
||||
if (rec->starttls == STARTTLS_ENABLED)
|
||||
g_string_append(str, "starttls, ");
|
||||
if (rec->use_tls)
|
||||
g_string_append(str, "tls, ");
|
||||
if (rec->tls_cert) {
|
||||
g_string_append_printf(str, "tls_cert: %s, ", rec->tls_cert);
|
||||
if (rec->tls_pkey)
|
||||
g_string_append_printf(str, "tls_pkey: %s, ", rec->tls_pkey);
|
||||
if (rec->tls_pass)
|
||||
g_string_append_printf(str, "(pass), ");
|
||||
}
|
||||
if (rec->tls_verify)
|
||||
g_string_append(str, "tls_verify, ");
|
||||
if (rec->tls_cafile)
|
||||
g_string_append_printf(str, "tls_cafile: %s, ", rec->tls_cafile);
|
||||
if (rec->tls_capath)
|
||||
g_string_append_printf(str, "tls_capath: %s, ", rec->tls_capath);
|
||||
if (rec->tls_ciphers)
|
||||
g_string_append_printf(str, "tls_ciphers: %s, ", rec->tls_ciphers);
|
||||
if (rec->tls_pinned_cert)
|
||||
g_string_append_printf(str, "tls_pinned_cert: %s, ", rec->tls_pinned_cert);
|
||||
if (rec->tls_pinned_pubkey)
|
||||
g_string_append_printf(str, "tls_pinned_pubkey: %s, ", rec->tls_pinned_pubkey);
|
||||
|
||||
if (rec->tls_cert) {
|
||||
g_string_append_printf(str, "tls_cert: %s, ", rec->tls_cert);
|
||||
if (rec->tls_pkey)
|
||||
g_string_append_printf(str, "tls_pkey: %s, ", rec->tls_pkey);
|
||||
if (rec->tls_pass)
|
||||
g_string_append_printf(str, "(pass), ");
|
||||
}
|
||||
if (!rec->tls_verify)
|
||||
g_string_append(str, "notls_verify, ");
|
||||
if (rec->tls_cafile)
|
||||
g_string_append_printf(str, "tls_cafile: %s, ", rec->tls_cafile);
|
||||
if (rec->tls_capath)
|
||||
g_string_append_printf(str, "tls_capath: %s, ", rec->tls_capath);
|
||||
if (rec->tls_ciphers)
|
||||
g_string_append_printf(str, "tls_ciphers: %s, ", rec->tls_ciphers);
|
||||
if (rec->tls_pinned_cert)
|
||||
g_string_append_printf(str, "tls_pinned_cert: %s, ", rec->tls_pinned_cert);
|
||||
if (rec->tls_pinned_pubkey)
|
||||
g_string_append_printf(str, "tls_pinned_pubkey: %s, ",
|
||||
rec->tls_pinned_pubkey);
|
||||
|
||||
if (rec->max_cmds_at_once > 0)
|
||||
g_string_append_printf(str, "cmdmax: %d, ", rec->max_cmds_at_once);
|
||||
if (rec->cmd_queue_speed > 0)
|
||||
|
|
@ -153,13 +182,20 @@ static void cmd_server_list(const char *data)
|
|||
void fe_irc_server_init(void)
|
||||
{
|
||||
signal_add("server add fill", (SIGNAL_FUNC) sig_server_add_fill);
|
||||
signal_add("server waiting cap ls", (SIGNAL_FUNC) sig_server_waiting_info);
|
||||
command_bind("server list", NULL, (SIGNAL_FUNC) cmd_server_list);
|
||||
|
||||
command_set_options("server add", "-ircnet -network -cmdspeed -cmdmax -querychans");
|
||||
command_set_options("server add",
|
||||
"-ircnet -network -cmdspeed -cmdmax -querychans starttls "
|
||||
"nostarttls disallow_starttls nodisallow_starttls cap nocap");
|
||||
command_set_options("server modify",
|
||||
"-ircnet -network -cmdspeed -cmdmax -querychans starttls nostarttls "
|
||||
"disallow_starttls nodisallow_starttls cap nocap");
|
||||
}
|
||||
|
||||
void fe_irc_server_deinit(void)
|
||||
{
|
||||
signal_remove("server add fill", (SIGNAL_FUNC) sig_server_add_fill);
|
||||
signal_remove("server waiting cap ls", (SIGNAL_FUNC) sig_server_waiting_info);
|
||||
command_unbind("server list", (SIGNAL_FUNC) cmd_server_list);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ FORMAT_REC fecommon_irc_formats[] = {
|
|||
{ "setupserver_header", "%#Server Port Network Settings", 0 },
|
||||
{ "setupserver_line", "%#%|$[!20]0 $[5]1 $[10]2 $3", 4, { 0, 1, 0, 0 } },
|
||||
{ "setupserver_footer", "", 0 },
|
||||
{ "server_waiting_cap_ls", "Waiting for CAP LS response...", 2, { 0, 0 } },
|
||||
{ "sasl_success", "SASL authentication succeeded", 0 },
|
||||
{ "sasl_error", "Cannot authenticate via SASL ($0)", 1, { 0 } },
|
||||
{ "cap_req", "Capabilities requested: $0", 1, { 0 } },
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ enum {
|
|||
IRCTXT_SETUPSERVER_HEADER,
|
||||
IRCTXT_SETUPSERVER_LINE,
|
||||
IRCTXT_SETUPSERVER_FOOTER,
|
||||
IRCTXT_SERVER_WAITING_CAP_LS,
|
||||
IRCTXT_SASL_SUCCESS,
|
||||
IRCTXT_SASL_ERROR,
|
||||
IRCTXT_CAP_REQ,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue