fixed crypter/signer in/out to conform with standard
[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 * @ingroup sa
51 */
52 enum ike_sa_state_t {
53
54 /**
55 * IKE_SA just got created, but is not initiating nor responding yet.
56 */
57 SA_CREATED,
58
59 /**
60 * IKE_SA gets initiated actively or passively
61 */
62 SA_CONNECTING,
63
64 /**
65 * IKE_SA is fully established
66 */
67 SA_ESTABLISHED,
68
69 /**
70 * IKE_SA is in progress of deletion
71 */
72 SA_DELETING,
73 };
74
75 /**
76 * String mappings for ike_sa_state_t.
77 */
78 extern mapping_t ike_sa_state_m[];
79
80
81 typedef struct ike_sa_t ike_sa_t;
82
83 /**
84 * @brief Class ike_sa_t representing an IKE_SA.
85 *
86 * An IKE_SA contains crypto information related to a connection
87 * with a peer. It contains multiple IPsec CHILD_SA, for which
88 * it is responsible. All traffic is handled by an IKE_SA, using
89 * transactions.
90 *
91 * @b Constructors:
92 * - ike_sa_create()
93 *
94 * @ingroup sa
95 */
96 struct ike_sa_t {
97
98 /**
99 * @brief Get the id of the SA.
100 *
101 * Returned ike_sa_id_t object is not getting cloned!
102 *
103 * @param this calling object
104 * @return ike_sa's ike_sa_id_t
105 */
106 ike_sa_id_t* (*get_id) (ike_sa_t *this);
107
108 /**
109 * @brief Get the state of the IKE_SA.
110 *
111 * @param this calling object
112 * @return state of the IKE_SA
113 */
114 ike_sa_state_t (*get_state) (ike_sa_t *this);
115
116 /**
117 * @brief Set the state of the IKE_SA.
118 *
119 * @param this calling object
120 * @param state state to set for the IKE_SA
121 */
122 void (*set_state) (ike_sa_t *this, ike_sa_state_t ike_sa);
123
124 /**
125 * @brief Initiate a new connection.
126 *
127 * The connection_t object is owned by the IKE_SA after the call, so
128 * do not modify or destroy it.
129 *
130 * @param this calling object
131 * @param connection connection to initiate
132 * @return
133 * - SUCCESS if initialization started
134 * - DESTROY_ME if initialization failed and IKE_SA MUST be deleted
135 */
136 status_t (*initiate) (ike_sa_t *this, connection_t *connection);
137
138 /**
139 * @brief Initiates the deletion of an IKE_SA.
140 *
141 * Sends a delete message to the remote peer and waits for
142 * its response. If the response comes in, or a timeout occurs,
143 * the IKE SA gets deleted.
144 *
145 * @param this calling object
146 * @return
147 * - SUCCESS if deletion is initialized
148 * - INVALID_STATE, if the IKE_SA is not in
149 * an established state and can not be
150 * delete (but destroyed).
151 */
152 status_t (*delete) (ike_sa_t *this);
153
154 /**
155 * @brief Retransmits a request.
156 *
157 * @param this calling object
158 * @param message_id ID of the request to retransmit
159 * @return
160 * - SUCCESS
161 * - NOT_FOUND if request doesn't have to be retransmited
162 */
163 status_t (*retransmit_request) (ike_sa_t *this, u_int32_t message_id);
164
165 /**
166 * @brief Processes a incoming IKEv2-Message.
167 *
168 * Message processing may fail. If a critical failure occurs,
169 * process_message() return DESTROY_ME. Then the caller must
170 * destroy the IKE_SA immediatly, as it is unusable.
171 *
172 * @param this calling object
173 * @param[in] message message to process
174 * @return
175 * - SUCCESS
176 * - FAILED
177 * - DESTROY_ME if this IKE_SA MUST be deleted
178 */
179 status_t (*process_message) (ike_sa_t *this, message_t *message);
180
181 /**
182 * @brief Check if NAT traversal is enabled for this IKE_SA.
183 *
184 * @param this calling object
185 * @return TRUE if NAT traversal enabled
186 */
187 bool (*is_natt_enabled) (ike_sa_t *this);
188
189 /**
190 * @brief Enable NAT detection for this IKE_SA.
191 *
192 * If a Network address translation is detected with
193 * NAT_DETECTION notifys, a SA must switch to ports
194 * 4500. To enable this behavior, call enable_natt().
195 * It is relevant which peer is NATted, this is specified
196 * with the "local" parameter. Call it twice when both
197 * are NATted.
198 *
199 * @param this calling object
200 * @param local TRUE, if we are NATted, FALSE if other
201 */
202 void (*enable_natt) (ike_sa_t *this, bool local);
203
204 /**
205 * @brief Sends a DPD request to the peer.
206 *
207 * To check if a peer is still alive, periodic
208 * empty INFORMATIONAL messages are sent if no
209 * other traffic was received.
210 *
211 * @param this calling object
212 * @return
213 * - SUCCESS
214 * - DESTROY_ME, if peer did not respond
215 */
216 status_t (*send_dpd) (ike_sa_t *this);
217
218 /**
219 * @brief Sends a keep alive packet.
220 *
221 * To refresh NAT tables in a NAT router
222 * between the peers, periodic empty
223 * UDP packets are sent if no other traffic
224 * was sent.
225 *
226 * @param this calling object
227 */
228 void (*send_keepalive) (ike_sa_t *this);
229
230 /**
231 * @brief Log the status of a the ike sa to a logger.
232 *
233 * The status of the IKE SA and all child SAs is logged.
234 * Supplying NULL as logger uses the internal child_sa logger
235 * to do the logging. The log is only done if the supplied
236 * connection name is NULL or matches the connections name.
237 *
238 * @param this calling object
239 * @param logger logger to use for logging
240 * @param name name of the connection
241 */
242 void (*log_status) (ike_sa_t *this, logger_t *logger, char *name);
243
244 /**
245 * @brief Get the internal stored connection_t object.
246 *
247 * @param this calling object
248 * @return pointer to the internal stored connection_t object
249 */
250 connection_t *(*get_connection) (ike_sa_t *this);
251
252 /**
253 * @brief Set the internal connection object.
254 *
255 * @param this calling object
256 * @param connection object of type connection_t
257 */
258 void (*set_connection) (ike_sa_t *this, connection_t *connection);
259
260 /**
261 * @brief Get the internal stored policy object.
262 *
263 * @param this calling object
264 * @return pointer to the internal stored policy_t object
265 */
266 policy_t *(*get_policy) (ike_sa_t *this);
267
268 /**
269 * @brief Set the internal policy_t object.
270 *
271 * @param this calling object
272 * @param policy object of type policy_t
273 */
274 void (*set_policy) (ike_sa_t *this, policy_t *policy);
275
276 /**
277 * @brief Derive all keys and create the transforms for IKE communication.
278 *
279 * Keys are derived using the diffie hellman secret, nonces and internal
280 * stored SPIs.
281 * Already existing objects get destroyed.
282 *
283 * @param this calling object
284 * @param proposal proposal which contains algorithms to use
285 * @param dh diffie hellman object with shared secret
286 * @param nonce_i initiators nonce
287 * @param nonce_r responders nonce
288 * @param initiator role of this IKE SA (TRUE = originial initiator)
289 */
290 status_t (*build_transforms) (ike_sa_t *this, proposal_t* proposal,
291 diffie_hellman_t *dh,
292 chunk_t nonce_i, chunk_t nonce_r,
293 bool initiator);
294
295 /**
296 * @brief Get the multi purpose prf.
297 *
298 * @param this calling object
299 * @return pointer to prf_t object
300 */
301 prf_t *(*get_prf) (ike_sa_t *this);
302
303 /**
304 * @brief Get the prf-object, which is used to derive keys for child SAs.
305 *
306 * @param this calling object
307 * @return pointer to prf_t object
308 */
309 prf_t *(*get_child_prf) (ike_sa_t *this);
310
311 /**
312 * @brief Get the prf used for authentication of initiator.
313 *
314 * @param this calling object
315 * @return pointer to prf_t object
316 */
317 prf_t *(*get_prf_auth_i) (ike_sa_t *this);
318
319 /**
320 * @brief Get the prf used for authentication of responder.
321 *
322 * @param this calling object
323 * @return pointer to prf_t object
324 */
325 prf_t *(*get_prf_auth_r) (ike_sa_t *this);
326
327 /**
328 * @brief Associates a child SA to this IKE SA
329 *
330 * @param this calling object
331 * @param child_sa child_sa to add
332 */
333 void (*add_child_sa) (ike_sa_t *this, child_sa_t *child_sa);
334
335 /**
336 * @brief Get a CHILD_SA identified by protocol and SPI.
337 *
338 * @param this calling object
339 * @param protocol protocol of the SA
340 * @param spi SPI of the CHILD_SA
341 * @param inbound TRUE if SPI is inbound, FALSE if outbound
342 * @return child_sa, or NULL if none found
343 */
344 child_sa_t* (*get_child_sa) (ike_sa_t *this, protocol_id_t protocol,
345 u_int32_t spi, bool inbound);
346
347 /**
348 * @brief Rekey the CHILD SA with the specified reqid.
349 *
350 * Looks for a CHILD SA owned by this IKE_SA, and start the rekeing.
351 *
352 * @param this calling object
353 * @param protocol protocol of the SA
354 * @param spi inbound SPI of the CHILD_SA
355 * @return
356 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
357 * - SUCCESS, if rekeying initiated
358 */
359 status_t (*rekey_child_sa) (ike_sa_t *this, protocol_id_t protocol, u_int32_t spi);
360
361 /**
362 * @brief Close the CHILD SA with the specified protocol/SPI.
363 *
364 * Looks for a CHILD SA owned by this IKE_SA, deletes it and
365 * notify's the remote peer about the delete. The associated
366 * states and policies in the kernel get deleted, if they exist.
367 *
368 * @param this calling object
369 * @param protocol protocol of the SA
370 * @param spi inbound SPI of the CHILD_SA
371 * @return
372 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
373 * - SUCCESS, if delete message sent
374 */
375 status_t (*delete_child_sa) (ike_sa_t *this, protocol_id_t protocol, u_int32_t spi);
376
377 /**
378 * @brief Destroy a CHILD SA with the specified protocol/SPI.
379 *
380 * Looks for a CHILD SA owned by this IKE_SA and destroys it.
381 *
382 * @param this calling object
383 * @param protocol protocol of the SA
384 * @param spi inbound SPI of the CHILD_SA
385 * @return
386 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
387 * - SUCCESS
388 */
389 status_t (*destroy_child_sa) (ike_sa_t *this, protocol_id_t protocol, u_int32_t spi);
390
391 /**
392 * @brief Destroys a ike_sa_t object.
393 *
394 * @param this calling object
395 */
396 void (*destroy) (ike_sa_t *this);
397 };
398
399 /**
400 * @brief Creates an ike_sa_t object with a specific ID.
401 *
402 * The ID gets cloned internally.
403 *
404 * @param ike_sa_id ike_sa_id_t object to associate with new IKE_SA
405 * @return ike_sa_t object
406 *
407 * @ingroup sa
408 */
409 ike_sa_t *ike_sa_create(ike_sa_id_t *ike_sa_id);
410
411 #endif /* IKE_SA_H_ */