Sat, 22 Sep 2007 16:19:34 +0000
Updated hinting to be less invasive
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 3 | * |
| 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19852
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7014 | 19 | * |
| 20 | */ | |
| 21 | #include "internal.h" | |
| 22 | ||
|
15952
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
23 | #include "account.h" |
|
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
24 | #include "debug.h" |
|
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
25 | #include "cipher.h" |
|
20379
eeb5eef9992c
Disable the account when the user cancels entering the password so the account isn't stuck in a weird unconnected state. Fixes #1791
Daniel Atallah <datallah@pidgin.im>
parents:
19993
diff
changeset
|
26 | #include "core.h" |
|
15952
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
27 | #include "conversation.h" |
|
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
28 | #include "request.h" |
|
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
29 | #include "sslconn.h" |
|
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
30 | #include "util.h" |
|
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
31 | #include "xmlnode.h" |
|
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
32 | |
| 7014 | 33 | #include "jutil.h" |
| 34 | #include "auth.h" | |
| 35 | #include "jabber.h" | |
| 36 | #include "iq.h" | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
37 | #include "notify.h" |
| 7014 | 38 | |
| 8397 | 39 | static void auth_old_result_cb(JabberStream *js, xmlnode *packet, |
| 40 | gpointer data); | |
| 7014 | 41 | |
| 8296 | 42 | gboolean |
| 43 | jabber_process_starttls(JabberStream *js, xmlnode *packet) | |
| 7014 | 44 | { |
| 45 | xmlnode *starttls; | |
| 46 | ||
| 7157 | 47 | if((starttls = xmlnode_get_child(packet, "starttls"))) { |
| 15884 | 48 | if(purple_ssl_is_supported()) { |
| 7157 | 49 | jabber_send_raw(js, |
| 7642 | 50 | "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1); |
| 8296 | 51 | return TRUE; |
| 7157 | 52 | } else if(xmlnode_get_child(starttls, "required")) { |
| 15884 | 53 | purple_connection_error(js->gc, _("Server requires TLS/SSL for login. No TLS/SSL support found.")); |
| 8296 | 54 | return TRUE; |
| 7157 | 55 | } |
| 7014 | 56 | } |
| 57 | ||
| 8296 | 58 | return FALSE; |
| 59 | } | |
| 60 | ||
| 8397 | 61 | static void finish_plaintext_authentication(JabberStream *js) |
| 62 | { | |
| 63 | if(js->auth_type == JABBER_AUTH_PLAIN) { | |
| 64 | xmlnode *auth; | |
| 65 | GString *response; | |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
10740
diff
changeset
|
66 | gchar *enc_out; |
| 8397 | 67 | |
| 68 | auth = xmlnode_new("auth"); | |
| 13808 | 69 | xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl"); |
|
20379
eeb5eef9992c
Disable the account when the user cancels entering the password so the account isn't stuck in a weird unconnected state. Fixes #1791
Daniel Atallah <datallah@pidgin.im>
parents:
19993
diff
changeset
|
70 | |
| 15271 | 71 | xmlnode_set_attrib(auth, "xmlns:ga", "http://www.google.com/talk/protocol/auth"); |
| 15293 | 72 | xmlnode_set_attrib(auth, "ga:client-uses-full-bind-result", "true"); |
|
20379
eeb5eef9992c
Disable the account when the user cancels entering the password so the account isn't stuck in a weird unconnected state. Fixes #1791
Daniel Atallah <datallah@pidgin.im>
parents:
19993
diff
changeset
|
73 | |
| 8397 | 74 | response = g_string_new(""); |
| 75 | response = g_string_append_len(response, "\0", 1); | |
| 76 | response = g_string_append(response, js->user->node); | |
| 77 | response = g_string_append_len(response, "\0", 1); | |
| 78 | response = g_string_append(response, | |
| 15884 | 79 | purple_connection_get_password(js->gc)); |
| 8397 | 80 | |
| 15884 | 81 | enc_out = purple_base64_encode((guchar *)response->str, response->len); |
| 8397 | 82 | |
| 83 | xmlnode_set_attrib(auth, "mechanism", "PLAIN"); | |
| 84 | xmlnode_insert_data(auth, enc_out, -1); | |
| 85 | g_free(enc_out); | |
| 86 | g_string_free(response, TRUE); | |
| 87 | ||
| 88 | jabber_send(js, auth); | |
| 89 | xmlnode_free(auth); | |
| 90 | } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) { | |
| 91 | JabberIq *iq; | |
| 92 | xmlnode *query, *x; | |
| 93 | ||
| 94 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth"); | |
| 95 | query = xmlnode_get_child(iq->node, "query"); | |
| 96 | x = xmlnode_new_child(query, "username"); | |
| 97 | xmlnode_insert_data(x, js->user->node, -1); | |
| 98 | x = xmlnode_new_child(query, "resource"); | |
| 99 | xmlnode_insert_data(x, js->user->resource, -1); | |
| 100 | x = xmlnode_new_child(query, "password"); | |
| 15884 | 101 | xmlnode_insert_data(x, purple_connection_get_password(js->gc), -1); |
| 8397 | 102 | jabber_iq_set_callback(iq, auth_old_result_cb, NULL); |
| 103 | jabber_iq_send(iq); | |
| 104 | } | |
| 105 | } | |
| 106 | ||
| 15884 | 107 | static void allow_plaintext_auth(PurpleAccount *account) |
| 8397 | 108 | { |
| 15884 | 109 | purple_account_set_bool(account, "auth_plain_in_clear", TRUE); |
| 8397 | 110 | |
| 111 | finish_plaintext_authentication(account->gc->proto_data); | |
| 112 | } | |
| 113 | ||
| 15884 | 114 | static void disallow_plaintext_auth(PurpleAccount *account) |
| 8397 | 115 | { |
| 15884 | 116 | purple_connection_error(account->gc, _("Server requires plaintext authentication over an unencrypted stream")); |
| 8397 | 117 | } |
| 118 | ||
| 12508 | 119 | #ifdef HAVE_CYRUS_SASL |
| 120 | ||
| 121 | static void jabber_auth_start_cyrus(JabberStream *); | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
122 | static void jabber_sasl_build_callbacks(JabberStream *); |
| 12508 | 123 | |
| 124 | /* Callbacks for Cyrus SASL */ | |
| 125 | ||
| 126 | static int jabber_sasl_cb_realm(void *ctx, int id, const char **avail, const char **result) | |
| 127 | { | |
| 128 | JabberStream *js = (JabberStream *)ctx; | |
| 129 | ||
| 130 | if (id != SASL_CB_GETREALM || !result) return SASL_BADPARAM; | |
| 131 | ||
| 132 | *result = js->user->domain; | |
| 133 | ||
| 134 | return SASL_OK; | |
| 135 | } | |
| 136 | ||
| 137 | static int jabber_sasl_cb_simple(void *ctx, int id, const char **res, unsigned *len) | |
| 138 | { | |
| 139 | JabberStream *js = (JabberStream *)ctx; | |
| 140 | ||
| 141 | switch(id) { | |
| 142 | case SASL_CB_AUTHNAME: | |
| 143 | *res = js->user->node; | |
| 144 | break; | |
| 145 | case SASL_CB_USER: | |
| 12543 | 146 | *res = ""; |
| 12508 | 147 | break; |
| 148 | default: | |
| 149 | return SASL_BADPARAM; | |
| 150 | } | |
| 151 | if (len) *len = strlen((char *)*res); | |
| 152 | return SASL_OK; | |
| 153 | } | |
| 154 | ||
| 155 | static int jabber_sasl_cb_secret(sasl_conn_t *conn, void *ctx, int id, sasl_secret_t **secret) | |
| 156 | { | |
| 157 | JabberStream *js = (JabberStream *)ctx; | |
| 15884 | 158 | const char *pw = purple_account_get_password(js->gc->account); |
| 12508 | 159 | size_t len; |
| 160 | static sasl_secret_t *x = NULL; | |
| 161 | ||
| 162 | if (!conn || !secret || id != SASL_CB_PASS) | |
| 163 | return SASL_BADPARAM; | |
| 164 | ||
| 165 | len = strlen(pw); | |
| 166 | x = (sasl_secret_t *) realloc(x, sizeof(sasl_secret_t) + len); | |
| 167 | ||
| 168 | if (!x) | |
| 169 | return SASL_NOMEM; | |
| 170 | ||
| 171 | x->len = len; | |
| 172 | strcpy((char*)x->data, pw); | |
| 173 | ||
| 174 | *secret = x; | |
| 175 | return SASL_OK; | |
| 176 | } | |
| 177 | ||
| 15884 | 178 | static void allow_cyrus_plaintext_auth(PurpleAccount *account) |
| 12508 | 179 | { |
| 15884 | 180 | purple_account_set_bool(account, "auth_plain_in_clear", TRUE); |
| 12508 | 181 | |
| 182 | jabber_auth_start_cyrus(account->gc->proto_data); | |
| 183 | } | |
| 184 | ||
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
185 | static gboolean auth_pass_generic(JabberStream *js, PurpleRequestFields *fields) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
186 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
187 | const char *entry; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
188 | gboolean remember; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
189 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
190 | entry = purple_request_fields_get_string(fields, "password"); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
191 | remember = purple_request_fields_get_bool(fields, "remember"); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
192 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
193 | if (!entry || !*entry) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
194 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
195 | purple_notify_error(js->gc->account, NULL, _("Password is required to sign on."), NULL); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
196 | return FALSE; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
197 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
198 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
199 | if (remember) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
200 | purple_account_set_remember_password(js->gc->account, TRUE); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
201 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
202 | purple_account_set_password(js->gc->account, entry); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
203 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
204 | return TRUE; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
205 | } |
|
20379
eeb5eef9992c
Disable the account when the user cancels entering the password so the account isn't stuck in a weird unconnected state. Fixes #1791
Daniel Atallah <datallah@pidgin.im>
parents:
19993
diff
changeset
|
206 | |
|
19852
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
207 | static void auth_pass_cb(PurpleConnection *conn, PurpleRequestFields *fields) |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
208 | { |
|
19852
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
209 | JabberStream *js; |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
210 | |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
211 | /* The password prompt dialog doesn't get disposed if the account disconnects */ |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
212 | if (!PURPLE_CONNECTION_IS_VALID(conn)) |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
213 | return; |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
214 | |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
215 | js = conn->proto_data; |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
216 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
217 | if (!auth_pass_generic(js, fields)) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
218 | return; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
219 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
220 | /* Rebuild our callbacks as we now have a password to offer */ |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
221 | jabber_sasl_build_callbacks(js); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
222 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
223 | /* Restart our connection */ |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
224 | jabber_auth_start_cyrus(js); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
225 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
226 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
227 | static void |
|
19852
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
228 | auth_old_pass_cb(PurpleConnection *conn, PurpleRequestFields *fields) |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
229 | { |
|
19852
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
230 | JabberStream *js; |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
231 | |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
232 | /* The password prompt dialog doesn't get disposed if the account disconnects */ |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
233 | if (!PURPLE_CONNECTION_IS_VALID(conn)) |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
234 | return; |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
235 | |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
236 | js = conn->proto_data; |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
237 | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
238 | if (!auth_pass_generic(js, fields)) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
239 | return; |
|
20379
eeb5eef9992c
Disable the account when the user cancels entering the password so the account isn't stuck in a weird unconnected state. Fixes #1791
Daniel Atallah <datallah@pidgin.im>
parents:
19993
diff
changeset
|
240 | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
241 | /* Restart our connection */ |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
242 | jabber_auth_start_old(js); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
243 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
244 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
245 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
246 | static void |
|
19852
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
247 | auth_no_pass_cb(PurpleConnection *conn, PurpleRequestFields *fields) |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
248 | { |
|
19852
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
249 | JabberStream *js; |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
250 | |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
251 | /* The password prompt dialog doesn't get disposed if the account disconnects */ |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
252 | if (!PURPLE_CONNECTION_IS_VALID(conn)) |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
253 | return; |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
254 | |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
255 | js = conn->proto_data; |
|
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
256 | |
|
20379
eeb5eef9992c
Disable the account when the user cancels entering the password so the account isn't stuck in a weird unconnected state. Fixes #1791
Daniel Atallah <datallah@pidgin.im>
parents:
19993
diff
changeset
|
257 | /* Disable the account as the user has canceled connecting */ |
|
eeb5eef9992c
Disable the account when the user cancels entering the password so the account isn't stuck in a weird unconnected state. Fixes #1791
Daniel Atallah <datallah@pidgin.im>
parents:
19993
diff
changeset
|
258 | purple_account_set_enabled(conn->account, purple_core_get_ui(), FALSE); |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
259 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
260 | |
| 12508 | 261 | static void jabber_auth_start_cyrus(JabberStream *js) |
| 262 | { | |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
263 | const char *clientout = NULL, *mech = NULL; |
| 12508 | 264 | char *enc_out; |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
265 | unsigned coutlen = 0; |
| 12508 | 266 | xmlnode *auth; |
| 267 | sasl_security_properties_t secprops; | |
| 268 | gboolean again; | |
| 269 | gboolean plaintext = TRUE; | |
| 270 | ||
| 271 | /* Set up security properties and options */ | |
| 272 | secprops.min_ssf = 0; | |
| 273 | secprops.security_flags = SASL_SEC_NOANONYMOUS; | |
| 274 | ||
| 275 | if (!js->gsc) { | |
| 13207 | 276 | secprops.max_ssf = -1; |
| 277 | secprops.maxbufsize = 4096; | |
| 15884 | 278 | plaintext = purple_account_get_bool(js->gc->account, "auth_plain_in_clear", FALSE); |
| 12508 | 279 | if (!plaintext) |
| 280 | secprops.security_flags |= SASL_SEC_NOPLAINTEXT; | |
| 281 | } else { | |
| 13207 | 282 | secprops.max_ssf = 0; |
| 283 | secprops.maxbufsize = 0; | |
| 12540 | 284 | plaintext = TRUE; |
| 12508 | 285 | } |
| 286 | secprops.property_names = 0; | |
| 287 | secprops.property_values = 0; | |
| 288 | ||
| 289 | do { | |
| 290 | again = FALSE; | |
| 291 | ||
|
15800
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
292 | js->sasl_state = sasl_client_new("xmpp", js->serverFQDN, NULL, NULL, js->sasl_cb, 0, &js->sasl); |
| 12508 | 293 | if (js->sasl_state==SASL_OK) { |
| 294 | sasl_setprop(js->sasl, SASL_SEC_PROPS, &secprops); | |
| 15884 | 295 | purple_debug_info("sasl", "Mechs found: %s\n", js->sasl_mechs->str); |
| 12508 | 296 | js->sasl_state = sasl_client_start(js->sasl, js->sasl_mechs->str, NULL, &clientout, &coutlen, &mech); |
| 297 | } | |
| 298 | switch (js->sasl_state) { | |
| 299 | /* Success */ | |
| 12543 | 300 | case SASL_OK: |
| 12508 | 301 | case SASL_CONTINUE: |
| 302 | break; | |
| 303 | case SASL_NOMECH: | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
304 | /* No mechanisms have offered to help */ |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
305 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
306 | /* Firstly, if we don't have a password try |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
307 | * to get one |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
308 | */ |
| 12508 | 309 | |
| 15884 | 310 | if (!purple_account_get_password(js->gc->account)) { |
|
19852
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
311 | purple_account_request_password(js->gc->account, G_CALLBACK(auth_pass_cb), G_CALLBACK(auth_no_pass_cb), js->gc); |
| 12508 | 312 | return; |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
313 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
314 | /* If we've got a password, but aren't sending |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
315 | * it in plaintext, see if we can turn on |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
316 | * plaintext auth |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
317 | */ |
| 12508 | 318 | } else if (!plaintext) { |
| 17050 | 319 | char *msg = g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), |
|
17070
539b9296175f
I changed my mind, this should display the whole account name
Nathan Walp <nwalp@pidgin.im>
parents:
17050
diff
changeset
|
320 | js->gc->account->username); |
|
20685
039aef89faf6
Updated hinting to be less invasive
Gabriel Schulhof <nix@go-nix.ca>
parents:
20684
diff
changeset
|
321 | purple_request_yes_no_with_hint(js->gc, _("Plaintext Authentication"), |
| 12508 | 322 | _("Plaintext Authentication"), |
| 17050 | 323 | msg, |
|
19422
30c77768cc4d
explicit merge of 'ce478c555c3d69e8321cbb75fa8060985522de7c'
Gabriel Schulhof <nix@go-nix.ca>
diff
changeset
|
324 | 2, js->gc->account, NULL, NULL, "account", js->gc->account, |
| 12508 | 325 | allow_cyrus_plaintext_auth, |
| 326 | disallow_plaintext_auth); | |
| 17050 | 327 | g_free(msg); |
| 12508 | 328 | return; |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
329 | /* Everything else has failed, so fail the |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
330 | * connection. Should probably have a better |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
331 | * error here. |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
332 | */ |
| 12508 | 333 | } else { |
| 15884 | 334 | purple_connection_error(js->gc, _("Server does not use any supported authentication method")); |
| 12508 | 335 | return; |
| 336 | } | |
| 337 | /* not reached */ | |
| 338 | break; | |
| 339 | ||
| 340 | /* Fatal errors. Give up and go home */ | |
| 341 | case SASL_BADPARAM: | |
| 342 | case SASL_NOMEM: | |
| 343 | break; | |
| 344 | ||
| 345 | /* For everything else, fail the mechanism and try again */ | |
| 346 | default: | |
| 15884 | 347 | purple_debug_info("sasl", "sasl_state is %d, failing the mech and trying again\n", js->sasl_state); |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
348 | |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
349 | /* |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
350 | * DAA: is this right? |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
351 | * The manpage says that "mech" will contain the chosen mechanism on success. |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
352 | * Presumably, if we get here that isn't the case and we shouldn't try again? |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
353 | * I suspect that this never happens. |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
354 | */ |
|
15800
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
355 | /* |
|
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
356 | * SXW: Yes, this is right. What this handles is the situation where a |
|
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
357 | * mechanism, say GSSAPI, is tried. If that mechanism fails, it may be |
|
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
358 | * due to mechanism specific issues, so we want to try one of the other |
|
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
359 | * supported mechanisms. This code handles that case |
|
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
360 | */ |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
361 | if (mech && strlen(mech) > 0) { |
| 12508 | 362 | char *pos; |
|
14237
e5ce1ba029f9
[gaim-migrate @ 16825]
Daniel Atallah <datallah@pidgin.im>
parents:
14232
diff
changeset
|
363 | if ((pos = strstr(js->sasl_mechs->str, mech))) { |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
364 | g_string_erase(js->sasl_mechs, pos-js->sasl_mechs->str, strlen(mech)); |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
365 | } |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
366 | again = TRUE; |
| 12508 | 367 | } |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
368 | |
| 12508 | 369 | sasl_dispose(&js->sasl); |
| 370 | } | |
| 371 | } while (again); | |
| 372 | ||
| 12543 | 373 | if (js->sasl_state == SASL_CONTINUE || js->sasl_state == SASL_OK) { |
| 12508 | 374 | auth = xmlnode_new("auth"); |
| 13808 | 375 | xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl"); |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
376 | xmlnode_set_attrib(auth, "mechanism", mech); |
| 12508 | 377 | if (clientout) { |
| 378 | if (coutlen == 0) { | |
| 379 | xmlnode_insert_data(auth, "=", -1); | |
| 380 | } else { | |
| 15884 | 381 | enc_out = purple_base64_encode((unsigned char*)clientout, coutlen); |
| 12508 | 382 | xmlnode_insert_data(auth, enc_out, -1); |
| 383 | g_free(enc_out); | |
| 384 | } | |
| 385 | } | |
| 386 | jabber_send(js, auth); | |
| 387 | xmlnode_free(auth); | |
| 388 | } else { | |
| 15884 | 389 | purple_connection_error(js->gc, "SASL authentication failed\n"); |
| 12508 | 390 | } |
| 391 | } | |
| 392 | ||
| 12543 | 393 | static int |
| 394 | jabber_sasl_cb_log(void *context, int level, const char *message) | |
| 395 | { | |
| 396 | if(level <= SASL_LOG_TRACE) | |
| 15884 | 397 | purple_debug_info("sasl", "%s\n", message); |
| 12543 | 398 | |
| 399 | return SASL_OK; | |
| 400 | } | |
| 401 | ||
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
402 | void |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
403 | jabber_sasl_build_callbacks(JabberStream *js) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
404 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
405 | int id; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
406 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
407 | /* Set up our callbacks structure */ |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
408 | if (js->sasl_cb == NULL) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
409 | js->sasl_cb = g_new0(sasl_callback_t,6); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
410 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
411 | id = 0; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
412 | js->sasl_cb[id].id = SASL_CB_GETREALM; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
413 | js->sasl_cb[id].proc = jabber_sasl_cb_realm; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
414 | js->sasl_cb[id].context = (void *)js; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
415 | id++; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
416 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
417 | js->sasl_cb[id].id = SASL_CB_AUTHNAME; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
418 | js->sasl_cb[id].proc = jabber_sasl_cb_simple; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
419 | js->sasl_cb[id].context = (void *)js; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
420 | id++; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
421 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
422 | js->sasl_cb[id].id = SASL_CB_USER; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
423 | js->sasl_cb[id].proc = jabber_sasl_cb_simple; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
424 | js->sasl_cb[id].context = (void *)js; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
425 | id++; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
426 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
427 | if (purple_account_get_password(js->gc->account) != NULL ) { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
428 | js->sasl_cb[id].id = SASL_CB_PASS; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
429 | js->sasl_cb[id].proc = jabber_sasl_cb_secret; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
430 | js->sasl_cb[id].context = (void *)js; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
431 | id++; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
432 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
433 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
434 | js->sasl_cb[id].id = SASL_CB_LOG; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
435 | js->sasl_cb[id].proc = jabber_sasl_cb_log; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
436 | js->sasl_cb[id].context = (void*)js; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
437 | id++; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
438 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
439 | js->sasl_cb[id].id = SASL_CB_LIST_END; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
440 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
441 | |
| 12508 | 442 | #endif |
| 443 | ||
| 8296 | 444 | void |
| 445 | jabber_auth_start(JabberStream *js, xmlnode *packet) | |
| 446 | { | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
447 | #ifndef HAVE_CYRUS_SASL |
| 12508 | 448 | gboolean digest_md5 = FALSE, plain=FALSE; |
| 449 | #endif | |
| 8296 | 450 | |
| 12508 | 451 | xmlnode *mechs, *mechnode; |
| 8296 | 452 | |
| 453 | ||
| 8016 | 454 | if(js->registration) { |
| 455 | jabber_register_start(js); | |
| 456 | return; | |
| 457 | } | |
| 458 | ||
| 7014 | 459 | mechs = xmlnode_get_child(packet, "mechanisms"); |
| 460 | ||
| 461 | if(!mechs) { | |
| 15884 | 462 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 7014 | 463 | return; |
| 464 | } | |
| 465 | ||
| 12508 | 466 | #ifdef HAVE_CYRUS_SASL |
| 467 | js->sasl_mechs = g_string_new(""); | |
| 468 | #endif | |
| 469 | ||
| 8135 | 470 | for(mechnode = xmlnode_get_child(mechs, "mechanism"); mechnode; |
| 471 | mechnode = xmlnode_get_next_twin(mechnode)) | |
| 7014 | 472 | { |
| 8135 | 473 | char *mech_name = xmlnode_get_data(mechnode); |
| 12508 | 474 | #ifdef HAVE_CYRUS_SASL |
| 475 | g_string_append(js->sasl_mechs, mech_name); | |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
476 | g_string_append_c(js->sasl_mechs, ' '); |
| 12508 | 477 | #else |
| 8135 | 478 | if(mech_name && !strcmp(mech_name, "DIGEST-MD5")) |
| 479 | digest_md5 = TRUE; | |
| 480 | else if(mech_name && !strcmp(mech_name, "PLAIN")) | |
| 481 | plain = TRUE; | |
| 12508 | 482 | #endif |
| 8135 | 483 | g_free(mech_name); |
| 7014 | 484 | } |
| 485 | ||
| 12508 | 486 | #ifdef HAVE_CYRUS_SASL |
| 487 | js->auth_type = JABBER_AUTH_CYRUS; | |
| 488 | ||
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
489 | jabber_sasl_build_callbacks(js); |
| 12508 | 490 | |
| 491 | jabber_auth_start_cyrus(js); | |
| 492 | #else | |
| 7703 | 493 | |
| 7645 | 494 | if(digest_md5) { |
| 8397 | 495 | xmlnode *auth; |
| 496 | ||
| 497 | js->auth_type = JABBER_AUTH_DIGEST_MD5; | |
| 498 | auth = xmlnode_new("auth"); | |
| 13808 | 499 | xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl"); |
| 7291 | 500 | xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5"); |
| 8397 | 501 | |
| 502 | jabber_send(js, auth); | |
| 503 | xmlnode_free(auth); | |
| 8086 | 504 | } else if(plain) { |
| 8397 | 505 | js->auth_type = JABBER_AUTH_PLAIN; |
| 7703 | 506 | |
| 15884 | 507 | if(js->gsc == NULL && !purple_account_get_bool(js->gc->account, "auth_plain_in_clear", FALSE)) { |
| 17050 | 508 | char *msg = g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), |
|
17070
539b9296175f
I changed my mind, this should display the whole account name
Nathan Walp <nwalp@pidgin.im>
parents:
17050
diff
changeset
|
509 | js->gc->account->username); |
|
20685
039aef89faf6
Updated hinting to be less invasive
Gabriel Schulhof <nix@go-nix.ca>
parents:
20684
diff
changeset
|
510 | purple_request_yes_no_with_hint(js->gc, _("Plaintext Authentication"), |
| 8397 | 511 | _("Plaintext Authentication"), |
| 17050 | 512 | msg, |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16395
diff
changeset
|
513 | 2, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16395
diff
changeset
|
514 | purple_connection_get_account(js->gc), NULL, NULL, |
|
19257
4fd028282b9b
Added hints to jabber auth.c
Gabriel Schulhof <nix@go-nix.ca>
parents:
19256
diff
changeset
|
515 | "account", purple_connection_get_account(js->gc), |
|
19256
5385b6130a3b
Added hints to jabber auth.c
Gabriel Schulhof <nix@go-nix.ca>
parents:
17272
diff
changeset
|
516 | allow_plaintext_auth, disallow_plaintext_auth); |
| 17050 | 517 | g_free(msg); |
| 8086 | 518 | return; |
| 519 | } | |
| 8397 | 520 | finish_plaintext_authentication(js); |
| 7014 | 521 | } else { |
| 15884 | 522 | purple_connection_error(js->gc, |
| 7014 | 523 | _("Server does not use any supported authentication method")); |
| 524 | } | |
| 12508 | 525 | #endif |
| 7014 | 526 | } |
| 527 | ||
| 7395 | 528 | static void auth_old_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 7014 | 529 | { |
| 530 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 531 | ||
| 7730 | 532 | if(type && !strcmp(type, "result")) { |
| 533 | jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); | |
| 534 | } else { | |
| 8401 | 535 | char *msg = jabber_parse_error(js, packet); |
| 536 | xmlnode *error; | |
| 537 | const char *err_code; | |
| 7014 | 538 | |
| 8401 | 539 | if((error = xmlnode_get_child(packet, "error")) && |
| 540 | (err_code = xmlnode_get_attrib(error, "code")) && | |
| 541 | !strcmp(err_code, "401")) { | |
| 542 | js->gc->wants_to_die = TRUE; | |
|
19993
867bd1dfe680
Clear the password when we get an auth. error and we're not saving passwords so that you don't need to go into the account settings to reset it. Fix #3083.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
543 | /* Clear the pasword if it isn't being saved */ |
|
867bd1dfe680
Clear the password when we get an auth. error and we're not saving passwords so that you don't need to go into the account settings to reset it. Fix #3083.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
544 | if (!purple_account_get_remember_password(js->gc->account)) |
|
867bd1dfe680
Clear the password when we get an auth. error and we're not saving passwords so that you don't need to go into the account settings to reset it. Fix #3083.
Daniel Atallah <datallah@pidgin.im>
parents:
19859
diff
changeset
|
545 | purple_account_set_password(js->gc->account, NULL); |
| 7730 | 546 | } |
| 7014 | 547 | |
| 15884 | 548 | purple_connection_error(js->gc, msg); |
| 8401 | 549 | g_free(msg); |
| 7014 | 550 | } |
| 551 | } | |
| 552 | ||
| 7395 | 553 | static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 7014 | 554 | { |
| 555 | JabberIq *iq; | |
| 556 | xmlnode *query, *x; | |
| 7514 | 557 | const char *type = xmlnode_get_attrib(packet, "type"); |
| 15884 | 558 | const char *pw = purple_connection_get_password(js->gc); |
| 7014 | 559 | |
| 7514 | 560 | if(!type) { |
| 15884 | 561 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 7014 | 562 | return; |
| 7515 | 563 | } else if(!strcmp(type, "error")) { |
| 8401 | 564 | char *msg = jabber_parse_error(js, packet); |
| 15884 | 565 | purple_connection_error(js->gc, msg); |
| 8401 | 566 | g_free(msg); |
| 7515 | 567 | } else if(!strcmp(type, "result")) { |
| 7514 | 568 | query = xmlnode_get_child(packet, "query"); |
| 569 | if(js->stream_id && xmlnode_get_child(query, "digest")) { | |
| 570 | unsigned char hashval[20]; | |
| 571 | char *s, h[41], *p; | |
| 572 | int i; | |
| 7014 | 573 | |
| 8397 | 574 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth"); |
| 575 | query = xmlnode_get_child(iq->node, "query"); | |
| 576 | x = xmlnode_new_child(query, "username"); | |
| 577 | xmlnode_insert_data(x, js->user->node, -1); | |
| 578 | x = xmlnode_new_child(query, "resource"); | |
| 579 | xmlnode_insert_data(x, js->user->resource, -1); | |
| 580 | ||
| 7514 | 581 | x = xmlnode_new_child(query, "digest"); |
| 582 | s = g_strdup_printf("%s%s", js->stream_id, pw); | |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10496
diff
changeset
|
583 | |
| 15884 | 584 | purple_cipher_digest_region("sha1", (guchar *)s, strlen(s), |
| 10687 | 585 | sizeof(hashval), hashval, NULL); |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10496
diff
changeset
|
586 | |
| 7514 | 587 | p = h; |
| 588 | for(i=0; i<20; i++, p+=2) | |
| 589 | snprintf(p, 3, "%02x", hashval[i]); | |
| 590 | xmlnode_insert_data(x, h, -1); | |
| 591 | g_free(s); | |
| 8397 | 592 | jabber_iq_set_callback(iq, auth_old_result_cb, NULL); |
| 593 | jabber_iq_send(iq); | |
| 594 | ||
| 595 | } else if(xmlnode_get_child(query, "password")) { | |
| 15884 | 596 | if(js->gsc == NULL && !purple_account_get_bool(js->gc->account, |
| 8397 | 597 | "auth_plain_in_clear", FALSE)) { |
|
20685
039aef89faf6
Updated hinting to be less invasive
Gabriel Schulhof <nix@go-nix.ca>
parents:
20684
diff
changeset
|
598 | purple_request_yes_no_with_hint(js->gc, _("Plaintext Authentication"), |
| 8397 | 599 | _("Plaintext Authentication"), |
| 600 | _("This server requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), | |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16395
diff
changeset
|
601 | 2, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
16395
diff
changeset
|
602 | purple_connection_get_account(js->gc), NULL, NULL, |
|
19257
4fd028282b9b
Added hints to jabber auth.c
Gabriel Schulhof <nix@go-nix.ca>
parents:
19256
diff
changeset
|
603 | "account", purple_connection_get_account(js->gc), |
|
19256
5385b6130a3b
Added hints to jabber auth.c
Gabriel Schulhof <nix@go-nix.ca>
parents:
17272
diff
changeset
|
604 | allow_plaintext_auth, disallow_plaintext_auth); |
| 8397 | 605 | return; |
| 606 | } | |
| 607 | finish_plaintext_authentication(js); | |
| 7514 | 608 | } else { |
| 15884 | 609 | purple_connection_error(js->gc, |
| 8397 | 610 | _("Server does not use any supported authentication method")); |
| 611 | return; | |
| 7514 | 612 | } |
| 7014 | 613 | } |
| 614 | } | |
| 615 | ||
| 616 | void jabber_auth_start_old(JabberStream *js) | |
| 617 | { | |
| 618 | JabberIq *iq; | |
| 619 | xmlnode *query, *username; | |
| 620 | ||
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
621 | #ifdef HAVE_CYRUS_SASL |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
622 | /* If we have Cyrus SASL, then passwords will have been set |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
623 | * to OPTIONAL for this protocol. So, we need to do our own |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
624 | * password prompting here |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
625 | */ |
|
20379
eeb5eef9992c
Disable the account when the user cancels entering the password so the account isn't stuck in a weird unconnected state. Fixes #1791
Daniel Atallah <datallah@pidgin.im>
parents:
19993
diff
changeset
|
626 | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
627 | if (!purple_account_get_password(js->gc->account)) { |
|
19852
4810415cdcfb
The cyrus SASL password prompt dialogs don't get disposed if the account disconnects. This fixes the callbacks not to assume that the connection is still valid.
Daniel Atallah <datallah@pidgin.im>
parents:
19337
diff
changeset
|
628 | purple_account_request_password(js->gc->account, G_CALLBACK(auth_old_pass_cb), G_CALLBACK(auth_no_pass_cb), js->gc); |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
629 | return; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
630 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
631 | #endif |
| 7014 | 632 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:auth"); |
| 633 | ||
| 634 | query = xmlnode_get_child(iq->node, "query"); | |
| 635 | username = xmlnode_new_child(query, "username"); | |
| 636 | xmlnode_insert_data(username, js->user->node, -1); | |
| 637 | ||
| 7395 | 638 | jabber_iq_set_callback(iq, auth_old_cb, NULL); |
| 7014 | 639 | |
| 640 | jabber_iq_send(iq); | |
| 641 | } | |
| 642 | ||
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
643 | /* Parts of this algorithm are inspired by stuff in libgsasl */ |
| 7014 | 644 | static GHashTable* parse_challenge(const char *challenge) |
| 645 | { | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
646 | const char *token_start, *val_start, *val_end, *cur; |
| 7014 | 647 | GHashTable *ret = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 648 | g_free, g_free); | |
| 649 | ||
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
650 | cur = challenge; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
651 | while(*cur != '\0') { |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
652 | /* Find the end of the token */ |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
653 | gboolean in_quotes = FALSE; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
654 | char *name, *value = NULL; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
655 | token_start = cur; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
656 | while(*cur != '\0' && (in_quotes || (!in_quotes && *cur != ','))) { |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
657 | if (*cur == '"') |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
658 | in_quotes = !in_quotes; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
659 | cur++; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
660 | } |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
661 | |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
662 | /* Find start of value. */ |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
663 | val_start = strchr(token_start, '='); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
664 | if (val_start == NULL || val_start > cur) |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
665 | val_start = cur; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
666 | |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
667 | if (token_start != val_start) { |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
668 | name = g_strndup(token_start, val_start - token_start); |
| 7014 | 669 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
670 | if (val_start != cur) { |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
671 | val_start++; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
672 | while (val_start != cur && (*val_start == ' ' || *val_start == '\t' |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
673 | || *val_start == '\r' || *val_start == '\n' |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
674 | || *val_start == '"')) |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
675 | val_start++; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
676 | |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
677 | val_end = cur; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
678 | while (val_end != val_start && (*val_end == ' ' || *val_end == ',' || *val_end == '\t' |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
679 | || *val_end == '\r' || *val_start == '\n' |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
680 | || *val_end == '"')) |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
681 | val_end--; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
682 | |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
683 | if (val_start != val_end) |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
684 | value = g_strndup(val_start, val_end - val_start + 1); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
685 | } |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
686 | |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
687 | g_hash_table_replace(ret, name, value); |
| 7014 | 688 | } |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
689 | |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
690 | /* Find the start of the next token, if there is one */ |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
691 | if (*cur != '\0') { |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
692 | cur++; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
693 | while (*cur == ' ' || *cur == ',' || *cur == '\t' |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
694 | || *cur == '\r' || *cur == '\n') |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
695 | cur++; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
696 | } |
| 7014 | 697 | } |
| 698 | ||
| 699 | return ret; | |
| 700 | } | |
| 701 | ||
|
11163
7fe2cec8e9e6
[gaim-migrate @ 13264]
Mark Doliner <markdoliner@pidgin.im>
parents:
11137
diff
changeset
|
702 | static char * |
| 7014 | 703 | generate_response_value(JabberID *jid, const char *passwd, const char *nonce, |
| 7267 | 704 | const char *cnonce, const char *a2, const char *realm) |
| 7014 | 705 | { |
| 15884 | 706 | PurpleCipher *cipher; |
| 707 | PurpleCipherContext *context; | |
|
11137
cf40226ddff7
[gaim-migrate @ 13201]
Mark Doliner <markdoliner@pidgin.im>
parents:
11127
diff
changeset
|
708 | guchar result[16]; |
| 10136 | 709 | size_t a1len; |
| 7014 | 710 | |
| 12549 | 711 | gchar *a1, *convnode=NULL, *convpasswd = NULL, *ha1, *ha2, *kd, *x, *z; |
| 7014 | 712 | |
|
19337
68471e68386a
Use -1 as length with g_convert() functions instead of strlen()
Daniel Atallah <datallah@pidgin.im>
parents:
19223
diff
changeset
|
713 | if((convnode = g_convert(jid->node, -1, "iso-8859-1", "utf-8", |
| 10136 | 714 | NULL, NULL, NULL)) == NULL) { |
| 715 | convnode = g_strdup(jid->node); | |
| 716 | } | |
|
19337
68471e68386a
Use -1 as length with g_convert() functions instead of strlen()
Daniel Atallah <datallah@pidgin.im>
parents:
19223
diff
changeset
|
717 | if(passwd && ((convpasswd = g_convert(passwd, -1, "iso-8859-1", |
| 12549 | 718 | "utf-8", NULL, NULL, NULL)) == NULL)) { |
| 10136 | 719 | convpasswd = g_strdup(passwd); |
| 720 | } | |
| 721 | ||
| 15884 | 722 | cipher = purple_ciphers_find_cipher("md5"); |
| 723 | context = purple_cipher_context_new(cipher, NULL); | |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10496
diff
changeset
|
724 | |
| 12549 | 725 | x = g_strdup_printf("%s:%s:%s", convnode, realm, convpasswd ? convpasswd : ""); |
| 15884 | 726 | purple_cipher_context_append(context, (const guchar *)x, strlen(x)); |
| 727 | purple_cipher_context_digest(context, sizeof(result), result, NULL); | |
| 7014 | 728 | |
| 10136 | 729 | a1 = g_strdup_printf("xxxxxxxxxxxxxxxx:%s:%s", nonce, cnonce); |
| 730 | a1len = strlen(a1); | |
| 731 | g_memmove(a1, result, 16); | |
| 7014 | 732 | |
| 15884 | 733 | purple_cipher_context_reset(context, NULL); |
| 734 | purple_cipher_context_append(context, (const guchar *)a1, a1len); | |
| 735 | purple_cipher_context_digest(context, sizeof(result), result, NULL); | |
| 7014 | 736 | |
| 15884 | 737 | ha1 = purple_base16_encode(result, 16); |
| 7014 | 738 | |
| 15884 | 739 | purple_cipher_context_reset(context, NULL); |
| 740 | purple_cipher_context_append(context, (const guchar *)a2, strlen(a2)); | |
| 741 | purple_cipher_context_digest(context, sizeof(result), result, NULL); | |
| 7014 | 742 | |
| 15884 | 743 | ha2 = purple_base16_encode(result, 16); |
| 7014 | 744 | |
| 745 | kd = g_strdup_printf("%s:%s:00000001:%s:auth:%s", ha1, nonce, cnonce, ha2); | |
| 746 | ||
| 15884 | 747 | purple_cipher_context_reset(context, NULL); |
| 748 | purple_cipher_context_append(context, (const guchar *)kd, strlen(kd)); | |
| 749 | purple_cipher_context_digest(context, sizeof(result), result, NULL); | |
| 750 | purple_cipher_context_destroy(context); | |
| 7014 | 751 | |
| 15884 | 752 | z = purple_base16_encode(result, 16); |
| 7014 | 753 | |
| 10136 | 754 | g_free(convnode); |
| 755 | g_free(convpasswd); | |
| 7014 | 756 | g_free(x); |
| 757 | g_free(a1); | |
| 758 | g_free(ha1); | |
| 759 | g_free(ha2); | |
| 760 | g_free(kd); | |
| 761 | ||
| 762 | return z; | |
| 763 | } | |
| 764 | ||
| 765 | void | |
| 766 | jabber_auth_handle_challenge(JabberStream *js, xmlnode *packet) | |
| 767 | { | |
| 768 | ||
| 7703 | 769 | if(js->auth_type == JABBER_AUTH_DIGEST_MD5) { |
| 7291 | 770 | char *enc_in = xmlnode_get_data(packet); |
| 771 | char *dec_in; | |
| 772 | char *enc_out; | |
| 773 | GHashTable *parts; | |
| 7014 | 774 | |
| 7395 | 775 | if(!enc_in) { |
| 15884 | 776 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 7395 | 777 | return; |
| 778 | } | |
| 779 | ||
| 15884 | 780 | dec_in = (char *)purple_base64_decode(enc_in, NULL); |
| 781 | purple_debug(PURPLE_DEBUG_MISC, "jabber", "decoded challenge (%d): %s\n", | |
| 7395 | 782 | strlen(dec_in), dec_in); |
| 7291 | 783 | |
| 784 | parts = parse_challenge(dec_in); | |
| 7014 | 785 | |
| 786 | ||
| 7291 | 787 | if (g_hash_table_lookup(parts, "rspauth")) { |
| 788 | char *rspauth = g_hash_table_lookup(parts, "rspauth"); | |
| 7014 | 789 | |
| 790 | ||
| 7291 | 791 | if(rspauth && js->expected_rspauth && |
| 792 | !strcmp(rspauth, js->expected_rspauth)) { | |
| 793 | jabber_send_raw(js, | |
| 7642 | 794 | "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", |
| 795 | -1); | |
| 7291 | 796 | } else { |
| 15884 | 797 | purple_connection_error(js->gc, _("Invalid challenge from server")); |
| 7291 | 798 | } |
| 799 | g_free(js->expected_rspauth); | |
| 800 | } else { | |
| 801 | /* assemble a response, and send it */ | |
| 802 | /* see RFC 2831 */ | |
| 803 | char *realm; | |
| 804 | char *nonce; | |
| 7014 | 805 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
806 | /* Make sure the auth string contains everything that should be there. |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
807 | This isn't everything in RFC2831, but it is what we need. */ |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
808 | |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
809 | nonce = g_hash_table_lookup(parts, "nonce"); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
810 | |
| 7291 | 811 | /* we're actually supposed to prompt the user for a realm if |
| 812 | * the server doesn't send one, but that really complicates things, | |
| 813 | * so i'm not gonna worry about it until is poses a problem to | |
| 814 | * someone, or I get really bored */ | |
| 815 | realm = g_hash_table_lookup(parts, "realm"); | |
| 816 | if(!realm) | |
| 817 | realm = js->user->domain; | |
| 7014 | 818 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
819 | if (nonce == NULL || realm == NULL) |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
820 | purple_connection_error(js->gc, _("Invalid challenge from server")); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
821 | else { |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
822 | GString *response = g_string_new(""); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
823 | char *a2; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
824 | char *auth_resp; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
825 | char *buf; |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
826 | char *cnonce; |
| 7014 | 827 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
828 | cnonce = g_strdup_printf("%x%u%x", g_random_int(), (int)time(NULL), |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
829 | g_random_int()); |
| 7291 | 830 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
831 | a2 = g_strdup_printf("AUTHENTICATE:xmpp/%s", realm); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
832 | auth_resp = generate_response_value(js->user, |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
833 | purple_connection_get_password(js->gc), nonce, cnonce, a2, realm); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
834 | g_free(a2); |
| 7291 | 835 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
836 | a2 = g_strdup_printf(":xmpp/%s", realm); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
837 | js->expected_rspauth = generate_response_value(js->user, |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
838 | purple_connection_get_password(js->gc), nonce, cnonce, a2, realm); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
839 | g_free(a2); |
| 7291 | 840 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
841 | g_string_append_printf(response, "username=\"%s\"", js->user->node); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
842 | g_string_append_printf(response, ",realm=\"%s\"", realm); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
843 | g_string_append_printf(response, ",nonce=\"%s\"", nonce); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
844 | g_string_append_printf(response, ",cnonce=\"%s\"", cnonce); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
845 | g_string_append_printf(response, ",nc=00000001"); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
846 | g_string_append_printf(response, ",qop=auth"); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
847 | g_string_append_printf(response, ",digest-uri=\"xmpp/%s\"", realm); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
848 | g_string_append_printf(response, ",response=%s", auth_resp); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
849 | g_string_append_printf(response, ",charset=utf-8"); |
| 7291 | 850 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
851 | g_free(auth_resp); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
852 | g_free(cnonce); |
| 7291 | 853 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
854 | enc_out = purple_base64_encode((guchar *)response->str, response->len); |
| 7291 | 855 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
856 | purple_debug(PURPLE_DEBUG_MISC, "jabber", "decoded response (%d): %s\n", response->len, response->str); |
| 7291 | 857 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
858 | buf = g_strdup_printf("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>%s</response>", enc_out); |
| 7291 | 859 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
860 | jabber_send_raw(js, buf, -1); |
| 7291 | 861 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
862 | g_free(buf); |
| 7291 | 863 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
864 | g_free(enc_out); |
| 7291 | 865 | |
|
17270
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
866 | g_string_free(response, TRUE); |
|
a995cb90663a
Added more robust parsing of the xmpp digest challenge and add validation that some required challenge fields are present. Fixes #1024
Daniel Atallah <datallah@pidgin.im>
parents:
17070
diff
changeset
|
867 | } |
| 7014 | 868 | } |
| 7291 | 869 | |
| 870 | g_free(enc_in); | |
| 871 | g_free(dec_in); | |
| 872 | g_hash_table_destroy(parts); | |
| 7014 | 873 | } |
| 12508 | 874 | #ifdef HAVE_CYRUS_SASL |
| 875 | else if (js->auth_type == JABBER_AUTH_CYRUS) { | |
| 876 | char *enc_in = xmlnode_get_data(packet); | |
| 877 | unsigned char *dec_in; | |
| 878 | char *enc_out; | |
| 879 | const char *c_out; | |
| 12543 | 880 | unsigned int clen; |
| 881 | gsize declen; | |
| 12508 | 882 | xmlnode *response; |
| 883 | ||
| 15884 | 884 | dec_in = purple_base64_decode(enc_in, &declen); |
| 12508 | 885 | |
| 886 | js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen, | |
| 887 | NULL, &c_out, &clen); | |
| 15170 | 888 | g_free(enc_in); |
| 12508 | 889 | g_free(dec_in); |
| 890 | if (js->sasl_state != SASL_CONTINUE && js->sasl_state != SASL_OK) { | |
| 15884 | 891 | purple_debug_error("jabber", "Error is %d : %s\n",js->sasl_state,sasl_errdetail(js->sasl)); |
| 892 | purple_connection_error(js->gc, _("SASL error")); | |
| 12508 | 893 | return; |
| 894 | } else { | |
| 895 | response = xmlnode_new("response"); | |
| 13808 | 896 | xmlnode_set_namespace(response, "urn:ietf:params:xml:ns:xmpp-sasl"); |
|
16724
724e0f6df95d
Don't try to base64 encode and then append an empty string
Mark Doliner <markdoliner@pidgin.im>
parents:
16564
diff
changeset
|
897 | if (clen > 0) { |
| 15884 | 898 | enc_out = purple_base64_encode((unsigned char*)c_out, clen); |
| 12508 | 899 | xmlnode_insert_data(response, enc_out, -1); |
| 900 | g_free(enc_out); | |
| 901 | } | |
| 902 | jabber_send(js, response); | |
| 903 | xmlnode_free(response); | |
| 904 | } | |
| 905 | } | |
| 906 | #endif | |
| 7014 | 907 | } |
| 908 | ||
| 909 | void jabber_auth_handle_success(JabberStream *js, xmlnode *packet) | |
| 910 | { | |
| 13808 | 911 | const char *ns = xmlnode_get_namespace(packet); |
| 12508 | 912 | #ifdef HAVE_CYRUS_SASL |
|
16395
f6df845a2956
Get rid of two really minor warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
16180
diff
changeset
|
913 | const void *x; |
| 12508 | 914 | #endif |
| 7014 | 915 | |
| 916 | if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) { | |
| 15884 | 917 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 7014 | 918 | return; |
| 919 | } | |
| 920 | ||
|
12520
3ec49915efd8
[gaim-migrate @ 14832]
Richard Laager <rlaager@pidgin.im>
parents:
12508
diff
changeset
|
921 | #ifdef HAVE_CYRUS_SASL |
| 12508 | 922 | /* The SASL docs say that if the client hasn't returned OK yet, we |
| 923 | * should try one more round against it | |
| 924 | */ | |
| 925 | if (js->sasl_state != SASL_OK) { | |
| 15170 | 926 | char *enc_in = xmlnode_get_data(packet); |
| 927 | unsigned char *dec_in = NULL; | |
|
15112
cf00caa09ed4
[gaim-migrate @ 17834]
Mark Doliner <markdoliner@pidgin.im>
parents:
14660
diff
changeset
|
928 | const char *c_out; |
|
cf00caa09ed4
[gaim-migrate @ 17834]
Mark Doliner <markdoliner@pidgin.im>
parents:
14660
diff
changeset
|
929 | unsigned int clen; |
| 15170 | 930 | gsize declen = 0; |
| 931 | ||
| 932 | if(enc_in != NULL) | |
| 15884 | 933 | dec_in = purple_base64_decode(enc_in, &declen); |
| 15170 | 934 | |
| 935 | js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen, NULL, &c_out, &clen); | |
| 936 | ||
| 937 | g_free(enc_in); | |
| 938 | g_free(dec_in); | |
| 939 | ||
| 12508 | 940 | if (js->sasl_state != SASL_OK) { |
| 941 | /* This should never happen! */ | |
| 15884 | 942 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 12508 | 943 | } |
| 944 | } | |
| 945 | /* If we've negotiated a security layer, we need to enable it */ | |
|
15143
37451143f5c4
[gaim-migrate @ 17867]
Mark Doliner <markdoliner@pidgin.im>
parents:
15112
diff
changeset
|
946 | sasl_getprop(js->sasl, SASL_SSF, &x); |
|
16395
f6df845a2956
Get rid of two really minor warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
16180
diff
changeset
|
947 | if (*(int *)x > 0) { |
|
15143
37451143f5c4
[gaim-migrate @ 17867]
Mark Doliner <markdoliner@pidgin.im>
parents:
15112
diff
changeset
|
948 | sasl_getprop(js->sasl, SASL_MAXOUTBUF, &x); |
|
16395
f6df845a2956
Get rid of two really minor warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
16180
diff
changeset
|
949 | js->sasl_maxbuf = *(int *)x; |
| 12508 | 950 | } |
| 951 | #endif | |
| 952 | ||
| 7014 | 953 | jabber_stream_set_state(js, JABBER_STREAM_REINITIALIZING); |
| 954 | } | |
| 955 | ||
| 956 | void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet) | |
| 957 | { | |
| 8401 | 958 | char *msg = jabber_parse_error(js, packet); |
| 7014 | 959 | |
| 8401 | 960 | if(!msg) { |
| 15884 | 961 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 8401 | 962 | } else { |
| 15884 | 963 | purple_connection_error(js->gc, msg); |
| 8401 | 964 | g_free(msg); |
| 7014 | 965 | } |
| 966 | } |