annotate libpurple/protocols/jabber/auth_scram.c @ 29091:b0fb53868142

jabber: Handle the case where the server success-with-data is sent as a challenge/response pair. This should also make it easier to feed C/R pairs via the tester.
author Paul Aurich <paul@darkrain42.org>
date Wed, 11 Nov 2009 20:32:09 +0000
parents c1d41b7484ff
children 65a34cce02e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
1 /*
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
2 * purple - Jabber Protocol Plugin
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
3 *
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
6 * source distribution.
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
7 *
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
11 * (at your option) any later version.
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
12 *
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
16 * GNU General Public License for more details.
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
17 *
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
21 *
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
22 */
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
23 #include "internal.h"
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
24
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
25 #include "auth.h"
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
26 #include "auth_scram.h"
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
27
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
28 #include "cipher.h"
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
29 #include "debug.h"
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
30
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
31 static const struct {
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
32 const char *mech_substr;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
33 const char *hash;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
34 } mech_hashes[] = {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
35 { "-SHA-1-", "sha1" },
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
36 };
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
37
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
38 static const struct {
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
39 const char *hash;
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
40 guint size;
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
41 } hash_sizes[] = {
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
42 { "sha1", 20 },
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
43 };
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
44
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
45 static const gchar *mech_to_hash(const char *mech)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
46 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
47 int i;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
48
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
49 g_return_val_if_fail(mech != NULL && *mech != '\0', NULL);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
50
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
51 for (i = 0; i < G_N_ELEMENTS(mech_hashes); ++i) {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
52 if (strstr(mech, mech_hashes[i].mech_substr))
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
53 return mech_hashes[i].hash;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
54 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
55
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
56 return NULL;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
57 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
58
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
59 static guint hash_to_output_len(const gchar *hash)
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
60 {
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
61 int i;
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
62
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
63 g_return_val_if_fail(hash != NULL && *hash != '\0', 0);
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
64
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
65 for (i = 0; i < G_N_ELEMENTS(hash_sizes); ++i) {
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
66 if (g_str_equal(hash, hash_sizes[i].hash))
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
67 return hash_sizes[i].size;
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
68 }
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
69
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
70 purple_debug_error("jabber", "Unknown SCRAM hash function %s\n", hash);
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
71
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
72 return 0;
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
73 }
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
74
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
75 guchar *jabber_scram_hi(const gchar *hash, const GString *str,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
76 GString *salt, guint iterations)
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
77 {
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
78 PurpleCipherContext *context;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
79 guchar *result;
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
80 guint i;
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
81 guint hash_len;
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
82 guchar *prev, *tmp;
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
83
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
84 g_return_val_if_fail(hash != NULL, NULL);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
85 g_return_val_if_fail(str != NULL && str->len > 0, NULL);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
86 g_return_val_if_fail(salt != NULL && salt->len > 0, NULL);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
87 g_return_val_if_fail(iterations > 0, NULL);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
88
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
89 hash_len = hash_to_output_len(hash);
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
90 g_return_val_if_fail(hash_len > 0, NULL);
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
91
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
92 prev = g_new0(guint8, hash_len);
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
93 tmp = g_new0(guint8, hash_len);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
94 result = g_new0(guint8, hash_len);
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
95
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
96 context = purple_cipher_context_new_by_name("hmac", NULL);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
97
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
98 /* Append INT(1), a four-octet encoding of the integer 1, most significant
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
99 * octet first. */
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
100 g_string_append_len(salt, "\0\0\0\1", 4);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
101
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
102 /* Compute U0 */
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
103 purple_cipher_context_set_option(context, "hash", (gpointer)hash);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
104 purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
105 purple_cipher_context_append(context, (guchar *)salt->str, salt->len);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
106 purple_cipher_context_digest(context, hash_len, result, NULL);
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
107
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
108 memcpy(prev, result, hash_len);
29086
398ff52e7d62 Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents: 29085
diff changeset
109
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
110 /* Compute U1...Ui */
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
111 for (i = 1; i < iterations; ++i) {
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
112 guint j;
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
113 purple_cipher_context_set_option(context, "hash", (gpointer)hash);
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
114 purple_cipher_context_set_key_with_len(context, (guchar *)str->str, str->len);
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
115 purple_cipher_context_append(context, prev, hash_len);
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
116 purple_cipher_context_digest(context, hash_len, tmp, NULL);
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
117
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
118 for (j = 0; j < hash_len; ++j)
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
119 result[j] ^= tmp[j];
29086
398ff52e7d62 Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents: 29085
diff changeset
120
29087
ec843b380a1d 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 <paul@darkrain42.org>
parents: 29086
diff changeset
121 memcpy(prev, tmp, hash_len);
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
122 }
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
123
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
124 purple_cipher_context_destroy(context);
29088
2b4465db73f1 Clean up the two temporary buffers.
Paul Aurich <paul@darkrain42.org>
parents: 29087
diff changeset
125 g_free(tmp);
2b4465db73f1 Clean up the two temporary buffers.
Paul Aurich <paul@darkrain42.org>
parents: 29087
diff changeset
126 g_free(prev);
29085
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
127 return result;
338eeaf371e2 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
128 }
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
129
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
130 /*
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
131 * Helper functions for doing the SCRAM calculations. The first argument
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
132 * is the hash algorithm and the second (len) is the length of the output
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
133 * buffer and key/data (the fourth argument).
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
134 * "str" is a NULL-terminated string for hmac().
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
135 *
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
136 * Needless to say, these are fragile.
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
137 */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
138 static void
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
139 hmac(const gchar *hash_alg, gsize len, guchar *out, const guchar *key, const gchar *str)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
140 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
141 PurpleCipherContext *context;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
142
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
143 context = purple_cipher_context_new_by_name("hmac", NULL);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
144 purple_cipher_context_set_option(context, "hash", (gpointer)hash_alg);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
145 purple_cipher_context_set_key_with_len(context, key, len);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
146 purple_cipher_context_append(context, (guchar *)str, strlen(str));
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
147 purple_cipher_context_digest(context, len, out, NULL);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
148 purple_cipher_context_destroy(context);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
149 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
150
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
151 static void
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
152 hash(const gchar *hash_alg, gsize len, guchar *out, const guchar *data)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
153 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
154 PurpleCipherContext *context;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
155
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
156 context = purple_cipher_context_new_by_name(hash_alg, NULL);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
157 purple_cipher_context_append(context, data, len);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
158 purple_cipher_context_digest(context, len, out, NULL);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
159 purple_cipher_context_destroy(context);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
160 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
161
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
162 gboolean
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
163 jabber_scram_calc_proofs(JabberScramData *data, GString *salt, guint iterations)
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
164 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
165 guint hash_len = hash_to_output_len(data->hash);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
166 guint i;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
167
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
168 GString *pass = g_string_new(data->password);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
169
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
170 guchar *salted_password;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
171 guchar client_key[hash_len];
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
172 guchar stored_key[hash_len];
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
173 guchar client_signature[hash_len];
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
174 guchar server_key[hash_len];
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
175
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
176 data->client_proof = g_string_sized_new(hash_len);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
177 data->client_proof->len = hash_len;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
178 data->server_signature = g_string_sized_new(hash_len);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
179 data->server_signature->len = hash_len;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
180
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
181 salted_password = jabber_scram_hi(data->hash, pass, salt, iterations);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
182 g_string_free(pass, TRUE);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
183 if (!salted_password)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
184 return FALSE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
185
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
186 /* client_key = HMAC(salted_password, "Client Key") */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
187 hmac(data->hash, hash_len, client_key, salted_password, "Client Key");
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
188 /* server_key = HMAC(salted_password, "Server Key") */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
189 hmac(data->hash, hash_len, server_key, salted_password, "Server Key");
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
190 g_free(salted_password);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
191
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
192 /* stored_key = HASH(client_key) */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
193 hash(data->hash, hash_len, stored_key, client_key);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
194
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
195 /* client_signature = HMAC(stored_key, auth_message) */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
196 hmac(data->hash, hash_len, client_signature, stored_key, data->auth_message->str);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
197 /* server_signature = HMAC(server_key, auth_message) */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
198 hmac(data->hash, hash_len, (guchar *)data->server_signature->str, server_key, data->auth_message->str);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
199
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
200 /* client_proof = client_key XOR client_signature */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
201 for (i = 0; i < hash_len; ++i)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
202 data->client_proof->str[i] = client_key[i] ^ client_signature[i];
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
203
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
204 return TRUE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
205 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
206
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
207 static gboolean
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
208 parse_server_step1(JabberScramData *data, const char *challenge,
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
209 gchar **out_nonce, GString **out_salt, guint *out_iterations)
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
210 {
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
211 char **tokens;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
212 char *token, *decoded, *tmp;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
213 gsize len;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
214 char *nonce = NULL;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
215 GString *salt = NULL;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
216 guint iterations;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
217
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
218 tokens = g_strsplit(challenge, ",", -1);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
219 if (tokens == NULL)
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
220 return FALSE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
221
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
222 token = tokens[0];
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
223 if (token[0] != 'r' || token[1] != '=')
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
224 goto err;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
225
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
226 /* Ensure that the first cnonce_len bytes of the nonce are the original
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
227 * cnonce we sent to the server.
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
228 */
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
229 if (!g_str_equal(data->cnonce, token + 2))
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
230 goto err;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
231
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
232 nonce = g_strdup(token + 2);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
233
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
234 /* The Salt, base64-encoded */
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
235 token = tokens[1];
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
236 if (token[0] != 's' || token[1] != '=')
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
237 goto err;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
238
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
239 decoded = (gchar *)purple_base64_decode(token + 2, &len);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
240 if (!decoded || *decoded == '\0') {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
241 g_free(decoded);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
242 goto err;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
243 }
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
244 salt = g_string_new_len(decoded, len);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
245 g_free(decoded);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
246
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
247 /* The iteration count */
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
248 token = tokens[2];
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
249 if (token[0] != 'i' || token[1] != '=' || token[2] == '\0')
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
250 goto err;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
251
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
252 /* Validate the string */
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
253 for (tmp = token + 2; *tmp; ++tmp)
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
254 if (!g_ascii_isdigit(*tmp))
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
255 goto err;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
256
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
257 iterations = strtoul(token + 2, NULL, 10);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
258
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
259 g_strfreev(tokens);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
260 *out_nonce = nonce;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
261 *out_salt = salt;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
262 *out_iterations = iterations;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
263 return TRUE;
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
264
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
265 err:
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
266 g_free(nonce);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
267 g_string_free(salt, TRUE);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
268 g_strfreev(tokens);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
269 return FALSE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
270 }
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
271
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
272 static gboolean
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
273 parse_server_step2(JabberScramData *data, const char *challenge, gchar **out_verifier)
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
274 {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
275 char **tokens;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
276 char *token;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
277
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
278 tokens = g_strsplit(challenge, ",", -1);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
279 if (tokens == NULL)
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
280 return FALSE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
281
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
282 token = tokens[0];
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
283 if (token[0] != 'v' || token[1] != '=' || token[2] == '\0') {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
284 g_strfreev(tokens);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
285 return FALSE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
286 }
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
287
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
288 *out_verifier = g_strdup(token + 2);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
289 g_strfreev(tokens);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
290 return TRUE;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
291 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
292
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
293 static gboolean
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
294 feed_parser(JabberScramData *data, gchar *in, gchar **out)
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
295 {
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
296 gboolean ret;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
297
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
298 g_return_val_if_fail(data != NULL, FALSE);
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
299
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
300 g_string_append_c(data->auth_message, ',');
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
301 g_string_append(data->auth_message, in);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
302
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
303 if (data->step == 1) {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
304 gchar *nonce, *proof;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
305 GString *salt;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
306 guint iterations;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
307
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
308 ret = parse_server_step1(data, in, &nonce, &salt, &iterations);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
309 if (!ret)
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
310 return FALSE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
311
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
312 g_string_append_c(data->auth_message, ',');
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
313
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
314 /* "biwsCg==" is the base64 encoding of "n,,". I promise. */
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
315 g_string_append_printf(data->auth_message, "c=%s,r=%s", "biwsCg==", nonce);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
316 #ifdef CHANNEL_BINDING
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
317 #error fix this
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
318 #endif
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
319
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
320 ret = jabber_scram_calc_proofs(data, salt, iterations);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
321 if (!ret)
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
322 return FALSE;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
323
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
324 proof = purple_base64_encode((guchar *)data->client_proof->str, data->client_proof->len);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
325 *out = g_strdup_printf("c=%s,r=%s,p=%s", "biwsCg==", nonce, proof);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
326 g_free(proof);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
327 } else if (data->step == 2) {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
328 gchar *server_sig, *enc_server_sig;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
329 gsize len;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
330
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
331 ret = parse_server_step2(data, in, &enc_server_sig);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
332 if (!ret)
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
333 return FALSE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
334
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
335 server_sig = (gchar *)purple_base64_decode(enc_server_sig, &len);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
336 g_free(enc_server_sig);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
337
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
338 if (server_sig == NULL || len != data->server_signature->len) {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
339 g_free(server_sig);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
340 return FALSE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
341 }
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
342
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
343 if (0 != memcmp(server_sig, data->server_signature->str, len)) {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
344 g_free(server_sig);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
345 return FALSE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
346 }
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
347 g_free(server_sig);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
348
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
349 *out = NULL;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
350 } else {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
351 purple_debug_error("jabber", "SCRAM: There is no step %d\n", data->step);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
352 return FALSE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
353 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
354
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
355 return TRUE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
356 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
357
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
358 static xmlnode *scram_start(JabberStream *js, xmlnode *mechanisms)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
359 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
360 xmlnode *reply;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
361 JabberScramData *data;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
362 guint64 cnonce;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
363 #ifdef CHANNEL_BINDING
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
364 gboolean binding_supported = TRUE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
365 #endif
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
366 gchar *dec_out, *enc_out;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
367
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
368 data = js->auth_mech_data = g_new0(JabberScramData, 1);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
369 data->hash = mech_to_hash(js->auth_mech->name);
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
370 data->password = purple_connection_get_password(js->gc);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
371
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
372 #ifdef CHANNEL_BINDING
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
373 if (strstr(js->auth_mech_name, "-PLUS"))
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
374 data->channel_binding = TRUE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
375 #endif
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
376 cnonce = ((guint64)g_random_int() << 32) | g_random_int();
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
377 data->cnonce = purple_base64_encode((guchar *)cnonce, sizeof(cnonce));
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
378
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
379 data->auth_message = g_string_new(NULL);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
380 g_string_printf(data->auth_message, "n=%s,r=%s",
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
381 js->user->node /* TODO: SaslPrep */,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
382 data->cnonce);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
383
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
384 data->step = 1;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
385
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
386 reply = xmlnode_new("auth");
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
387 xmlnode_set_namespace(reply, "urn:ietf:params:xml:ns:xmpp-sasl");
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
388 xmlnode_set_attrib(reply, "mechanism", js->auth_mech->name);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
389
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
390 /* TODO: Channel binding */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
391 dec_out = g_strdup_printf("%c,,%s", 'n', data->auth_message->str);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
392 enc_out = purple_base64_encode((guchar *)dec_out, strlen(dec_out));
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
393 purple_debug_misc("jabber", "initial SCRAM message '%s'\n", dec_out);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
394
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
395 xmlnode_insert_data(reply, enc_out, -1);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
396
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
397 g_free(enc_out);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
398 g_free(dec_out);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
399
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
400 return reply;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
401 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
402
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
403 static xmlnode *scram_handle_challenge(JabberStream *js, xmlnode *challenge)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
404 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
405 JabberScramData *data = js->auth_mech_data;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
406 xmlnode *reply;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
407 gchar *enc_in, *dec_in;
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
408 gchar *enc_out = NULL, *dec_out = NULL;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
409 gsize len;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
410
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
411 enc_in = xmlnode_get_data(challenge);
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
412 if (!enc_in || *enc_in == '\0') {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
413 reply = xmlnode_new("abort");
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
414 xmlnode_set_namespace(reply, "urn:ietf:params:xml:ns:xmpp-sasl");
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
415 data->step = -1;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
416 goto out;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
417 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
418
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
419 dec_in = (gchar *)purple_base64_decode(enc_in, &len);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
420 g_free(enc_in);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
421 if (!dec_in || len != strlen(dec_in)) {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
422 /* Danger afoot; SCRAM shouldn't contain NUL bytes */
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
423 reply = xmlnode_new("abort");
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
424 xmlnode_set_namespace(reply, "urn:ietf:params:xml:ns:xmpp-sasl");
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
425 data->step = -1;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
426 goto out;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
427 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
428
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
429 purple_debug_misc("jabber", "decoded challenge: %s\n", dec_in);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
430
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
431 if (!feed_parser(data, dec_in, &dec_out)) {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
432 reply = xmlnode_new("abort");
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
433 xmlnode_set_namespace(reply, "urn:ietf:params:xml:ns:xmpp-sasl");
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
434 data->step = -1;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
435 goto out;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
436 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
437
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
438 data->step += 1;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
439
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
440 reply = xmlnode_new("response");
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
441 xmlnode_set_namespace(reply, "urn:ietf:params:xml:ns:xmpp-sasl");
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
442
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
443 purple_debug_misc("jabber", "decoded response: %s\n", dec_out ? dec_out : "(null)");
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
444 if (dec_out) {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
445 enc_out = purple_base64_encode((guchar *)dec_out, strlen(dec_out));
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
446 xmlnode_insert_data(reply, enc_out, -1);
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
447 }
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
448
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
449 out:
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
450 g_free(enc_out);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
451 g_free(dec_out);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
452
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
453 return reply;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
454 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
455
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
456 static gboolean scram_handle_success(JabberStream *js, xmlnode *packet)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
457 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
458 JabberScramData *data = js->auth_mech_data;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
459 char *enc_in, *dec_in;
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
460 char *dec_out = NULL;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
461 gsize len;
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
462
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
463 enc_in = xmlnode_get_data(packet);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
464 g_return_val_if_fail(enc_in != NULL && *enc_in != '\0', FALSE);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
465
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
466 if (data->step == 3)
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
467 return TRUE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
468
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
469 if (data->step != 2)
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
470 return FALSE;
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
471
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
472 dec_in = (gchar *)purple_base64_decode(enc_in, &len);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
473 g_free(enc_in);
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
474 if (!dec_in || len != strlen(dec_in)) {
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
475 /* Danger afoot; SCRAM shouldn't contain NUL bytes */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
476 g_free(dec_in);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
477 return FALSE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
478 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
479
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
480 purple_debug_misc("jabber", "decoded success: %s\n", dec_in);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
481
29091
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
482 if (!feed_parser(data, dec_in, &dec_out) || dec_out != NULL) {
b0fb53868142 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <paul@darkrain42.org>
parents: 29089
diff changeset
483 g_free(dec_out);
29089
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
484 return FALSE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
485 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
486
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
487 /* Hooray */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
488 return TRUE;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
489 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
490
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
491 static void scram_dispose(JabberStream *js)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
492 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
493 if (js->auth_mech_data) {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
494 JabberScramData *data = js->auth_mech_data;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
495
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
496 g_free(data->cnonce);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
497 if (data->auth_message)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
498 g_string_free(data->auth_message, TRUE);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
499 if (data->client_proof)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
500 g_string_free(data->client_proof, TRUE);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
501 if (data->server_signature)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
502 g_string_free(data->server_signature, TRUE);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
503 g_free(data);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
504 js->auth_mech_data = NULL;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
505 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
506 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
507
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
508 static JabberSaslMech scram_sha1_mech = {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
509 50, /* priority */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
510 "SCRAM-SHA-1", /* name */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
511 scram_start,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
512 scram_handle_challenge,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
513 scram_handle_success,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
514 NULL, /* handle_failure */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
515 scram_dispose
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
516 };
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
517
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
518 #ifdef CHANNEL_BINDING
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
519 /* With channel binding */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
520 static JabberSaslMech scram_sha1_plus_mech = {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
521 scram_sha1_mech.priority + 1, /* priority */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
522 "SCRAM-SHA-1-PLUS", /* name */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
523 scram_start,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
524 scram_handle_challenge,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
525 scram_handle_success,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
526 NULL, /* handle_failure */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
527 scram_dispose
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
528 };
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
529 #endif
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
530
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
531 /* For tests */
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
532 JabberSaslMech *jabber_scram_get_sha1(void)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
533 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
534 return &scram_sha1_mech;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
535 }
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
536
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
537 JabberSaslMech **jabber_auth_get_scram_mechs(gint *count)
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
538 {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
539 static JabberSaslMech *mechs[] = {
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
540 &scram_sha1_mech,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
541 #ifdef CHANNEL_BINDING
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
542 &scram_sha1_plus_mech,
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
543 #endif
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
544 };
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
545
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
546 g_return_val_if_fail(count != NULL, NULL);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
547
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
548 *count = G_N_ELEMENTS(mechs);
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
549 return mechs;
c1d41b7484ff jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents: 29088
diff changeset
550 }