From: Nathan W. <fac...@us...> - 2003-10-17 20:06:15
|
Update of /cvsroot/gaim/gaim/src/protocols/jabber In directory sc8-pr-cvs1:/tmp/cvs-serv20472/src/protocols/jabber Modified Files: JEPS auth.c jabber.c jabber.h Log Message: disable jabber SASL for the moment, until the RFCs are actually approved, since the authentication stuff is still in a state of flux Index: JEPS =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/JEPS,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- JEPS 30 Sep 2003 14:37:05 -0000 1.3 +++ JEPS 17 Oct 2003 20:03:43 -0000 1.4 @@ -1,7 +1,5 @@ 0004: NEED Data Gathering and Reporting -0011: NEED (or just do disco?) - Jabber Browsing 0012: DONE Last Activity 0018: DONE (Is it?) Index: auth.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/auth.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -p -r1.6 -r1.7 --- auth.c 15 Oct 2003 04:45:36 -0000 1.6 +++ auth.c 17 Oct 2003 20:03:43 -0000 1.7 @@ -38,8 +38,9 @@ jabber_auth_start(JabberStream *js, xmln { xmlnode *mechs, *mechnode; xmlnode *starttls; + xmlnode *auth; - gboolean digest_md5 = FALSE; + gboolean digest_md5 = FALSE, plain=FALSE; if((starttls = xmlnode_get_child(packet, "starttls"))) { if(gaim_ssl_is_supported()) { @@ -65,17 +66,29 @@ jabber_auth_start(JabberStream *js, xmln char *mech_name = xmlnode_get_data(mechnode); if(mech_name && !strcmp(mech_name, "DIGEST-MD5")) digest_md5 = TRUE; + else if(mech_name && !strcmp(mech_name, "PLAIN")) + plain = TRUE; g_free(mech_name); } } + auth = xmlnode_new("auth"); + xmlnode_set_attrib(auth, "xmlns", "urn:ietf:params:xml:ns:xmpp-sasl"); if(digest_md5) { - jabber_send_raw(js, "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" - " mechanism='DIGEST-MD5' />"); + xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5"); + js->auth_type = JABBER_AUTH_DIGEST_MD5; + /* + } else if(plain) { + js->auth_type = JABBER_AUTH_PLAIN; + */ } else { gaim_connection_error(js->gc, _("Server does not use any supported authentication method")); + xmlnode_free(auth); + return; } + jabber_send(js, auth); + xmlnode_free(auth); } static void auth_old_result_cb(JabberStream *js, xmlnode *packet) @@ -248,91 +261,101 @@ generate_response_value(JabberID *jid, c void jabber_auth_handle_challenge(JabberStream *js, xmlnode *packet) { - char *enc_in = xmlnode_get_data(packet); - char *dec_in; - char *enc_out; - GHashTable *parts; - gaim_base64_decode(enc_in, &dec_in, NULL); + if(js->auth_type == JABBER_AUTH_PLAIN) { + /* XXX: implement me! */ + } else if(js->auth_type == JABBER_AUTH_DIGEST_MD5) { + char *enc_in = xmlnode_get_data(packet); + char *dec_in; + char *enc_out; + GHashTable *parts; - parts = parse_challenge(dec_in); + gaim_base64_decode(enc_in, &dec_in, NULL); - /* we're actually supposed to prompt the user for a realm if - * the server doesn't send one, but that really complicates things, - * so i'm not gonna worry about it until is poses a problem to someone, - * or I get really bored */ + parts = parse_challenge(dec_in); - if(g_hash_table_lookup(parts, "realm")) { - /* assemble a response, and send it */ - /* see RFC 2831 */ - GString *response = g_string_new(""); - char *a2; - char *auth_resp; - char *buf; - char *cnonce; - char *realm; - char *nonce; - cnonce = g_strdup_printf("%x%u%x", g_random_int(), (int)time(NULL), - g_random_int()); - nonce = g_hash_table_lookup(parts, "nonce"); - realm = g_hash_table_lookup(parts, "realm"); + if (g_hash_table_lookup(parts, "rspauth")) { + char *rspauth = g_hash_table_lookup(parts, "rspauth"); - a2 = g_strdup_printf("AUTHENTICATE:xmpp/%s", realm); - auth_resp = generate_response_value(js->user, - gaim_account_get_password(js->gc->account), nonce, cnonce, a2, realm); - g_free(a2); - a2 = g_strdup_printf(":xmpp/%s", realm); - js->expected_rspauth = generate_response_value(js->user, - gaim_account_get_password(js->gc->account), nonce, cnonce, a2, realm); - g_free(a2); + if(rspauth && js->expected_rspauth && + !strcmp(rspauth, js->expected_rspauth)) { + jabber_send_raw(js, + "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />"); + } else { + gaim_connection_error(js->gc, _("Invalid challenge from server")); + } + g_free(js->expected_rspauth); + } else { + /* assemble a response, and send it */ + /* see RFC 2831 */ + GString *response = g_string_new(""); + char *a2; + char *auth_resp; + char *buf; + char *cnonce; + char *realm; + char *nonce; + /* we're actually supposed to prompt the user for a realm if + * the server doesn't send one, but that really complicates things, + * so i'm not gonna worry about it until is poses a problem to + * someone, or I get really bored */ + realm = g_hash_table_lookup(parts, "realm"); + if(!realm) + realm = js->user->domain; - g_string_append_printf(response, "username=\"%s\"", js->user->node); - g_string_append_printf(response, ",realm=\"%s\"", realm); - g_string_append_printf(response, ",nonce=\"%s\"", nonce); - g_string_append_printf(response, ",cnonce=\"%s\"", cnonce); - g_string_append_printf(response, ",nc=00000001"); - g_string_append_printf(response, ",qop=auth"); - g_string_append_printf(response, ",digest-uri=\"xmpp/%s\"", realm); - g_string_append_printf(response, ",response=%s", auth_resp); - g_string_append_printf(response, ",charset=utf-8"); - g_string_append_printf(response, ",authzid=\"%s@%s/%s\"", - js->user->node, js->user->domain, js->user->resource); + cnonce = g_strdup_printf("%x%u%x", g_random_int(), (int)time(NULL), + g_random_int()); + nonce = g_hash_table_lookup(parts, "nonce"); - g_free(auth_resp); - g_free(cnonce); - enc_out = gaim_base64_encode(response->str, response->len); + a2 = g_strdup_printf("AUTHENTICATE:xmpp/%s", realm); + auth_resp = generate_response_value(js->user, + gaim_account_get_password(js->gc->account), nonce, cnonce, a2, realm); + g_free(a2); - gaim_debug(GAIM_DEBUG_MISC, "jabber", "decoded response (%d): %s\n", response->len, response->str); + a2 = g_strdup_printf(":xmpp/%s", realm); + js->expected_rspauth = generate_response_value(js->user, + gaim_account_get_password(js->gc->account), nonce, cnonce, a2, realm); + g_free(a2); - buf = g_strdup_printf("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>%s</response>", enc_out); - jabber_send_raw(js, buf); + g_string_append_printf(response, "username=\"%s\"", js->user->node); + g_string_append_printf(response, ",realm=\"%s\"", realm); + g_string_append_printf(response, ",nonce=\"%s\"", nonce); + g_string_append_printf(response, ",cnonce=\"%s\"", cnonce); + g_string_append_printf(response, ",nc=00000001"); + g_string_append_printf(response, ",qop=auth"); + g_string_append_printf(response, ",digest-uri=\"xmpp/%s\"", realm); + g_string_append_printf(response, ",response=%s", auth_resp); + g_string_append_printf(response, ",charset=utf-8"); + g_string_append_printf(response, ",authzid=\"%s@%s/%s\"", + js->user->node, js->user->domain, js->user->resource); - g_free(buf); + g_free(auth_resp); + g_free(cnonce); - g_free(enc_out); + enc_out = gaim_base64_encode(response->str, response->len); - g_string_free(response, TRUE); - } else if (g_hash_table_lookup(parts, "rspauth")) { - char *rspauth = g_hash_table_lookup(parts, "rspauth"); + gaim_debug(GAIM_DEBUG_MISC, "jabber", "decoded response (%d): %s\n", response->len, response->str); + buf = g_strdup_printf("<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>%s</response>", enc_out); - if(rspauth && !strcmp(rspauth, js->expected_rspauth)) { - jabber_send_raw(js, - "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />"); - } else { - gaim_connection_error(js->gc, _("Invalid challenge from server")); + jabber_send_raw(js, buf); + + g_free(buf); + + g_free(enc_out); + + g_string_free(response, TRUE); } - g_free(js->expected_rspauth); - } - g_free(enc_in); - g_free(dec_in); - g_hash_table_destroy(parts); + g_free(enc_in); + g_free(dec_in); + g_hash_table_destroy(parts); + } } void jabber_auth_handle_success(JabberStream *js, xmlnode *packet) Index: jabber.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jabber.c,v retrieving revision 1.204 retrieving revision 1.205 diff -u -d -p -r1.204 -r1.205 --- jabber.c 15 Oct 2003 06:32:13 -0000 1.204 +++ jabber.c 17 Oct 2003 20:03:43 -0000 1.205 @@ -63,8 +63,9 @@ static void jabber_stream_init(JabberStr open_stream = g_strdup_printf("<stream:stream to='%s' " "xmlns='jabber:client' " - "xmlns:stream='http://etherx.jabber.org/streams' " - "version='1.0'>", js->user->domain); + "xmlns:stream='http://etherx.jabber.org/streams'>", + /* "version='1.0'>" */ + js->user->domain); jabber_send_raw(js, open_stream); Index: jabber.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/jabber.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -p -r1.8 -r1.9 --- jabber.h 6 Oct 2003 02:04:55 -0000 1.8 +++ jabber.h 17 Oct 2003 20:03:44 -0000 1.9 @@ -49,6 +49,11 @@ typedef struct _JabberStream JABBER_PROTO_0_9, JABBER_PROTO_1_0 } protocol_version; + enum { + JABBER_AUTH_NONE, + JABBER_AUTH_DIGEST_MD5, + JABBER_AUTH_PLAIN + } auth_type; char *stream_id; JabberStreamState state; |