moved eap_from_string() fomr libcharon to libstrongswan to make it available in starter
[strongswan.git] / src / libstrongswan / credentials / auth_cfg.h
1 /*
2 * Copyright (C) 2007-2009 Martin Willi
3 * Copyright (C) 2008 Tobias Brunner
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup auth_cfg auth_cfg
19 * @{ @ingroup credentials
20 */
21
22 #ifndef AUTH_CFG_H_
23 #define AUTH_CFG_H_
24
25 #include <utils/enumerator.h>
26
27 typedef struct auth_cfg_t auth_cfg_t;
28 typedef enum auth_rule_t auth_rule_t;
29 typedef enum auth_class_t auth_class_t;
30 typedef enum eap_type_t eap_type_t;
31
32 /**
33 * Class of authentication to use. This is different to auth_method_t in that
34 * it does not specify a method, but a class of acceptable methods. The found
35 * certificate finally dictates wich method is used.
36 */
37 enum auth_class_t {
38 /** any class acceptable */
39 AUTH_CLASS_ANY = 0,
40 /** authentication using public keys (RSA, ECDSA) */
41 AUTH_CLASS_PUBKEY = 1,
42 /** authentication using a pre-shared secrets */
43 AUTH_CLASS_PSK = 2,
44 /** authentication using EAP */
45 AUTH_CLASS_EAP = 3,
46 };
47
48 /**
49 * enum strings for auth_class_t
50 */
51 extern enum_name_t *auth_class_names;
52
53 /**
54 * EAP types, defines the EAP method implementation
55 */
56 enum eap_type_t {
57 EAP_IDENTITY = 1,
58 EAP_NOTIFICATION = 2,
59 EAP_NAK = 3,
60 EAP_MD5 = 4,
61 EAP_OTP = 5,
62 EAP_GTC = 6,
63 EAP_TLS = 13,
64 EAP_SIM = 18,
65 EAP_TTLS = 21,
66 EAP_AKA = 23,
67 EAP_MSCHAPV2 = 26,
68 /** not a method, but an implementation providing different methods */
69 EAP_RADIUS = 253,
70 EAP_EXPANDED = 254,
71 EAP_EXPERIMENTAL = 255,
72 };
73
74 /**
75 * enum names for eap_type_t.
76 */
77 extern enum_name_t *eap_type_names;
78
79 /**
80 * short string enum names for eap_type_t.
81 */
82 extern enum_name_t *eap_type_short_names;
83
84 /**
85 * Lookup the EAP method type from a string.
86 *
87 * @param name EAP method name (such as "md5", "aka")
88 * @return method type, 0 if unkown
89 */
90 eap_type_t eap_type_from_string(char *name);
91
92 /**
93 * Authentication config to use during authentication process.
94 *
95 * Each authentication config contains a set of rules. These rule-sets are used
96 * in two ways:
97 * - For configs specifying local authentication behavior, the rules define
98 * which authentication method in which way.
99 * - For configs specifying remote peer authentication, the rules define
100 * constraints the peer has to fullfill.
101 *
102 * Additionally to the rules, there is a set of helper items. These are used
103 * to transport credentials during the authentication process.
104 */
105 enum auth_rule_t {
106
107 /** identity to use for IKEv2 authentication exchange, identification_t* */
108 AUTH_RULE_IDENTITY,
109 /** authentication class, auth_class_t */
110 AUTH_RULE_AUTH_CLASS,
111 /** EAP identity to use within EAP-Identity exchange, identification_t* */
112 AUTH_RULE_EAP_IDENTITY,
113 /** EAP type to propose for peer authentication, eap_type_t */
114 AUTH_RULE_EAP_TYPE,
115 /** EAP vendor for vendor specific type, u_int32_t */
116 AUTH_RULE_EAP_VENDOR,
117 /** certificate authority, certificate_t* */
118 AUTH_RULE_CA_CERT,
119 /** intermediate certificate in trustchain, certificate_t* */
120 AUTH_RULE_IM_CERT,
121 /** subject certificate, certificate_t* */
122 AUTH_RULE_SUBJECT_CERT,
123 /** result of a CRL validation, cert_validation_t */
124 AUTH_RULE_CRL_VALIDATION,
125 /** result of a OCSP validation, cert_validation_t */
126 AUTH_RULE_OCSP_VALIDATION,
127 /** subject is member of a group, identification_t*
128 * The group membership constraint is fulfilled if the subject is member of
129 * one group defined in the constraints. */
130 AUTH_RULE_GROUP,
131
132 /** intermediate certificate, certificate_t* */
133 AUTH_HELPER_IM_CERT,
134 /** subject certificate, certificate_t* */
135 AUTH_HELPER_SUBJECT_CERT,
136 /** Hash and URL of a intermediate certificate, char* */
137 AUTH_HELPER_IM_HASH_URL,
138 /** Hash and URL of a end-entity certificate, char* */
139 AUTH_HELPER_SUBJECT_HASH_URL,
140 };
141
142 /**
143 * enum name for auth_rule_t.
144 */
145 extern enum_name_t *auth_rule_names;
146
147 /**
148 * Authentication/Authorization round.
149 *
150 * RFC4739 defines multiple authentication rounds. This class defines such
151 * a round from a configuration perspective, either for the local or the remote
152 * peer. Local config are called "rulesets", as they define how we authenticate.
153 * Remote peer configs are called "constraits", they define what is needed to
154 * complete the authentication round successfully.
155 *
156 * @verbatim
157
158 [Repeat for each configuration]
159 +--------------------------------------------------+
160 | |
161 | |
162 | +----------+ IKE_AUTH +--------- + |
163 | | config | -----------> | | |
164 | | ruleset | | | |
165 | +----------+ [ <----------- ] | | |
166 | [ optional EAP ] | Peer | |
167 | +----------+ [ -----------> ] | | |
168 | | config | | | |
169 | | constr. | <----------- | | |
170 | +----------+ IKE_AUTH +--------- + |
171 | |
172 | |
173 +--------------------------------------------------+
174
175 @endverbatim
176 *
177 * Values for each items are either pointers (casted to void*) or short
178 * integers (use uintptr_t cast).
179 */
180 struct auth_cfg_t {
181
182 /**
183 * Add an rule to the set.
184 *
185 * @param rule rule type
186 * @param ... associated value to rule
187 */
188 void (*add)(auth_cfg_t *this, auth_rule_t rule, ...);
189
190 /**
191 * Get an rule value.
192 *
193 * @param rule rule type
194 * @return bool if item has been found
195 */
196 void* (*get)(auth_cfg_t *this, auth_rule_t rule);
197
198 /**
199 * Create an enumerator over added rules.
200 *
201 * @return enumerator over (auth_rule_t, union{void*,uintpr_t})
202 */
203 enumerator_t* (*create_enumerator)(auth_cfg_t *this);
204
205 /**
206 * Replace an rule at enumerator position.
207 *
208 * @param pos enumerator position position
209 * @param rule rule type
210 * @param ... associated value to rule
211 */
212 void (*replace)(auth_cfg_t *this, enumerator_t *pos,
213 auth_rule_t rule, ...);
214
215 /**
216 * Check if a used config fulfills a set of configured constraints.
217 *
218 * @param constraints required authorization rules
219 * @param log_error wheter to log compliance errors
220 * @return TRUE if this complies with constraints
221 */
222 bool (*complies)(auth_cfg_t *this, auth_cfg_t *constraints, bool log_error);
223
224 /**
225 * Merge items from other into this.
226 *
227 * @param other items to read for merge
228 * @param copy TRUE to copy items, FALSE to move them
229 */
230 void (*merge)(auth_cfg_t *this, auth_cfg_t *other, bool copy);
231
232 /**
233 * Purge all rules in a config.
234 *
235 * @param keep_ca wheter to keep AUTH_RULE_CA_CERT entries
236 */
237 void (*purge)(auth_cfg_t *this, bool keep_ca);
238
239 /**
240 * Check two configs for equality.
241 *
242 * @param other other config to compaire against this
243 * @return TRUE if auth infos identical
244 */
245 bool (*equals)(auth_cfg_t *this, auth_cfg_t *other);
246
247 /**
248 * Clone a authentication config, including all rules.
249 *
250 * @return cloned configuration
251 */
252 auth_cfg_t* (*clone)(auth_cfg_t *this);
253
254 /**
255 * Destroy a config with all associated rules/values.
256 */
257 void (*destroy)(auth_cfg_t *this);
258 };
259
260 /**
261 * Create a authentication config.
262 */
263 auth_cfg_t *auth_cfg_create();
264
265 #endif /** AUTH_CFG_H_ @}*/