Mercurial > pidgin.yaz
annotate libpurple/tests/test_jabber_scram.c @ 29099:464d022d7d6e
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
The non-libidn code has not been tested.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 30 Nov 2009 20:34:54 +0000 |
parents | 65a34cce02e3 |
children | 1c1910b17ae5 |
rev | line source |
---|---|
29086
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
1 #include <string.h> |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
2 |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
3 #include "tests.h" |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
4 #include "../util.h" |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
5 #include "../protocols/jabber/auth_scram.h" |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
6 |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
7 #define assert_pbkdf2_equal(password, salt, count, expected) { \ |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
8 GString *p = g_string_new(password); \ |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
9 GString *s = g_string_new(salt); \ |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
10 guchar *result = jabber_scram_hi("sha1", p, s, count); \ |
29086
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
11 fail_if(result == NULL, "Hi() returned NULL"); \ |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
12 fail_if(0 != memcmp(result, expected, 20), "Hi() returned invalid result"); \ |
29086
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
13 g_string_free(s, TRUE); \ |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
14 g_string_free(p, TRUE); \ |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
15 } |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
16 |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
17 START_TEST(test_pbkdf2) |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
18 { |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
19 assert_pbkdf2_equal("password", "salt", 1, "\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6"); |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
20 assert_pbkdf2_equal("password", "salt", 2, "\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a\xce\x1d\x41\xf0\xd8\xde\x89\x57"); |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
21 assert_pbkdf2_equal("password", "salt", 4096, "\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26\xf7\x21\xd0\x65\xa4\x29\xc1"); |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
22 |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
23 #if 0 |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
24 /* This causes libcheck to time out :-D */ |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
25 assert_pbkdf2_equal("password", "salt", 16777216, "\xee\xfe\x3d\x61\xcd\x4d\xa4\xe4\xe9\x94\x5b\x3d\x6b\xa2\x15\x8c\x26\x34\xe9\x84"); |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
26 #endif |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
27 } |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
28 END_TEST |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
29 |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
30 START_TEST(test_proofs) |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
31 { |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
32 JabberScramData *data = g_new0(JabberScramData, 1); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
33 gboolean ret; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
34 GString *salt; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
35 const char *client_proof; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
36 /* const char *server_signature; */ |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
37 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
38 data->hash = "sha1"; |
29099
464d022d7d6e
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <paul@darkrain42.org>
parents:
29093
diff
changeset
|
39 data->password = g_strdup("password"); |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
40 data->auth_message = g_string_new("n=username@jabber.org,r=8jLxB5515dhFxBil5A0xSXMH," |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
41 "r=8jLxB5515dhFxBil5A0xSXMHabc,s=c2FsdA==,i=1," |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
42 "c=biws,r=8jLxB5515dhFxBil5A0xSXMHabc"); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
43 client_proof = "\x48\x61\x30\xa5\x61\x0b\xae\xb9\xe4\x11\xa8\xfd\xa5\xcd\x34\x1d\x8a\x3c\x28\x17"; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
44 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
45 salt = g_string_new("salt"); |
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
|
46 ret = jabber_scram_calc_proofs(data, salt, 1); |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
47 fail_if(ret == FALSE, "Failed to calculate SCRAM proofs!"); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
48 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
49 fail_unless(0 == memcmp(client_proof, data->client_proof->str, 20)); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
50 g_string_free(salt, TRUE); |
29099
464d022d7d6e
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <paul@darkrain42.org>
parents:
29093
diff
changeset
|
51 |
464d022d7d6e
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <paul@darkrain42.org>
parents:
29093
diff
changeset
|
52 jabber_scram_data_destroy(data); |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
53 } |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
54 END_TEST |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
55 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
56 START_TEST(test_mech) |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
57 { |
29093
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
58 JabberScramData *data = g_new0(JabberScramData, 1); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
59 gboolean ret; |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
60 gchar *out; |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
61 |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
62 data->step = 1; |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
63 data->hash = "sha1"; |
29099
464d022d7d6e
jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <paul@darkrain42.org>
parents:
29093
diff
changeset
|
64 data->password = g_strdup("password"); |
29093
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
65 data->cnonce = g_strdup("H7yDYKAWBCrM2Fa5SxGa4iez"); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
66 data->auth_message = g_string_new("n=paul,r=H7yDYKAWBCrM2Fa5SxGa4iez"); |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
67 |
29093
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
68 ret = jabber_scram_feed_parser(data, "r=H7yDYKAWBCrM2Fa5SxGa4iezFPVDPpDUcGxPkH3RzP,s=3rXeErP/os7jUNqU,i=4096", &out); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
69 fail_unless(ret == TRUE); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
70 fail_unless(g_str_equal(out, "c=biws,r=H7yDYKAWBCrM2Fa5SxGa4iezFPVDPpDUcGxPkH3RzP,p=pXkak78EuwwOEwk2/h/OzD7NkEI="), "Failed. Got %s instead", out); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
71 g_free(out); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
72 |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
73 data->step = 2; |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
74 ret = jabber_scram_feed_parser(data, "v=ldX4EBNnOgDnNTOCmbSfBHAUCOs=", &out); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
75 fail_unless(ret == TRUE); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
76 fail_unless(out == NULL); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
77 |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
78 jabber_scram_data_destroy(data); |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
79 } |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
80 END_TEST |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
81 |
29086
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
82 Suite * |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
83 jabber_scram_suite(void) |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
84 { |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
85 Suite *s = suite_create("Jabber SASL SCRAM functions"); |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
86 |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
87 TCase *tc = tcase_create("PBKDF2 Functionality"); |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
88 tcase_add_test(tc, test_pbkdf2); |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
89 suite_add_tcase(s, tc); |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
90 |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
91 tc = tcase_create("SCRAM Proofs"); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
92 tcase_add_test(tc, test_proofs); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
93 suite_add_tcase(s, tc); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29086
diff
changeset
|
94 |
29093
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
95 tc = tcase_create("SCRAM exchange"); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
96 tcase_add_test(tc, test_mech); |
65a34cce02e3
jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <paul@darkrain42.org>
parents:
29091
diff
changeset
|
97 suite_add_tcase(s, tc); |
29086
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
98 return s; |
398ff52e7d62
Fix the Hi() function and actually 'mtn add' the test file.
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
99 } |