Tue, 08 May 2007 00:28:22 +0000
Patch #265. Fix to Google Talk formatting
| 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 | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 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" |
|
c087855dc551
Re-arrange #includes so 'make check' stands a chance of passing during
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
26 | #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
|
27 | #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
|
28 | #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
|
29 | #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
|
30 | #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
|
31 | |
| 7014 | 32 | #include "jutil.h" |
| 33 | #include "auth.h" | |
| 34 | #include "jabber.h" | |
| 35 | #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
|
36 | #include "notify.h" |
| 7014 | 37 | |
| 8397 | 38 | static void auth_old_result_cb(JabberStream *js, xmlnode *packet, |
| 39 | gpointer data); | |
| 7014 | 40 | |
| 8296 | 41 | gboolean |
| 42 | jabber_process_starttls(JabberStream *js, xmlnode *packet) | |
| 7014 | 43 | { |
| 44 | xmlnode *starttls; | |
| 45 | ||
| 7157 | 46 | if((starttls = xmlnode_get_child(packet, "starttls"))) { |
| 15884 | 47 | if(purple_ssl_is_supported()) { |
| 7157 | 48 | jabber_send_raw(js, |
| 7642 | 49 | "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1); |
| 8296 | 50 | return TRUE; |
| 7157 | 51 | } else if(xmlnode_get_child(starttls, "required")) { |
| 15884 | 52 | purple_connection_error(js->gc, _("Server requires TLS/SSL for login. No TLS/SSL support found.")); |
| 8296 | 53 | return TRUE; |
| 7157 | 54 | } |
| 7014 | 55 | } |
| 56 | ||
| 8296 | 57 | return FALSE; |
| 58 | } | |
| 59 | ||
| 8397 | 60 | static void finish_plaintext_authentication(JabberStream *js) |
| 61 | { | |
| 62 | if(js->auth_type == JABBER_AUTH_PLAIN) { | |
| 63 | xmlnode *auth; | |
| 64 | GString *response; | |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
10740
diff
changeset
|
65 | gchar *enc_out; |
| 8397 | 66 | |
| 67 | auth = xmlnode_new("auth"); | |
| 13808 | 68 | xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl"); |
| 15271 | 69 | |
| 70 | xmlnode_set_attrib(auth, "xmlns:ga", "http://www.google.com/talk/protocol/auth"); | |
| 15293 | 71 | xmlnode_set_attrib(auth, "ga:client-uses-full-bind-result", "true"); |
| 15271 | 72 | |
| 8397 | 73 | response = g_string_new(""); |
| 74 | response = g_string_append_len(response, "\0", 1); | |
| 75 | response = g_string_append(response, js->user->node); | |
| 76 | response = g_string_append_len(response, "\0", 1); | |
| 77 | response = g_string_append(response, | |
| 15884 | 78 | purple_connection_get_password(js->gc)); |
| 8397 | 79 | |
| 15884 | 80 | enc_out = purple_base64_encode((guchar *)response->str, response->len); |
| 8397 | 81 | |
| 82 | xmlnode_set_attrib(auth, "mechanism", "PLAIN"); | |
| 83 | xmlnode_insert_data(auth, enc_out, -1); | |
| 84 | g_free(enc_out); | |
| 85 | g_string_free(response, TRUE); | |
| 86 | ||
| 87 | jabber_send(js, auth); | |
| 88 | xmlnode_free(auth); | |
| 89 | } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) { | |
| 90 | JabberIq *iq; | |
| 91 | xmlnode *query, *x; | |
| 92 | ||
| 93 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth"); | |
| 94 | query = xmlnode_get_child(iq->node, "query"); | |
| 95 | x = xmlnode_new_child(query, "username"); | |
| 96 | xmlnode_insert_data(x, js->user->node, -1); | |
| 97 | x = xmlnode_new_child(query, "resource"); | |
| 98 | xmlnode_insert_data(x, js->user->resource, -1); | |
| 99 | x = xmlnode_new_child(query, "password"); | |
| 15884 | 100 | xmlnode_insert_data(x, purple_connection_get_password(js->gc), -1); |
| 8397 | 101 | jabber_iq_set_callback(iq, auth_old_result_cb, NULL); |
| 102 | jabber_iq_send(iq); | |
| 103 | } | |
| 104 | } | |
| 105 | ||
| 15884 | 106 | static void allow_plaintext_auth(PurpleAccount *account) |
| 8397 | 107 | { |
| 15884 | 108 | purple_account_set_bool(account, "auth_plain_in_clear", TRUE); |
| 8397 | 109 | |
| 110 | finish_plaintext_authentication(account->gc->proto_data); | |
| 111 | } | |
| 112 | ||
| 15884 | 113 | static void disallow_plaintext_auth(PurpleAccount *account) |
| 8397 | 114 | { |
| 15884 | 115 | purple_connection_error(account->gc, _("Server requires plaintext authentication over an unencrypted stream")); |
| 8397 | 116 | } |
| 117 | ||
| 12508 | 118 | #ifdef HAVE_CYRUS_SASL |
| 119 | ||
| 120 | 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
|
121 | static void jabber_sasl_build_callbacks(JabberStream *); |
| 12508 | 122 | |
| 123 | /* Callbacks for Cyrus SASL */ | |
| 124 | ||
| 125 | static int jabber_sasl_cb_realm(void *ctx, int id, const char **avail, const char **result) | |
| 126 | { | |
| 127 | JabberStream *js = (JabberStream *)ctx; | |
| 128 | ||
| 129 | if (id != SASL_CB_GETREALM || !result) return SASL_BADPARAM; | |
| 130 | ||
| 131 | *result = js->user->domain; | |
| 132 | ||
| 133 | return SASL_OK; | |
| 134 | } | |
| 135 | ||
| 136 | static int jabber_sasl_cb_simple(void *ctx, int id, const char **res, unsigned *len) | |
| 137 | { | |
| 138 | JabberStream *js = (JabberStream *)ctx; | |
| 139 | ||
| 140 | switch(id) { | |
| 141 | case SASL_CB_AUTHNAME: | |
| 142 | *res = js->user->node; | |
| 143 | break; | |
| 144 | case SASL_CB_USER: | |
| 12543 | 145 | *res = ""; |
| 12508 | 146 | break; |
| 147 | default: | |
| 148 | return SASL_BADPARAM; | |
| 149 | } | |
| 150 | if (len) *len = strlen((char *)*res); | |
| 151 | return SASL_OK; | |
| 152 | } | |
| 153 | ||
| 154 | static int jabber_sasl_cb_secret(sasl_conn_t *conn, void *ctx, int id, sasl_secret_t **secret) | |
| 155 | { | |
| 156 | JabberStream *js = (JabberStream *)ctx; | |
| 15884 | 157 | const char *pw = purple_account_get_password(js->gc->account); |
| 12508 | 158 | size_t len; |
| 159 | static sasl_secret_t *x = NULL; | |
| 160 | ||
| 161 | if (!conn || !secret || id != SASL_CB_PASS) | |
| 162 | return SASL_BADPARAM; | |
| 163 | ||
| 164 | len = strlen(pw); | |
| 165 | x = (sasl_secret_t *) realloc(x, sizeof(sasl_secret_t) + len); | |
| 166 | ||
| 167 | if (!x) | |
| 168 | return SASL_NOMEM; | |
| 169 | ||
| 170 | x->len = len; | |
| 171 | strcpy((char*)x->data, pw); | |
| 172 | ||
| 173 | *secret = x; | |
| 174 | return SASL_OK; | |
| 175 | } | |
| 176 | ||
| 15884 | 177 | static void allow_cyrus_plaintext_auth(PurpleAccount *account) |
| 12508 | 178 | { |
| 15884 | 179 | purple_account_set_bool(account, "auth_plain_in_clear", TRUE); |
| 12508 | 180 | |
| 181 | jabber_auth_start_cyrus(account->gc->proto_data); | |
| 182 | } | |
| 183 | ||
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
184 | 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
|
185 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
186 | const char *entry; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
187 | gboolean remember; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
188 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
189 | 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
|
190 | 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
|
191 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
192 | if (!entry || !*entry) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
193 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
194 | 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
|
195 | return FALSE; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
196 | } |
|
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 | if (remember) |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
199 | 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
|
200 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
201 | 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
|
202 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
203 | return TRUE; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
204 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
205 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
206 | static void auth_pass_cb(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
|
207 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
208 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
209 | 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
|
210 | return; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
211 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
212 | /* 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
|
213 | 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
|
214 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
215 | /* Restart our connection */ |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
216 | 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
|
217 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
218 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
219 | static void |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
220 | auth_old_pass_cb(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
|
221 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
222 | 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
|
223 | return; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
224 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
225 | /* Restart our connection */ |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
226 | 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
|
227 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
228 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
229 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
230 | static void |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
231 | auth_no_pass_cb(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
|
232 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
233 | purple_connection_error(js->gc, _("Password is required to sign on.")); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
234 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
235 | |
| 12508 | 236 | static void jabber_auth_start_cyrus(JabberStream *js) |
| 237 | { | |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
238 | const char *clientout = NULL, *mech = NULL; |
| 12508 | 239 | char *enc_out; |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
240 | unsigned coutlen = 0; |
| 12508 | 241 | xmlnode *auth; |
| 242 | sasl_security_properties_t secprops; | |
| 243 | gboolean again; | |
| 244 | gboolean plaintext = TRUE; | |
| 245 | ||
| 246 | /* Set up security properties and options */ | |
| 247 | secprops.min_ssf = 0; | |
| 248 | secprops.security_flags = SASL_SEC_NOANONYMOUS; | |
| 249 | ||
| 250 | if (!js->gsc) { | |
| 13207 | 251 | secprops.max_ssf = -1; |
| 252 | secprops.maxbufsize = 4096; | |
| 15884 | 253 | plaintext = purple_account_get_bool(js->gc->account, "auth_plain_in_clear", FALSE); |
| 12508 | 254 | if (!plaintext) |
| 255 | secprops.security_flags |= SASL_SEC_NOPLAINTEXT; | |
| 256 | } else { | |
| 13207 | 257 | secprops.max_ssf = 0; |
| 258 | secprops.maxbufsize = 0; | |
| 12540 | 259 | plaintext = TRUE; |
| 12508 | 260 | } |
| 261 | secprops.property_names = 0; | |
| 262 | secprops.property_values = 0; | |
| 263 | ||
| 264 | do { | |
| 265 | again = FALSE; | |
| 266 | ||
|
15800
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
267 | js->sasl_state = sasl_client_new("xmpp", js->serverFQDN, NULL, NULL, js->sasl_cb, 0, &js->sasl); |
| 12508 | 268 | if (js->sasl_state==SASL_OK) { |
| 269 | sasl_setprop(js->sasl, SASL_SEC_PROPS, &secprops); | |
| 15884 | 270 | purple_debug_info("sasl", "Mechs found: %s\n", js->sasl_mechs->str); |
| 12508 | 271 | js->sasl_state = sasl_client_start(js->sasl, js->sasl_mechs->str, NULL, &clientout, &coutlen, &mech); |
| 272 | } | |
| 273 | switch (js->sasl_state) { | |
| 274 | /* Success */ | |
| 12543 | 275 | case SASL_OK: |
| 12508 | 276 | case SASL_CONTINUE: |
| 277 | break; | |
| 278 | 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
|
279 | /* 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
|
280 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
281 | /* 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
|
282 | * to get one |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
283 | */ |
| 12508 | 284 | |
| 15884 | 285 | if (!purple_account_get_password(js->gc->account)) { |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
286 | purple_account_request_password(js->gc->account, G_CALLBACK(auth_pass_cb), G_CALLBACK(auth_no_pass_cb), js); |
| 12508 | 287 | return; |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
288 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
289 | /* 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
|
290 | * 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
|
291 | * plaintext auth |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
292 | */ |
| 12508 | 293 | } else if (!plaintext) { |
| 15884 | 294 | purple_request_yes_no(js->gc, _("Plaintext Authentication"), |
| 12508 | 295 | _("Plaintext Authentication"), |
| 296 | _("This server requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), | |
|
16564
482de7e2868f
Fix jabber sasl build.
Daniel Atallah <datallah@pidgin.im>
parents:
16490
diff
changeset
|
297 | 2, js->gc->account, NULL, NULL, NULL, |
| 12508 | 298 | allow_cyrus_plaintext_auth, |
| 299 | disallow_plaintext_auth); | |
| 300 | return; | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
301 | /* 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
|
302 | * 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
|
303 | * error here. |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
304 | */ |
| 12508 | 305 | } else { |
| 15884 | 306 | purple_connection_error(js->gc, _("Server does not use any supported authentication method")); |
| 12508 | 307 | return; |
| 308 | } | |
| 309 | /* not reached */ | |
| 310 | break; | |
| 311 | ||
| 312 | /* Fatal errors. Give up and go home */ | |
| 313 | case SASL_BADPARAM: | |
| 314 | case SASL_NOMEM: | |
| 315 | break; | |
| 316 | ||
| 317 | /* For everything else, fail the mechanism and try again */ | |
| 318 | default: | |
| 15884 | 319 | 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
|
320 | |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
321 | /* |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
322 | * DAA: is this right? |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
323 | * 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
|
324 | * 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
|
325 | * I suspect that this never happens. |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
326 | */ |
|
15800
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
327 | /* |
|
2d0ec4fe2681
pass the correct domain to cyrus sasl (sf patch 1663064)
Nathan Walp <nwalp@pidgin.im>
parents:
15435
diff
changeset
|
328 | * 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
|
329 | * 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
|
330 | * 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
|
331 | * 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
|
332 | */ |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
333 | if (mech && strlen(mech) > 0) { |
| 12508 | 334 | char *pos; |
|
14237
e5ce1ba029f9
[gaim-migrate @ 16825]
Daniel Atallah <datallah@pidgin.im>
parents:
14232
diff
changeset
|
335 | if ((pos = strstr(js->sasl_mechs->str, mech))) { |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
336 | 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
|
337 | } |
|
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
338 | again = TRUE; |
| 12508 | 339 | } |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
340 | |
| 12508 | 341 | sasl_dispose(&js->sasl); |
| 342 | } | |
| 343 | } while (again); | |
| 344 | ||
| 12543 | 345 | if (js->sasl_state == SASL_CONTINUE || js->sasl_state == SASL_OK) { |
| 12508 | 346 | auth = xmlnode_new("auth"); |
| 13808 | 347 | 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
|
348 | xmlnode_set_attrib(auth, "mechanism", mech); |
| 12508 | 349 | if (clientout) { |
| 350 | if (coutlen == 0) { | |
| 351 | xmlnode_insert_data(auth, "=", -1); | |
| 352 | } else { | |
| 15884 | 353 | enc_out = purple_base64_encode((unsigned char*)clientout, coutlen); |
| 12508 | 354 | xmlnode_insert_data(auth, enc_out, -1); |
| 355 | g_free(enc_out); | |
| 356 | } | |
| 357 | } | |
| 358 | jabber_send(js, auth); | |
| 359 | xmlnode_free(auth); | |
| 360 | } else { | |
| 15884 | 361 | purple_connection_error(js->gc, "SASL authentication failed\n"); |
| 12508 | 362 | } |
| 363 | } | |
| 364 | ||
| 12543 | 365 | static int |
| 366 | jabber_sasl_cb_log(void *context, int level, const char *message) | |
| 367 | { | |
| 368 | if(level <= SASL_LOG_TRACE) | |
| 15884 | 369 | purple_debug_info("sasl", "%s\n", message); |
| 12543 | 370 | |
| 371 | return SASL_OK; | |
| 372 | } | |
| 373 | ||
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
374 | void |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
375 | 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
|
376 | { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
377 | int id; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
378 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
379 | /* 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
|
380 | 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
|
381 | 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
|
382 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
383 | id = 0; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
384 | 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
|
385 | 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
|
386 | 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
|
387 | id++; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
388 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
389 | 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
|
390 | 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
|
391 | 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
|
392 | id++; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
393 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
394 | 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
|
395 | 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
|
396 | 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
|
397 | id++; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
398 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
399 | 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
|
400 | 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
|
401 | 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
|
402 | 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
|
403 | id++; |
|
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 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
406 | 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
|
407 | 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
|
408 | 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
|
409 | id++; |
|
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 | 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
|
412 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
413 | |
| 12508 | 414 | #endif |
| 415 | ||
| 8296 | 416 | void |
| 417 | jabber_auth_start(JabberStream *js, xmlnode *packet) | |
| 418 | { | |
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
419 | #ifndef HAVE_CYRUS_SASL |
| 12508 | 420 | gboolean digest_md5 = FALSE, plain=FALSE; |
| 421 | #endif | |
| 8296 | 422 | |
| 12508 | 423 | xmlnode *mechs, *mechnode; |
| 8296 | 424 | |
| 425 | ||
| 8016 | 426 | if(js->registration) { |
| 427 | jabber_register_start(js); | |
| 428 | return; | |
| 429 | } | |
| 430 | ||
| 7014 | 431 | mechs = xmlnode_get_child(packet, "mechanisms"); |
| 432 | ||
| 433 | if(!mechs) { | |
| 15884 | 434 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 7014 | 435 | return; |
| 436 | } | |
| 437 | ||
| 12508 | 438 | #ifdef HAVE_CYRUS_SASL |
| 439 | js->sasl_mechs = g_string_new(""); | |
| 440 | #endif | |
| 441 | ||
| 8135 | 442 | for(mechnode = xmlnode_get_child(mechs, "mechanism"); mechnode; |
| 443 | mechnode = xmlnode_get_next_twin(mechnode)) | |
| 7014 | 444 | { |
| 8135 | 445 | char *mech_name = xmlnode_get_data(mechnode); |
| 12508 | 446 | #ifdef HAVE_CYRUS_SASL |
| 447 | g_string_append(js->sasl_mechs, mech_name); | |
|
14232
331b5d0a2fd4
[gaim-migrate @ 16820]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
448 | g_string_append_c(js->sasl_mechs, ' '); |
| 12508 | 449 | #else |
| 8135 | 450 | if(mech_name && !strcmp(mech_name, "DIGEST-MD5")) |
| 451 | digest_md5 = TRUE; | |
| 452 | else if(mech_name && !strcmp(mech_name, "PLAIN")) | |
| 453 | plain = TRUE; | |
| 12508 | 454 | #endif |
| 8135 | 455 | g_free(mech_name); |
| 7014 | 456 | } |
| 457 | ||
| 12508 | 458 | #ifdef HAVE_CYRUS_SASL |
| 459 | js->auth_type = JABBER_AUTH_CYRUS; | |
| 460 | ||
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
461 | jabber_sasl_build_callbacks(js); |
| 12508 | 462 | |
| 463 | jabber_auth_start_cyrus(js); | |
| 464 | #else | |
| 7703 | 465 | |
| 7645 | 466 | if(digest_md5) { |
| 8397 | 467 | xmlnode *auth; |
| 468 | ||
| 469 | js->auth_type = JABBER_AUTH_DIGEST_MD5; | |
| 470 | auth = xmlnode_new("auth"); | |
| 13808 | 471 | xmlnode_set_namespace(auth, "urn:ietf:params:xml:ns:xmpp-sasl"); |
| 7291 | 472 | xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5"); |
| 8397 | 473 | |
| 474 | jabber_send(js, auth); | |
| 475 | xmlnode_free(auth); | |
| 8086 | 476 | } else if(plain) { |
| 8397 | 477 | js->auth_type = JABBER_AUTH_PLAIN; |
| 7703 | 478 | |
| 15884 | 479 | if(js->gsc == NULL && !purple_account_get_bool(js->gc->account, "auth_plain_in_clear", FALSE)) { |
| 480 | purple_request_yes_no(js->gc, _("Plaintext Authentication"), | |
| 8397 | 481 | _("Plaintext Authentication"), |
| 482 | _("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
|
483 | 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
|
484 | purple_connection_get_account(js->gc), NULL, NULL, |
|
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
|
485 | purple_connection_get_account(js->gc), allow_plaintext_auth, |
| 8397 | 486 | disallow_plaintext_auth); |
| 8086 | 487 | return; |
| 488 | } | |
| 8397 | 489 | finish_plaintext_authentication(js); |
| 7014 | 490 | } else { |
| 15884 | 491 | purple_connection_error(js->gc, |
| 7014 | 492 | _("Server does not use any supported authentication method")); |
| 493 | } | |
| 12508 | 494 | #endif |
| 7014 | 495 | } |
| 496 | ||
| 7395 | 497 | static void auth_old_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 7014 | 498 | { |
| 499 | const char *type = xmlnode_get_attrib(packet, "type"); | |
| 500 | ||
| 7730 | 501 | if(type && !strcmp(type, "result")) { |
| 502 | jabber_stream_set_state(js, JABBER_STREAM_CONNECTED); | |
| 503 | } else { | |
| 8401 | 504 | char *msg = jabber_parse_error(js, packet); |
| 505 | xmlnode *error; | |
| 506 | const char *err_code; | |
| 7014 | 507 | |
| 8401 | 508 | if((error = xmlnode_get_child(packet, "error")) && |
| 509 | (err_code = xmlnode_get_attrib(error, "code")) && | |
| 510 | !strcmp(err_code, "401")) { | |
| 511 | js->gc->wants_to_die = TRUE; | |
| 7730 | 512 | } |
| 7014 | 513 | |
| 15884 | 514 | purple_connection_error(js->gc, msg); |
| 8401 | 515 | g_free(msg); |
| 7014 | 516 | } |
| 517 | } | |
| 518 | ||
| 7395 | 519 | static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 7014 | 520 | { |
| 521 | JabberIq *iq; | |
| 522 | xmlnode *query, *x; | |
| 7514 | 523 | const char *type = xmlnode_get_attrib(packet, "type"); |
| 15884 | 524 | const char *pw = purple_connection_get_password(js->gc); |
| 7014 | 525 | |
| 7514 | 526 | if(!type) { |
| 15884 | 527 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 7014 | 528 | return; |
| 7515 | 529 | } else if(!strcmp(type, "error")) { |
| 8401 | 530 | char *msg = jabber_parse_error(js, packet); |
| 15884 | 531 | purple_connection_error(js->gc, msg); |
| 8401 | 532 | g_free(msg); |
| 7515 | 533 | } else if(!strcmp(type, "result")) { |
| 7514 | 534 | query = xmlnode_get_child(packet, "query"); |
| 535 | if(js->stream_id && xmlnode_get_child(query, "digest")) { | |
| 536 | unsigned char hashval[20]; | |
| 537 | char *s, h[41], *p; | |
| 538 | int i; | |
| 7014 | 539 | |
| 8397 | 540 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth"); |
| 541 | query = xmlnode_get_child(iq->node, "query"); | |
| 542 | x = xmlnode_new_child(query, "username"); | |
| 543 | xmlnode_insert_data(x, js->user->node, -1); | |
| 544 | x = xmlnode_new_child(query, "resource"); | |
| 545 | xmlnode_insert_data(x, js->user->resource, -1); | |
| 546 | ||
| 7514 | 547 | x = xmlnode_new_child(query, "digest"); |
| 548 | s = g_strdup_printf("%s%s", js->stream_id, pw); | |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10496
diff
changeset
|
549 | |
| 15884 | 550 | purple_cipher_digest_region("sha1", (guchar *)s, strlen(s), |
| 10687 | 551 | sizeof(hashval), hashval, NULL); |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10496
diff
changeset
|
552 | |
| 7514 | 553 | p = h; |
| 554 | for(i=0; i<20; i++, p+=2) | |
| 555 | snprintf(p, 3, "%02x", hashval[i]); | |
| 556 | xmlnode_insert_data(x, h, -1); | |
| 557 | g_free(s); | |
| 8397 | 558 | jabber_iq_set_callback(iq, auth_old_result_cb, NULL); |
| 559 | jabber_iq_send(iq); | |
| 560 | ||
| 561 | } else if(xmlnode_get_child(query, "password")) { | |
| 15884 | 562 | if(js->gsc == NULL && !purple_account_get_bool(js->gc->account, |
| 8397 | 563 | "auth_plain_in_clear", FALSE)) { |
| 15884 | 564 | purple_request_yes_no(js->gc, _("Plaintext Authentication"), |
| 8397 | 565 | _("Plaintext Authentication"), |
| 566 | _("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
|
567 | 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
|
568 | purple_connection_get_account(js->gc), NULL, NULL, |
|
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
|
569 | purple_connection_get_account(js->gc), allow_plaintext_auth, |
| 8397 | 570 | disallow_plaintext_auth); |
| 571 | return; | |
| 572 | } | |
| 573 | finish_plaintext_authentication(js); | |
| 7514 | 574 | } else { |
| 15884 | 575 | purple_connection_error(js->gc, |
| 8397 | 576 | _("Server does not use any supported authentication method")); |
| 577 | return; | |
| 7514 | 578 | } |
| 7014 | 579 | } |
| 580 | } | |
| 581 | ||
| 582 | void jabber_auth_start_old(JabberStream *js) | |
| 583 | { | |
| 584 | JabberIq *iq; | |
| 585 | xmlnode *query, *username; | |
| 586 | ||
|
16180
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
587 | #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
|
588 | /* 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
|
589 | * 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
|
590 | * password prompting here |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
591 | */ |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
592 | |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
593 | if (!purple_account_get_password(js->gc->account)) { |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
594 | purple_account_request_password(js->gc->account, G_CALLBACK(auth_old_pass_cb), G_CALLBACK(auth_no_pass_cb), js); |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
595 | return; |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
596 | } |
|
82761882c366
patch from Simon Wilkinson to support Jabber/XMPP w/o passwords
Nathan Walp <nwalp@pidgin.im>
parents:
15952
diff
changeset
|
597 | #endif |
| 7014 | 598 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:auth"); |
| 599 | ||
| 600 | query = xmlnode_get_child(iq->node, "query"); | |
| 601 | username = xmlnode_new_child(query, "username"); | |
| 602 | xmlnode_insert_data(username, js->user->node, -1); | |
| 603 | ||
| 7395 | 604 | jabber_iq_set_callback(iq, auth_old_cb, NULL); |
| 7014 | 605 | |
| 606 | jabber_iq_send(iq); | |
| 607 | } | |
| 608 | ||
| 609 | static GHashTable* parse_challenge(const char *challenge) | |
| 610 | { | |
| 611 | GHashTable *ret = g_hash_table_new_full(g_str_hash, g_str_equal, | |
| 612 | g_free, g_free); | |
| 613 | char **pairs; | |
| 614 | int i; | |
| 615 | ||
| 616 | pairs = g_strsplit(challenge, ",", -1); | |
| 617 | ||
| 618 | for(i=0; pairs[i]; i++) { | |
| 619 | char **keyval = g_strsplit(pairs[i], "=", 2); | |
| 620 | if(keyval[0] && keyval[1]) { | |
| 621 | if(keyval[1][0] == '"' && keyval[1][strlen(keyval[1])-1] == '"') | |
| 622 | g_hash_table_replace(ret, g_strdup(keyval[0]), g_strndup(keyval[1]+1, strlen(keyval[1])-2)); | |
| 623 | else | |
| 624 | g_hash_table_replace(ret, g_strdup(keyval[0]), g_strdup(keyval[1])); | |
| 625 | } | |
| 626 | g_strfreev(keyval); | |
| 627 | } | |
| 628 | ||
| 629 | g_strfreev(pairs); | |
| 630 | ||
| 631 | return ret; | |
| 632 | } | |
| 633 | ||
|
11163
7fe2cec8e9e6
[gaim-migrate @ 13264]
Mark Doliner <markdoliner@pidgin.im>
parents:
11137
diff
changeset
|
634 | static char * |
| 7014 | 635 | generate_response_value(JabberID *jid, const char *passwd, const char *nonce, |
| 7267 | 636 | const char *cnonce, const char *a2, const char *realm) |
| 7014 | 637 | { |
| 15884 | 638 | PurpleCipher *cipher; |
| 639 | PurpleCipherContext *context; | |
|
11137
cf40226ddff7
[gaim-migrate @ 13201]
Mark Doliner <markdoliner@pidgin.im>
parents:
11127
diff
changeset
|
640 | guchar result[16]; |
| 10136 | 641 | size_t a1len; |
| 7014 | 642 | |
| 12549 | 643 | gchar *a1, *convnode=NULL, *convpasswd = NULL, *ha1, *ha2, *kd, *x, *z; |
| 7014 | 644 | |
| 10136 | 645 | if((convnode = g_convert(jid->node, strlen(jid->node), "iso-8859-1", "utf-8", |
| 646 | NULL, NULL, NULL)) == NULL) { | |
| 647 | convnode = g_strdup(jid->node); | |
| 648 | } | |
| 12549 | 649 | if(passwd && ((convpasswd = g_convert(passwd, strlen(passwd), "iso-8859-1", |
| 650 | "utf-8", NULL, NULL, NULL)) == NULL)) { | |
| 10136 | 651 | convpasswd = g_strdup(passwd); |
| 652 | } | |
| 653 | ||
| 15884 | 654 | cipher = purple_ciphers_find_cipher("md5"); |
| 655 | context = purple_cipher_context_new(cipher, NULL); | |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10496
diff
changeset
|
656 | |
| 12549 | 657 | x = g_strdup_printf("%s:%s:%s", convnode, realm, convpasswd ? convpasswd : ""); |
| 15884 | 658 | purple_cipher_context_append(context, (const guchar *)x, strlen(x)); |
| 659 | purple_cipher_context_digest(context, sizeof(result), result, NULL); | |
| 7014 | 660 | |
| 10136 | 661 | a1 = g_strdup_printf("xxxxxxxxxxxxxxxx:%s:%s", nonce, cnonce); |
| 662 | a1len = strlen(a1); | |
| 663 | g_memmove(a1, result, 16); | |
| 7014 | 664 | |
| 15884 | 665 | purple_cipher_context_reset(context, NULL); |
| 666 | purple_cipher_context_append(context, (const guchar *)a1, a1len); | |
| 667 | purple_cipher_context_digest(context, sizeof(result), result, NULL); | |
| 7014 | 668 | |
| 15884 | 669 | ha1 = purple_base16_encode(result, 16); |
| 7014 | 670 | |
| 15884 | 671 | purple_cipher_context_reset(context, NULL); |
| 672 | purple_cipher_context_append(context, (const guchar *)a2, strlen(a2)); | |
| 673 | purple_cipher_context_digest(context, sizeof(result), result, NULL); | |
| 7014 | 674 | |
| 15884 | 675 | ha2 = purple_base16_encode(result, 16); |
| 7014 | 676 | |
| 677 | kd = g_strdup_printf("%s:%s:00000001:%s:auth:%s", ha1, nonce, cnonce, ha2); | |
| 678 | ||
| 15884 | 679 | purple_cipher_context_reset(context, NULL); |
| 680 | purple_cipher_context_append(context, (const guchar *)kd, strlen(kd)); | |
| 681 | purple_cipher_context_digest(context, sizeof(result), result, NULL); | |
| 682 | purple_cipher_context_destroy(context); | |
| 7014 | 683 | |
| 15884 | 684 | z = purple_base16_encode(result, 16); |
| 7014 | 685 | |
| 10136 | 686 | g_free(convnode); |
| 687 | g_free(convpasswd); | |
| 7014 | 688 | g_free(x); |
| 689 | g_free(a1); | |
| 690 | g_free(ha1); | |
| 691 | g_free(ha2); | |
| 692 | g_free(kd); | |
| 693 | ||
| 694 | return z; | |
| 695 | } | |
| 696 | ||
| 697 | void | |
| 698 | jabber_auth_handle_challenge(JabberStream *js, xmlnode *packet) | |
| 699 | { | |
| 700 | ||
| 7703 | 701 | if(js->auth_type == JABBER_AUTH_DIGEST_MD5) { |
| 7291 | 702 | char *enc_in = xmlnode_get_data(packet); |
| 703 | char *dec_in; | |
| 704 | char *enc_out; | |
| 705 | GHashTable *parts; | |
| 7014 | 706 | |
| 7395 | 707 | if(!enc_in) { |
| 15884 | 708 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 7395 | 709 | return; |
| 710 | } | |
| 711 | ||
| 15884 | 712 | dec_in = (char *)purple_base64_decode(enc_in, NULL); |
| 713 | purple_debug(PURPLE_DEBUG_MISC, "jabber", "decoded challenge (%d): %s\n", | |
| 7395 | 714 | strlen(dec_in), dec_in); |
| 7291 | 715 | |
| 716 | parts = parse_challenge(dec_in); | |
| 7014 | 717 | |
| 718 | ||
| 7291 | 719 | if (g_hash_table_lookup(parts, "rspauth")) { |
| 720 | char *rspauth = g_hash_table_lookup(parts, "rspauth"); | |
| 7014 | 721 | |
| 722 | ||
| 7291 | 723 | if(rspauth && js->expected_rspauth && |
| 724 | !strcmp(rspauth, js->expected_rspauth)) { | |
| 725 | jabber_send_raw(js, | |
| 7642 | 726 | "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", |
| 727 | -1); | |
| 7291 | 728 | } else { |
| 15884 | 729 | purple_connection_error(js->gc, _("Invalid challenge from server")); |
| 7291 | 730 | } |
| 731 | g_free(js->expected_rspauth); | |
| 732 | } else { | |
| 733 | /* assemble a response, and send it */ | |
| 734 | /* see RFC 2831 */ | |
| 735 | GString *response = g_string_new(""); | |
| 736 | char *a2; | |
| 737 | char *auth_resp; | |
| 738 | char *buf; | |
| 739 | char *cnonce; | |
| 740 | char *realm; | |
| 741 | char *nonce; | |
| 7014 | 742 | |
| 7291 | 743 | /* we're actually supposed to prompt the user for a realm if |
| 744 | * the server doesn't send one, but that really complicates things, | |
| 745 | * so i'm not gonna worry about it until is poses a problem to | |
| 746 | * someone, or I get really bored */ | |
| 747 | realm = g_hash_table_lookup(parts, "realm"); | |
| 748 | if(!realm) | |
| 749 | realm = js->user->domain; | |
| 7014 | 750 | |
| 7291 | 751 | cnonce = g_strdup_printf("%x%u%x", g_random_int(), (int)time(NULL), |
| 752 | g_random_int()); | |
| 753 | nonce = g_hash_table_lookup(parts, "nonce"); | |
| 7014 | 754 | |
| 755 | ||
| 7291 | 756 | a2 = g_strdup_printf("AUTHENTICATE:xmpp/%s", realm); |
| 757 | auth_resp = generate_response_value(js->user, | |
| 15884 | 758 | purple_connection_get_password(js->gc), nonce, cnonce, a2, realm); |
| 7291 | 759 | g_free(a2); |
| 760 | ||
| 761 | a2 = g_strdup_printf(":xmpp/%s", realm); | |
| 762 | js->expected_rspauth = generate_response_value(js->user, | |
| 15884 | 763 | purple_connection_get_password(js->gc), nonce, cnonce, a2, realm); |
| 7291 | 764 | g_free(a2); |
| 765 | ||
| 766 | ||
| 767 | g_string_append_printf(response, "username=\"%s\"", js->user->node); | |
| 768 | g_string_append_printf(response, ",realm=\"%s\"", realm); | |
| 769 | g_string_append_printf(response, ",nonce=\"%s\"", nonce); | |
| 770 | g_string_append_printf(response, ",cnonce=\"%s\"", cnonce); | |
| 771 | g_string_append_printf(response, ",nc=00000001"); | |
| 772 | g_string_append_printf(response, ",qop=auth"); | |
| 773 | g_string_append_printf(response, ",digest-uri=\"xmpp/%s\"", realm); | |
| 774 | g_string_append_printf(response, ",response=%s", auth_resp); | |
| 775 | g_string_append_printf(response, ",charset=utf-8"); | |
| 776 | ||
| 777 | g_free(auth_resp); | |
| 778 | g_free(cnonce); | |
| 779 | ||
| 15884 | 780 | enc_out = purple_base64_encode((guchar *)response->str, response->len); |
| 7291 | 781 | |
| 15884 | 782 | purple_debug(PURPLE_DEBUG_MISC, "jabber", "decoded response (%d): %s\n", response->len, response->str); |
| 7291 | 783 | |
| 784 | buf = g_strdup_printf("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>%s</response>", enc_out); | |
| 785 | ||
| 7642 | 786 | jabber_send_raw(js, buf, -1); |
| 7291 | 787 | |
| 788 | g_free(buf); | |
| 789 | ||
| 790 | g_free(enc_out); | |
| 791 | ||
| 792 | g_string_free(response, TRUE); | |
| 7014 | 793 | } |
| 7291 | 794 | |
| 795 | g_free(enc_in); | |
| 796 | g_free(dec_in); | |
| 797 | g_hash_table_destroy(parts); | |
| 7014 | 798 | } |
| 12508 | 799 | #ifdef HAVE_CYRUS_SASL |
| 800 | else if (js->auth_type == JABBER_AUTH_CYRUS) { | |
| 801 | char *enc_in = xmlnode_get_data(packet); | |
| 802 | unsigned char *dec_in; | |
| 803 | char *enc_out; | |
| 804 | const char *c_out; | |
| 12543 | 805 | unsigned int clen; |
| 806 | gsize declen; | |
| 12508 | 807 | xmlnode *response; |
| 808 | ||
| 15884 | 809 | dec_in = purple_base64_decode(enc_in, &declen); |
| 12508 | 810 | |
| 811 | js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen, | |
| 812 | NULL, &c_out, &clen); | |
| 15170 | 813 | g_free(enc_in); |
| 12508 | 814 | g_free(dec_in); |
| 815 | if (js->sasl_state != SASL_CONTINUE && js->sasl_state != SASL_OK) { | |
| 15884 | 816 | purple_debug_error("jabber", "Error is %d : %s\n",js->sasl_state,sasl_errdetail(js->sasl)); |
| 817 | purple_connection_error(js->gc, _("SASL error")); | |
| 12508 | 818 | return; |
| 819 | } else { | |
| 820 | response = xmlnode_new("response"); | |
| 13808 | 821 | 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
|
822 | if (clen > 0) { |
| 15884 | 823 | enc_out = purple_base64_encode((unsigned char*)c_out, clen); |
| 12508 | 824 | xmlnode_insert_data(response, enc_out, -1); |
| 825 | g_free(enc_out); | |
| 826 | } | |
| 827 | jabber_send(js, response); | |
| 828 | xmlnode_free(response); | |
| 829 | } | |
| 830 | } | |
| 831 | #endif | |
| 7014 | 832 | } |
| 833 | ||
| 834 | void jabber_auth_handle_success(JabberStream *js, xmlnode *packet) | |
| 835 | { | |
| 13808 | 836 | const char *ns = xmlnode_get_namespace(packet); |
| 12508 | 837 | #ifdef HAVE_CYRUS_SASL |
|
16395
f6df845a2956
Get rid of two really minor warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
16180
diff
changeset
|
838 | const void *x; |
| 12508 | 839 | #endif |
| 7014 | 840 | |
| 841 | if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) { | |
| 15884 | 842 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 7014 | 843 | return; |
| 844 | } | |
| 845 | ||
|
12520
3ec49915efd8
[gaim-migrate @ 14832]
Richard Laager <rlaager@pidgin.im>
parents:
12508
diff
changeset
|
846 | #ifdef HAVE_CYRUS_SASL |
| 12508 | 847 | /* The SASL docs say that if the client hasn't returned OK yet, we |
| 848 | * should try one more round against it | |
| 849 | */ | |
| 850 | if (js->sasl_state != SASL_OK) { | |
| 15170 | 851 | char *enc_in = xmlnode_get_data(packet); |
| 852 | unsigned char *dec_in = NULL; | |
|
15112
cf00caa09ed4
[gaim-migrate @ 17834]
Mark Doliner <markdoliner@pidgin.im>
parents:
14660
diff
changeset
|
853 | const char *c_out; |
|
cf00caa09ed4
[gaim-migrate @ 17834]
Mark Doliner <markdoliner@pidgin.im>
parents:
14660
diff
changeset
|
854 | unsigned int clen; |
| 15170 | 855 | gsize declen = 0; |
| 856 | ||
| 857 | if(enc_in != NULL) | |
| 15884 | 858 | dec_in = purple_base64_decode(enc_in, &declen); |
| 15170 | 859 | |
| 860 | js->sasl_state = sasl_client_step(js->sasl, (char*)dec_in, declen, NULL, &c_out, &clen); | |
| 861 | ||
| 862 | g_free(enc_in); | |
| 863 | g_free(dec_in); | |
| 864 | ||
| 12508 | 865 | if (js->sasl_state != SASL_OK) { |
| 866 | /* This should never happen! */ | |
| 15884 | 867 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 12508 | 868 | } |
| 869 | } | |
| 870 | /* 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
|
871 | 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
|
872 | if (*(int *)x > 0) { |
|
15143
37451143f5c4
[gaim-migrate @ 17867]
Mark Doliner <markdoliner@pidgin.im>
parents:
15112
diff
changeset
|
873 | 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
|
874 | js->sasl_maxbuf = *(int *)x; |
| 12508 | 875 | } |
| 876 | #endif | |
| 877 | ||
| 7014 | 878 | jabber_stream_set_state(js, JABBER_STREAM_REINITIALIZING); |
| 879 | } | |
| 880 | ||
| 881 | void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet) | |
| 882 | { | |
| 8401 | 883 | char *msg = jabber_parse_error(js, packet); |
| 7014 | 884 | |
| 8401 | 885 | if(!msg) { |
| 15884 | 886 | purple_connection_error(js->gc, _("Invalid response from server.")); |
| 8401 | 887 | } else { |
| 15884 | 888 | purple_connection_error(js->gc, msg); |
| 8401 | 889 | g_free(msg); |
| 7014 | 890 | } |
| 891 | } |