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