29c6634b8e1c89b112e815b41aa4d4ade68a93ab
[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 * Authentication config to use during authentication process.
86 *
87 * Each authentication config contains a set of rules. These rule-sets are used
88 * in two ways:
89 * - For configs specifying local authentication behavior, the rules define
90 * which authentication method in which way.
91 * - For configs specifying remote peer authentication, the rules define
92 * constraints the peer has to fullfill.
93 *
94 * Additionally to the rules, there is a set of helper items. These are used
95 * to transport credentials during the authentication process.
96 */
97 enum auth_rule_t {
98
99 /** identity to use for IKEv2 authentication exchange, identification_t* */
100 AUTH_RULE_IDENTITY,
101 /** authentication class, auth_class_t */
102 AUTH_RULE_AUTH_CLASS,
103 /** EAP identity to use within EAP-Identity exchange, identification_t* */
104 AUTH_RULE_EAP_IDENTITY,
105 /** EAP type to propose for peer authentication, eap_type_t */
106 AUTH_RULE_EAP_TYPE,
107 /** EAP vendor for vendor specific type, u_int32_t */
108 AUTH_RULE_EAP_VENDOR,
109 /** certificate authority, certificate_t* */
110 AUTH_RULE_CA_CERT,
111 /** intermediate certificate in trustchain, certificate_t* */
112 AUTH_RULE_IM_CERT,
113 /** subject certificate, certificate_t* */
114 AUTH_RULE_SUBJECT_CERT,
115 /** result of a CRL validation, cert_validation_t */
116 AUTH_RULE_CRL_VALIDATION,
117 /** result of a OCSP validation, cert_validation_t */
118 AUTH_RULE_OCSP_VALIDATION,
119 /** subject is member of a group, identification_t*
120 * The group membership constraint is fulfilled if the subject is member of
121 * one group defined in the constraints. */
122 AUTH_RULE_GROUP,
123
124 /** intermediate certificate, certificate_t* */
125 AUTH_HELPER_IM_CERT,
126 /** subject certificate, certificate_t* */
127 AUTH_HELPER_SUBJECT_CERT,
128 /** Hash and URL of a intermediate certificate, char* */
129 AUTH_HELPER_IM_HASH_URL,
130 /** Hash and URL of a end-entity certificate, char* */
131 AUTH_HELPER_SUBJECT_HASH_URL,
132 };
133
134 /**
135 * enum name for auth_rule_t.
136 */
137 extern enum_name_t *auth_rule_names;
138
139 /**
140 * Authentication/Authorization round.
141 *
142 * RFC4739 defines multiple authentication rounds. This class defines such
143 * a round from a configuration perspective, either for the local or the remote
144 * peer. Local config are called "rulesets", as they define how we authenticate.
145 * Remote peer configs are called "constraits", they define what is needed to
146 * complete the authentication round successfully.
147 *
148 * @verbatim
149
150 [Repeat for each configuration]
151 +--------------------------------------------------+
152 | |
153 | |
154 | +----------+ IKE_AUTH +--------- + |
155 | | config | -----------> | | |
156 | | ruleset | | | |
157 | +----------+ [ <----------- ] | | |
158 | [ optional EAP ] | Peer | |
159 | +----------+ [ -----------> ] | | |
160 | | config | | | |
161 | | constr. | <----------- | | |
162 | +----------+ IKE_AUTH +--------- + |
163 | |
164 | |
165 +--------------------------------------------------+
166
167 @endverbatim
168 *
169 * Values for each items are either pointers (casted to void*) or short
170 * integers (use uintptr_t cast).
171 */
172 struct auth_cfg_t {
173
174 /**
175 * Add an rule to the set.
176 *
177 * @param rule rule type
178 * @param ... associated value to rule
179 */
180 void (*add)(auth_cfg_t *this, auth_rule_t rule, ...);
181
182 /**
183 * Get an rule value.
184 *
185 * @param rule rule type
186 * @return bool if item has been found
187 */
188 void* (*get)(auth_cfg_t *this, auth_rule_t rule);
189
190 /**
191 * Create an enumerator over added rules.
192 *
193 * @return enumerator over (auth_rule_t, union{void*,uintpr_t})
194 */
195 enumerator_t* (*create_enumerator)(auth_cfg_t *this);
196
197 /**
198 * Replace an rule at enumerator position.
199 *
200 * @param pos enumerator position position
201 * @param rule rule type
202 * @param ... associated value to rule
203 */
204 void (*replace)(auth_cfg_t *this, enumerator_t *pos,
205 auth_rule_t rule, ...);
206
207 /**
208 * Check if a used config fulfills a set of configured constraints.
209 *
210 * @param constraints required authorization rules
211 * @param log_error wheter to log compliance errors
212 * @return TRUE if this complies with constraints
213 */
214 bool (*complies)(auth_cfg_t *this, auth_cfg_t *constraints, bool log_error);
215
216 /**
217 * Merge items from other into this.
218 *
219 * @param other items to read for merge
220 * @param copy TRUE to copy items, FALSE to move them
221 */
222 void (*merge)(auth_cfg_t *this, auth_cfg_t *other, bool copy);
223
224 /**
225 * Purge all rules in a config.
226 *
227 * @param keep_ca wheter to keep AUTH_RULE_CA_CERT entries
228 */
229 void (*purge)(auth_cfg_t *this, bool keep_ca);
230
231 /**
232 * Check two configs for equality.
233 *
234 * @param other other config to compaire against this
235 * @return TRUE if auth infos identical
236 */
237 bool (*equals)(auth_cfg_t *this, auth_cfg_t *other);
238
239 /**
240 * Clone a authentication config, including all rules.
241 *
242 * @return cloned configuration
243 */
244 auth_cfg_t* (*clone)(auth_cfg_t *this);
245
246 /**
247 * Destroy a config with all associated rules/values.
248 */
249 void (*destroy)(auth_cfg_t *this);
250 };
251
252 /**
253 * Create a authentication config.
254 */
255 auth_cfg_t *auth_cfg_create();
256
257 #endif /** AUTH_CFG_H_ @}*/