Mon, 04 Dec 2023 02:21:08 -0600
Implement CTCP ACTION and VERSION
Testing Done:
Used irssi to send `CTCP VERSION` to a channel and the pidgin3 user directly and verified the response was sent and that the default message was still displayed.
Bugs closed: PIDGIN-17721
Reviewed at https://reviews.imfreedom.org/r/2863/
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
1 | /* |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
2 | * Purple - Internet Messaging Library |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
3 | * Copyright (C) Pidgin Developers <devel@pidgin.im> |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
4 | * |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
5 | * This program is free software; you can redistribute it and/or modify |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation; either version 2 of the License, or |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
9 | * |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
14 | * |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
16 | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
17 | */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
18 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
19 | #include <glib/gi18n-lib.h> |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
20 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
21 | #include <hasl.h> |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
22 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
23 | #include "purpleircv3sasl.h" |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
24 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
25 | #include "purpleircv3capabilities.h" |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
26 | #include "purpleircv3connection.h" |
|
42510
fe16c4d773b4
IRCv3: Add constants for all existing errors, messages, and replies.
Gary Kramlich <grim@reaperworld.com>
parents:
42333
diff
changeset
|
27 | #include "purpleircv3constants.h" |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
28 | #include "purpleircv3core.h" |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
29 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
30 | #define PURPLE_IRCV3_SASL_DATA_KEY ("sasl-data") |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
31 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
32 | typedef struct { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
33 | PurpleConnection *connection; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
34 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
35 | HaslContext *ctx; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
36 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
37 | GString *server_in_buffer; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
38 | } PurpleIRCv3SASLData; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
39 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
40 | /****************************************************************************** |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
41 | * Helpers |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
42 | *****************************************************************************/ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
43 | static const char * |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
44 | purple_ircv3_sasl_get_username(PurpleConnection *connection) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
45 | PurpleAccount *account = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
46 | const char *username = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
47 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
48 | account = purple_connection_get_account(connection); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
49 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
50 | username = purple_account_get_string(account, "sasl-login-name", ""); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
51 | if(username != NULL && username[0] != '\0') { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
52 | return username; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
53 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
54 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
55 | return purple_connection_get_display_name(connection); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
56 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
57 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
58 | /****************************************************************************** |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
59 | * SASL Helpers |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
60 | *****************************************************************************/ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
61 | static void |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
62 | purple_ircv3_sasl_data_free(PurpleIRCv3SASLData *data) { |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
63 | g_clear_object(&data->ctx); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
64 | |
|
42045
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
65 | g_string_free(data->server_in_buffer, TRUE); |
|
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
66 | |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
67 | g_free(data); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
68 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
69 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
70 | static void |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
71 | purple_ircv3_sasl_data_add(PurpleConnection *connection, HaslContext *ctx) { |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
72 | PurpleIRCv3SASLData *data = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
73 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
74 | data = g_new0(PurpleIRCv3SASLData, 1); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
75 | g_object_set_data_full(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
76 | data, (GDestroyNotify)purple_ircv3_sasl_data_free); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
77 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
78 | /* We don't reference this because the life cycle of this data is tied |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
79 | * directly to the connection and adding a reference to the connection |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
80 | * would keep both alive forever. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
81 | */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
82 | data->connection = connection; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
83 | data->ctx = ctx; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
84 | |
|
42045
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
85 | /* We truncate the server_in_buffer when we need to so that we can minimize |
|
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
86 | * allocations and simplify the logic involved with it. |
|
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
87 | */ |
|
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
88 | data->server_in_buffer = g_string_new(""); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
89 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
90 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
91 | static void |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
92 | purple_ircv3_sasl_attempt(PurpleIRCv3Connection *connection) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
93 | PurpleIRCv3SASLData *data = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
94 | const char *next_mechanism = NULL; |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
95 | const char *current = NULL; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
96 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
97 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
98 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
99 | current = hasl_context_get_current_mechanism(data->ctx); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
100 | if(current != NULL) { |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
101 | g_message("SASL '%s' mechanism failed", current); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
102 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
103 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
104 | next_mechanism = hasl_context_next(data->ctx); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
105 | if(next_mechanism == NULL) { |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
106 | GError *error = g_error_new(PURPLE_CONNECTION_ERROR, |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
107 | PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
108 | _("No valid SASL mechanisms found")); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
109 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
110 | purple_connection_take_error(PURPLE_CONNECTION(connection), error); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
111 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
112 | return; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
113 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
114 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
115 | g_message("trying SASL '%s' mechanism", next_mechanism); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
116 | |
|
42510
fe16c4d773b4
IRCv3: Add constants for all existing errors, messages, and replies.
Gary Kramlich <grim@reaperworld.com>
parents:
42333
diff
changeset
|
117 | purple_ircv3_connection_writef(connection, "%s %s", |
|
fe16c4d773b4
IRCv3: Add constants for all existing errors, messages, and replies.
Gary Kramlich <grim@reaperworld.com>
parents:
42333
diff
changeset
|
118 | PURPLE_IRCV3_MSG_AUTHENTICATE, |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
119 | next_mechanism); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
120 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
121 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
122 | static void |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
123 | purple_ircv3_sasl_start(PurpleIRCv3Capabilities *caps) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
124 | PurpleIRCv3Connection *connection = NULL; |
|
42044
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
125 | PurpleAccount *account = NULL; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
126 | PurpleConnection *purple_connection = NULL; |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
127 | HaslContext *ctx = NULL; |
|
42044
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
128 | const char *mechanisms = NULL; |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
129 | gboolean toggle = FALSE; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
130 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
131 | connection = purple_ircv3_capabilities_get_connection(caps); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
132 | purple_connection = PURPLE_CONNECTION(connection); |
|
42044
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
133 | account = purple_connection_get_account(purple_connection); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
134 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
135 | ctx = hasl_context_new(); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
136 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
137 | /* At this point we are ready to start our SASL negotiation, so add a wait |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
138 | * counter to the capabilities and start the negotiations! |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
139 | */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
140 | purple_ircv3_capabilities_add_wait(caps); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
141 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
142 | /* Determine what mechanisms we're allowing and tell the context. */ |
|
42044
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
143 | mechanisms = purple_account_get_string(account, "sasl-mechanisms", ""); |
|
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
144 | if(purple_strempty(mechanisms)) { |
|
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
145 | /* If the user didn't specify any mechanisms, grab the mechanisms that |
|
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
146 | * the server advertised. |
|
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
147 | */ |
|
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
148 | mechanisms = purple_ircv3_capabilities_lookup(caps, "sasl", NULL); |
|
37eaa6065a9a
IRCv3: Add an account option to specify the SASL mechanisms
Gary Kramlich <grim@reaperworld.com>
parents:
42040
diff
changeset
|
149 | } |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
150 | hasl_context_set_allowed_mechanisms(ctx, mechanisms); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
151 | |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
152 | /* Add the values we know to the context. */ |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
153 | hasl_context_set_username(ctx, purple_ircv3_sasl_get_username(purple_connection)); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
154 | hasl_context_set_password(ctx, purple_connection_get_password(purple_connection)); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
155 | |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
156 | toggle = purple_account_get_bool(account, "use-tls", TRUE); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
157 | hasl_context_set_tls(ctx, toggle); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
158 | |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
159 | toggle = purple_account_get_bool(account, "plain-sasl-in-clear", FALSE); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
160 | hasl_context_set_allow_clear_text(ctx, toggle); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
161 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
162 | /* Create our SASLData object, add it to the connection. */ |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
163 | purple_ircv3_sasl_data_add(purple_connection, ctx); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
164 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
165 | /* Make it go! */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
166 | purple_ircv3_sasl_attempt(connection); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
167 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
168 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
169 | /****************************************************************************** |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
170 | * Callbacks |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
171 | *****************************************************************************/ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
172 | static void |
|
42040
86284f7119e1
IRCv3: Add detail to the ack and nak signals for PurpleIRCv3Capabilities
Gary Kramlich <grim@reaperworld.com>
parents:
42027
diff
changeset
|
173 | purple_ircv3_sasl_ack_cb(PurpleIRCv3Capabilities *caps, |
|
86284f7119e1
IRCv3: Add detail to the ack and nak signals for PurpleIRCv3Capabilities
Gary Kramlich <grim@reaperworld.com>
parents:
42027
diff
changeset
|
174 | G_GNUC_UNUSED const char *capability, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
175 | G_GNUC_UNUSED gpointer data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
176 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
177 | purple_ircv3_sasl_start(caps); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
178 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
179 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
180 | /****************************************************************************** |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
181 | * Internal API |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
182 | *****************************************************************************/ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
183 | void |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
184 | purple_ircv3_sasl_request(PurpleIRCv3Capabilities *capabilities) { |
|
42287
8fc84ffcdcb2
IRCv3: Use constants for capability names
Gary Kramlich <grim@reaperworld.com>
parents:
42271
diff
changeset
|
185 | purple_ircv3_capabilities_request(capabilities, |
|
8fc84ffcdcb2
IRCv3: Use constants for capability names
Gary Kramlich <grim@reaperworld.com>
parents:
42271
diff
changeset
|
186 | PURPLE_IRCV3_CAPABILITY_SASL); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
187 | |
|
42287
8fc84ffcdcb2
IRCv3: Use constants for capability names
Gary Kramlich <grim@reaperworld.com>
parents:
42271
diff
changeset
|
188 | g_signal_connect(capabilities, "ack::" PURPLE_IRCV3_CAPABILITY_SASL, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
189 | G_CALLBACK(purple_ircv3_sasl_ack_cb), NULL); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
190 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
191 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
192 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
193 | purple_ircv3_sasl_logged_in(G_GNUC_UNUSED PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
194 | G_GNUC_UNUSED GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
195 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
196 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
197 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
198 | PurpleIRCv3SASLData *data = NULL; |
|
42271
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
199 | PurpleAccount *account = NULL; |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
200 | const char *sasl_name = NULL; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
201 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
202 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
203 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
204 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
205 | "RPL_LOGGEDIN received with no SASL data " |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
206 | "present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
207 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
208 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
209 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
210 | |
|
42271
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
211 | /* Check if the SASL login name is not set. If it is not set, set it to the |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
212 | * current nick as it was successful. |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
213 | */ |
|
42271
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
214 | account = purple_connection_get_account(PURPLE_CONNECTION(connection)); |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
215 | sasl_name = purple_account_get_string(account, "sasl-login-name", ""); |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
216 | if(purple_strempty(sasl_name)) { |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
217 | char **userparts = NULL; |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
218 | const char *username = NULL; |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
219 | |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
220 | username = purple_contact_info_get_username(PURPLE_CONTACT_INFO(account)); |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
221 | userparts = g_strsplit(username, "@", 2); |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
222 | |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
223 | purple_account_set_string(account, "sasl-login-name", userparts[0]); |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
224 | |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
225 | g_strfreev(userparts); |
|
1a7cacfd281f
Set the sasl login name on successful login if not set
Gary Kramlich <grim@reaperworld.com>
parents:
42081
diff
changeset
|
226 | } |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
227 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
228 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
229 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
230 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
231 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
232 | purple_ircv3_sasl_logged_out(G_GNUC_UNUSED PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
233 | G_GNUC_UNUSED GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
234 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
235 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
236 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
237 | PurpleIRCv3SASLData *data = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
238 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
239 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
240 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
241 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
242 | "RPL_LOGGEDOUT received with no SASL data " |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
243 | "present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
244 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
245 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
246 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
247 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
248 | /* Not sure how to trigger this or what we should do in this case to be |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
249 | * honest, so just note it for now. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
250 | * -- GK 2023-01-12 |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
251 | */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
252 | g_warning("Server sent SASL logged out"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
253 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
254 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
255 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
256 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
257 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
258 | purple_ircv3_sasl_nick_locked(PurpleIRCv3Message *v3_message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
259 | GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
260 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
261 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
262 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
263 | PurpleIRCv3SASLData *data = NULL; |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
264 | GStrv params = NULL; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
265 | char *message = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
266 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
267 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
268 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
269 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
270 | "ERR_NICKLOCKED received with no SASL data " |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
271 | "present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
272 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
273 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
274 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
275 | |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
276 | params = purple_ircv3_message_get_params(v3_message); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
277 | message = g_strjoinv(" ", params); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
278 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
279 | g_set_error(error, PURPLE_CONNECTION_ERROR, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
280 | PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
281 | _("Nick name is locked: %s"), message); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
282 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
283 | g_free(message); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
284 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
285 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
286 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
287 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
288 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
289 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
290 | purple_ircv3_sasl_success(G_GNUC_UNUSED PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
291 | GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
292 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
293 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
294 | PurpleIRCv3Capabilities *capabilities = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
295 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
296 | PurpleIRCv3SASLData *data = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
297 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
298 | capabilities = purple_ircv3_connection_get_capabilities(connection); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
299 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
300 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
301 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
302 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
303 | "RPL_SASLSUCCESS received with no SASL data " |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
304 | "present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
305 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
306 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
307 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
308 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
309 | /* This needs to be after we've checked the SASL data otherwise we might |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
310 | * end up removing a wait that we don't own. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
311 | */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
312 | purple_ircv3_capabilities_remove_wait(capabilities); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
313 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
314 | g_message("successfully authenticated with SASL '%s' mechanism.", |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
315 | hasl_context_get_current_mechanism(data->ctx)); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
316 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
317 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
318 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
319 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
320 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
321 | purple_ircv3_sasl_failed(G_GNUC_UNUSED PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
322 | G_GNUC_UNUSED GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
323 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
324 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
325 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
326 | PurpleIRCv3SASLData *data = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
327 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
328 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
329 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
330 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
331 | "ERR_SASLFAIL received with no SASL data present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
332 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
333 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
334 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
335 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
336 | purple_ircv3_sasl_attempt(connection); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
337 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
338 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
339 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
340 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
341 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
342 | purple_ircv3_sasl_message_too_long(G_GNUC_UNUSED PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
343 | G_GNUC_UNUSED GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
344 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
345 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
346 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
347 | PurpleIRCv3SASLData *data = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
348 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
349 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
350 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
351 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
352 | "ERR_SASLTOOLONG received with no SASL data " |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
353 | "present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
354 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
355 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
356 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
357 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
358 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
359 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
360 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
361 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
362 | purple_ircv3_sasl_aborted(G_GNUC_UNUSED PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
363 | G_GNUC_UNUSED GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
364 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
365 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
366 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
367 | PurpleIRCv3SASLData *data = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
368 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
369 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
370 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
371 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
372 | "ERR_SASLABORTED received with no SASL data " |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
373 | "present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
374 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
375 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
376 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
377 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
378 | /* This is supposed to get sent, when the client sends `AUTHENTICATE *`, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
379 | * but we don't do this, so I guess we'll note it for now...? |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
380 | * --GK 2023-01-12 |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
381 | */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
382 | g_warning("The server claims we aborted SASL authentication."); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
383 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
384 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
385 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
386 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
387 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
388 | purple_ircv3_sasl_already_authed(G_GNUC_UNUSED PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
389 | G_GNUC_UNUSED GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
390 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
391 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
392 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
393 | PurpleIRCv3SASLData *data = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
394 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
395 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
396 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
397 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
398 | "ERR_SASLALREADY received with no SASL data " |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
399 | "present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
400 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
401 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
402 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
403 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
404 | /* Similar to aborted above, we don't allow this, so just note that it |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
405 | * happened. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
406 | * -- GK 2023-01-12 |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
407 | */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
408 | g_warning("Server claims we tried to SASL authenticate again."); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
409 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
410 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
411 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
412 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
413 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
414 | purple_ircv3_sasl_mechanisms(PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
415 | G_GNUC_UNUSED GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
416 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
417 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
418 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
419 | PurpleIRCv3SASLData *data = NULL; |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
420 | GStrv params = NULL; |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
421 | guint n_params = 0; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
422 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
423 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
424 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
425 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
426 | "RPL_SASLMECHS received with no SASL data " |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
427 | "present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
428 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
429 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
430 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
431 | |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
432 | params = purple_ircv3_message_get_params(message); |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
433 | if(params != NULL) { |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
434 | n_params = g_strv_length(params); |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
435 | } |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
436 | |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
437 | /* We need to find a server that sends this message. The specification says |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
438 | * it _may_ be sent when the client sends AUTHENTICATE with an unknown |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
439 | * mechanism, but ergo doesn't. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
440 | * |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
441 | * We can't just blindly accept the new list either, as depending on how |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
442 | * the server implements it, we'll need to remove mechanisms we've already |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
443 | * tried in the event the server just dumps the entire list. As we're not |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
444 | * currently tracking which mechanisms we've tried, this will have to be |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
445 | * addressed as well. |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
446 | */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
447 | if(n_params > 0) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
448 | char *message = g_strjoinv(" ", params); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
449 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
450 | g_message("Server sent the following SASL mechanisms: %s", message); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
451 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
452 | g_free(message); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
453 | } else { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
454 | g_message("Server sent an empty list of SASL mechanisms"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
455 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
456 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
457 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
458 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
459 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
460 | gboolean |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
461 | purple_ircv3_sasl_authenticate(PurpleIRCv3Message *message, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
462 | GError **error, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
463 | gpointer user_data) |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
464 | { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
465 | PurpleIRCv3Connection *connection = user_data; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
466 | PurpleIRCv3SASLData *data = NULL; |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
467 | GStrv params = NULL; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
468 | char *payload = NULL; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
469 | gboolean done = FALSE; |
|
42333
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
470 | guint n_params = 0; |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
471 | |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
472 | params = purple_ircv3_message_get_params(message); |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
473 | if(params != NULL) { |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
474 | n_params = g_strv_length(params); |
|
a34601ac633c
Add PurpleIRCv3Message represent messages rather than multiple variables
Gary Kramlich <grim@reaperworld.com>
parents:
42287
diff
changeset
|
475 | } |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
476 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
477 | if(n_params != 1) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
478 | g_set_error(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
479 | "ignoring AUTHENTICATE with %d parameters", n_params); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
480 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
481 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
482 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
483 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
484 | payload = params[0]; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
485 | data = g_object_get_data(G_OBJECT(connection), PURPLE_IRCV3_SASL_DATA_KEY); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
486 | if(data == NULL) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
487 | g_set_error_literal(error, PURPLE_IRCV3_DOMAIN, 0, |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
488 | "AUTHENTICATE received with no SASL data present"); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
489 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
490 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
491 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
492 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
493 | /* If the server sent us a payload, combine the chunks. */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
494 | if(payload[0] != '+') { |
|
42045
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
495 | g_string_append(data->server_in_buffer, payload); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
496 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
497 | if(strlen(payload) < 400) { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
498 | done = TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
499 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
500 | } else { |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
501 | /* The server sent a + which is an empty message or the final message |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
502 | * ended on a 400 byte barrier. */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
503 | done = TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
504 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
505 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
506 | if(done) { |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
507 | HaslMechanismResult res = 0; |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
508 | GError *local_error = NULL; |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
509 | guint8 *server_in = NULL; |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
510 | guint8 *client_out = NULL; |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
511 | gsize server_in_length = 0; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
512 | size_t client_out_length = 0; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
513 | |
|
42045
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
514 | /* If we have a buffer, base64 decode it, and then truncate it. */ |
|
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
515 | if(data->server_in_buffer->len > 0) { |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
516 | server_in = g_base64_decode(data->server_in_buffer->str, |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
517 | &server_in_length); |
|
42045
bfe15fc3cbf4
IRCv3: Get SCRAM-SHA-256 working
Gary Kramlich <grim@reaperworld.com>
parents:
42044
diff
changeset
|
518 | g_string_truncate(data->server_in_buffer, 0); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
519 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
520 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
521 | /* Try to move to the next step of the sasl client. */ |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
522 | res = hasl_context_step(data->ctx, server_in, server_in_length, |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
523 | &client_out, &client_out_length, &local_error); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
524 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
525 | /* We should be done with server_in, so free it.*/ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
526 | g_clear_pointer(&server_in, g_free); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
527 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
528 | if(res == HASL_MECHANISM_RESULT_ERROR) { |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
529 | g_propagate_error(error, local_error); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
530 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
531 | return FALSE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
532 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
533 | |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
534 | if(local_error != NULL) { |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
535 | g_warning("hasl_context_step returned an error without an error " |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
536 | "status: %s", local_error->message); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
537 | |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
538 | g_clear_error(&local_error); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
539 | } |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
540 | |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
541 | /* If we got an output for the client, write it out. */ |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
542 | if(client_out_length > 0) { |
|
42081
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
543 | char *encoded = NULL; |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
544 | |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
545 | encoded = g_base64_encode(client_out, client_out_length); |
|
16ef7725e459
IRCv3: Port to our new SASL library named Hasl
Gary Kramlich <grim@reaperworld.com>
parents:
42046
diff
changeset
|
546 | g_clear_pointer(&client_out, g_free); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
547 | |
|
42510
fe16c4d773b4
IRCv3: Add constants for all existing errors, messages, and replies.
Gary Kramlich <grim@reaperworld.com>
parents:
42333
diff
changeset
|
548 | purple_ircv3_connection_writef(connection, "%s %s", |
|
fe16c4d773b4
IRCv3: Add constants for all existing errors, messages, and replies.
Gary Kramlich <grim@reaperworld.com>
parents:
42333
diff
changeset
|
549 | PURPLE_IRCV3_MSG_AUTHENTICATE, |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
550 | encoded); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
551 | g_free(encoded); |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
552 | } else { |
|
42510
fe16c4d773b4
IRCv3: Add constants for all existing errors, messages, and replies.
Gary Kramlich <grim@reaperworld.com>
parents:
42333
diff
changeset
|
553 | purple_ircv3_connection_writef(connection, "%s +", |
|
fe16c4d773b4
IRCv3: Add constants for all existing errors, messages, and replies.
Gary Kramlich <grim@reaperworld.com>
parents:
42333
diff
changeset
|
554 | PURPLE_IRCV3_MSG_AUTHENTICATE); |
|
42023
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
555 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
556 | } |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
557 | |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
558 | return TRUE; |
|
5bda87b90d8d
Implement SASL for IRCv3 using GSASL
Gary Kramlich <grim@reaperworld.com>
parents:
diff
changeset
|
559 | } |