From 31ecd41c8fd69fbe7a62e97b0cc5e2583e3447e3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Oct 2015 00:03:15 +0100 Subject: [PATCH 1/3] Renamed PREF_CERT_PATH -> PREF_TLS_CERTPATH --- src/command/commands.c | 6 +++--- src/config/preferences.c | 6 +++--- src/config/preferences.h | 2 +- src/xmpp/connection.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 808f573e..370c466c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -168,18 +168,18 @@ cmd_tls(ProfWin *window, const char * const command, gchar **args) } if (g_file_test(args[2], G_FILE_TEST_IS_DIR)) { - prefs_set_string(PREF_CERT_PATH, args[2]); + prefs_set_string(PREF_TLS_CERTPATH, args[2]); cons_show("Certificate path set to: %s", args[2]); } else { cons_show("Directory %s does not exist.", args[2]); } return TRUE; } else if (g_strcmp0(args[1], "clear") == 0) { - prefs_set_string(PREF_CERT_PATH, NULL); + prefs_set_string(PREF_TLS_CERTPATH, NULL); cons_show("Certificate path cleared"); return TRUE; } else if (args[1] == NULL) { - char *path = prefs_get_string(PREF_CERT_PATH); + char *path = prefs_get_string(PREF_TLS_CERTPATH); if (path) { cons_show("Trusted certificate path: %s", path); prefs_free_string(path); diff --git a/src/config/preferences.c b/src/config/preferences.c index 746e76d4..283e9158 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -634,7 +634,7 @@ _get_group(preference_t pref) case PREF_CARBONS: case PREF_RECEIPTS_SEND: case PREF_RECEIPTS_REQUEST: - case PREF_CERT_PATH: + case PREF_TLS_CERTPATH: return PREF_GROUP_CONNECTION; case PREF_OTR_LOG: case PREF_OTR_POLICY: @@ -781,8 +781,8 @@ _get_key(preference_t pref) return "enc.warn"; case PREF_PGP_LOG: return "log"; - case PREF_CERT_PATH: - return "certpath"; + case PREF_TLS_CERTPATH: + return "tls.certpath"; case PREF_TLS_SHOW: return "tls.show"; case PREF_LASTACTIVITY: diff --git a/src/config/preferences.h b/src/config/preferences.h index bf5f1e46..46bdd550 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -111,7 +111,7 @@ typedef enum { PREF_INPBLOCK_DYNAMIC, PREF_ENC_WARN, PREF_PGP_LOG, - PREF_CERT_PATH, + PREF_TLS_CERTPATH, PREF_TLS_SHOW, PREF_LASTACTIVITY, } preference_t; diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 2b7db8be..5a27a63e 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -435,7 +435,7 @@ _jabber_connect(const char * const fulljid, const char * const passwd, } #ifdef HAVE_LIBMESODE - char *cert_path = prefs_get_string(PREF_CERT_PATH); + char *cert_path = prefs_get_string(PREF_TLS_CERTPATH); if (cert_path) { xmpp_conn_tlscert_path(jabber_conn.conn, cert_path); } From 9d2745e462eabafcab51e04ec9ad225a13cf9a6f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Oct 2015 00:17:45 +0100 Subject: [PATCH 2/3] Removed --disable-tls command line option --- docs/profanity.1 | 6 +----- src/main.c | 4 +--- src/profanity.c | 10 +++++----- src/profanity.h | 2 +- src/xmpp/connection.c | 7 +------ src/xmpp/xmpp.h | 2 +- tests/unittests/xmpp/stub_xmpp.c | 2 +- 7 files changed, 11 insertions(+), 22 deletions(-) diff --git a/docs/profanity.1 b/docs/profanity.1 index 63cd0677..64fa02e1 100644 --- a/docs/profanity.1 +++ b/docs/profanity.1 @@ -3,7 +3,7 @@ Profanity \- a simple console based XMPP chat client. .SH SYNOPSIS .B profanity -[\-vhd] [\-l level] [\-a account] +[\-vh] [\-l level] [\-a account] .SH DESCRIPTION .B Profanity is a simple lightweight console based XMPP chat client. Its emphasis is @@ -25,10 +25,6 @@ Auto connect to an account on startup, .I ACCOUNT must be an existing account. .TP -.BI "\-d, \-\-disable\-tls" -Disable TLS for servers that either don't support it, or claim to but do not -complete the handshake. -.TP .BI "\-l, \-\-log "LEVEL Set the logging level, .I LEVEL diff --git a/src/main.c b/src/main.c index 49e1defc..42730049 100644 --- a/src/main.c +++ b/src/main.c @@ -42,7 +42,6 @@ #include "profanity.h" #include "command/command.h" -static gboolean disable_tls = FALSE; static gboolean version = FALSE; static char *log = "INFO"; static char *account_name = NULL; @@ -58,7 +57,6 @@ main(int argc, char **argv) static GOptionEntry entries[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL }, - { "disable-tls", 'd', 0, G_OPTION_ARG_NONE, &disable_tls, "Disable TLS", NULL }, { "account", 'a', 0, G_OPTION_ARG_STRING, &account_name, "Auto connect to an account on startup" }, { "log",'l', 0, G_OPTION_ARG_STRING, &log, "Set logging levels, DEBUG, INFO (default), WARN, ERROR", "LEVEL" }, { NULL } @@ -137,7 +135,7 @@ main(int argc, char **argv) return 0; } - prof_run(disable_tls, log, account_name); + prof_run(log, account_name); return 0; } diff --git a/src/profanity.c b/src/profanity.c index 4dc2af3d..8233178b 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -73,7 +73,7 @@ #include "config/tlscerts.h" static void _check_autoaway(void); -static void _init(const int disable_tls, char *log_level); +static void _init(char *log_level); static void _shutdown(void); static void _create_directories(void); static void _connect_default(const char * const account); @@ -92,9 +92,9 @@ char *saved_status; static gboolean cont = TRUE; void -prof_run(const int disable_tls, char *log_level, char *account_name) +prof_run(char *log_level, char *account_name) { - _init(disable_tls, log_level); + _init(log_level); _connect_default(account_name); ui_update(); @@ -297,7 +297,7 @@ _check_autoaway() } static void -_init(const int disable_tls, char *log_level) +_init(char *log_level) { setlocale(LC_ALL, ""); // ignore SIGPIPE @@ -326,7 +326,7 @@ _init(const int disable_tls, char *log_level) theme_init(theme); prefs_free_string(theme); ui_init(); - jabber_init(disable_tls); + jabber_init(); cmd_init(); log_info("Initialising contact list"); roster_init(); diff --git a/src/profanity.h b/src/profanity.h index 269c616a..123e2f00 100644 --- a/src/profanity.h +++ b/src/profanity.h @@ -38,7 +38,7 @@ #include "resource.h" #include "xmpp/xmpp.h" -void prof_run(const int disable_tls, char *log_level, char *account_name); +void prof_run(char *log_level, char *account_name); void prof_handle_idle(void); void prof_handle_activity(void); diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 5a27a63e..fa29a70e 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -70,7 +70,6 @@ static struct _jabber_conn_t { jabber_conn_status_t conn_status; char *presence_message; int priority; - int tls_disabled; char *domain; } jabber_conn; @@ -115,14 +114,13 @@ void _connection_free_saved_details(void); void _connection_free_session_data(void); void -jabber_init(const int disable_tls) +jabber_init(void) { log_info("Initialising XMPP"); jabber_conn.conn_status = JABBER_STARTED; jabber_conn.presence_message = NULL; jabber_conn.conn = NULL; jabber_conn.ctx = NULL; - jabber_conn.tls_disabled = disable_tls; jabber_conn.domain = NULL; presence_sub_requests_init(); caps_init(); @@ -430,9 +428,6 @@ _jabber_connect(const char * const fulljid, const char * const passwd, } xmpp_conn_set_jid(jabber_conn.conn, fulljid); xmpp_conn_set_pass(jabber_conn.conn, passwd); - if (jabber_conn.tls_disabled) { - xmpp_conn_disable_tls(jabber_conn.conn); - } #ifdef HAVE_LIBMESODE char *cert_path = prefs_get_string(PREF_TLS_CERTPATH); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 839df9a7..ddf83c64 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -137,7 +137,7 @@ typedef struct data_form_t { } DataForm; // connection functions -void jabber_init(const int disable_tls); +void jabber_init(void); jabber_conn_status_t jabber_connect_with_details(const char * const jid, const char * const passwd, const char * const altdomain, const int port); jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const account); diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c index 14a0b01d..ba1f2e34 100644 --- a/tests/unittests/xmpp/stub_xmpp.c +++ b/tests/unittests/xmpp/stub_xmpp.c @@ -6,7 +6,7 @@ #include "xmpp/xmpp.h" // connection functions -void jabber_init(const int disable_tls) {} +void jabber_init(void) {} jabber_conn_status_t jabber_connect_with_details(const char * const jid, const char * const passwd, const char * const altdomain, const int port) From 6640a0891fb51b74c8377745ee1e5585f741a0be Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 18 Oct 2015 03:06:23 +0100 Subject: [PATCH 3/3] Force tls on all connections, add tls policy account property --- src/command/command.c | 81 ++++++++++++++++++++++++-- src/command/commands.c | 26 ++++++++- src/config/account.c | 10 +++- src/config/account.h | 4 +- src/config/accounts.c | 28 ++++++++- src/config/accounts.h | 3 +- src/event/client_events.c | 4 +- src/event/client_events.h | 2 +- src/ui/console.c | 3 + src/xmpp/connection.c | 32 +++++++--- src/xmpp/xmpp.h | 2 +- tests/functionaltests/proftest.c | 2 +- tests/functionaltests/test_connect.c | 2 +- tests/unittests/config/stub_accounts.c | 1 + tests/unittests/test_cmd_account.c | 14 ++--- tests/unittests/test_cmd_connect.c | 6 +- tests/unittests/test_cmd_join.c | 8 +-- tests/unittests/test_cmd_otr.c | 2 +- tests/unittests/xmpp/stub_xmpp.c | 2 +- 19 files changed, 190 insertions(+), 42 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 1b8def1a..ec8696fe 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -168,12 +168,12 @@ static struct cmd_t command_defs[] = }, { "/connect", - cmd_connect, parse_args, 0, 5, NULL, + cmd_connect, parse_args, 0, 7, NULL, CMD_TAGS( CMD_TAG_CONNECTION) CMD_SYN( "/connect []", - "/connect [server ] [port ]") + "/connect [server ] [port ] [tls force|allow|disable]") CMD_DESC( "Login to a chat service. " "If no account is specified, the default is used if one is configured. " @@ -181,12 +181,16 @@ static struct cmd_t command_defs[] = CMD_ARGS( { "", "The local account you wish to connect with, or a JID if connecting for the first time." }, { "server ", "Supply a server if it is different to the domain part of your JID." }, - { "port ", "The port to use if different to the default (5222, or 5223 for SSL)." }) + { "port ", "The port to use if different to the default (5222, or 5223 for SSL)." }, + { "tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." }, + { "tls allow", "Use TLS for the connection if it is available." }, + { "tls disable", "Disable TLS for the connection." }) CMD_EXAMPLES( "/connect", "/connect myuser@gmail.com", "/connect myuser@mycompany.com server talk.google.com", "/connect bob@someplace port 5678", + "/connect me@localhost.test.org server 127.0.0.1 tls disable", "/connect me@chatty server chatty.com port 5443") }, @@ -1491,6 +1495,7 @@ static struct cmd_t command_defs[] = "/account set otr ", "/account set pgpkeyid ", "/account set startscript