annotate src/protocols/jabber/auth.c @ 7310:dd4b4a187171

[gaim-migrate @ 7894] assorted jabber tweaks committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 21 Oct 2003 17:18:46 +0000
parents 632cee95cc5c
children b250288fa948
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"
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 void
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 jabber_auth_start(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 xmlnode *mechs, *mechnode;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 xmlnode *starttls;
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
41 xmlnode *auth;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
43 gboolean digest_md5 = FALSE, plain=FALSE;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44
7157
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
45 if((starttls = xmlnode_get_child(packet, "starttls"))) {
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
46 if(gaim_ssl_is_supported()) {
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
47 jabber_send_raw(js,
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
48 "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
49 return;
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"));
fae7cfe975fd [gaim-migrate @ 7724]
Nathan Walp <nwalp@pidgin.im>
parents: 7147
diff changeset
52 return;
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
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56 mechs = xmlnode_get_child(packet, "mechanisms");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 if(!mechs) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 gaim_connection_error(js->gc, _("Invalid response from server"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 for(mechnode = mechs->child; mechnode; mechnode = mechnode->next)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 if(mechnode->type == NODE_TYPE_TAG) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 char *mech_name = xmlnode_get_data(mechnode);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 if(mech_name && !strcmp(mech_name, "DIGEST-MD5"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 digest_md5 = TRUE;
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
69 else if(mech_name && !strcmp(mech_name, "PLAIN"))
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
70 plain = TRUE;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 g_free(mech_name);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
75 auth = xmlnode_new("auth");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
76 xmlnode_set_attrib(auth, "xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 if(digest_md5) {
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
78 xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
79 js->auth_type = JABBER_AUTH_DIGEST_MD5;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
80 /*
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
81 } else if(plain) {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
82 js->auth_type = JABBER_AUTH_PLAIN;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
83 */
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 gaim_connection_error(js->gc,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 _("Server does not use any supported authentication method"));
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
87 xmlnode_free(auth);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
88 return;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 }
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
90 jabber_send(js, auth);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
91 xmlnode_free(auth);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94 static void auth_old_result_cb(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96 const char *type = xmlnode_get_attrib(packet, "type");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 if(type && !strcmp(type, "error")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 xmlnode *error = xmlnode_get_child(packet, "error");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 const char *err_code;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 char *err_text;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102 char *buf;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 err_code = xmlnode_get_attrib(error, "code");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 err_text = xmlnode_get_data(error);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 if(!err_code)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 err_code = "";
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109 if(!err_text)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 err_text = g_strdup(_("Unknown"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112 if(!strcmp(err_code, "401"))
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113 js->gc->wants_to_die = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 buf = g_strdup_printf("Error %s: %s",
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116 err_code, err_text);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 gaim_connection_error(js->gc, buf);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 g_free(err_text);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 g_free(buf);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 jabber_stream_set_state(js, JABBER_STREAM_CONNECTED);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125 static void auth_old_cb(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 JabberIq *iq;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128 xmlnode *query, *x;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 gboolean digest = FALSE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130 const char *pw = gaim_account_get_password(js->gc->account);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 query = xmlnode_get_child(packet, "query");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
133 if(js->stream_id && xmlnode_get_child(query, "digest")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134 digest = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 } else if(!xmlnode_get_child(query, "password")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 gaim_connection_error(js->gc,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 _("Server does not use any supported authentication method"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142 query = xmlnode_get_child(iq->node, "query");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 x = xmlnode_new_child(query, "username");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 xmlnode_insert_data(x, js->user->node, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 x = xmlnode_new_child(query, "resource");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 xmlnode_insert_data(x, js->user->resource, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 if(digest) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 unsigned char hashval[20];
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 char *s, h[41], *p;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 int i;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 x = xmlnode_new_child(query, "digest");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154 s = g_strdup_printf("%s%s", js->stream_id, pw);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 shaBlock((unsigned char *)s, strlen(s), hashval);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 p = h;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157 for(i=0; i<20; i++, p+=2)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 snprintf(p, 3, "%02x", hashval[i]);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 xmlnode_insert_data(x, h, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 g_free(s);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162 x = xmlnode_new_child(query, "password");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 xmlnode_insert_data(x, pw, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 jabber_iq_set_callback(iq, auth_old_result_cb);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 jabber_iq_send(iq);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171 void jabber_auth_start_old(JabberStream *js)
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 JabberIq *iq;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
174 xmlnode *query, *username;
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 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:auth");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
177
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
178 query = xmlnode_get_child(iq->node, "query");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
179 username = xmlnode_new_child(query, "username");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
180 xmlnode_insert_data(username, js->user->node, -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
181
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
182 jabber_iq_set_callback(iq, auth_old_cb);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
183
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184 jabber_iq_send(iq);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
185 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
187 static GHashTable* parse_challenge(const char *challenge)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
188 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
189 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
190 g_free, g_free);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191 char **pairs;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
192 int i;
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 pairs = g_strsplit(challenge, ",", -1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
196 for(i=0; pairs[i]; i++) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197 char **keyval = g_strsplit(pairs[i], "=", 2);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 if(keyval[0] && keyval[1]) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199 if(keyval[1][0] == '"' && keyval[1][strlen(keyval[1])-1] == '"')
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 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
201 else
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
202 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
203 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204 g_strfreev(keyval);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 g_strfreev(pairs);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 return ret;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 static unsigned char*
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 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
214 const char *cnonce, const char *a2, const char *realm)
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 md5_state_t ctx;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217 md5_byte_t result[16];
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 char *x, *y, *a1, *ha1, *ha2, *kd, *z;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220
7267
109817b028a6 [gaim-migrate @ 7844]
Nathan Walp <nwalp@pidgin.im>
parents: 7255
diff changeset
221 x = g_strdup_printf("%s:%s:%s", jid->node, realm, passwd);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222 md5_init(&ctx);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 md5_append(&ctx, x, strlen(x));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224 md5_finish(&ctx, result);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226 y = g_strndup(result, 16);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228 a1 = g_strdup_printf("%s:%s:%s:%s@%s/%s", y, nonce, cnonce, jid->node,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229 jid->domain, jid->resource);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
230
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231 md5_init(&ctx);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 md5_append(&ctx, a1, strlen(a1));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 md5_finish(&ctx, result);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234
7106
db6bd3e794d8 [gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
235 ha1 = gaim_base16_encode(result, 16);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 md5_init(&ctx);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 md5_append(&ctx, a2, strlen(a2));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 md5_finish(&ctx, result);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240
7106
db6bd3e794d8 [gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
241 ha2 = gaim_base16_encode(result, 16);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243 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
244
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 md5_init(&ctx);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 md5_append(&ctx, kd, strlen(kd));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 md5_finish(&ctx, result);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248
7106
db6bd3e794d8 [gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents: 7014
diff changeset
249 z = gaim_base16_encode(result, 16);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 g_free(x);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 g_free(y);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 g_free(a1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 g_free(ha1);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 g_free(ha2);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 g_free(kd);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 return z;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 }
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 void
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 jabber_auth_handle_challenge(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
265 if(js->auth_type == JABBER_AUTH_PLAIN) {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
266 /* XXX: implement me! */
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
267 } else if(js->auth_type == JABBER_AUTH_DIGEST_MD5) {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
268 char *enc_in = xmlnode_get_data(packet);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
269 char *dec_in;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
270 char *enc_out;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
271 GHashTable *parts;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
273 gaim_base64_decode(enc_in, &dec_in, NULL);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
274
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
275 parts = parse_challenge(dec_in);
7014
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
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
278 if (g_hash_table_lookup(parts, "rspauth")) {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
279 char *rspauth = g_hash_table_lookup(parts, "rspauth");
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
282 if(rspauth && js->expected_rspauth &&
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
283 !strcmp(rspauth, js->expected_rspauth)) {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
284 jabber_send_raw(js,
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
285 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
286 } else {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
287 gaim_connection_error(js->gc, _("Invalid challenge from server"));
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
288 }
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
289 g_free(js->expected_rspauth);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
290 } else {
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
291 /* assemble a response, and send it */
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
292 /* see RFC 2831 */
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
293 GString *response = g_string_new("");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
294 char *a2;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
295 char *auth_resp;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
296 char *buf;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
297 char *cnonce;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
298 char *realm;
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
299 char *nonce;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
301 /* 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
302 * the server doesn't send one, but that really complicates things,
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
303 * 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
304 * someone, or I get really bored */
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
305 realm = g_hash_table_lookup(parts, "realm");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
306 if(!realm)
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
307 realm = js->user->domain;
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
308
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
309 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
310 g_random_int());
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
311 nonce = g_hash_table_lookup(parts, "nonce");
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
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
314 a2 = g_strdup_printf("AUTHENTICATE:xmpp/%s", realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
315 auth_resp = generate_response_value(js->user,
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
316 gaim_account_get_password(js->gc->account), nonce, cnonce, a2, realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
317 g_free(a2);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
318
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
319 a2 = g_strdup_printf(":xmpp/%s", realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
320 js->expected_rspauth = generate_response_value(js->user,
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
321 gaim_account_get_password(js->gc->account), nonce, cnonce, a2, realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
322 g_free(a2);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
323
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
324
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
325 g_string_append_printf(response, "username=\"%s\"", js->user->node);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
326 g_string_append_printf(response, ",realm=\"%s\"", realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
327 g_string_append_printf(response, ",nonce=\"%s\"", nonce);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
328 g_string_append_printf(response, ",cnonce=\"%s\"", cnonce);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
329 g_string_append_printf(response, ",nc=00000001");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
330 g_string_append_printf(response, ",qop=auth");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
331 g_string_append_printf(response, ",digest-uri=\"xmpp/%s\"", realm);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
332 g_string_append_printf(response, ",response=%s", auth_resp);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
333 g_string_append_printf(response, ",charset=utf-8");
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
334 g_string_append_printf(response, ",authzid=\"%s@%s/%s\"",
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
335 js->user->node, js->user->domain, js->user->resource);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
336
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
337 g_free(auth_resp);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
338 g_free(cnonce);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
339
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
340 enc_out = gaim_base64_encode(response->str, response->len);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
341
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
342 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
343
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
344 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
345
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
346 jabber_send_raw(js, buf);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
347
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
348 g_free(buf);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
349
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
350 g_free(enc_out);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
351
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
352 g_string_free(response, TRUE);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
353 }
7291
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
354
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
355 g_free(enc_in);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
356 g_free(dec_in);
632cee95cc5c [gaim-migrate @ 7872]
Nathan Walp <nwalp@pidgin.im>
parents: 7267
diff changeset
357 g_hash_table_destroy(parts);
7014
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
358 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
359 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
360
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
361 void jabber_auth_handle_success(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
362 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
363 const char *ns = xmlnode_get_attrib(packet, "xmlns");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
364
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
365 if(!ns || strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
366 gaim_connection_error(js->gc, _("Invalid response from server"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
367 return;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
368 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
369
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
370 jabber_stream_set_state(js, JABBER_STREAM_REINITIALIZING);
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
371 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
372
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
373 void jabber_auth_handle_failure(JabberStream *js, xmlnode *packet)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
374 {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
375 const char *ns = xmlnode_get_attrib(packet, "xmlns");
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
376
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
377 if(!ns)
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
378 gaim_connection_error(js->gc, _("Invalid response from server"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
379 else if(!strcmp(ns, "urn:ietf:params:xml:ns:xmpp-sasl")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
380 if(xmlnode_get_child(packet, "bad-protocol")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
381 gaim_connection_error(js->gc, _("Bad Protocol"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
382 } else if(xmlnode_get_child(packet, "encryption-required")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
383 js->gc->wants_to_die = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
384 gaim_connection_error(js->gc, _("Encryption Required"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
385 } else if(xmlnode_get_child(packet, "invalid-authzid")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
386 js->gc->wants_to_die = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
387 gaim_connection_error(js->gc, _("Invalid authzid"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
388 } else if(xmlnode_get_child(packet, "invalid-mechanism")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
389 js->gc->wants_to_die = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
390 gaim_connection_error(js->gc, _("Invalid Mechanism"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
391 } else if(xmlnode_get_child(packet, "invalid-realm")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
392 gaim_connection_error(js->gc, _("Invalid Realm"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
393 } else if(xmlnode_get_child(packet, "mechanism-too-weak")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
394 js->gc->wants_to_die = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
395 gaim_connection_error(js->gc, _("Mechanism Too Weak"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
396 } else if(xmlnode_get_child(packet, "not-authorized")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
397 js->gc->wants_to_die = TRUE;
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
398 gaim_connection_error(js->gc, _("Not Authorized"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
399 } else if(xmlnode_get_child(packet, "temporary-auth-failure")) {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
400 gaim_connection_error(js->gc,
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
401 _("Temporary Authentication Failure"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
402 } else {
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
403 gaim_connection_error(js->gc, _("Authentication Failure"));
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
404 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
405 }
67c4e9d39242 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
406 }