- new configuration support added to ike_sa and states
[strongswan.git] / Source / charon / sa / ike_sa.h
1 /**
2 * @file ike_sa.h
3 *
4 * @brief Interface of ike_sa_id_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef IKE_SA_H_
24 #define IKE_SA_H_
25
26 #include <types.h>
27 #include <encoding/message.h>
28 #include <encoding/payloads/proposal_substructure.h>
29 #include <sa/ike_sa_id.h>
30 #include <config/configuration_manager.h>
31 #include <utils/logger.h>
32 #include <utils/randomizer.h>
33 #include <sa/states/state.h>
34 #include <transforms/prfs/prf.h>
35 #include <transforms/crypters/crypter.h>
36 #include <transforms/signers/signer.h>
37
38
39
40 /**
41 * Nonce size in bytes of all sent nonces
42 *
43 * @ingroup sa
44 */
45 #define NONCE_SIZE 16
46
47 typedef struct ike_sa_t ike_sa_t;
48
49 /**
50 * @brief Class ike_sa_t. An object of this type is managed by an
51 * ike_sa_manager_t object and represents an IKE_SA.
52 *
53 * @ingroup sa
54 */
55 struct ike_sa_t {
56
57 /**
58 * @brief Processes a incoming IKEv2-Message of type message_t
59 *
60 * @param this ike_sa_t object object
61 * @param[in] message message_t object to process
62 * @return SUCCESSFUL if succeeded, FAILED otherwise
63 */
64 status_t (*process_message) (ike_sa_t *this,message_t *message);
65
66 /**
67 * @brief Initiate a new connection with given configuration name.
68 *
69 * @param this calling object
70 * @param name name of the configuration
71 * @return TODO
72 */
73 status_t (*initialize_connection) (ike_sa_t *this, char *name);
74
75 /**
76 * @brief Get the id of the SA.
77 *
78 * @param this ike_sa_t object object
79 * @return ike_sa's ike_sa_id_t
80 */
81 ike_sa_id_t* (*get_id) (ike_sa_t *this);
82
83 /**
84 * @brief Destroys a ike_sa_t object.
85 *
86 * @param this ike_sa_t object
87 */
88 void (*destroy) (ike_sa_t *this);
89 };
90
91 typedef struct protected_ike_sa_t protected_ike_sa_t;
92
93 /**
94 * @brief Protected data of an ike_sa_t object.
95 *
96 * This members should only be accessed from
97 * the varius state classes.
98 *
99 * @ingroup sa
100 */
101 struct protected_ike_sa_t {
102
103 /**
104 * Public part of a ike_sa_t object
105 */
106 ike_sa_t public;
107
108 /**
109 * Builds an empty IKEv2-Message and fills in default informations.
110 *
111 * Depending on the type of message (request or response), the message id is
112 * either message_id_out or message_id_in.
113 *
114 * Used in every state.
115 *
116 * @param this calling object
117 * @param type exchange type of new message
118 * @param request TRUE, if message has to be a request
119 * @param message new message is stored at this location
120 */
121 void (*build_message) (protected_ike_sa_t *this, exchange_type_t type, bool request, message_t **message);
122
123 /**
124 * Initiate a new connection with given configuration name
125 *
126 * @param this calling object
127 * @param dh_shared_secret shared secret of diffie hellman exchange
128 * @param initiator_nonce nonce of initiator
129 * @param responder_nonce nonce of responder
130 */
131 void (*compute_secrets) (protected_ike_sa_t *this,chunk_t dh_shared_secret,chunk_t initiator_nonce, chunk_t responder_nonce);
132
133 /**
134 * Gets the internal stored logger_t object for given ike_sa_t object.
135 *
136 * @param this calling object
137 * @return pointer to the internal stored logger_t object
138 */
139 logger_t *(*get_logger) (protected_ike_sa_t *this);
140
141 /**
142 * Gets the internal stored init_config_t object.
143 *
144 * Returned value has to get checked for NULL value!
145 *
146 * @param this calling object
147 * @return pointer to the internal stored init_config_t object
148 */
149 init_config_t *(*get_init_config) (protected_ike_sa_t *this);
150
151 /**
152 * Sets the internal init_config_t object.
153 *
154 * @param this calling object
155 * @param init_config object of type init_config_t
156 */
157 void (*set_init_config) (protected_ike_sa_t *this,init_config_t *init_config);
158
159 /**
160 * Gets the internal stored sa_config_t object.
161 *
162 * Returned value has to get checked for NULL value!
163 *
164 * @param this calling object
165 * @return pointer to the internal stored sa_config_t object
166 */
167 sa_config_t *(*get_sa_config) (protected_ike_sa_t *this);
168
169 /**
170 * Sets the internal sa_config_t object.
171 *
172 * @param this calling object
173 * @param sa_config object of type sa_config_t
174 */
175 void (*set_sa_config) (protected_ike_sa_t *this,sa_config_t *sa_config);
176
177 /**
178 * Gets the internal stored host_t object for my host.
179 *
180 * @param this calling object
181 * @return pointer to the internal stored host_t object
182 */
183 host_t *(*get_my_host) (protected_ike_sa_t *this);
184
185 /**
186 * Gets the internal stored host_t object for other host.
187 *
188 * @param this calling object
189 * @return pointer to the internal stored host_t object
190 */
191 host_t *(*get_other_host) (protected_ike_sa_t *this);
192
193 /**
194 * Sets the internal stored host_t object for my host.
195 *
196 * Allready existing object gets destroyed. object gets not cloned!
197 *
198 * @param this calling object
199 * @param my_host pointer to the new host_t object
200 */
201 void (*set_my_host) (protected_ike_sa_t *this,host_t * my_host);
202
203 /**
204 * Sets the internal stored host_t object for other host.
205 *
206 * Allready existing object gets destroyed. object gets not cloned!
207 *
208 * @param this calling object
209 * @param other_host pointer to the new host_t object
210 */
211 void (*set_other_host) (protected_ike_sa_t *this,host_t *other_host);
212
213 /**
214 * Creates all needed transform objects for given ike_sa_t using
215 * the informations stored in a ike_proposal_t object
216 *
217 * Allready existing objects get destroyed.
218 *
219 * @param this calling object
220 * @param proposal proposal used to get informations for transform
221 * objects (algorithms, key lengths, etc.)
222 */
223 status_t (*create_transforms_from_proposal) (protected_ike_sa_t *this,ike_proposal_t * proposal);
224
225 /**
226 * Sets the last requested message.
227 *
228 * Allready set last requested message gets destroyed. object gets not cloned!
229 *
230 * @param this calling object
231 * @param message pointer to the new last requested message
232 * @return
233 * - SUCCESS
234 * - FAILED if message id is not next expected one
235 */
236 status_t (*set_last_requested_message) (protected_ike_sa_t *this,message_t * message);
237
238 /**
239 * Sets the last responded message.
240 *
241 * Allready set last requested message gets destroyed. object gets not cloned!
242 *
243 * @param this calling object
244 * @param message pointer to the new last responded message
245 * return
246 * - SUCCESS
247 * - FAILED if message id is not next expected one
248 */
249 status_t (*set_last_responded_message) (protected_ike_sa_t *this,message_t * message);
250
251 /**
252 * Gets the internal stored randomizer_t object.
253 *
254 * @param this calling object
255 * @return pointer to the internal randomizer_t object
256 */
257 randomizer_t *(*get_randomizer) (protected_ike_sa_t *this);
258
259 /**
260 * Sets the new state_t object of the IKE_SA object.
261 *
262 * The old state_t object gets not destroyed. It's the callers duty to
263 * make sure old state is destroyed (Normally the old state is the caller ).
264 *
265 * @param this calling object
266 * @param state pointer to the new state_t object
267 */
268 void (*set_new_state) (protected_ike_sa_t *this,state_t *state);
269
270 /**
271 * Gets the internal stored initiator crypter_t object.
272 *
273 * @param this calling object
274 * @return pointer to crypter_t object
275 */
276 crypter_t *(*get_crypter_initiator) (protected_ike_sa_t *this);
277
278 /**
279 * Gets the internal stored initiator signer object.
280 *
281 * @param this calling object
282 * @return pointer to signer_t object
283 */
284 signer_t *(*get_signer_initiator) (protected_ike_sa_t *this);
285
286 };
287
288
289
290 /**
291 * Creates an ike_sa_t object with a specific ike_sa_id_t object
292 *
293 * @param[in] ike_sa_id ike_sa_id_t object to associate with new IKE_SA.
294 * The object is internal getting cloned
295 * and so has to be destroyed by the caller.
296 *
297 * @warning the Content of internal ike_sa_id_t object can change over time
298 * e.g. when a IKE_SA_INIT has been finished.
299 *
300 * @return created ike_sa_t object
301 *
302 * @ingroup sa
303 */
304 ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id);
305
306 #endif /*IKE_SA_H_*/