libpurple/protocols/jabber/auth_scram.h

Sun, 16 Jun 2013 05:59:31 +0530

author
Ankit Vani <a@nevitus.org>
date
Sun, 16 Jun 2013 05:59:31 +0530
branch
soc.2013.gobjectification
changeset 34567
ea5103f66b0e
parent 34556
087db73b115d
child 35026
fde23518e1e5
permissions
-rw-r--r--

Refactor the codebase to use PurpleHash

28862
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
1 /**
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
2 * @file auth_scram.h Implementation of SASL-SCRAM authentication
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
3 *
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
4 * purple
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
5 *
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
6 * Purple is the legal property of its developers, whose names are too numerous
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
8 * source distribution.
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
9 *
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
13 * (at your option) any later version.
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
14 *
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
18 * GNU General Public License for more details.
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
19 *
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
23 */
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
24 #ifndef PURPLE_JABBER_AUTH_SCRAM_H_
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
25 #define PURPLE_JABBER_AUTH_SCRAM_H_
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
26
28866
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
27 /*
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
28 * Every function in this file is ONLY exposed for tests.
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
29 * DO NOT USE ANYTHING HERE OR YOU WILL BE SENT TO THE PIT OF DESPAIR.
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
30 */
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
31
34567
ea5103f66b0e Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents: 34556
diff changeset
32 #include "hash.h"
34556
087db73b115d Refactored protocols bonjour, gg, jabber to use the GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 29081
diff changeset
33
28866
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
34 /* Per-connection state stored between messages.
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
35 * This is stored in js->auth_data_mech.
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
36 */
29081
ce668db953aa jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29027
diff changeset
37 typedef struct {
ce668db953aa jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29027
diff changeset
38 const char *mech_substr;
34567
ea5103f66b0e Refactor the codebase to use PurpleHash
Ankit Vani <a@nevitus.org>
parents: 34556
diff changeset
39 PurpleHash *(*new_cipher)(void);
29081
ce668db953aa jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29027
diff changeset
40 guint size;
ce668db953aa jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29027
diff changeset
41 } JabberScramHash;
28866
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
42
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
43 typedef struct {
29081
ce668db953aa jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29027
diff changeset
44 const JabberScramHash *hash;
28866
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
45 char *cnonce;
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
46 GString *auth_message;
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
47
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
48 GString *client_proof;
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
49 GString *server_signature;
29027
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28926
diff changeset
50
6af29b140195 jabber: Add SASLprep and the username substitution called for in draft-ietf-sasl-scram-10 5.1.
Paul Aurich <darkrain42@pidgin.im>
parents: 28926
diff changeset
51 gchar *password;
28866
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
52 gboolean channel_binding;
28868
7415cb6c4587 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents: 28866
diff changeset
53 int step;
28866
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
54 } JabberScramData;
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
55
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
56 #include "auth.h"
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
57
28862
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
58 /**
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
59 * Implements the Hi() function as described in the SASL-SCRAM I-D.
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
60 *
29081
ce668db953aa jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29027
diff changeset
61 * @param hash The struct corresponding to the hash function to be used.
28862
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
62 * @param str The string to perform the PBKDF2 operation on.
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
63 * @param salt The salt.
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
64 * @param iterations The number of iterations to perform.
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
65 *
28866
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
66 * @returns A newly allocated string containing the result. The string is
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
67 * NOT null-terminated and its length is the length of the binary
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
68 * output of the hash function in-use.
28862
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
69 */
29081
ce668db953aa jabber: Clean up the SCRAM code a little.
Paul Aurich <darkrain42@pidgin.im>
parents: 29027
diff changeset
70 guchar *jabber_scram_hi(const JabberScramHash *hash, const GString *str,
28866
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
71 GString *salt, guint iterations);
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
72
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
73 /**
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
74 * Calculates the proofs as described in Section 3 of the SASL-SCRAM I-D.
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
75 *
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
76 * @param data A JabberScramData structure. hash and auth_message must be
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
77 * set. client_proof and server_signature will be set as a result
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
78 * of this function.
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
79 * @param salt The salt (as specified by the server)
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
80 * @param iterations The number of iterations to perform.
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
81 *
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
82 * @returns TRUE if the proofs were successfully calculated. FALSE otherwise.
e3d867ce000b jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <darkrain42@pidgin.im>
parents: 28862
diff changeset
83 */
28868
7415cb6c4587 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents: 28866
diff changeset
84 gboolean jabber_scram_calc_proofs(JabberScramData *data, GString *salt,
7415cb6c4587 jabber: Handle the case where the server success-with-data is sent as a challenge/response pair.
Paul Aurich <darkrain42@pidgin.im>
parents: 28866
diff changeset
85 guint iterations);
28862
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
86
28926
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
87 /**
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
88 * Feed the algorithm with the data from the server.
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
89 */
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
90 gboolean jabber_scram_feed_parser(JabberScramData *data, gchar *in, gchar **out);
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
91
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
92 /**
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
93 * Clean up and destroy the data struct
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
94 */
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
95 void jabber_scram_data_destroy(JabberScramData *data);
a737800d1445 jabber: Fix up the remaining issues and add a test case that interoperates with gsasl. Woot.
Paul Aurich <darkrain42@pidgin.im>
parents: 28868
diff changeset
96
28862
8a37b7df0850 jabber: Add the Hi() function (PBKDF2).
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
97 #endif /* PURPLE_JABBER_AUTH_SCRAM_H_ */

mercurial