Moved EAP type/code definitions to a seprate header file in libstrongswan
[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
31 /**
32 * Class of authentication to use. This is different to auth_method_t in that
33 * it does not specify a method, but a class of acceptable methods. The found
34 * certificate finally dictates wich method is used.
35 */
36 enum auth_class_t {
37 /** any class acceptable */
38 AUTH_CLASS_ANY = 0,
39 /** authentication using public keys (RSA, ECDSA) */
40 AUTH_CLASS_PUBKEY = 1,
41 /** authentication using a pre-shared secrets */
42 AUTH_CLASS_PSK = 2,
43 /** authentication using EAP */
44 AUTH_CLASS_EAP = 3,
45 };
46
47 /**
48 * enum strings for auth_class_t
49 */
50 extern enum_name_t *auth_class_names;
51
52 /**
53 * Authentication config to use during authentication process.
54 *
55 * Each authentication config contains a set of rules. These rule-sets are used
56 * in two ways:
57 * - For configs specifying local authentication behavior, the rules define
58 * which authentication method in which way.
59 * - For configs specifying remote peer authentication, the rules define
60 * constraints the peer has to fullfill.
61 *
62 * Additionally to the rules, there is a set of helper items. These are used
63 * to transport credentials during the authentication process.
64 */
65 enum auth_rule_t {
66
67 /** identity to use for IKEv2 authentication exchange, identification_t* */
68 AUTH_RULE_IDENTITY,
69 /** authentication class, auth_class_t */
70 AUTH_RULE_AUTH_CLASS,
71 /** EAP identity to use within EAP-Identity exchange, identification_t* */
72 AUTH_RULE_EAP_IDENTITY,
73 /** EAP type to propose for peer authentication, eap_type_t */
74 AUTH_RULE_EAP_TYPE,
75 /** EAP vendor for vendor specific type, u_int32_t */
76 AUTH_RULE_EAP_VENDOR,
77 /** certificate authority, certificate_t* */
78 AUTH_RULE_CA_CERT,
79 /** intermediate certificate in trustchain, certificate_t* */
80 AUTH_RULE_IM_CERT,
81 /** subject certificate, certificate_t* */
82 AUTH_RULE_SUBJECT_CERT,
83 /** result of a CRL validation, cert_validation_t */
84 AUTH_RULE_CRL_VALIDATION,
85 /** result of a OCSP validation, cert_validation_t */
86 AUTH_RULE_OCSP_VALIDATION,
87 /** subject is member of a group, identification_t*
88 * The group membership constraint is fulfilled if the subject is member of
89 * one group defined in the constraints. */
90 AUTH_RULE_GROUP,
91
92 /** intermediate certificate, certificate_t* */
93 AUTH_HELPER_IM_CERT,
94 /** subject certificate, certificate_t* */
95 AUTH_HELPER_SUBJECT_CERT,
96 /** Hash and URL of a intermediate certificate, char* */
97 AUTH_HELPER_IM_HASH_URL,
98 /** Hash and URL of a end-entity certificate, char* */
99 AUTH_HELPER_SUBJECT_HASH_URL,
100 };
101
102 /**
103 * enum name for auth_rule_t.
104 */
105 extern enum_name_t *auth_rule_names;
106
107 /**
108 * Authentication/Authorization round.
109 *
110 * RFC4739 defines multiple authentication rounds. This class defines such
111 * a round from a configuration perspective, either for the local or the remote
112 * peer. Local config are called "rulesets", as they define how we authenticate.
113 * Remote peer configs are called "constraits", they define what is needed to
114 * complete the authentication round successfully.
115 *
116 * @verbatim
117
118 [Repeat for each configuration]
119 +--------------------------------------------------+
120 | |
121 | |
122 | +----------+ IKE_AUTH +--------- + |
123 | | config | -----------> | | |
124 | | ruleset | | | |
125 | +----------+ [ <----------- ] | | |
126 | [ optional EAP ] | Peer | |
127 | +----------+ [ -----------> ] | | |
128 | | config | | | |
129 | | constr. | <----------- | | |
130 | +----------+ IKE_AUTH +--------- + |
131 | |
132 | |
133 +--------------------------------------------------+
134
135 @endverbatim
136 *
137 * Values for each items are either pointers (casted to void*) or short
138 * integers (use uintptr_t cast).
139 */
140 struct auth_cfg_t {
141
142 /**
143 * Add an rule to the set.
144 *
145 * @param rule rule type
146 * @param ... associated value to rule
147 */
148 void (*add)(auth_cfg_t *this, auth_rule_t rule, ...);
149
150 /**
151 * Get an rule value.
152 *
153 * @param rule rule type
154 * @return bool if item has been found
155 */
156 void* (*get)(auth_cfg_t *this, auth_rule_t rule);
157
158 /**
159 * Create an enumerator over added rules.
160 *
161 * @return enumerator over (auth_rule_t, union{void*,uintpr_t})
162 */
163 enumerator_t* (*create_enumerator)(auth_cfg_t *this);
164
165 /**
166 * Replace an rule at enumerator position.
167 *
168 * @param pos enumerator position position
169 * @param rule rule type
170 * @param ... associated value to rule
171 */
172 void (*replace)(auth_cfg_t *this, enumerator_t *pos,
173 auth_rule_t rule, ...);
174
175 /**
176 * Check if a used config fulfills a set of configured constraints.
177 *
178 * @param constraints required authorization rules
179 * @param log_error wheter to log compliance errors
180 * @return TRUE if this complies with constraints
181 */
182 bool (*complies)(auth_cfg_t *this, auth_cfg_t *constraints, bool log_error);
183
184 /**
185 * Merge items from other into this.
186 *
187 * @param other items to read for merge
188 * @param copy TRUE to copy items, FALSE to move them
189 */
190 void (*merge)(auth_cfg_t *this, auth_cfg_t *other, bool copy);
191
192 /**
193 * Purge all rules in a config.
194 *
195 * @param keep_ca wheter to keep AUTH_RULE_CA_CERT entries
196 */
197 void (*purge)(auth_cfg_t *this, bool keep_ca);
198
199 /**
200 * Check two configs for equality.
201 *
202 * @param other other config to compaire against this
203 * @return TRUE if auth infos identical
204 */
205 bool (*equals)(auth_cfg_t *this, auth_cfg_t *other);
206
207 /**
208 * Clone a authentication config, including all rules.
209 *
210 * @return cloned configuration
211 */
212 auth_cfg_t* (*clone)(auth_cfg_t *this);
213
214 /**
215 * Destroy a config with all associated rules/values.
216 */
217 void (*destroy)(auth_cfg_t *this);
218 };
219
220 /**
221 * Create a authentication config.
222 */
223 auth_cfg_t *auth_cfg_create();
224
225 #endif /** AUTH_CFG_H_ @}*/