Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/auth_digest_md5.c @ 29107:4f45aae3ace1
Let's try a more complex set of return states / values for auth mechs.
This won't build with Cyrus support yet.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Tue, 01 Dec 2009 07:32:53 +0000 |
parents | cea22db36ffc |
children | b94fd073187c |
comparison
equal
deleted
inserted
replaced
29106:554ae3e78952 | 29107:4f45aae3ace1 |
---|---|
28 #include "xmlnode.h" | 28 #include "xmlnode.h" |
29 | 29 |
30 #include "auth.h" | 30 #include "auth.h" |
31 #include "jabber.h" | 31 #include "jabber.h" |
32 | 32 |
33 static xmlnode *digest_md5_start(JabberStream *js, xmlnode *packet) | 33 static JabberSaslState |
34 { | 34 digest_md5_start(JabberStream *js, xmlnode *packet, xmlnode **response, |
35 xmlnode *auth; | 35 const char **msg) |
36 | 36 { |
37 auth = xmlnode_new("auth"); | 37 xmlnode *auth = xmlnode_new("auth"); |
38 xmlnode_set_namespace(auth, NS_XMPP_SASL); | 38 xmlnode_set_namespace(auth, NS_XMPP_SASL); |
39 xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5"); | 39 xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5"); |
40 | 40 |
41 return auth; | 41 *response = auth; |
42 return JABBER_SASL_STATE_CONTINUE; | |
42 } | 43 } |
43 | 44 |
44 /* Parts of this algorithm are inspired by stuff in libgsasl */ | 45 /* Parts of this algorithm are inspired by stuff in libgsasl */ |
45 static GHashTable* parse_challenge(const char *challenge) | 46 static GHashTable* parse_challenge(const char *challenge) |
46 { | 47 { |
161 g_free(kd); | 162 g_free(kd); |
162 | 163 |
163 return z; | 164 return z; |
164 } | 165 } |
165 | 166 |
166 static xmlnode *digest_md5_handle_challenge(JabberStream *js, xmlnode *packet) | 167 static JabberSaslState |
168 digest_md5_handle_challenge(JabberStream *js, xmlnode *packet, | |
169 xmlnode **response, const char **msg) | |
167 { | 170 { |
168 xmlnode *reply = NULL; | 171 xmlnode *reply = NULL; |
169 char *enc_in = xmlnode_get_data(packet); | 172 char *enc_in = xmlnode_get_data(packet); |
170 char *dec_in; | 173 char *dec_in; |
171 char *enc_out; | 174 char *enc_out; |
172 GHashTable *parts; | 175 GHashTable *parts; |
176 JabberSaslState state = JABBER_SASL_STATE_CONTINUE; | |
173 | 177 |
174 if (!enc_in) { | 178 if (!enc_in) { |
175 purple_connection_error_reason(js->gc, | 179 *msg = _("Invalid response from server"); |
176 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 180 return JABBER_SASL_STATE_FAIL; |
177 _("Invalid response from server")); | |
178 return NULL; | |
179 } | 181 } |
180 | 182 |
181 dec_in = (char *)purple_base64_decode(enc_in, NULL); | 183 dec_in = (char *)purple_base64_decode(enc_in, NULL); |
182 purple_debug_misc("jabber", "decoded challenge (%" | 184 purple_debug_misc("jabber", "decoded challenge (%" |
183 G_GSIZE_FORMAT "): %s\n", strlen(dec_in), dec_in); | 185 G_GSIZE_FORMAT "): %s\n", strlen(dec_in), dec_in); |
189 | 191 |
190 if (rspauth && purple_strequal(rspauth, js->expected_rspauth)) { | 192 if (rspauth && purple_strequal(rspauth, js->expected_rspauth)) { |
191 reply = xmlnode_new("response"); | 193 reply = xmlnode_new("response"); |
192 xmlnode_set_namespace(reply, NS_XMPP_SASL); | 194 xmlnode_set_namespace(reply, NS_XMPP_SASL); |
193 } else { | 195 } else { |
194 purple_connection_error_reason(js->gc, | 196 *msg = _("Invalid challenge from server"); |
195 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 197 state = JABBER_SASL_STATE_FAIL; |
196 _("Invalid challenge from server")); | |
197 } | 198 } |
198 g_free(js->expected_rspauth); | 199 g_free(js->expected_rspauth); |
199 js->expected_rspauth = NULL; | 200 js->expected_rspauth = NULL; |
200 } else { | 201 } else { |
201 /* assemble a response, and send it */ | 202 /* assemble a response, and send it */ |
214 * someone, or I get really bored */ | 215 * someone, or I get really bored */ |
215 realm = g_hash_table_lookup(parts, "realm"); | 216 realm = g_hash_table_lookup(parts, "realm"); |
216 if(!realm) | 217 if(!realm) |
217 realm = js->user->domain; | 218 realm = js->user->domain; |
218 | 219 |
219 if (nonce == NULL || realm == NULL) | 220 if (nonce == NULL || realm == NULL) { |
220 purple_connection_error_reason(js->gc, | 221 *msg = _("Invalid challenge from server"); |
221 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 222 state = JABBER_SASL_STATE_FAIL; |
222 _("Invalid challenge from server")); | 223 } else { |
223 else { | |
224 GString *response = g_string_new(""); | 224 GString *response = g_string_new(""); |
225 char *a2; | 225 char *a2; |
226 char *auth_resp; | 226 char *auth_resp; |
227 char *cnonce; | 227 char *cnonce; |
228 | 228 |
270 | 270 |
271 g_free(enc_in); | 271 g_free(enc_in); |
272 g_free(dec_in); | 272 g_free(dec_in); |
273 g_hash_table_destroy(parts); | 273 g_hash_table_destroy(parts); |
274 | 274 |
275 return reply; | 275 *response = reply; |
276 return state; | |
276 } | 277 } |
277 | 278 |
278 static JabberSaslMech digest_md5_mech = { | 279 static JabberSaslMech digest_md5_mech = { |
279 10, /* priority */ | 280 10, /* priority */ |
280 "DIGEST-MD5", /* name */ | 281 "DIGEST-MD5", /* name */ |