annotate src/protocols/jabber/auth.c @ 9594:15d09e546cee

[gaim-migrate @ 10437] I changed the 2 preferences dealing with auto-responses. It's a drop down box. Check it out. I also made Gaim not load .gaimrc committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 25 Jul 2004 22:13:03 +0000
parents c13a4913a071
children a5bd6d78717d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /*
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * gaim - Jabber Protocol Plugin
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com>
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 */
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 #include "jutil.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "auth.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "xmlnode.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 #include "jabber.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "iq.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 #include "sha.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 #include "debug.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 #include "md5.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 #include "util.h"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 #include "sslconn.h"
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
34 #include "request.h"
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
35
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
36 static void auth_old_result_cb(JabberStream *js, xmlnode *packet,
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
37 gpointer data);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38
8296
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
39 gboolean
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
40 jabber_process_starttls(JabberStream *js, xmlnode *packet)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 xmlnode *starttls;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43
7157
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
44 if((starttls = xmlnode_get_child(packet, "starttls"))) {
7630
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7515
diff changeset
45 if(gaim_account_get_bool(js->gc->account, "use_tls", TRUE) &&
2df4d470c12a [gaim-migrate @ 8254]
Nathan Walp <nwalp@pidgin.im>
parents: 7515
diff changeset
46 gaim_ssl_is_supported()) {
7157
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
47 jabber_send_raw(js,
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7630
diff changeset
48 "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1);
8296
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
49 return TRUE;
7157
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
50 } else if(xmlnode_get_child(starttls, "required")) {
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
51 gaim_connection_error(js->gc, _("Server requires SSL for login"));
8296
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
52 return TRUE;
7157
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
53 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55
8296
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
56 return FALSE;
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
57 }
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
58
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
59 static void finish_plaintext_authentication(JabberStream *js)
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
60 {
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
61 if(js->auth_type == JABBER_AUTH_PLAIN) {
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
62 xmlnode *auth;
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
63 GString *response;
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
64 char *enc_out;
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
65
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
66 auth = xmlnode_new("auth");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
67 xmlnode_set_attrib(auth, "xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
68
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
69 response = g_string_new("");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
70 response = g_string_append_len(response, "\0", 1);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
71 response = g_string_append(response, js->user->node);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
72 response = g_string_append_len(response, "\0", 1);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
73 response = g_string_append(response,
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
74 gaim_account_get_password(js->gc->account));
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
75
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
76 enc_out = gaim_base64_encode(response->str, response->len);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
77
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
78 xmlnode_set_attrib(auth, "mechanism", "PLAIN");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
79 xmlnode_insert_data(auth, enc_out, -1);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
80 g_free(enc_out);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
81 g_string_free(response, TRUE);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
82
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
83 jabber_send(js, auth);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
84 xmlnode_free(auth);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
85 } else if(js->auth_type == JABBER_AUTH_IQ_AUTH) {
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
86 JabberIq *iq;
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
87 xmlnode *query, *x;
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
88
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
89 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
90 query = xmlnode_get_child(iq->node, "query");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
91 x = xmlnode_new_child(query, "username");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
92 xmlnode_insert_data(x, js->user->node, -1);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
93 x = xmlnode_new_child(query, "resource");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
94 xmlnode_insert_data(x, js->user->resource, -1);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
95 x = xmlnode_new_child(query, "password");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
96 xmlnode_insert_data(x, gaim_account_get_password(js->gc->account), -1);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
97 jabber_iq_set_callback(iq, auth_old_result_cb, NULL);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
98 jabber_iq_send(iq);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
99 }
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
100 }
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
101
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
102 static void allow_plaintext_auth(GaimAccount *account)
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
103 {
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
104 gaim_account_set_bool(account, "auth_plain_in_clear", TRUE);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
105
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
106 finish_plaintext_authentication(account->gc->proto_data);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
107 }
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
108
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
109 static void disallow_plaintext_auth(GaimAccount *account)
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
110 {
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
111 gaim_connection_error(account->gc, _("Server requires plaintext authentication over an unencrypted stream"));
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
112 }
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
113
8296
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
114 void
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
115 jabber_auth_start(JabberStream *js, xmlnode *packet)
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
116 {
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
117 xmlnode *mechs, *mechnode;
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
118
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
119 gboolean digest_md5 = FALSE, plain=FALSE;
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
120
dd6fe7d965aa [gaim-migrate @ 9020]
Nathan Walp <nwalp@pidgin.im>
parents: 8223
diff changeset
121
8016
7bae464195c4 [gaim-migrate @ 8696]
Nathan Walp <nwalp@pidgin.im>
parents: 7981
diff changeset
122 if(js->registration) {
7bae464195c4 [gaim-migrate @ 8696]
Nathan Walp <nwalp@pidgin.im>
parents: 7981
diff changeset
123 jabber_register_start(js);
7bae464195c4 [gaim-migrate @ 8696]
Nathan Walp <nwalp@pidgin.im>
parents: 7981
diff changeset
124 return;
7bae464195c4 [gaim-migrate @ 8696]
Nathan Walp <nwalp@pidgin.im>
parents: 7981
diff changeset
125 }
7bae464195c4 [gaim-migrate @ 8696]
Nathan Walp <nwalp@pidgin.im>
parents: 7981
diff changeset
126
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 mechs = xmlnode_get_child(packet, "mechanisms");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 if(!mechs) {
7981
ad5c8f01882b [gaim-migrate @ 8658]
Luke Schierer <lschiere@pidgin.im>
parents: 7813
diff changeset
130 gaim_connection_error(js->gc, _("Invalid response from server."));
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
133
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8110
diff changeset
134 for(mechnode = xmlnode_get_child(mechs, "mechanism"); mechnode;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8110
diff changeset
135 mechnode = xmlnode_get_next_twin(mechnode))
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8110
diff changeset
137 char *mech_name = xmlnode_get_data(mechnode);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8110
diff changeset
138 if(mech_name && !strcmp(mech_name, "DIGEST-MD5"))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8110
diff changeset
139 digest_md5 = TRUE;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8110
diff changeset
140 else if(mech_name && !strcmp(mech_name, "PLAIN"))
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8110
diff changeset
141 plain = TRUE;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8110
diff changeset
142 g_free(mech_name);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144
7703
e0e73a26f130 [gaim-migrate @ 8348]
Nathan Walp <nwalp@pidgin.im>
parents: 7645
diff changeset
145
7645
28100686bde9 [gaim-migrate @ 8288]
Nathan Walp <nwalp@pidgin.im>
parents: 7644
diff changeset
146 if(digest_md5) {
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
147 xmlnode *auth;
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
148
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
149 js->auth_type = JABBER_AUTH_DIGEST_MD5;
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
150 auth = xmlnode_new("auth");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
151 xmlnode_set_attrib(auth, "xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
152 xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5");
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
153
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
154 jabber_send(js, auth);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
155 xmlnode_free(auth);
8086
55431e80a783 [gaim-migrate @ 8785]
Nathan Walp <nwalp@pidgin.im>
parents: 8084
diff changeset
156 } else if(plain) {
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
157 js->auth_type = JABBER_AUTH_PLAIN;
7703
e0e73a26f130 [gaim-migrate @ 8348]
Nathan Walp <nwalp@pidgin.im>
parents: 7645
diff changeset
158
8086
55431e80a783 [gaim-migrate @ 8785]
Nathan Walp <nwalp@pidgin.im>
parents: 8084
diff changeset
159 if(js->gsc == NULL && !gaim_account_get_bool(js->gc->account, "auth_plain_in_clear", FALSE)) {
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
160 gaim_request_yes_no(js->gc, _("Plaintext Authentication"),
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
161 _("Plaintext Authentication"),
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
162 _("This server requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"),
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
163 2, js->gc->account, allow_plaintext_auth,
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
164 disallow_plaintext_auth);
8086
55431e80a783 [gaim-migrate @ 8785]
Nathan Walp <nwalp@pidgin.im>
parents: 8084
diff changeset
165 return;
55431e80a783 [gaim-migrate @ 8785]
Nathan Walp <nwalp@pidgin.im>
parents: 8084
diff changeset
166 }
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
167 finish_plaintext_authentication(js);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 gaim_connection_error(js->gc,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170 _("Server does not use any supported authentication method"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
172 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
173
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
174 static void auth_old_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176 const char *type = xmlnode_get_attrib(packet, "type");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
177
7730
01eb54bb41dc [gaim-migrate @ 8375]
Nathan Walp <nwalp@pidgin.im>
parents: 7704
diff changeset
178 if(type && !strcmp(type, "result")) {
01eb54bb41dc [gaim-migrate @ 8375]
Nathan Walp <nwalp@pidgin.im>
parents: 7704
diff changeset
179 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED);
01eb54bb41dc [gaim-migrate @ 8375]
Nathan Walp <nwalp@pidgin.im>
parents: 7704
diff changeset
180 } else {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
181 char *msg = jabber_parse_error(js, packet);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
182 xmlnode *error;
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
183 const char *err_code;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
185 if((error = xmlnode_get_child(packet, "error")) &&
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
186 (err_code = xmlnode_get_attrib(error, "code")) &&
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
187 !strcmp(err_code, "401")) {
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
188 js->gc->wants_to_die = TRUE;
7730
01eb54bb41dc [gaim-migrate @ 8375]
Nathan Walp <nwalp@pidgin.im>
parents: 7704
diff changeset
189 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
190
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
191 gaim_connection_error(js->gc, msg);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
192 g_free(msg);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
193 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
194 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
196 static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 JabberIq *iq;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199 xmlnode *query, *x;
7514
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
200 const char *type = xmlnode_get_attrib(packet, "type");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 const char *pw = gaim_account_get_password(js->gc->account);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202
7514
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
203 if(!type) {
7981
ad5c8f01882b [gaim-migrate @ 8658]
Luke Schierer <lschiere@pidgin.im>
parents: 7813
diff changeset
204 gaim_connection_error(js->gc, _("Invalid response from server."));
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205 return;
7515
6cd392e0d6ea [gaim-migrate @ 8128]
Nathan Walp <nwalp@pidgin.im>
parents: 7514
diff changeset
206 } else if(!strcmp(type, "error")) {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
207 char *msg = jabber_parse_error(js, packet);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
208 gaim_connection_error(js->gc, msg);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
209 g_free(msg);
7515
6cd392e0d6ea [gaim-migrate @ 8128]
Nathan Walp <nwalp@pidgin.im>
parents: 7514
diff changeset
210 } else if(!strcmp(type, "result")) {
7514
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
211 query = xmlnode_get_child(packet, "query");
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
212 if(js->stream_id && xmlnode_get_child(query, "digest")) {
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
213 unsigned char hashval[20];
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
214 char *s, h[41], *p;
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
215 int i;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
217 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
218 query = xmlnode_get_child(iq->node, "query");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
219 x = xmlnode_new_child(query, "username");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
220 xmlnode_insert_data(x, js->user->node, -1);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
221 x = xmlnode_new_child(query, "resource");
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
222 xmlnode_insert_data(x, js->user->resource, -1);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
223
7514
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
224 x = xmlnode_new_child(query, "digest");
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
225 s = g_strdup_printf("%s%s", js->stream_id, pw);
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
226 shaBlock((unsigned char *)s, strlen(s), hashval);
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
227 p = h;
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
228 for(i=0; i<20; i++, p+=2)
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
229 snprintf(p, 3, "%02x", hashval[i]);
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
230 xmlnode_insert_data(x, h, -1);
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
231 g_free(s);
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
232 jabber_iq_set_callback(iq, auth_old_result_cb, NULL);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
233 jabber_iq_send(iq);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
234
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
235 } else if(xmlnode_get_child(query, "password")) {
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
236 if(js->gsc == NULL && !gaim_account_get_bool(js->gc->account,
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
237 "auth_plain_in_clear", FALSE)) {
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
238 gaim_request_yes_no(js->gc, _("Plaintext Authentication"),
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
239 _("Plaintext Authentication"),
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
240 _("This server requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"),
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
241 2, js->gc->account, allow_plaintext_auth,
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
242 disallow_plaintext_auth);
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
243 return;
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
244 }
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
245 finish_plaintext_authentication(js);
7514
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
246 } else {
8397
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
247 gaim_connection_error(js->gc,
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
248 _("Server does not use any supported authentication method"));
b63debdf5a92 [gaim-migrate @ 9126]
Nathan Walp <nwalp@pidgin.im>
parents: 8296
diff changeset
249 return;
7514
43a214a385d1 [gaim-migrate @ 8127]
Nathan Walp <nwalp@pidgin.im>
parents: 7425
diff changeset
250 }
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 void jabber_auth_start_old(JabberStream *js)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 JabberIq *iq;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 xmlnode *query, *username;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:auth");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261 query = xmlnode_get_child(iq->node, "query");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 username = xmlnode_new_child(query, "username");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 xmlnode_insert_data(username, js->user->node, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
265 jabber_iq_set_callback(iq, auth_old_cb, NULL);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267 jabber_iq_send(iq);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 static GHashTable* parse_challenge(const char *challenge)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 GHashTable *ret = g_hash_table_new_full(g_str_hash, g_str_equal,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273 g_free, g_free);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 char **pairs;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 int i;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277 pairs = g_strsplit(challenge, ",", -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 for(i=0; pairs[i]; i++) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280 char **keyval = g_strsplit(pairs[i], "=", 2);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281 if(keyval[0] && keyval[1]) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
282 if(keyval[1][0] == '"' && keyval[1][strlen(keyval[1])-1] == '"')
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283 g_hash_table_replace(ret, g_strdup(keyval[0]), g_strndup(keyval[1]+1, strlen(keyval[1])-2));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
284 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285 g_hash_table_replace(ret, g_strdup(keyval[0]), g_strdup(keyval[1]));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
287 g_strfreev(keyval);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
290 g_strfreev(pairs);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292 return ret;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
295 static unsigned char*
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296 generate_response_value(JabberID *jid, const char *passwd, const char *nonce,
7267
109817b028a6 [gaim-migrate @ 7844]
Nathan Walp <nwalp@pidgin.im>
parents: 7255
diff changeset
297 const char *cnonce, const char *a2, const char *realm)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 md5_state_t ctx;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300 md5_byte_t result[16];
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
302 char *x, *y, *a1, *ha1, *ha2, *kd, *z;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
303
7267
109817b028a6 [gaim-migrate @ 7844]
Nathan Walp <nwalp@pidgin.im>
parents: 7255
diff changeset
304 x = g_strdup_printf("%s:%s:%s", jid->node, realm, passwd);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305 md5_init(&ctx);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306 md5_append(&ctx, x, strlen(x));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307 md5_finish(&ctx, result);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309 y = g_strndup(result, 16);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310
8223
1e145b735b05 [gaim-migrate @ 8946]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
311 a1 = g_strdup_printf("%s:%s:%s", y, nonce, cnonce);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
312
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 md5_init(&ctx);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314 md5_append(&ctx, a1, strlen(a1));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 md5_finish(&ctx, result);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316
7106
db6bd3e794d8 [gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
317 ha1 = gaim_base16_encode(result, 16);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
318
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 md5_init(&ctx);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320 md5_append(&ctx, a2, strlen(a2));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 md5_finish(&ctx, result);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322
7106
db6bd3e794d8 [gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
323 ha2 = gaim_base16_encode(result, 16);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
325 kd = g_strdup_printf("%s:%s:00000001:%s:auth:%s", ha1, nonce, cnonce, ha2);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 md5_init(&ctx);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328 md5_append(&ctx, kd, strlen(kd));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329 md5_finish(&ctx, result);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330
7106
db6bd3e794d8 [gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
331 z = gaim_base16_encode(result, 16);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 g_free(x);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
334 g_free(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335 g_free(a1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336 g_free(ha1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 g_free(ha2);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 g_free(kd);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 return z;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343 void
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344 jabber_auth_handle_challenge(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346
7703
e0e73a26f130 [gaim-migrate @ 8348]
Nathan Walp <nwalp@pidgin.im>
parents: 7645
diff changeset
347 if(js->auth_type == JABBER_AUTH_DIGEST_MD5) {
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
348 char *enc_in = xmlnode_get_data(packet);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
349 char *dec_in;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
350 char *enc_out;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
351 GHashTable *parts;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
352
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
353 if(!enc_in) {
7981
ad5c8f01882b [gaim-migrate @ 8658]
Luke Schierer <lschiere@pidgin.im>
parents: 7813
diff changeset
354 gaim_connection_error(js->gc, _("Invalid response from server."));
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
355 return;
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
356 }
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
357
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
358 gaim_base64_decode(enc_in, &dec_in, NULL);
7395
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
359 gaim_debug(GAIM_DEBUG_MISC, "jabber", "decoded challenge (%d): %s\n",
b250288fa948 [gaim-migrate @ 7990]
Nathan Walp <nwalp@pidgin.im>
parents: 7291
diff changeset
360 strlen(dec_in), dec_in);
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
361
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
362 parts = parse_challenge(dec_in);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
363
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
364
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
365 if (g_hash_table_lookup(parts, "rspauth")) {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
366 char *rspauth = g_hash_table_lookup(parts, "rspauth");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
367
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
368
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
369 if(rspauth && js->expected_rspauth &&
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
370 !strcmp(rspauth, js->expected_rspauth)) {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
371 jabber_send_raw(js,
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7630
diff changeset
372 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />",
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7630
diff changeset
373 -1);
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
374 } else {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
375 gaim_connection_error(js->gc, _("Invalid challenge from server"));
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
376 }
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
377 g_free(js->expected_rspauth);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
378 } else {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
379 /* assemble a response, and send it */
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
380 /* see RFC 2831 */
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
381 GString *response = g_string_new("");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
382 char *a2;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
383 char *auth_resp;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
384 char *buf;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
385 char *cnonce;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
386 char *realm;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
387 char *nonce;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
388
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
389 /* we're actually supposed to prompt the user for a realm if
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
390 * the server doesn't send one, but that really complicates things,
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
391 * so i'm not gonna worry about it until is poses a problem to
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
392 * someone, or I get really bored */
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
393 realm = g_hash_table_lookup(parts, "realm");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
394 if(!realm)
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
395 realm = js->user->domain;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
396
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
397 cnonce = g_strdup_printf("%x%u%x", g_random_int(), (int)time(NULL),
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
398 g_random_int());
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
399 nonce = g_hash_table_lookup(parts, "nonce");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
400
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
401
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
402 a2 = g_strdup_printf("AUTHENTICATE:xmpp/%s", realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
403 auth_resp = generate_response_value(js->user,
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
404 gaim_account_get_password(js->gc->account), nonce, cnonce, a2, realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
405 g_free(a2);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
406
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
407 a2 = g_strdup_printf(":xmpp/%s", realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
408 js->expected_rspauth = generate_response_value(js->user,
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
409 gaim_account_get_password(js->gc->account), nonce, cnonce, a2, realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
410 g_free(a2);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
411
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
412
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
413 g_string_append_printf(response, "username=\"%s\"", js->user->node);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
414 g_string_append_printf(response, ",realm=\"%s\"", realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
415 g_string_append_printf(response, ",nonce=\"%s\"", nonce);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
416 g_string_append_printf(response, ",cnonce=\"%s\"", cnonce);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
417 g_string_append_printf(response, ",nc=00000001");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
418 g_string_append_printf(response, ",qop=auth");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
419 g_string_append_printf(response, ",digest-uri=\"xmpp/%s\"", realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
420 g_string_append_printf(response, ",response=%s", auth_resp);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
421 g_string_append_printf(response, ",charset=utf-8");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
422
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
423 g_free(auth_resp);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
424 g_free(cnonce);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
425
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
426 enc_out = gaim_base64_encode(response->str, response->len);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
427
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
428 gaim_debug(GAIM_DEBUG_MISC, "jabber", "decoded response (%d): %s\n", response->len, response->str);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
429
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
430 buf = g_strdup_printf("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>%s</response>", enc_out);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
431
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7630
diff changeset
432 jabber_send_raw(js, buf, -1);
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
433
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
434 g_free(buf);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
435
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
436 g_free(enc_out);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
437
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
438 g_string_free(response, TRUE);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
439 }
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
440
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
441 g_free(enc_in);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
442 g_free(dec_in);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
443 g_hash_table_destroy(parts);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
444 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
445 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
446
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
447 void jabber_auth_handle_success(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
448 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
449 const char *ns = xmlnode_get_attrib(packet, "xmlns");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
450
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
451 if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
7981
ad5c8f01882b [gaim-migrate @ 8658]
Luke Schierer <lschiere@pidgin.im>
parents: 7813
diff changeset
452 gaim_connection_error(js->gc, _("Invalid response from server."));
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
453 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
454 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
455
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
456 jabber_stream_set_state(js, JABBER_STREAM_REINITIALIZING);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
457 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
458
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
459 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
460 {
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
461 char *msg = jabber_parse_error(js, packet);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
462
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
463 if(!msg) {
7981
ad5c8f01882b [gaim-migrate @ 8658]
Luke Schierer <lschiere@pidgin.im>
parents: 7813
diff changeset
464 gaim_connection_error(js->gc, _("Invalid response from server."));
8401
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
465 } else {
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
466 gaim_connection_error(js->gc, msg);
c13a4913a071 [gaim-migrate @ 9130]
Nathan Walp <nwalp@pidgin.im>
parents: 8397
diff changeset
467 g_free(msg);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
468 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
469 }