mech.h revision 1.1
1/* $Id: mech.h,v 1.1 2010/11/27 21:23:59 agc Exp $ */
2
3/* Copyright (c) 2010 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Mateusz Kocielski.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *        This product includes software developed by the NetBSD
20 *        Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 *    contributors may be used to endorse or promote products derived
23 *    from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED.	IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _MECH_H_
39#define _MECH_H_
40
41#include <stdint.h>
42#include <sys/queue.h>
43#include "dict.h"
44
45/** mechanism status */
46enum {
47	STATUS_AUTHENTICATION,	/**< authentication in progress */
48	STATUS_AUTHENTICATED	/**< session authenticated. this value is used
49				   after last step of the authentication and
50				   means only that last step was performed. */
51};
52
53/** mechanism flags - currently unused */
54enum {
55	FLAG_NONE	= 0, 		/**< none flag */
56	FLAG_ANONYMOUS	= 1 << 0,	/**< anonymous authentication */
57	FLAG_DICTIONARY = 1 << 1,	/**< dictionary attack against
58					 * authentication is possible */
59	FLAG_PLAINTEXT	= 1 << 2,	/**< mechanism uses plaintext for sharing
60				  	   secrets */
61	FLAG_MUTUAL	= 1 << 3	/**< mutual authentication */
62};
63
64/** mechanism cont return values - used by _cont() functions */
65enum {
66	MECH_ERROR	= -1,	/**< error */
67	MECH_OK		= 0,	/**< mechanism authenticated */
68	MECH_STEP	= 1	/**< mechanism needs one or more steps more */
69};
70
71/** mechanism session */
72typedef struct saslc__mech_sess_t {
73	uint32_t status;	/**< status of authentication */
74	uint32_t step;		/**< step counter */
75} saslc__mech_sess_t;
76
77/* mechanism functions */
78typedef int (*saslc__mech_create_t)(saslc_sess_t *);
79typedef int (*saslc__mech_cont_t)(saslc_sess_t *, const void *, size_t,
80    void **, size_t *);
81typedef int (*saslc__mech_encode_t)(saslc_sess_t *, const void *, size_t,
82    void **, size_t *);
83typedef int (*saslc__mech_decode_t)(saslc_sess_t *, const void *, size_t,
84    void **, size_t *);
85typedef int (*saslc__mech_destroy_t)(saslc_sess_t *);
86
87/** mechanism structure */
88typedef struct saslc__mech_t {
89	const char *name; /**< mechanism name */
90	const uint32_t flags; /**< mechanism flags */
91	saslc__mech_create_t create; /**< create function - creates mechanism
92					instance */
93	saslc__mech_cont_t cont; /**< step function - performs one step of
94					authentication */
95	saslc__mech_encode_t encode; /**< encoding function - encodes input
96					according to negotiated security
97					layer */
98	saslc__mech_decode_t decode; /**< decoding function - decodes input
99					according to negotiated security
100					layer */
101	saslc__mech_destroy_t destroy; /**< destroy function - destroys
102					  mechanism instance */
103} saslc__mech_t;
104
105/** mechanism list */
106
107/* mechanisms list node */
108typedef struct saslc__mech_list_node_t {
109	LIST_ENTRY(saslc__mech_list_node_t) nodes;
110	const saslc__mech_t *mech; /**< mechanism */
111	saslc__dict_t *prop; /**< mechanism configuration */
112} saslc__mech_list_node_t;
113
114/* mechanisms list head */
115typedef struct saslc__mech_list_t saslc__mech_list_t;
116LIST_HEAD(saslc__mech_list_t, saslc__mech_list_node_t);
117
118/* mechanism list functions */
119saslc__mech_list_t *saslc__mech_list_create(saslc_t *);
120void saslc__mech_list_destroy(saslc__mech_list_t *);
121saslc__mech_list_node_t *saslc__mech_list_get(saslc__mech_list_t *, const char *);
122
123/* generic functions */
124int saslc__mech_generic_create(saslc_sess_t *);
125int saslc__mech_generic_destroy(saslc_sess_t *);
126
127/* additional functions */
128int saslc__mech_strdup(saslc_sess_t *, char **, size_t *, const char *,
129    const char *);
130
131#endif /* ! _MECH_H_ */
132