summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Potter <agpotter@gmail.com>2021-03-26 17:27:37 -0700
committerSébastien Helleu <flashcode@flashtux.org>2021-05-16 10:00:30 +0200
commit94c902adfcbc7bae5039fe383ddfc5064297d40c (patch)
tree8fca3990db5140e48001a6c6b1fd7a5b25b52032 /src
parent670c5cd7456e4c9c3be0d3ef8a5cadd9df764b43 (diff)
downloadweechat-94c902adfcbc7bae5039fe383ddfc5064297d40c.zip
irc, buflist: add bar item "tls_version" with options for colors, add buflist format "${format_tls_version}" (issue #1622)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/buflist/buflist-bar-item.c10
-rw-r--r--src/plugins/buflist/buflist-command.c5
-rw-r--r--src/plugins/buflist/buflist-config.c16
-rw-r--r--src/plugins/buflist/buflist-config.h1
-rw-r--r--src/plugins/irc/irc-bar-item.c64
-rw-r--r--src/plugins/irc/irc-color.h3
-rw-r--r--src/plugins/irc/irc-config.c43
-rw-r--r--src/plugins/irc/irc-config.h3
-rw-r--r--src/plugins/irc/irc-protocol.c1
-rw-r--r--src/plugins/irc/irc-server.c33
-rw-r--r--src/plugins/irc/irc-server.h1
-rw-r--r--src/plugins/xfer/xfer-chat.c1
12 files changed, 178 insertions, 3 deletions
diff --git a/src/plugins/buflist/buflist-bar-item.c b/src/plugins/buflist/buflist-bar-item.c
index 88972cf8c..90cb7234d 100644
--- a/src/plugins/buflist/buflist-bar-item.c
+++ b/src/plugins/buflist/buflist-bar-item.c
@@ -312,7 +312,7 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
const char *hotlist_priority[4] = { "low", "message", "private",
"highlight" };
const char indent_empty[1] = { '\0' };
- const char *ptr_lag, *ptr_item_name;
+ const char *ptr_lag, *ptr_item_name, *ptr_tls_version;
int item_index, num_buffers, is_channel, is_private;
int i, j, length_max_number, current_buffer, number, prev_number, priority;
int rc, count, line_number, line_number_current_buffer;
@@ -596,6 +596,14 @@ buflist_bar_item_buflist_cb (const void *pointer, void *data,
"format_lag", "");
}
+ /* tls version */
+ ptr_tls_version = weechat_buffer_get_string (ptr_buffer, "localvar_tls_version");
+ weechat_hashtable_set (
+ buflist_hashtable_extra_vars,
+ "format_tls_version",
+ (ptr_tls_version && ptr_tls_version[0]) ?
+ weechat_config_string (buflist_config_format_tls_version) : "");
+
/* check condition: if false, the buffer is not displayed */
condition = weechat_string_eval_expression (
weechat_config_string (buflist_config_look_display_conditions),
diff --git a/src/plugins/buflist/buflist-command.c b/src/plugins/buflist/buflist-command.c
index 51ed01d37..7a8dfc7da 100644
--- a/src/plugins/buflist/buflist-command.c
+++ b/src/plugins/buflist/buflist-command.c
@@ -168,7 +168,10 @@ buflist_command_init ()
" - ${hotlist_priority}: \"none\", \"low\", \"message\", "
"\"private\" or \"highlight\"\n"
" - ${format_lag}: the lag for an IRC server buffer, empty if "
- "there's no lag (evaluation of option buflist.format.lag)"),
+ "there's no lag (evaluation of option buflist.format.lag)\n"
+ " - ${format_tls_version}: indicator of TLS version for a server "
+ "buffer, empty for channels. (evaluation of option "
+ "buflist.format.tls_version)"),
"enable|disable|toggle || bar || refresh",
&buflist_command_buflist, NULL, NULL);
}
diff --git a/src/plugins/buflist/buflist-config.c b/src/plugins/buflist/buflist-config.c
index ffd9a1877..9acac0036 100644
--- a/src/plugins/buflist/buflist-config.c
+++ b/src/plugins/buflist/buflist-config.c
@@ -59,6 +59,7 @@ struct t_config_option *buflist_config_format_lag;
struct t_config_option *buflist_config_format_name;
struct t_config_option *buflist_config_format_nick_prefix;
struct t_config_option *buflist_config_format_number;
+struct t_config_option *buflist_config_format_tls_version;
struct t_hook **buflist_config_signals_refresh = NULL;
int buflist_config_num_signals_refresh = 0;
@@ -403,7 +404,7 @@ buflist_config_add_eval_for_formats (const char *string)
char *formats[] = { "format_buffer", "format_number", "indent",
"format_nick_prefix", "format_name",
"format_hotlist", "hotlist", "format_lag",
- "color_hotlist", NULL };
+ "color_hotlist", "format_tls_version", NULL };
char *result, *tmp, format[512], format_eval[512];
int i;
@@ -773,6 +774,19 @@ buflist_config_init ()
NULL, NULL, NULL,
&buflist_config_change_buflist, NULL, NULL,
NULL, NULL, NULL);
+ buflist_config_format_tls_version = weechat_config_new_option (
+ buflist_config_file, ptr_section,
+ "tls_version", "string",
+ N_("format for tls_version on an IRC server buffer "
+ "(note: content is evaluated, see /help buflist)"),
+ NULL, 0, 0,
+ " ${color:default}(${if:${tls_version}==TLS1.3?${color:green}:"
+ "${if:${tls_version}==TLS1.2?${color:yellow}:${color:red}}}"
+ "${tls_version}${color:default})",
+ NULL, 0,
+ NULL, NULL, NULL,
+ &buflist_config_change_buflist, NULL, NULL,
+ NULL, NULL, NULL);
return 1;
}
diff --git a/src/plugins/buflist/buflist-config.h b/src/plugins/buflist/buflist-config.h
index 1a368fcde..2a655da06 100644
--- a/src/plugins/buflist/buflist-config.h
+++ b/src/plugins/buflist/buflist-config.h
@@ -58,6 +58,7 @@ extern struct t_config_option *buflist_config_format_lag;
extern struct t_config_option *buflist_config_format_name;
extern struct t_config_option *buflist_config_format_nick_prefix;
extern struct t_config_option *buflist_config_format_number;
+extern struct t_config_option *buflist_config_format_tls_version;
extern char **buflist_config_sort_fields[BUFLIST_BAR_NUM_ITEMS];
extern int buflist_config_sort_fields_count[BUFLIST_BAR_NUM_ITEMS];
diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c
index 2a39596ea..0990d02d1 100644
--- a/src/plugins/irc/irc-bar-item.c
+++ b/src/plugins/irc/irc-bar-item.c
@@ -23,6 +23,8 @@
#include <stdio.h>
#include <string.h>
+#include <gnutls/gnutls.h>
+
#include "../weechat-plugin.h"
#include "irc.h"
#include "irc-buffer.h"
@@ -520,6 +522,65 @@ irc_bar_item_lag (const void *pointer, void *data,
}
/*
+ * Returns content of bar item "tls_version": bar item with TLS version value.
+ */
+
+char *
+irc_bar_item_tls_version (const void *pointer, void *data,
+ struct t_gui_bar_item *item,
+ struct t_gui_window *window, struct t_gui_buffer *buffer,
+ struct t_hashtable *extra_info)
+{
+ char buf[128];
+ struct t_irc_server *server;
+ gnutls_protocol_t version;
+ const char *color;
+
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) item;
+ (void) window;
+ (void) extra_info;
+
+ if (!buffer)
+ return NULL;
+
+ irc_buffer_get_server_and_channel (buffer, &server, NULL);
+ if (server && server->is_connected)
+ {
+ if (server->ssl_connected)
+ {
+ version = gnutls_protocol_get_version (server->gnutls_sess);
+ switch (version)
+ {
+ case GNUTLS_TLS1_3:
+ color = IRC_COLOR_ITEM_TLS_VERSION_OK;
+ break;
+ case GNUTLS_TLS1_2:
+ color = IRC_COLOR_ITEM_TLS_VERSION_DEPRECATED;
+ break;
+ default:
+ color = IRC_COLOR_ITEM_TLS_VERSION_INSECURE;
+ }
+ snprintf (buf, sizeof (buf), "%s%s", color,
+ gnutls_protocol_get_name (version));
+ return strdup (buf);
+ }
+ else
+ {
+ snprintf (buf, sizeof (buf), "%s%s",
+ IRC_COLOR_ITEM_TLS_VERSION_INSECURE,
+ _("cleartext"));
+ return strdup (buf);
+ }
+ }
+
+ return NULL;
+}
+
+
+/*
* Returns content of bar item "input_prompt": bar item with input prompt.
*/
@@ -775,6 +836,7 @@ irc_bar_item_buffer_switch (const void *pointer, void *data,
weechat_bar_item_update ("irc_nick");
weechat_bar_item_update ("irc_host");
weechat_bar_item_update ("irc_nick_host");
+ weechat_bar_item_update ("tls_version");
return WEECHAT_RC_OK;
}
@@ -822,6 +884,8 @@ irc_bar_item_init ()
&irc_bar_item_nick_modes, NULL, NULL);
weechat_bar_item_new ("irc_nick_prefix",
&irc_bar_item_nick_prefix, NULL, NULL);
+ weechat_bar_item_new ("tls_version",
+ &irc_bar_item_tls_version, NULL, NULL);
weechat_hook_focus ("buffer_nicklist",
&irc_bar_item_focus_buffer_nicklist, NULL, NULL);
diff --git a/src/plugins/irc/irc-color.h b/src/plugins/irc/irc-color.h
index 0b4f62597..20383f65c 100644
--- a/src/plugins/irc/irc-color.h
+++ b/src/plugins/irc/irc-color.h
@@ -99,6 +99,9 @@
#define IRC_COLOR_ITEM_LAG_COUNTING weechat_color(weechat_config_string(irc_config_color_item_lag_counting))
#define IRC_COLOR_ITEM_LAG_FINISHED weechat_color(weechat_config_string(irc_config_color_item_lag_finished))
#define IRC_COLOR_ITEM_NICK_MODES weechat_color(weechat_config_string(irc_config_color_item_nick_modes))
+#define IRC_COLOR_ITEM_TLS_VERSION_OK weechat_color(weechat_config_string(irc_config_color_item_tls_version_ok))
+#define IRC_COLOR_ITEM_TLS_VERSION_DEPRECATED weechat_color(weechat_config_string(irc_config_color_item_tls_version_deprecated))
+#define IRC_COLOR_ITEM_TLS_VERSION_INSECURE weechat_color(weechat_config_string(irc_config_color_item_tls_version_insecure))
struct t_irc_color_ansi_state
{
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index c6ad6b52d..e64d171f7 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -116,6 +116,9 @@ struct t_config_option *irc_config_color_item_channel_modes;
struct t_config_option *irc_config_color_item_lag_counting;
struct t_config_option *irc_config_color_item_lag_finished;
struct t_config_option *irc_config_color_item_nick_modes;
+struct t_config_option *irc_config_color_item_tls_version_ok;
+struct t_config_option *irc_config_color_item_tls_version_deprecated;
+struct t_config_option *irc_config_color_item_tls_version_insecure;
struct t_config_option *irc_config_color_message_account;
struct t_config_option *irc_config_color_message_join;
struct t_config_option *irc_config_color_message_chghost;
@@ -699,6 +702,22 @@ irc_config_change_color_item_nick_modes (const void *pointer, void *data,
}
/*
+ * Callback for changes on options "irc.color.item_tls_version_*".
+ */
+
+void
+irc_config_change_color_item_tls_version (const void *pointer, void *data,
+ struct t_config_option *option)
+{
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) option;
+
+ weechat_bar_item_update ("tls_version");
+}
+
+/*
* Callback for changes on option "irc.color.mirc_remap".
*/
@@ -3228,6 +3247,30 @@ irc_config_init ()
NULL, NULL, NULL,
&irc_config_change_color_item_nick_modes, NULL, NULL,
NULL, NULL, NULL);
+ irc_config_color_item_tls_version_ok = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "item_tls_version_ok", "color",
+ N_("color for max supported TLS version in bar item \"tls_version\""),
+ NULL, -1, 0, "green", NULL, 0,
+ NULL, NULL, NULL,
+ &irc_config_change_color_item_tls_version, NULL, NULL,
+ NULL, NULL, NULL);
+ irc_config_color_item_tls_version_deprecated = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "item_tls_version_deprecated", "color",
+ N_("color for deprecated TLS versions in bar item \"tls_version\""),
+ NULL, -1, 0, "yellow", NULL, 0,
+ NULL, NULL, NULL,
+ &irc_config_change_color_item_tls_version, NULL, NULL,
+ NULL, NULL, NULL);
+ irc_config_color_item_tls_version_insecure = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "item_tls_version_insecure", "color",
+ N_("color for insecure TLS versions in bar item \"tls_version\""),
+ NULL, -1, 0, "red", NULL, 0,
+ NULL, NULL, NULL,
+ &irc_config_change_color_item_tls_version, NULL, NULL,
+ NULL, NULL, NULL);
irc_config_color_message_account = weechat_config_new_option (
irc_config_file, ptr_section,
"message_account", "color",
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index b0d6a849f..cbd7f45f1 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -154,6 +154,9 @@ extern struct t_config_option *irc_config_color_item_channel_modes;
extern struct t_config_option *irc_config_color_item_lag_counting;
extern struct t_config_option *irc_config_color_item_lag_finished;
extern struct t_config_option *irc_config_color_item_nick_modes;
+extern struct t_config_option *irc_config_color_item_tls_version_ok;
+extern struct t_config_option *irc_config_color_item_tls_version_deprecated;
+extern struct t_config_option *irc_config_color_item_tls_version_insecure;
extern struct t_config_option *irc_config_color_message_account;
extern struct t_config_option *irc_config_color_message_chghost;
extern struct t_config_option *irc_config_color_message_join;
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 5be5796f4..f5f91b9e0 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -2994,6 +2994,7 @@ IRC_PROTOCOL_CALLBACK(001)
server->is_connected = 1;
server->reconnect_delay = 0;
server->monitor_time = time (NULL) + 5;
+ irc_server_set_tls_version (server);
if (server->hook_timer_connection)
{
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index a8fc93ea4..abe307d70 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -1119,6 +1119,37 @@ irc_server_set_lag (struct t_irc_server *server)
}
/*
+ * Sets tls_version in server buffer (local variable), update bar item
+ * "tls_version".
+ */
+
+void
+irc_server_set_tls_version (struct t_irc_server *server)
+{
+ gnutls_protocol_t version;
+
+ if (server->is_connected)
+ {
+ if (server->ssl_connected)
+ {
+ version = gnutls_protocol_get_version (server->gnutls_sess);
+ weechat_buffer_set (server->buffer, "localvar_set_tls_version",
+ gnutls_protocol_get_name (version));
+ }
+ else
+ {
+ weechat_buffer_set (server->buffer, "localvar_set_tls_version",
+ _("cleartext"));
+ }
+ }
+ else
+ {
+ weechat_buffer_set (server->buffer, "localvar_del_tls_version", "");
+ }
+ weechat_bar_item_update ("tls_version");
+}
+
+/*
* Gets prefix_modes for server (for example: "ohv").
*
* Returns default modes if prefix_modes is not set in server.
@@ -3732,6 +3763,8 @@ irc_server_close_connection (struct t_irc_server *server)
/* server is now disconnected */
server->is_connected = 0;
server->ssl_connected = 0;
+
+ irc_server_set_tls_version (server);
}
/*
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 11d8bf281..535b61c90 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -323,6 +323,7 @@ extern const char *irc_server_get_chantypes (struct t_irc_server *server);
extern void irc_server_set_prefix_modes_chars (struct t_irc_server *server,
const char *prefix);
extern void irc_server_set_lag (struct t_irc_server *server);
+extern void irc_server_set_tls_version (struct t_irc_server *server);
extern const char *irc_server_get_prefix_modes (struct t_irc_server *server);
extern const char *irc_server_get_prefix_chars (struct t_irc_server *server);
extern int irc_server_get_prefix_mode_index (struct t_irc_server *server,
diff --git a/src/plugins/xfer/xfer-chat.c b/src/plugins/xfer/xfer-chat.c
index bb60a8b20..070ee0712 100644
--- a/src/plugins/xfer/xfer-chat.c
+++ b/src/plugins/xfer/xfer-chat.c
@@ -391,6 +391,7 @@ xfer_chat_open_buffer (struct t_xfer *xfer)
weechat_buffer_set (xfer->buffer, "localvar_set_type", "private");
weechat_buffer_set (xfer->buffer, "localvar_set_nick", xfer->local_nick);
weechat_buffer_set (xfer->buffer, "localvar_set_channel", xfer->remote_nick);
+ weechat_buffer_set (xfer->buffer, "localvar_set_tls_version", _("cleartext"));
weechat_buffer_set (xfer->buffer, "highlight_words_add", "$nick");
}