libpurple/protocols/jabber/auth_plain.c

Tue, 10 Sep 2013 21:47:37 +0200

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Tue, 10 Sep 2013 21:47:37 +0200
changeset 34331
c8486462bb63
parent 32157
39ba2e2492ee
child 34940
c0aef3b64c56
permissions
-rw-r--r--

Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters

28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
1 /*
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
2 * purple - Jabber Protocol Plugin
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
3 *
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
6 * source distribution.
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
7 *
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
12 *
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
17 *
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
21 *
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
22 */
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
23 #include "internal.h"
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
24
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
25 #include "account.h"
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
26 #include "debug.h"
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
27 #include "request.h"
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
28 #include "util.h"
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
29 #include "xmlnode.h"
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
30
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
31 #include "jabber.h"
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
32 #include "auth.h"
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
33
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
34 static xmlnode *finish_plaintext_authentication(JabberStream *js)
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
35 {
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
36 xmlnode *auth;
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
37 GString *response;
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
38 gchar *enc_out;
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
39
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
40 auth = xmlnode_new("auth");
29008
1f288722b5cd jabber: Use NS_XMPP_SASL
Paul Aurich <darkrain42@pidgin.im>
parents: 28855
diff changeset
41 xmlnode_set_namespace(auth, NS_XMPP_SASL);
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
42
30807
f6622ebcf964 jabber: Partial revert (everything but ChangeLog) of 945ef5abc5
Paul Aurich <darkrain42@pidgin.im>
parents: 30154
diff changeset
43 xmlnode_set_attrib(auth, "xmlns:ga", "http://www.google.com/talk/protocol/auth");
f6622ebcf964 jabber: Partial revert (everything but ChangeLog) of 945ef5abc5
Paul Aurich <darkrain42@pidgin.im>
parents: 30154
diff changeset
44 xmlnode_set_attrib(auth, "ga:client-uses-full-bind-result", "true");
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
45
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
46 response = g_string_new("");
30154
e09336f17448 jabber: Nothing to see here
Paul Aurich <darkrain42@pidgin.im>
parents: 30151
diff changeset
47 response = g_string_append_c(response, '\0');
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
48 response = g_string_append(response, js->user->node);
30154
e09336f17448 jabber: Nothing to see here
Paul Aurich <darkrain42@pidgin.im>
parents: 30151
diff changeset
49 response = g_string_append_c(response, '\0');
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
50 response = g_string_append(response,
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
51 purple_connection_get_password(js->gc));
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
52
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
53 enc_out = purple_base64_encode((guchar *)response->str, response->len);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
54
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
55 xmlnode_set_attrib(auth, "mechanism", "PLAIN");
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
56 xmlnode_insert_data(auth, enc_out, -1);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
57 g_free(enc_out);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
58 g_string_free(response, TRUE);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
59
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
60 return auth;
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
61 }
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
62
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
63 static void allow_plaintext_auth(PurpleAccount *account)
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
64 {
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
65 PurpleConnection *gc = purple_account_get_connection(account);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
66 JabberStream *js = purple_connection_get_protocol_data(gc);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
67 xmlnode *response;
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
68
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
69 purple_account_set_bool(account, "auth_plain_in_clear", TRUE);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
70
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
71 response = finish_plaintext_authentication(js);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
72 jabber_send(js, response);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
73 xmlnode_free(response);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
74 }
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
75
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
76 static void disallow_plaintext_auth(PurpleAccount *account)
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
77 {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 30807
diff changeset
78 purple_connection_error(purple_account_get_connection(account),
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
79 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR,
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
80 _("Server requires plaintext authentication over an unencrypted stream"));
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
81 }
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
82
29084
3a821d391ac0 Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents: 29008
diff changeset
83 static JabberSaslState
29090
b351fcdeede7 jabber: Fix that leak I mentioned (and fix a mistake where error/response weren't NULL-initialized)
Paul Aurich <darkrain42@pidgin.im>
parents: 29084
diff changeset
84 jabber_plain_start(JabberStream *js, xmlnode *packet, xmlnode **response, char **error)
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
85 {
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
86 PurpleAccount *account = purple_connection_get_account(js->gc);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
87 char *msg;
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
88
29084
3a821d391ac0 Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents: 29008
diff changeset
89 if (jabber_stream_is_ssl(js) || purple_account_get_bool(account, "auth_plain_in_clear", FALSE)) {
3a821d391ac0 Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents: 29008
diff changeset
90 *response = finish_plaintext_authentication(js);
3a821d391ac0 Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents: 29008
diff changeset
91 return JABBER_SASL_STATE_OK;
3a821d391ac0 Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents: 29008
diff changeset
92 }
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
93
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
94 msg = g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"),
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
95 purple_account_get_username(account));
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
96 purple_request_yes_no(js->gc, _("Plaintext Authentication"),
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
97 _("Plaintext Authentication"),
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
98 msg,
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
99 1,
34331
c8486462bb63 Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 32157
diff changeset
100 purple_request_cpar_from_account(account),
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
101 account, allow_plaintext_auth, disallow_plaintext_auth);
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
102 g_free(msg);
29084
3a821d391ac0 Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents: 29008
diff changeset
103 return JABBER_SASL_STATE_CONTINUE;
28855
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
104 }
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
105
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
106 static JabberSaslMech plain_mech = {
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
107 0, /* priority */
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
108 "PLAIN", /* name */
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
109 jabber_plain_start,
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
110 NULL, /* handle_challenge */
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
111 NULL, /* handle_success */
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
112 NULL, /* handle_failure */
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
113 NULL /* dispose */
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
114 };
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
115
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
116 JabberSaslMech *jabber_auth_get_plain_mech(void)
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
117 {
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
118 return &plain_mech;
c5bc85f9c00e jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
119 }

mercurial