Mercurial > pidgin.yaz
annotate libpurple/protocols/jabber/auth_scram.h @ 29089:c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Client proof calculations function properly, but parsing is untested.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 09 Nov 2009 03:42:26 +0000 |
parents | 338eeaf371e2 |
children | b0fb53868142 |
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 * @file auth_scram.h Implementation of SASL-SCRAM authentication |
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 |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
5 * |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
6 * 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
|
7 * 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
|
8 * source distribution. |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
9 * |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
10 * 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
|
11 * 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
|
12 * 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
|
13 * (at your option) any later version. |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
14 * |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
15 * 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
|
16 * 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
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
18 * GNU General Public License for more details. |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
19 * |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
20 * 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
|
21 * 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
|
22 * 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
|
23 */ |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
24 #ifndef PURPLE_JABBER_AUTH_SCRAM_H_ |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
25 #define PURPLE_JABBER_AUTH_SCRAM_H_ |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
26 |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
27 /* |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
28 * Every function in this file is ONLY exposed for tests. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
29 * DO NOT USE ANYTHING HERE OR YOU WILL BE SENT TO THE PIT OF DESPAIR. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
30 */ |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
31 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
32 /* Per-connection state stored between messages. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
33 * This is stored in js->auth_data_mech. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
34 */ |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
35 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
36 typedef struct { |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
37 const char *hash; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
38 char *cnonce; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
39 GString *auth_message; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
40 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
41 GString *client_proof; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
42 GString *server_signature; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
43 gboolean channel_binding; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
44 } JabberScramData; |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
45 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
46 #include "auth.h" |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
47 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
48 JabberSaslMech *jabber_scram_get_sha1(void); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
49 |
29085
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
50 /** |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
51 * Implements the Hi() function as described in the SASL-SCRAM I-D. |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
52 * |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
53 * @param hash The name of a hash function to be used with HMAC. This should |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
54 * be suitable to be passed to the libpurple cipher API. Typically |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
55 * it will be "sha1". |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
56 * @param str The string to perform the PBKDF2 operation on. |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
57 * @param salt The salt. |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
58 * @param iterations The number of iterations to perform. |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
59 * |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
60 * @returns A newly allocated string containing the result. The string is |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
61 * NOT null-terminated and its length is the length of the binary |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
62 * output of the hash function in-use. |
29085
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
63 */ |
29089
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
64 guchar *jabber_scram_hi(const char *hash, const GString *str, |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
65 GString *salt, guint iterations); |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
66 |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
67 /** |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
68 * Calculates the proofs as described in Section 3 of the SASL-SCRAM I-D. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
69 * |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
70 * @param data A JabberScramData structure. hash and auth_message must be |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
71 * set. client_proof and server_signature will be set as a result |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
72 * of this function. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
73 * @param password The user's password. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
74 * @param salt The salt (as specified by the server) |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
75 * @param iterations The number of iterations to perform. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
76 * |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
77 * @returns TRUE if the proofs were successfully calculated. FALSE otherwise. |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
78 */ |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
79 gboolean jabber_scram_calc_proofs(JabberScramData *data, const char *password, |
c1d41b7484ff
jabber: Complete (though untested) SCRAM implementation.
Paul Aurich <paul@darkrain42.org>
parents:
29085
diff
changeset
|
80 GString *salt, guint iterations); |
29085
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
81 |
338eeaf371e2
jabber: Add the Hi() function (PBKDF2).
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
82 #endif /* PURPLE_JABBER_AUTH_SCRAM_H_ */ |