2 * purple - Jabber Protocol Plugin
4 * Purple is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
34 static PurpleXmlNode
*finish_plaintext_authentication(JabberStream
*js
)
40 auth
= purple_xmlnode_new("auth");
41 purple_xmlnode_set_namespace(auth
, NS_XMPP_SASL
);
43 purple_xmlnode_set_attrib(auth
, "xmlns:ga", "http://www.google.com/talk/protocol/auth");
44 purple_xmlnode_set_attrib(auth
, "ga:client-uses-full-bind-result", "true");
46 response
= g_string_new("");
47 response
= g_string_append_c(response
, '\0');
48 response
= g_string_append(response
, js
->user
->node
);
49 response
= g_string_append_c(response
, '\0');
50 response
= g_string_append(response
,
51 purple_connection_get_password(js
->gc
));
53 enc_out
= purple_base64_encode((guchar
*)response
->str
, response
->len
);
55 purple_xmlnode_set_attrib(auth
, "mechanism", "PLAIN");
56 purple_xmlnode_insert_data(auth
, enc_out
, -1);
58 g_string_free(response
, TRUE
);
63 static void allow_plaintext_auth(PurpleAccount
*account
)
65 PurpleConnection
*gc
= purple_account_get_connection(account
);
66 JabberStream
*js
= purple_connection_get_protocol_data(gc
);
67 PurpleXmlNode
*response
;
69 purple_account_set_bool(account
, "auth_plain_in_clear", TRUE
);
71 response
= finish_plaintext_authentication(js
);
72 jabber_send(js
, response
);
73 purple_xmlnode_free(response
);
76 static void disallow_plaintext_auth(PurpleAccount
*account
)
78 purple_connection_error(purple_account_get_connection(account
),
79 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR
,
80 _("Server requires plaintext authentication over an unencrypted stream"));
83 static JabberSaslState
84 jabber_plain_start(JabberStream
*js
, PurpleXmlNode
*packet
, PurpleXmlNode
**response
, char **error
)
86 PurpleAccount
*account
= purple_connection_get_account(js
->gc
);
89 if (jabber_stream_is_ssl(js
) || purple_account_get_bool(account
, "auth_plain_in_clear", FALSE
)) {
90 *response
= finish_plaintext_authentication(js
);
91 return JABBER_SASL_STATE_OK
;
94 msg
= g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"),
95 purple_account_get_username(account
));
96 purple_request_yes_no(js
->gc
, _("Plaintext Authentication"),
97 _("Plaintext Authentication"),
100 purple_request_cpar_from_account(account
),
101 account
, allow_plaintext_auth
, disallow_plaintext_auth
);
103 return JABBER_SASL_STATE_CONTINUE
;
106 static JabberSaslMech plain_mech
= {
110 NULL
, /* handle_challenge */
111 NULL
, /* handle_success */
112 NULL
, /* handle_failure */
116 JabberSaslMech
*jabber_auth_get_plain_mech(void)