Tue, 02 Nov 2021 00:30:07 -0500
Fix some bugs with proxies for xmpp
Testing Done:
Compiled and ran, was unable to get it to actually use charles proxy though.
Reviewed at https://reviews.imfreedom.org/r/1118/
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
1 | /* |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
2 | * purple - Jabber Protocol Plugin |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
3 | * |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
6 | * source distribution. |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
7 | * |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
11 | * (at your option) any later version. |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
12 | * |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
16 | * GNU General Public License for more details. |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
17 | * |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
21 | * |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
22 | */ |
|
40439
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40358
diff
changeset
|
23 | #include <glib/gi18n-lib.h> |
|
e9838d634d5e
Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents:
40358
diff
changeset
|
24 | |
|
40358
e6fe6fc1f516
move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents:
38854
diff
changeset
|
25 | #include <purple.h> |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
26 | |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
27 | #include "auth.h" |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
28 | #include "auth_scram.h" |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
29 | |
|
29081
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
30 | static const JabberScramHash hashes[] = { |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
31 | { "-SHA-1", G_CHECKSUM_SHA1 }, |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
32 | }; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
33 | |
|
29081
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
34 | static const JabberScramHash *mech_to_hash(const char *mech) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
35 | { |
|
36256
a437550a9308
Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31460
diff
changeset
|
36 | gsize i; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
37 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
38 | g_return_val_if_fail(mech != NULL && *mech != '\0', NULL); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
39 | |
|
29081
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
40 | for (i = 0; i < G_N_ELEMENTS(hashes); ++i) { |
|
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
41 | if (strstr(mech, hashes[i].mech_substr)) |
|
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
42 | return &(hashes[i]); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
43 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
44 | |
|
28927
24ee4d53dc68
jabber: Interop with Prosody (via Tobias' code). Hooray!
Paul Aurich <darkrain42@pidgin.im>
parents:
28926
diff
changeset
|
45 | purple_debug_error("jabber", "Unknown SCRAM mechanism %s\n", mech); |
|
29081
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
46 | g_return_val_if_reached(NULL); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
47 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
48 | |
|
29081
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
49 | guchar *jabber_scram_hi(const JabberScramHash *hash, const GString *str, |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
50 | GString *salt, guint iterations) |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
51 | { |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
52 | GHmac *hmac; |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
53 | gsize digest_len; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
54 | guchar *result; |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
55 | guint i; |
|
28864
5b3810bb7f1a
How is it that there's no programmatic way to get the output size of the hash functions without resorting to a hardcoded table? Or did I miss something?
Paul Aurich <darkrain42@pidgin.im>
parents:
28863
diff
changeset
|
56 | guchar *prev, *tmp; |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
57 | |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
58 | g_return_val_if_fail(hash != NULL, NULL); |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
59 | g_return_val_if_fail(str != NULL && str->len > 0, NULL); |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
60 | g_return_val_if_fail(salt != NULL && salt->len > 0, NULL); |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
61 | g_return_val_if_fail(iterations > 0, NULL); |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
62 | |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
63 | digest_len = g_checksum_type_get_length(hash->type); |
|
38310
ae7cce77183a
jabber: Use correct variable type for SCRAM auth HMAC code.
Mike Ruprecht <cmaiku@gmail.com>
parents:
38306
diff
changeset
|
64 | prev = g_new0(guchar, digest_len); |
|
ae7cce77183a
jabber: Use correct variable type for SCRAM auth HMAC code.
Mike Ruprecht <cmaiku@gmail.com>
parents:
38306
diff
changeset
|
65 | tmp = g_new0(guchar, digest_len); |
|
ae7cce77183a
jabber: Use correct variable type for SCRAM auth HMAC code.
Mike Ruprecht <cmaiku@gmail.com>
parents:
38306
diff
changeset
|
66 | result = g_new0(guchar, digest_len); |
|
28864
5b3810bb7f1a
How is it that there's no programmatic way to get the output size of the hash functions without resorting to a hardcoded table? Or did I miss something?
Paul Aurich <darkrain42@pidgin.im>
parents:
28863
diff
changeset
|
67 | |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
68 | hmac = g_hmac_new(hash->type, (guchar *)str->str, str->len); |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
69 | |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
70 | /* Append INT(1), a four-octet encoding of the integer 1, most significant |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
71 | * octet first. */ |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
72 | g_string_append_len(salt, "\0\0\0\1", 4); |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
73 | |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
74 | /* Compute U0 */ |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
75 | g_hmac_update(hmac, (guchar *)salt->str, salt->len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
76 | g_hmac_get_digest(hmac, result, &digest_len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
77 | g_hmac_unref(hmac); |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
78 | |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
79 | memcpy(prev, result, digest_len); |
|
28863
b4e8c372e06b
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <darkrain42@pidgin.im>
parents:
28862
diff
changeset
|
80 | |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
81 | /* Compute U1...Ui */ |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
82 | for (i = 1; i < iterations; ++i) { |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
83 | guint j; |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
84 | hmac = g_hmac_new(hash->type, (guchar *)str->str, str->len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
85 | g_hmac_update(hmac, prev, digest_len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
86 | g_hmac_get_digest(hmac, tmp, &digest_len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
87 | g_hmac_unref(hmac); |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
88 | |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
89 | for (j = 0; j < digest_len; ++j) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
90 | result[j] ^= tmp[j]; |
|
28863
b4e8c372e06b
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <darkrain42@pidgin.im>
parents:
28862
diff
changeset
|
91 | |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
92 | memcpy(prev, tmp, digest_len); |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
93 | } |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
94 | |
|
28865
554be021cd4c
Clean up the two temporary buffers.
Paul Aurich <darkrain42@pidgin.im>
parents:
28864
diff
changeset
|
95 | g_free(tmp); |
|
554be021cd4c
Clean up the two temporary buffers.
Paul Aurich <darkrain42@pidgin.im>
parents:
28864
diff
changeset
|
96 | g_free(prev); |
|
28862
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
97 | return result; |
|
8a37b7df0850
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
98 | } |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
99 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
100 | /* |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
101 | * Helper functions for doing the SCRAM calculations. The first argument |
|
29081
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
102 | * is the hash algorithm. All buffers must be of the appropriate size |
|
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
103 | * according to the JabberScramHash. |
|
ce668db953aa
jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents:
29080
diff
changeset
|
104 | * |
|
38303
1e7a57174d26
jabber/auth_scram: prefix the names of the 'hmac' and 'hash' functions
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
105 | * "str" is a NULL-terminated string for jabber_scram_hmac(). |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
106 | * |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
107 | * Needless to say, these are fragile. |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
108 | */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
109 | static void |
|
38303
1e7a57174d26
jabber/auth_scram: prefix the names of the 'hmac' and 'hash' functions
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
110 | jabber_scram_hmac(const JabberScramHash *hash, guchar *out, const guchar *key, const gchar *str) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
111 | { |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
112 | GHmac *hmac; |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
113 | gsize digest_len = g_checksum_type_get_length(hash->type); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
114 | |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
115 | hmac = g_hmac_new(hash->type, key, digest_len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
116 | g_hmac_update(hmac, (guchar *)str, -1); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
117 | g_hmac_get_digest(hmac, out, &digest_len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
118 | g_hmac_unref(hmac); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
119 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
120 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
121 | static void |
|
38303
1e7a57174d26
jabber/auth_scram: prefix the names of the 'hmac' and 'hash' functions
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
122 | jabber_scram_hash(const JabberScramHash *hash, guchar *out, const guchar *data) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
123 | { |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
124 | GChecksum *checksum; |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
125 | gsize digest_len = g_checksum_type_get_length(hash->type); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
126 | |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
127 | checksum = g_checksum_new(hash->type); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
128 | g_checksum_update(checksum, data, digest_len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
129 | g_checksum_get_digest(checksum, out, &digest_len); |
|
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
130 | g_checksum_free(checksum); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
131 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
132 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
133 | gboolean |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
134 | jabber_scram_calc_proofs(JabberScramData *data, GString *salt, guint iterations) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
135 | { |
|
38306
3751be7f48c3
jabber: Port to use GHmac instead of PurpleHMACCipher
Mike Ruprecht <cmaiku@gmail.com>
parents:
36286
diff
changeset
|
136 | guint hash_len = g_checksum_type_get_length(data->hash->type); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
137 | guint i; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
138 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
139 | GString *pass = g_string_new(data->password); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
140 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
141 | guchar *salted_password; |
|
29088
6f36294367f4
jabber: Ugh, make this C89-compliant. Bah.
Paul Aurich <darkrain42@pidgin.im>
parents:
29084
diff
changeset
|
142 | guchar *client_key, *stored_key, *client_signature, *server_key; |
|
6f36294367f4
jabber: Ugh, make this C89-compliant. Bah.
Paul Aurich <darkrain42@pidgin.im>
parents:
29084
diff
changeset
|
143 | |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
144 | data->client_proof = g_string_sized_new(hash_len); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
145 | data->client_proof->len = hash_len; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
146 | data->server_signature = g_string_sized_new(hash_len); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
147 | data->server_signature->len = hash_len; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
148 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
149 | salted_password = jabber_scram_hi(data->hash, pass, salt, iterations); |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
150 | |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
151 | memset(pass->str, 0, pass->allocated_len); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
152 | g_string_free(pass, TRUE); |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
153 | |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
154 | if (!salted_password) |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
155 | return FALSE; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
156 | |
|
33689
7b2708ac0e9c
Fix a leak in Jabber auth.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31460
diff
changeset
|
157 | client_key = g_new0(guchar, hash_len); |
|
7b2708ac0e9c
Fix a leak in Jabber auth.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31460
diff
changeset
|
158 | stored_key = g_new0(guchar, hash_len); |
|
7b2708ac0e9c
Fix a leak in Jabber auth.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31460
diff
changeset
|
159 | client_signature = g_new0(guchar, hash_len); |
|
7b2708ac0e9c
Fix a leak in Jabber auth.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31460
diff
changeset
|
160 | server_key = g_new0(guchar, hash_len); |
|
7b2708ac0e9c
Fix a leak in Jabber auth.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
31460
diff
changeset
|
161 | |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
162 | /* client_key = HMAC(salted_password, "Client Key") */ |
|
38303
1e7a57174d26
jabber/auth_scram: prefix the names of the 'hmac' and 'hash' functions
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
163 | jabber_scram_hmac(data->hash, client_key, salted_password, "Client Key"); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
164 | /* server_key = HMAC(salted_password, "Server Key") */ |
|
38303
1e7a57174d26
jabber/auth_scram: prefix the names of the 'hmac' and 'hash' functions
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
165 | jabber_scram_hmac(data->hash, server_key, salted_password, "Server Key"); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
166 | g_free(salted_password); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
167 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
168 | /* stored_key = HASH(client_key) */ |
|
38303
1e7a57174d26
jabber/auth_scram: prefix the names of the 'hmac' and 'hash' functions
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
169 | jabber_scram_hash(data->hash, stored_key, client_key); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
170 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
171 | /* client_signature = HMAC(stored_key, auth_message) */ |
|
38303
1e7a57174d26
jabber/auth_scram: prefix the names of the 'hmac' and 'hash' functions
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
172 | jabber_scram_hmac(data->hash, client_signature, stored_key, data->auth_message->str); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
173 | /* server_signature = HMAC(server_key, auth_message) */ |
|
38303
1e7a57174d26
jabber/auth_scram: prefix the names of the 'hmac' and 'hash' functions
dx <dx@dxzone.com.ar>
parents:
36256
diff
changeset
|
174 | jabber_scram_hmac(data->hash, (guchar *)data->server_signature->str, server_key, data->auth_message->str); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
175 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
176 | /* client_proof = client_key XOR client_signature */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
177 | for (i = 0; i < hash_len; ++i) |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
178 | data->client_proof->str[i] = client_key[i] ^ client_signature[i]; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
179 | |
|
29088
6f36294367f4
jabber: Ugh, make this C89-compliant. Bah.
Paul Aurich <darkrain42@pidgin.im>
parents:
29084
diff
changeset
|
180 | g_free(server_key); |
|
6f36294367f4
jabber: Ugh, make this C89-compliant. Bah.
Paul Aurich <darkrain42@pidgin.im>
parents:
29084
diff
changeset
|
181 | g_free(client_signature); |
|
6f36294367f4
jabber: Ugh, make this C89-compliant. Bah.
Paul Aurich <darkrain42@pidgin.im>
parents:
29084
diff
changeset
|
182 | g_free(stored_key); |
|
6f36294367f4
jabber: Ugh, make this C89-compliant. Bah.
Paul Aurich <darkrain42@pidgin.im>
parents:
29084
diff
changeset
|
183 | g_free(client_key); |
|
6f36294367f4
jabber: Ugh, make this C89-compliant. Bah.
Paul Aurich <darkrain42@pidgin.im>
parents:
29084
diff
changeset
|
184 | |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
185 | return TRUE; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
186 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
187 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
188 | static gboolean |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
189 | parse_server_step1(JabberScramData *data, const char *challenge, |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
190 | gchar **out_nonce, GString **out_salt, guint *out_iterations) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
191 | { |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
192 | char **tokens; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
193 | char *token, *decoded, *tmp; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
194 | gsize len; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
195 | char *nonce = NULL; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
196 | GString *salt = NULL; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
197 | guint iterations; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
198 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
199 | tokens = g_strsplit(challenge, ",", -1); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
200 | if (tokens == NULL) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
201 | return FALSE; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
202 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
203 | token = tokens[0]; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
204 | if (token[0] != 'r' || token[1] != '=') |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
205 | goto err; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
206 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
207 | /* Ensure that the first cnonce_len bytes of the nonce are the original |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
208 | * cnonce we sent to the server. |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
209 | */ |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
210 | if (0 != strncmp(data->cnonce, token + 2, strlen(data->cnonce))) |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
211 | goto err; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
212 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
213 | nonce = g_strdup(token + 2); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
214 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
215 | /* The Salt, base64-encoded */ |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
216 | token = tokens[1]; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
217 | if (token[0] != 's' || token[1] != '=') |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
218 | goto err; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
219 | |
|
38341
3da74e727e78
Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents:
38310
diff
changeset
|
220 | decoded = (gchar *)g_base64_decode(token + 2, &len); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
221 | if (!decoded || *decoded == '\0') { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
222 | g_free(decoded); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
223 | goto err; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
224 | } |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
225 | salt = g_string_new_len(decoded, len); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
226 | g_free(decoded); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
227 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
228 | /* The iteration count */ |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
229 | token = tokens[2]; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
230 | if (token[0] != 'i' || token[1] != '=' || token[2] == '\0') |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
231 | goto err; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
232 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
233 | /* Validate the string */ |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
234 | for (tmp = token + 2; *tmp; ++tmp) |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
235 | if (!g_ascii_isdigit(*tmp)) |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
236 | goto err; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
237 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
238 | iterations = strtoul(token + 2, NULL, 10); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
239 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
240 | g_strfreev(tokens); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
241 | *out_nonce = nonce; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
242 | *out_salt = salt; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
243 | *out_iterations = iterations; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
244 | return TRUE; |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
245 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
246 | err: |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
247 | g_free(nonce); |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
248 | if (salt) |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
249 | g_string_free(salt, TRUE); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
250 | g_strfreev(tokens); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
251 | return FALSE; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
252 | } |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
253 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
254 | static gboolean |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
255 | parse_server_step2(JabberScramData *data, const char *challenge, gchar **out_verifier) |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
256 | { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
257 | char **tokens; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
258 | char *token; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
259 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
260 | tokens = g_strsplit(challenge, ",", -1); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
261 | if (tokens == NULL) |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
262 | return FALSE; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
263 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
264 | token = tokens[0]; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
265 | if (token[0] != 'v' || token[1] != '=' || token[2] == '\0') { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
266 | g_strfreev(tokens); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
267 | return FALSE; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
268 | } |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
269 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
270 | *out_verifier = g_strdup(token + 2); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
271 | g_strfreev(tokens); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
272 | return TRUE; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
273 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
274 | |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
275 | gboolean |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
276 | jabber_scram_feed_parser(JabberScramData *data, gchar *in, gchar **out) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
277 | { |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
278 | gboolean ret; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
279 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
280 | g_return_val_if_fail(data != NULL, FALSE); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
281 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
282 | g_string_append_c(data->auth_message, ','); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
283 | g_string_append(data->auth_message, in); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
284 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
285 | if (data->step == 1) { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
286 | gchar *nonce, *proof; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
287 | GString *salt; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
288 | guint iterations; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
289 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
290 | ret = parse_server_step1(data, in, &nonce, &salt, &iterations); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
291 | if (!ret) |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
292 | return FALSE; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
293 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
294 | g_string_append_c(data->auth_message, ','); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
295 | |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
296 | /* "biws" is the base64 encoding of "n,,". I promise. */ |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
297 | g_string_append_printf(data->auth_message, "c=%s,r=%s", "biws", nonce); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
298 | #ifdef CHANNEL_BINDING |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
299 | #error fix this |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
300 | #endif |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
301 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
302 | ret = jabber_scram_calc_proofs(data, salt, iterations); |
| 30036 | 303 | |
| 304 | g_string_free(salt, TRUE); | |
| 305 | salt = NULL; | |
| 306 | if (!ret) { | |
| 307 | g_free(nonce); | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
308 | return FALSE; |
| 30036 | 309 | } |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
310 | |
|
38341
3da74e727e78
Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents:
38310
diff
changeset
|
311 | proof = g_base64_encode((guchar *)data->client_proof->str, data->client_proof->len); |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
312 | *out = g_strdup_printf("c=%s,r=%s,p=%s", "biws", nonce, proof); |
| 30036 | 313 | g_free(nonce); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
314 | g_free(proof); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
315 | } else if (data->step == 2) { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
316 | gchar *server_sig, *enc_server_sig; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
317 | gsize len; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
318 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
319 | ret = parse_server_step2(data, in, &enc_server_sig); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
320 | if (!ret) |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
321 | return FALSE; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
322 | |
|
38341
3da74e727e78
Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents:
38310
diff
changeset
|
323 | server_sig = (gchar *)g_base64_decode(enc_server_sig, &len); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
324 | g_free(enc_server_sig); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
325 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
326 | if (server_sig == NULL || len != data->server_signature->len) { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
327 | g_free(server_sig); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
328 | return FALSE; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
329 | } |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
330 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
331 | if (0 != memcmp(server_sig, data->server_signature->str, len)) { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
332 | g_free(server_sig); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
333 | return FALSE; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
334 | } |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
335 | g_free(server_sig); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
336 | |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
337 | *out = NULL; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
338 | } else { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
339 | purple_debug_error("jabber", "SCRAM: There is no step %d\n", data->step); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
340 | return FALSE; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
341 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
342 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
343 | return TRUE; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
344 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
345 | |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
346 | static gchar *escape_username(const gchar *in) |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
347 | { |
|
29080
ad5cd77354db
jabber: Should have looked for this function earlier.
Paul Aurich <darkrain42@pidgin.im>
parents:
29027
diff
changeset
|
348 | gchar *tmp, *tmp2; |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
349 | |
|
29080
ad5cd77354db
jabber: Should have looked for this function earlier.
Paul Aurich <darkrain42@pidgin.im>
parents:
29027
diff
changeset
|
350 | tmp = purple_strreplace(in, "=", "=3D"); |
|
31460
e9358ca4e626
jabber: Oops. Clearly the wrong escape sequence here for ','.
Paul Aurich <darkrain42@pidgin.im>
parents:
30306
diff
changeset
|
351 | tmp2 = purple_strreplace(tmp, ",", "=2C"); |
|
29080
ad5cd77354db
jabber: Should have looked for this function earlier.
Paul Aurich <darkrain42@pidgin.im>
parents:
29027
diff
changeset
|
352 | g_free(tmp); |
|
ad5cd77354db
jabber: Should have looked for this function earlier.
Paul Aurich <darkrain42@pidgin.im>
parents:
29027
diff
changeset
|
353 | return tmp2; |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
354 | } |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
355 | |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
356 | static JabberSaslState |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
357 | scram_start(JabberStream *js, PurpleXmlNode *mechanisms, PurpleXmlNode **out, char **error) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
358 | { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
359 | PurpleXmlNode *reply; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
360 | JabberScramData *data; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
361 | guint64 cnonce; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
362 | #ifdef CHANNEL_BINDING |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
363 | gboolean binding_supported = TRUE; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
364 | #endif |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
365 | gchar *dec_out, *enc_out; |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
366 | gchar *prepped_node, *tmp; |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
367 | gchar *prepped_pass; |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
368 | |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
369 | prepped_node = jabber_saslprep(js->user->node); |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
370 | if (!prepped_node) { |
|
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:
29088
diff
changeset
|
371 | *error = g_strdup(_("Unable to canonicalize username")); |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
372 | return JABBER_SASL_STATE_FAIL; |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
373 | } |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
374 | |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
375 | tmp = escape_username(prepped_node); |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
376 | g_free(prepped_node); |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
377 | prepped_node = tmp; |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
378 | |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
379 | prepped_pass = jabber_saslprep(purple_connection_get_password(js->gc)); |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
380 | if (!prepped_pass) { |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
381 | g_free(prepped_node); |
|
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:
29088
diff
changeset
|
382 | *error = g_strdup(_("Unable to canonicalize password")); |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
383 | return JABBER_SASL_STATE_FAIL; |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
384 | } |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
385 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
386 | data = js->auth_mech_data = g_new0(JabberScramData, 1); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
387 | data->hash = mech_to_hash(js->auth_mech->name); |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
388 | data->password = prepped_pass; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
389 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
390 | #ifdef CHANNEL_BINDING |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
391 | if (strstr(js->auth_mech_name, "-PLUS")) |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
392 | data->channel_binding = TRUE; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
393 | #endif |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
394 | cnonce = ((guint64)g_random_int() << 32) | g_random_int(); |
|
38341
3da74e727e78
Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents:
38310
diff
changeset
|
395 | data->cnonce = g_base64_encode((guchar *)&cnonce, sizeof(cnonce)); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
396 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
397 | data->auth_message = g_string_new(NULL); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
398 | g_string_printf(data->auth_message, "n=%s,r=%s", |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
399 | prepped_node, data->cnonce); |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
400 | g_free(prepped_node); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
401 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
402 | data->step = 1; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
403 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
404 | reply = purple_xmlnode_new("auth"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
405 | purple_xmlnode_set_namespace(reply, NS_XMPP_SASL); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
406 | purple_xmlnode_set_attrib(reply, "mechanism", js->auth_mech->name); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
407 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
408 | /* TODO: Channel binding */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
409 | dec_out = g_strdup_printf("%c,,%s", 'n', data->auth_message->str); |
|
38341
3da74e727e78
Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents:
38310
diff
changeset
|
410 | enc_out = g_base64_encode((guchar *)dec_out, strlen(dec_out)); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
411 | purple_debug_misc("jabber", "initial SCRAM message '%s'\n", dec_out); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
412 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
413 | purple_xmlnode_insert_data(reply, enc_out, -1); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
414 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
415 | g_free(enc_out); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
416 | g_free(dec_out); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
417 | |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
418 | *out = reply; |
|
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
419 | return JABBER_SASL_STATE_CONTINUE; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
420 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
421 | |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
422 | static JabberSaslState |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
423 | scram_handle_challenge(JabberStream *js, PurpleXmlNode *challenge, PurpleXmlNode **out, char **error) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
424 | { |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
425 | JabberScramData *data = js->auth_mech_data; |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
426 | PurpleXmlNode *reply; |
| 30036 | 427 | gchar *enc_in, *dec_in = NULL; |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
428 | gchar *enc_out = NULL, *dec_out = NULL; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
429 | gsize len; |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
430 | JabberSaslState state = JABBER_SASL_STATE_FAIL; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
431 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
432 | enc_in = purple_xmlnode_get_data(challenge); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
433 | if (!enc_in || *enc_in == '\0') { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
434 | reply = purple_xmlnode_new("abort"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
435 | purple_xmlnode_set_namespace(reply, NS_XMPP_SASL); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
436 | data->step = -1; |
|
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:
29088
diff
changeset
|
437 | *error = g_strdup(_("Invalid challenge from server")); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
438 | goto out; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
439 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
440 | |
|
38341
3da74e727e78
Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents:
38310
diff
changeset
|
441 | dec_in = (gchar *)g_base64_decode(enc_in, &len); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
442 | if (!dec_in || len != strlen(dec_in)) { |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
443 | /* Danger afoot; SCRAM shouldn't contain NUL bytes */ |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
444 | reply = purple_xmlnode_new("abort"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
445 | purple_xmlnode_set_namespace(reply, NS_XMPP_SASL); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
446 | data->step = -1; |
|
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:
29088
diff
changeset
|
447 | *error = g_strdup(_("Malicious challenge from server")); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
448 | goto out; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
449 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
450 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
451 | purple_debug_misc("jabber", "decoded challenge: %s\n", dec_in); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
452 | |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
453 | if (!jabber_scram_feed_parser(data, dec_in, &dec_out)) { |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
454 | reply = purple_xmlnode_new("abort"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
455 | purple_xmlnode_set_namespace(reply, NS_XMPP_SASL); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
456 | data->step = -1; |
|
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:
29088
diff
changeset
|
457 | *error = g_strdup(_("Invalid challenge from server")); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
458 | goto out; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
459 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
460 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
461 | data->step += 1; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
462 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
463 | reply = purple_xmlnode_new("response"); |
|
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
464 | purple_xmlnode_set_namespace(reply, NS_XMPP_SASL); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
465 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
466 | purple_debug_misc("jabber", "decoded response: %s\n", dec_out ? dec_out : "(null)"); |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
467 | if (dec_out) { |
|
38341
3da74e727e78
Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents:
38310
diff
changeset
|
468 | enc_out = g_base64_encode((guchar *)dec_out, strlen(dec_out)); |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
469 | purple_xmlnode_insert_data(reply, enc_out, -1); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
470 | } |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
471 | |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
472 | state = JABBER_SASL_STATE_CONTINUE; |
|
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
473 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
474 | out: |
| 30036 | 475 | g_free(enc_in); |
| 476 | g_free(dec_in); | |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
477 | g_free(enc_out); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
478 | g_free(dec_out); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
479 | |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
480 | *out = reply; |
|
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
481 | return state; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
482 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
483 | |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
484 | static JabberSaslState |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
485 | scram_handle_success(JabberStream *js, PurpleXmlNode *packet, char **error) |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
486 | { |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
487 | JabberScramData *data = js->auth_mech_data; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
488 | char *enc_in, *dec_in; |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
489 | char *dec_out = NULL; |
|
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
490 | gsize len; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
491 | |
|
34935
686fa55b0deb
Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents:
34889
diff
changeset
|
492 | enc_in = purple_xmlnode_get_data(packet); |
|
30306
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
493 | if (data->step != 3 && (!enc_in || *enc_in == '\0')) { |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
494 | *error = g_strdup(_("Invalid challenge from server")); |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
495 | g_free(enc_in); |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
496 | return JABBER_SASL_STATE_FAIL; |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
497 | } |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
498 | |
|
30306
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
499 | if (data->step == 3) { |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
500 | /* |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
501 | * If the server took the slow approach (sending the verifier |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
502 | * as a challenge/response pair), we get here. |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
503 | */ |
|
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
504 | g_free(enc_in); |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
505 | return JABBER_SASL_STATE_OK; |
|
30306
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
506 | } |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
507 | |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
508 | if (data->step != 2) { |
|
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:
29088
diff
changeset
|
509 | *error = g_strdup(_("Unexpected response from server")); |
|
30306
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
510 | g_free(enc_in); |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
511 | return 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:
29081
diff
changeset
|
512 | } |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
513 | |
|
38341
3da74e727e78
Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents:
38310
diff
changeset
|
514 | dec_in = (gchar *)g_base64_decode(enc_in, &len); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
515 | g_free(enc_in); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
516 | if (!dec_in || len != strlen(dec_in)) { |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
517 | /* Danger afoot; SCRAM shouldn't contain NUL bytes */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
518 | g_free(dec_in); |
|
30306
e7dea71588a5
jabber: Fix a case where a broken server would hang the connection.
Paul Aurich <darkrain42@pidgin.im>
parents:
30136
diff
changeset
|
519 | *error = g_strdup(_("Malicious 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:
29081
diff
changeset
|
520 | return JABBER_SASL_STATE_FAIL; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
521 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
522 | |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
523 | purple_debug_misc("jabber", "decoded success: %s\n", dec_in); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
524 | |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
525 | if (!jabber_scram_feed_parser(data, dec_in, &dec_out) || dec_out != NULL) { |
| 30036 | 526 | g_free(dec_in); |
|
28868
7415cb6c4587
jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents:
28866
diff
changeset
|
527 | g_free(dec_out); |
|
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:
29088
diff
changeset
|
528 | *error = 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:
29081
diff
changeset
|
529 | return JABBER_SASL_STATE_FAIL; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
530 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
531 | |
| 30036 | 532 | g_free(dec_in); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
533 | /* Hooray */ |
|
29084
3a821d391ac0
Let's try a more complex set of return states / values for auth mechs.
Paul Aurich <darkrain42@pidgin.im>
parents:
29081
diff
changeset
|
534 | return JABBER_SASL_STATE_OK; |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
535 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
536 | |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
537 | void jabber_scram_data_destroy(JabberScramData *data) |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
538 | { |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
539 | g_free(data->cnonce); |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
540 | if (data->auth_message) |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
541 | g_string_free(data->auth_message, TRUE); |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
542 | if (data->client_proof) |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
543 | g_string_free(data->client_proof, TRUE); |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
544 | if (data->server_signature) |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
545 | g_string_free(data->server_signature, TRUE); |
|
29027
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
546 | if (data->password) { |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
547 | memset(data->password, 0, strlen(data->password)); |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
548 | g_free(data->password); |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
549 | } |
|
6af29b140195
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents:
29008
diff
changeset
|
550 | |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
551 | g_free(data); |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
552 | } |
|
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
553 | |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
554 | static void scram_dispose(JabberStream *js) |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
555 | { |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
556 | if (js->auth_mech_data) { |
|
28926
a737800d1445
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents:
28868
diff
changeset
|
557 | jabber_scram_data_destroy(js->auth_mech_data); |
|
28866
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
558 | js->auth_mech_data = NULL; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
559 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
560 | } |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
561 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
562 | static JabberSaslMech scram_sha1_mech = { |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
563 | 50, /* priority */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
564 | "SCRAM-SHA-1", /* name */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
565 | scram_start, |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
566 | scram_handle_challenge, |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
567 | scram_handle_success, |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
568 | NULL, /* handle_failure */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
569 | scram_dispose |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
570 | }; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
571 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
572 | #ifdef CHANNEL_BINDING |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
573 | /* With channel binding */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
574 | static JabberSaslMech scram_sha1_plus_mech = { |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
575 | scram_sha1_mech.priority + 1, /* priority */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
576 | "SCRAM-SHA-1-PLUS", /* name */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
577 | scram_start, |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
578 | scram_handle_challenge, |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
579 | scram_handle_success, |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
580 | NULL, /* handle_failure */ |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
581 | scram_dispose |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
582 | }; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
583 | #endif |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
584 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
585 | JabberSaslMech **jabber_auth_get_scram_mechs(gint *count) |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
586 | { |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
587 | static JabberSaslMech *mechs[] = { |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
588 | &scram_sha1_mech, |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
589 | #ifdef CHANNEL_BINDING |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
590 | &scram_sha1_plus_mech, |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
591 | #endif |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
592 | }; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
593 | |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
594 | *count = G_N_ELEMENTS(mechs); |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
595 | return mechs; |
|
e3d867ce000b
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents:
28865
diff
changeset
|
596 | } |