Wed, 08 Feb 2023 06:17:57 -0600
IRCv3: Add an account option to specify the SASL mechanisms
This allows the user to only try the SASL mechanism they want to use instead of
potentially trying a few that won't work based on what the server advertised.
This also allows us to use SASL mechanisms that the server supports but doesn't
advertise for some reason.
Testing Done:
Set the field to `SCRAM-SHA-256` and connected to my local ergo. I verified that ONLY `SCRAM-SHA-256` was attempted (and failed see [PIDGIN-17744](https://issues.imfreedom.org/issue/PIDGIN-17744).
I deleted the value from the entry as well as from accounts.xml and verified that the server advertised values were what were used.
Bugs closed: PIDGIN-17740
Reviewed at https://reviews.imfreedom.org/r/2222/
| libpurple/protocols/ircv3/purpleircv3protocol.c | file | annotate | diff | comparison | revisions | |
| libpurple/protocols/ircv3/purpleircv3sasl.c | file | annotate | diff | comparison | revisions |
--- a/libpurple/protocols/ircv3/purpleircv3protocol.c Sun Jan 29 12:10:40 2023 -0600 +++ b/libpurple/protocols/ircv3/purpleircv3protocol.c Wed Feb 08 06:17:57 2023 -0600 @@ -67,6 +67,10 @@ "sasl-login-name", ""); options = g_list_append(options, option); + option = purple_account_option_string_new(_("SASL mechanisms"), + "sasl-mechanisms", ""); + options = g_list_append(options, option); + option = purple_account_option_bool_new(_("Allow plaintext SASL auth over " "unencrypted connection"), "plain-sasl-in-clear", FALSE);
--- a/libpurple/protocols/ircv3/purpleircv3sasl.c Sun Jan 29 12:10:40 2023 -0600 +++ b/libpurple/protocols/ircv3/purpleircv3sasl.c Wed Feb 08 06:17:57 2023 -0600 @@ -262,13 +262,15 @@ static void purple_ircv3_sasl_start(PurpleIRCv3Capabilities *caps) { PurpleIRCv3Connection *connection = NULL; + PurpleAccount *account = NULL; PurpleConnection *purple_connection = NULL; Gsasl *ctx = NULL; - const char *advertised = NULL; + const char *mechanisms = NULL; gint res; connection = purple_ircv3_capabilities_get_connection(caps); purple_connection = PURPLE_CONNECTION(connection); + account = purple_connection_get_account(purple_connection); res = gsasl_init(&ctx); if(res != GSASL_OK) { @@ -284,12 +286,16 @@ */ purple_ircv3_capabilities_add_wait(caps); - /* Grab the mechanisms that the server advertised and save them on the - * connection. */ - advertised = purple_ircv3_capabilities_lookup(caps, "sasl", NULL); + mechanisms = purple_account_get_string(account, "sasl-mechanisms", ""); + if(purple_strempty(mechanisms)) { + /* If the user didn't specify any mechanisms, grab the mechanisms that + * the server advertised. + */ + mechanisms = purple_ircv3_capabilities_lookup(caps, "sasl", NULL); + } /* Create our SASLData object, add it to the connection. */ - purple_ircv3_sasl_data_add(purple_connection, ctx, advertised); + purple_ircv3_sasl_data_add(purple_connection, ctx, mechanisms); /* Make it go! */ purple_ircv3_sasl_attempt(connection);