/src/pidgin/libpurple/protocols/jabber/auth_plain.c
Line | Count | Source |
1 | | /* |
2 | | * purple - Jabber Protocol Plugin |
3 | | * |
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 |
6 | | * source distribution. |
7 | | * |
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. |
12 | | * |
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. |
17 | | * |
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 |
21 | | * |
22 | | */ |
23 | | #include "internal.h" |
24 | | |
25 | | #include "account.h" |
26 | | #include "debug.h" |
27 | | #include "request.h" |
28 | | #include "util.h" |
29 | | #include "xmlnode.h" |
30 | | |
31 | | #include "jabber.h" |
32 | | #include "auth.h" |
33 | | |
34 | | static xmlnode *finish_plaintext_authentication(JabberStream *js) |
35 | 0 | { |
36 | 0 | xmlnode *auth; |
37 | 0 | GString *response; |
38 | 0 | gchar *enc_out; |
39 | |
|
40 | 0 | auth = xmlnode_new("auth"); |
41 | 0 | xmlnode_set_namespace(auth, NS_XMPP_SASL); |
42 | |
|
43 | 0 | xmlnode_set_attrib(auth, "xmlns:ga", "http://www.google.com/talk/protocol/auth"); |
44 | 0 | xmlnode_set_attrib(auth, "ga:client-uses-full-bind-result", "true"); |
45 | |
|
46 | 0 | response = g_string_new(""); |
47 | 0 | response = g_string_append_c(response, '\0'); |
48 | 0 | response = g_string_append(response, js->user->node); |
49 | 0 | response = g_string_append_c(response, '\0'); |
50 | 0 | response = g_string_append(response, |
51 | 0 | purple_connection_get_password(js->gc)); |
52 | |
|
53 | 0 | enc_out = purple_base64_encode((guchar *)response->str, response->len); |
54 | |
|
55 | 0 | xmlnode_set_attrib(auth, "mechanism", "PLAIN"); |
56 | 0 | xmlnode_insert_data(auth, enc_out, -1); |
57 | 0 | g_free(enc_out); |
58 | 0 | g_string_free(response, TRUE); |
59 | |
|
60 | 0 | return auth; |
61 | 0 | } |
62 | | |
63 | | static void allow_plaintext_auth(PurpleAccount *account) |
64 | 0 | { |
65 | 0 | PurpleConnection *gc = purple_account_get_connection(account); |
66 | 0 | JabberStream *js = purple_connection_get_protocol_data(gc); |
67 | 0 | xmlnode *response; |
68 | |
|
69 | 0 | purple_account_set_bool(account, "auth_plain_in_clear", TRUE); |
70 | |
|
71 | 0 | response = finish_plaintext_authentication(js); |
72 | 0 | jabber_send(js, response); |
73 | 0 | xmlnode_free(response); |
74 | 0 | } |
75 | | |
76 | | static void disallow_plaintext_auth(PurpleAccount *account) |
77 | 0 | { |
78 | 0 | purple_connection_error_reason(purple_account_get_connection(account), |
79 | 0 | PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
80 | 0 | _("Server requires plaintext authentication over an unencrypted stream")); |
81 | 0 | } |
82 | | |
83 | | static JabberSaslState |
84 | | jabber_plain_start(JabberStream *js, xmlnode *packet, xmlnode **response, char **error) |
85 | 0 | { |
86 | 0 | PurpleAccount *account = purple_connection_get_account(js->gc); |
87 | 0 | char *msg; |
88 | |
|
89 | 0 | if (jabber_stream_is_ssl(js) || purple_account_get_bool(account, "auth_plain_in_clear", FALSE)) { |
90 | 0 | *response = finish_plaintext_authentication(js); |
91 | 0 | return JABBER_SASL_STATE_OK; |
92 | 0 | } |
93 | | |
94 | 0 | msg = g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), |
95 | 0 | purple_account_get_username(account)); |
96 | 0 | purple_request_yes_no(js->gc, _("Plaintext Authentication"), |
97 | 0 | _("Plaintext Authentication"), |
98 | 0 | msg, |
99 | 0 | 1, |
100 | 0 | account, NULL, NULL, |
101 | 0 | account, allow_plaintext_auth, disallow_plaintext_auth); |
102 | 0 | g_free(msg); |
103 | 0 | return JABBER_SASL_STATE_CONTINUE; |
104 | 0 | } |
105 | | |
106 | | static JabberSaslMech plain_mech = { |
107 | | 0, /* priority */ |
108 | | "PLAIN", /* name */ |
109 | | jabber_plain_start, |
110 | | NULL, /* handle_challenge */ |
111 | | NULL, /* handle_success */ |
112 | | NULL, /* handle_failure */ |
113 | | NULL /* dispose */ |
114 | | }; |
115 | | |
116 | | JabberSaslMech *jabber_auth_get_plain_mech(void) |
117 | 0 | { |
118 | 0 | return &plain_mech; |
119 | 0 | } |