updated some inline docs
[strongswan.git] / src / charon / sa / ike_sa.h
1 /**
2 * @file ike_sa.h
3 *
4 * @brief Interface of ike_sa_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
10 * Copyright (C) 2005-2006 Martin Willi
11 * Copyright (C) 2005 Jan Hutter
12 * Hochschule fuer Technik Rapperswil
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 */
24
25 #ifndef IKE_SA_H_
26 #define IKE_SA_H_
27
28 #include <types.h>
29 #include <encoding/message.h>
30 #include <encoding/payloads/proposal_substructure.h>
31 #include <sa/ike_sa_id.h>
32 #include <sa/child_sa.h>
33 #include <config/configuration.h>
34 #include <utils/logger.h>
35 #include <utils/randomizer.h>
36 #include <crypto/prfs/prf.h>
37 #include <crypto/crypters/crypter.h>
38 #include <crypto/signers/signer.h>
39 #include <config/connections/connection.h>
40 #include <config/policies/policy.h>
41 #include <config/proposal.h>
42 #include <utils/logger.h>
43
44
45 typedef enum ike_sa_state_t ike_sa_state_t;
46
47 /**
48 * @brief State of an IKE_SA.
49 *
50 * An IKE_SA passes various states in its lifetime. A newly created
51 * SA is in the state CREATED.
52 * @verbatim
53 +----------------+
54 ¦ SA_CREATED ¦
55 +----------------+
56 ¦
57 on initiate()---> ¦ <----- on IKE_SA_INIT received
58 ¦
59 +----------------+
60 ¦ SA_CONNECTING ¦
61 +----------------+
62 ¦
63 ¦ <----- on IKE_AUTH successfully completed
64 ¦
65 +----------------+
66 ¦ SA_ESTABLISHED ¦
67 +----------------+
68 ¦
69 on delete()---> ¦ <----- on IKE_SA delete request received
70 ¦
71 +----------------+
72 ¦ SA_DELETING ¦
73 +----------------+
74 ¦
75 ¦ <----- after delete() acknowledged
76 ¦
77 \¦/
78 X
79 / \
80 @endverbatim
81 *
82 * @ingroup sa
83 */
84 enum ike_sa_state_t {
85
86 /**
87 * IKE_SA just got created, but is not initiating nor responding yet.
88 */
89 SA_CREATED,
90
91 /**
92 * IKE_SA gets initiated actively or passively
93 */
94 SA_CONNECTING,
95
96 /**
97 * IKE_SA is fully established
98 */
99 SA_ESTABLISHED,
100
101 /**
102 * IKE_SA is in progress of deletion
103 */
104 SA_DELETING,
105 };
106
107 /**
108 * String mappings for ike_sa_state_t.
109 */
110 extern mapping_t ike_sa_state_m[];
111
112
113 typedef struct ike_sa_t ike_sa_t;
114
115 /**
116 * @brief Class ike_sa_t representing an IKE_SA.
117 *
118 * An IKE_SA contains crypto information related to a connection
119 * with a peer. It contains multiple IPsec CHILD_SA, for which
120 * it is responsible. All traffic is handled by an IKE_SA, using
121 * transactions.
122 *
123 * @b Constructors:
124 * - ike_sa_create()
125 *
126 * @ingroup sa
127 */
128 struct ike_sa_t {
129
130 /**
131 * @brief Get the id of the SA.
132 *
133 * Returned ike_sa_id_t object is not getting cloned!
134 *
135 * @param this calling object
136 * @return ike_sa's ike_sa_id_t
137 */
138 ike_sa_id_t* (*get_id) (ike_sa_t *this);
139
140 /**
141 * @brief Get the state of the IKE_SA.
142 *
143 * @param this calling object
144 * @return state of the IKE_SA
145 */
146 ike_sa_state_t (*get_state) (ike_sa_t *this);
147
148 /**
149 * @brief Set the state of the IKE_SA.
150 *
151 * @param this calling object
152 * @param state state to set for the IKE_SA
153 */
154 void (*set_state) (ike_sa_t *this, ike_sa_state_t ike_sa);
155
156 /**
157 * @brief Initiate a new connection.
158 *
159 * The connection_t object is owned by the IKE_SA after the call, so
160 * do not modify or destroy it.
161 *
162 * @param this calling object
163 * @param connection connection to initiate
164 * @return
165 * - SUCCESS if initialization started
166 * - DESTROY_ME if initialization failed and IKE_SA MUST be deleted
167 */
168 status_t (*initiate) (ike_sa_t *this, connection_t *connection);
169
170 /**
171 * @brief Initiates the deletion of an IKE_SA.
172 *
173 * Sends a delete message to the remote peer and waits for
174 * its response. If the response comes in, or a timeout occurs,
175 * the IKE SA gets deleted.
176 *
177 * @param this calling object
178 * @return
179 * - SUCCESS if deletion is initialized
180 * - INVALID_STATE, if the IKE_SA is not in
181 * an established state and can not be
182 * delete (but destroyed).
183 */
184 status_t (*delete) (ike_sa_t *this);
185
186 /**
187 * @brief Retransmits a request.
188 *
189 * @param this calling object
190 * @param message_id ID of the request to retransmit
191 * @return
192 * - SUCCESS
193 * - NOT_FOUND if request doesn't have to be retransmited
194 */
195 status_t (*retransmit_request) (ike_sa_t *this, u_int32_t message_id);
196
197 /**
198 * @brief Processes a incoming IKEv2-Message.
199 *
200 * Message processing may fail. If a critical failure occurs,
201 * process_message() return DESTROY_ME. Then the caller must
202 * destroy the IKE_SA immediatly, as it is unusable.
203 *
204 * @param this calling object
205 * @param[in] message message to process
206 * @return
207 * - SUCCESS
208 * - FAILED
209 * - DESTROY_ME if this IKE_SA MUST be deleted
210 */
211 status_t (*process_message) (ike_sa_t *this, message_t *message);
212
213 /**
214 * @brief Check if NAT traversal is enabled for this IKE_SA.
215 *
216 * @param this calling object
217 * @return TRUE if NAT traversal enabled
218 */
219 bool (*is_natt_enabled) (ike_sa_t *this);
220
221 /**
222 * @brief Enable NAT detection for this IKE_SA.
223 *
224 * If a Network address translation is detected with
225 * NAT_DETECTION notifys, a SA must switch to ports
226 * 4500. To enable this behavior, call enable_natt().
227 * It is relevant which peer is NATted, this is specified
228 * with the "local" parameter. Call it twice when both
229 * are NATted.
230 *
231 * @param this calling object
232 * @param local TRUE, if we are NATted, FALSE if other
233 */
234 void (*enable_natt) (ike_sa_t *this, bool local);
235
236 /**
237 * @brief Sends a DPD request to the peer.
238 *
239 * To check if a peer is still alive, periodic
240 * empty INFORMATIONAL messages are sent if no
241 * other traffic was received.
242 *
243 * @param this calling object
244 * @return
245 * - SUCCESS
246 * - DESTROY_ME, if peer did not respond
247 */
248 status_t (*send_dpd) (ike_sa_t *this);
249
250 /**
251 * @brief Sends a keep alive packet.
252 *
253 * To refresh NAT tables in a NAT router
254 * between the peers, periodic empty
255 * UDP packets are sent if no other traffic
256 * was sent.
257 *
258 * @param this calling object
259 */
260 void (*send_keepalive) (ike_sa_t *this);
261
262 /**
263 * @brief Log the status of a the ike sa to a logger.
264 *
265 * The status of the IKE SA and all child SAs is logged.
266 * Supplying NULL as logger uses the internal child_sa logger
267 * to do the logging. The log is only done if the supplied
268 * connection name is NULL or matches the connections name.
269 *
270 * @param this calling object
271 * @param logger logger to use for logging
272 * @param name name of the connection
273 */
274 void (*log_status) (ike_sa_t *this, logger_t *logger, char *name);
275
276 /**
277 * @brief Get the internal stored connection_t object.
278 *
279 * @param this calling object
280 * @return pointer to the internal stored connection_t object
281 */
282 connection_t *(*get_connection) (ike_sa_t *this);
283
284 /**
285 * @brief Set the internal connection object.
286 *
287 * @param this calling object
288 * @param connection object of type connection_t
289 */
290 void (*set_connection) (ike_sa_t *this, connection_t *connection);
291
292 /**
293 * @brief Get the internal stored policy object.
294 *
295 * @param this calling object
296 * @return pointer to the internal stored policy_t object
297 */
298 policy_t *(*get_policy) (ike_sa_t *this);
299
300 /**
301 * @brief Set the internal policy_t object.
302 *
303 * @param this calling object
304 * @param policy object of type policy_t
305 */
306 void (*set_policy) (ike_sa_t *this, policy_t *policy);
307
308 /**
309 * @brief Derive all keys and create the transforms for IKE communication.
310 *
311 * Keys are derived using the diffie hellman secret, nonces and internal
312 * stored SPIs.
313 * Already existing objects get destroyed.
314 *
315 * @param this calling object
316 * @param proposal proposal which contains algorithms to use
317 * @param dh diffie hellman object with shared secret
318 * @param nonce_i initiators nonce
319 * @param nonce_r responders nonce
320 * @param initiator role of this IKE SA (TRUE = originial initiator)
321 */
322 status_t (*build_transforms) (ike_sa_t *this, proposal_t* proposal,
323 diffie_hellman_t *dh,
324 chunk_t nonce_i, chunk_t nonce_r,
325 bool initiator);
326
327 /**
328 * @brief Get the multi purpose prf.
329 *
330 * @param this calling object
331 * @return pointer to prf_t object
332 */
333 prf_t *(*get_prf) (ike_sa_t *this);
334
335 /**
336 * @brief Get the prf-object, which is used to derive keys for child SAs.
337 *
338 * @param this calling object
339 * @return pointer to prf_t object
340 */
341 prf_t *(*get_child_prf) (ike_sa_t *this);
342
343 /**
344 * @brief Get the prf used for authentication of initiator.
345 *
346 * @param this calling object
347 * @return pointer to prf_t object
348 */
349 prf_t *(*get_prf_auth_i) (ike_sa_t *this);
350
351 /**
352 * @brief Get the prf used for authentication of responder.
353 *
354 * @param this calling object
355 * @return pointer to prf_t object
356 */
357 prf_t *(*get_prf_auth_r) (ike_sa_t *this);
358
359 /**
360 * @brief Associates a child SA to this IKE SA
361 *
362 * @param this calling object
363 * @param child_sa child_sa to add
364 */
365 void (*add_child_sa) (ike_sa_t *this, child_sa_t *child_sa);
366
367 /**
368 * @brief Get a CHILD_SA identified by protocol and SPI.
369 *
370 * @param this calling object
371 * @param protocol protocol of the SA
372 * @param spi SPI of the CHILD_SA
373 * @param inbound TRUE if SPI is inbound, FALSE if outbound
374 * @return child_sa, or NULL if none found
375 */
376 child_sa_t* (*get_child_sa) (ike_sa_t *this, protocol_id_t protocol,
377 u_int32_t spi, bool inbound);
378
379 /**
380 * @brief Rekey the CHILD SA with the specified reqid.
381 *
382 * Looks for a CHILD SA owned by this IKE_SA, and start the rekeing.
383 *
384 * @param this calling object
385 * @param protocol protocol of the SA
386 * @param spi inbound SPI of the CHILD_SA
387 * @return
388 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
389 * - SUCCESS, if rekeying initiated
390 */
391 status_t (*rekey_child_sa) (ike_sa_t *this, protocol_id_t protocol, u_int32_t spi);
392
393 /**
394 * @brief Close the CHILD SA with the specified protocol/SPI.
395 *
396 * Looks for a CHILD SA owned by this IKE_SA, deletes it and
397 * notify's the remote peer about the delete. The associated
398 * states and policies in the kernel get deleted, if they exist.
399 *
400 * @param this calling object
401 * @param protocol protocol of the SA
402 * @param spi inbound SPI of the CHILD_SA
403 * @return
404 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
405 * - SUCCESS, if delete message sent
406 */
407 status_t (*delete_child_sa) (ike_sa_t *this, protocol_id_t protocol, u_int32_t spi);
408
409 /**
410 * @brief Destroy a CHILD SA with the specified protocol/SPI.
411 *
412 * Looks for a CHILD SA owned by this IKE_SA and destroys it.
413 *
414 * @param this calling object
415 * @param protocol protocol of the SA
416 * @param spi inbound SPI of the CHILD_SA
417 * @return
418 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
419 * - SUCCESS
420 */
421 status_t (*destroy_child_sa) (ike_sa_t *this, protocol_id_t protocol, u_int32_t spi);
422
423 /**
424 * @brief Destroys a ike_sa_t object.
425 *
426 * @param this calling object
427 */
428 void (*destroy) (ike_sa_t *this);
429 };
430
431 /**
432 * @brief Creates an ike_sa_t object with a specific ID.
433 *
434 * The ID gets cloned internally.
435 *
436 * @param ike_sa_id ike_sa_id_t object to associate with new IKE_SA
437 * @return ike_sa_t object
438 *
439 * @ingroup sa
440 */
441 ike_sa_t *ike_sa_create(ike_sa_id_t *ike_sa_id);
442
443 #endif /* IKE_SA_H_ */