Sun, 16 Jun 2013 05:59:31 +0530
Refactor the codebase to use PurpleHash
|
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 "debug.h" |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
26 | #include "ciphers/md5hash.h" |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
27 | #include "util.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
28 | #include "xmlnode.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
29 | |
|
31394
dd9b4ed08d0a
jabber: Test harness for DIGEST-MD5 parsing function.
Paul Aurich <darkrain42@pidgin.im>
parents:
30857
diff
changeset
|
30 | #include "auth_digest_md5.h" |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
31 | #include "auth.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
32 | #include "jabber.h" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
33 | |
|
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
|
34 | static JabberSaslState |
|
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
35 | digest_md5_start(JabberStream *js, xmlnode *packet, xmlnode **response, |
|
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
|
36 | char **error) |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
37 | { |
|
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
|
38 | xmlnode *auth = xmlnode_new("auth"); |
|
29008
1f288722b5cd
jabber: Use NS_XMPP_SASL
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
39 | 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
|
40 | xmlnode_set_attrib(auth, "mechanism", "DIGEST-MD5"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
41 | |
|
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
|
42 | *response = auth; |
|
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
43 | 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
|
44 | } |
|
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 | /* Parts of this algorithm are inspired by stuff in libgsasl */ |
|
31394
dd9b4ed08d0a
jabber: Test harness for DIGEST-MD5 parsing function.
Paul Aurich <darkrain42@pidgin.im>
parents:
30857
diff
changeset
|
47 | GHashTable* jabber_auth_digest_md5_parse(const char *challenge) |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
48 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
49 | const char *token_start, *val_start, *val_end, *cur; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
50 | GHashTable *ret = g_hash_table_new_full(g_str_hash, g_str_equal, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
51 | g_free, g_free); |
|
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 | cur = challenge; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
54 | while(*cur != '\0') { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
55 | /* Find the end of the token */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
56 | gboolean in_quotes = FALSE; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
57 | char *name, *value = NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
58 | token_start = cur; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
59 | while(*cur != '\0' && (in_quotes || (!in_quotes && *cur != ','))) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
60 | if (*cur == '"') |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
61 | in_quotes = !in_quotes; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
62 | cur++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
63 | } |
|
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 | /* Find start of value. */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
66 | val_start = strchr(token_start, '='); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
67 | if (val_start == NULL || val_start > cur) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
68 | val_start = cur; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
69 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
70 | if (token_start != val_start) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
71 | name = g_strndup(token_start, val_start - token_start); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
72 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
73 | if (val_start != cur) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
74 | val_start++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
75 | while (val_start != cur && (*val_start == ' ' || *val_start == '\t' |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
76 | || *val_start == '\r' || *val_start == '\n' |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
77 | || *val_start == '"')) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
78 | val_start++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
79 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
80 | val_end = cur; |
|
31395
c47def35b008
jabber: Properly parse realm="" in DIGEST-MD5, which is apparently valid.
Paul Aurich <darkrain42@pidgin.im>
parents:
31394
diff
changeset
|
81 | while (val_end >= val_start && (*val_end == ' ' || *val_end == ',' || *val_end == '\t' |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
82 | || *val_end == '\r' || *val_end == '\n' |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
83 | || *val_end == '"' || *val_end == '\0')) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
84 | val_end--; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
85 | |
|
31395
c47def35b008
jabber: Properly parse realm="" in DIGEST-MD5, which is apparently valid.
Paul Aurich <darkrain42@pidgin.im>
parents:
31394
diff
changeset
|
86 | if (val_end - val_start + 1 >= 0) |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
87 | value = g_strndup(val_start, val_end - val_start + 1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
88 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
89 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
90 | g_hash_table_replace(ret, name, value); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
91 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
92 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
93 | /* Find the start of the next token, if there is one */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
94 | if (*cur != '\0') { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
95 | cur++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
96 | while (*cur == ' ' || *cur == ',' || *cur == '\t' |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
97 | || *cur == '\r' || *cur == '\n') |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
98 | cur++; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
99 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
100 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
101 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
102 | return ret; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
103 | } |
|
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 | static char * |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
106 | generate_response_value(JabberID *jid, const char *passwd, const char *nonce, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
107 | const char *cnonce, const char *a2, const char *realm) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
108 | { |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
109 | PurpleHash *hash; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
110 | guchar result[16]; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
111 | size_t a1len; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
112 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
113 | gchar *a1, *convnode=NULL, *convpasswd = NULL, *ha1, *ha2, *kd, *x, *z; |
|
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 | if((convnode = g_convert(jid->node, -1, "iso-8859-1", "utf-8", |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
116 | NULL, NULL, NULL)) == NULL) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
117 | convnode = g_strdup(jid->node); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
118 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
119 | if(passwd && ((convpasswd = g_convert(passwd, -1, "iso-8859-1", |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
120 | "utf-8", NULL, NULL, NULL)) == NULL)) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
121 | convpasswd = g_strdup(passwd); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
122 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
123 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
124 | hash = purple_md5_hash_new(); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
125 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
126 | x = g_strdup_printf("%s:%s:%s", convnode, realm, convpasswd ? convpasswd : ""); |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
127 | purple_hash_append(hash, (const guchar *)x, strlen(x)); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
128 | purple_hash_digest(hash, result, sizeof(result)); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
129 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
130 | a1 = g_strdup_printf("xxxxxxxxxxxxxxxx:%s:%s", nonce, cnonce); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
131 | a1len = strlen(a1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
132 | g_memmove(a1, result, 16); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
133 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
134 | purple_hash_reset(hash); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
135 | purple_hash_append(hash, (const guchar *)a1, a1len); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
136 | purple_hash_digest(hash, result, sizeof(result)); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
137 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
138 | ha1 = purple_base16_encode(result, 16); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
139 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
140 | purple_hash_reset(hash); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
141 | purple_hash_append(hash, (const guchar *)a2, strlen(a2)); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
142 | purple_hash_digest(hash, result, sizeof(result)); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
143 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
144 | ha2 = purple_base16_encode(result, 16); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
145 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
146 | kd = g_strdup_printf("%s:%s:00000001:%s:auth:%s", ha1, nonce, cnonce, ha2); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
147 | |
|
34567
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
148 | purple_hash_reset(hash); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
149 | purple_hash_append(hash, (const guchar *)kd, strlen(kd)); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
150 | purple_hash_digest(hash, result, sizeof(result)); |
|
ea5103f66b0e
Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents:
34556
diff
changeset
|
151 | g_object_unref(hash); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
152 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
153 | z = purple_base16_encode(result, 16); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
154 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
155 | g_free(convnode); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
156 | g_free(convpasswd); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
157 | g_free(x); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
158 | g_free(a1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
159 | g_free(ha1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
160 | g_free(ha2); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
161 | g_free(kd); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
162 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
163 | return z; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
164 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
165 | |
|
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
|
166 | static JabberSaslState |
|
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
167 | digest_md5_handle_challenge(JabberStream *js, xmlnode *packet, |
|
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
|
168 | xmlnode **response, char **msg) |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
169 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
170 | xmlnode *reply = NULL; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
171 | char *enc_in = xmlnode_get_data(packet); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
172 | char *dec_in; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
173 | char *enc_out; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
174 | GHashTable *parts; |
|
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
|
175 | JabberSaslState state = JABBER_SASL_STATE_CONTINUE; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
176 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
177 | if (!enc_in) { |
|
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
|
178 | *msg = g_strdup(_("Invalid response from server")); |
|
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
|
179 | return JABBER_SASL_STATE_FAIL; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
180 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
181 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
182 | dec_in = (char *)purple_base64_decode(enc_in, NULL); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
183 | purple_debug_misc("jabber", "decoded challenge (%" |
|
30857
1a7e2da2ab01
Fix for CVE-2010-3711. Properly validate the return value from
Daniel Atallah <datallah@pidgin.im>
parents:
30161
diff
changeset
|
184 | G_GSIZE_FORMAT "): %s\n", |
|
33788
83e5594ced88
Fix a few bogus NULL checks
Daniel Atallah <datallah@pidgin.im>
parents:
31395
diff
changeset
|
185 | strlen(dec_in), |
|
83e5594ced88
Fix a few bogus NULL checks
Daniel Atallah <datallah@pidgin.im>
parents:
31395
diff
changeset
|
186 | dec_in); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
187 | |
|
31394
dd9b4ed08d0a
jabber: Test harness for DIGEST-MD5 parsing function.
Paul Aurich <darkrain42@pidgin.im>
parents:
30857
diff
changeset
|
188 | parts = jabber_auth_digest_md5_parse(dec_in); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
189 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
190 | if (g_hash_table_lookup(parts, "rspauth")) { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
191 | char *rspauth = g_hash_table_lookup(parts, "rspauth"); |
|
30150
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
192 | char *expected_rspauth = js->auth_mech_data; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
193 | |
|
30150
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
194 | if (rspauth && purple_strequal(rspauth, expected_rspauth)) { |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
195 | reply = xmlnode_new("response"); |
|
29008
1f288722b5cd
jabber: Use NS_XMPP_SASL
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
196 | xmlnode_set_namespace(reply, NS_XMPP_SASL); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
197 | } else { |
|
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
|
198 | *msg = g_strdup(_("Invalid challenge from server")); |
|
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
|
199 | state = JABBER_SASL_STATE_FAIL; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
200 | } |
|
30150
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
201 | g_free(js->auth_mech_data); |
|
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
202 | js->auth_mech_data = NULL; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
203 | } else { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
204 | /* assemble a response, and send it */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
205 | /* see RFC 2831 */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
206 | char *realm; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
207 | char *nonce; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
208 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
209 | /* Make sure the auth string contains everything that should be there. |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
210 | This isn't everything in RFC2831, but it is what we need. */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
211 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
212 | nonce = g_hash_table_lookup(parts, "nonce"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
213 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
214 | /* we're actually supposed to prompt the user for a realm if |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
215 | * the server doesn't send one, but that really complicates things, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
216 | * so i'm not gonna worry about it until is poses a problem to |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
217 | * someone, or I get really bored */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
218 | realm = g_hash_table_lookup(parts, "realm"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
219 | if(!realm) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
220 | realm = js->user->domain; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
221 | |
|
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
|
222 | if (nonce == NULL || realm == NULL) { |
|
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
|
223 | *msg = g_strdup(_("Invalid challenge from server")); |
|
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
|
224 | state = JABBER_SASL_STATE_FAIL; |
|
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
225 | } else { |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
226 | GString *response = g_string_new(""); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
227 | char *a2; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
228 | char *auth_resp; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
229 | char *cnonce; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
230 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
231 | cnonce = g_strdup_printf("%x%u%x", g_random_int(), (int)time(NULL), |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
232 | g_random_int()); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
233 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
234 | a2 = g_strdup_printf("AUTHENTICATE:xmpp/%s", realm); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
235 | auth_resp = generate_response_value(js->user, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
236 | purple_connection_get_password(js->gc), nonce, cnonce, a2, realm); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
237 | g_free(a2); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
238 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
239 | a2 = g_strdup_printf(":xmpp/%s", realm); |
|
30150
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
240 | js->auth_mech_data = generate_response_value(js->user, |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
241 | purple_connection_get_password(js->gc), nonce, cnonce, a2, realm); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
242 | g_free(a2); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
243 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
244 | g_string_append_printf(response, "username=\"%s\"", js->user->node); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
245 | g_string_append_printf(response, ",realm=\"%s\"", realm); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
246 | g_string_append_printf(response, ",nonce=\"%s\"", nonce); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
247 | g_string_append_printf(response, ",cnonce=\"%s\"", cnonce); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
248 | g_string_append_printf(response, ",nc=00000001"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
249 | g_string_append_printf(response, ",qop=auth"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
250 | g_string_append_printf(response, ",digest-uri=\"xmpp/%s\"", realm); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
251 | g_string_append_printf(response, ",response=%s", auth_resp); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
252 | g_string_append_printf(response, ",charset=utf-8"); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
253 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
254 | g_free(auth_resp); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
255 | g_free(cnonce); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
256 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
257 | 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
|
258 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
259 | purple_debug_misc("jabber", "decoded response (%" |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
260 | G_GSIZE_FORMAT "): %s\n", |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
261 | response->len, response->str); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
262 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
263 | reply = xmlnode_new("response"); |
|
29008
1f288722b5cd
jabber: Use NS_XMPP_SASL
Paul Aurich <darkrain42@pidgin.im>
parents:
28855
diff
changeset
|
264 | xmlnode_set_namespace(reply, NS_XMPP_SASL); |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
265 | xmlnode_insert_data(reply, enc_out, -1); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
266 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
267 | g_free(enc_out); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
268 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
269 | g_string_free(response, TRUE); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
270 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
271 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
272 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
273 | g_free(enc_in); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
274 | g_free(dec_in); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
275 | g_hash_table_destroy(parts); |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
276 | |
|
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
|
277 | *response = reply; |
|
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
278 | return state; |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
279 | } |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
280 | |
|
30150
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
281 | static void |
|
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
282 | digest_md5_dispose(JabberStream *js) |
|
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
283 | { |
|
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
284 | g_free(js->auth_mech_data); |
|
30161
2ab3f130a8a9
NULL mech_data in digest_md5_dispose (what SCRAM and digest-md5 do elsewhere)
Paul Aurich <darkrain42@pidgin.im>
parents:
30150
diff
changeset
|
285 | js->auth_mech_data = NULL; |
|
30150
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
286 | } |
|
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
287 | |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
288 | static JabberSaslMech digest_md5_mech = { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
289 | 10, /* priority */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
290 | "DIGEST-MD5", /* name */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
291 | digest_md5_start, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
292 | digest_md5_handle_challenge, |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
293 | NULL, /* handle_success */ |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
294 | NULL, /* handle_failure */ |
|
30150
883c3fc1f638
jabber: Use the auth_mech_data JabberStream member for what it's for.
Paul Aurich <darkrain42@pidgin.im>
parents:
29090
diff
changeset
|
295 | digest_md5_dispose, |
|
28855
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
296 | }; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
297 | |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
298 | JabberSaslMech *jabber_auth_get_digest_md5_mech(void) |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
299 | { |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
300 | return &digest_md5_mech; |
|
c5bc85f9c00e
jabber: Factor the SASL auth methods into their own files.
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
301 | } |