ike-sa: Add option to force the destruction of an IKE_SA after initiating a delete
[strongswan.git] / src / libcharon / sa / ike_sa.h
1 /*
2 * Copyright (C) 2006-2018 Tobias Brunner
3 * Copyright (C) 2006 Daniel Roethlisberger
4 * Copyright (C) 2005-2009 Martin Willi
5 * Copyright (C) 2005 Jan Hutter
6 * HSR Hochschule fuer Technik Rapperswil
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 */
18
19 /**
20 * @defgroup ike_sa ike_sa
21 * @{ @ingroup sa
22 */
23
24 #ifndef IKE_SA_H_
25 #define IKE_SA_H_
26
27 typedef enum ike_extension_t ike_extension_t;
28 typedef enum ike_condition_t ike_condition_t;
29 typedef enum ike_sa_state_t ike_sa_state_t;
30 typedef enum statistic_t statistic_t;
31 typedef struct ike_sa_t ike_sa_t;
32
33 #include <library.h>
34 #include <attributes/attribute_handler.h>
35 #include <encoding/message.h>
36 #include <encoding/payloads/proposal_substructure.h>
37 #include <encoding/payloads/configuration_attribute.h>
38 #include <sa/ike_sa_id.h>
39 #include <sa/child_sa.h>
40 #include <sa/task.h>
41 #include <sa/task_manager.h>
42 #include <sa/keymat.h>
43 #include <config/peer_cfg.h>
44 #include <config/ike_cfg.h>
45 #include <credentials/auth_cfg.h>
46 #include <networking/packet.h>
47
48 /**
49 * Timeout in seconds after that a half open IKE_SA gets deleted.
50 */
51 #define HALF_OPEN_IKE_SA_TIMEOUT 30
52
53 /**
54 * Interval to send keepalives when NATed, in seconds.
55 */
56 #define KEEPALIVE_INTERVAL 20
57
58 /**
59 * After which time rekeying should be retried if it failed, in seconds.
60 */
61 #define RETRY_INTERVAL 15
62
63 /**
64 * Jitter to subtract from RETRY_INTERVAL to randomize rekey retry.
65 */
66 #define RETRY_JITTER 10
67
68 /**
69 * Number of redirects allowed within REDIRECT_LOOP_DETECT_PERIOD.
70 */
71 #define MAX_REDIRECTS 5
72
73 /**
74 * Time period in seconds in which at most MAX_REDIRECTS are allowed.
75 */
76 #define REDIRECT_LOOP_DETECT_PERIOD 300
77
78 /**
79 * Extensions (or optional features) the peer supports
80 */
81 enum ike_extension_t {
82
83 /**
84 * peer supports NAT traversal as specified in RFC4306 or RFC3947
85 * including some RFC3947 drafts
86 */
87 EXT_NATT = (1<<0),
88
89 /**
90 * peer supports MOBIKE (RFC4555)
91 */
92 EXT_MOBIKE = (1<<1),
93
94 /**
95 * peer supports HTTP cert lookups as specified in RFC4306
96 */
97 EXT_HASH_AND_URL = (1<<2),
98
99 /**
100 * peer supports multiple authentication exchanges, RFC4739
101 */
102 EXT_MULTIPLE_AUTH = (1<<3),
103
104 /**
105 * peer uses strongSwan, accept private use extensions
106 */
107 EXT_STRONGSWAN = (1<<4),
108
109 /**
110 * peer supports EAP-only authentication, draft-eronen-ipsec-ikev2-eap-auth
111 */
112 EXT_EAP_ONLY_AUTHENTICATION = (1<<5),
113
114 /**
115 * peer is probably a Windows RAS client
116 */
117 EXT_MS_WINDOWS = (1<<6),
118
119 /**
120 * peer supports XAuth authentication, draft-ietf-ipsec-isakmp-xauth-06
121 */
122 EXT_XAUTH = (1<<7),
123
124 /**
125 * peer supports DPD detection, RFC 3706 (or IKEv2)
126 */
127 EXT_DPD = (1<<8),
128
129 /**
130 * peer supports Cisco Unity configuration attributes
131 */
132 EXT_CISCO_UNITY = (1<<9),
133
134 /**
135 * peer supports NAT traversal as specified in
136 * draft-ietf-ipsec-nat-t-ike-02 .. -03
137 */
138 EXT_NATT_DRAFT_02_03 = (1<<10),
139
140 /**
141 * peer supports proprietary IKEv1 or standardized IKEv2 fragmentation
142 */
143 EXT_IKE_FRAGMENTATION = (1<<11),
144
145 /**
146 * Signature Authentication, RFC 7427
147 */
148 EXT_SIGNATURE_AUTH = (1<<12),
149
150 /**
151 * IKEv2 Redirect Mechanism, RFC 5685
152 */
153 EXT_IKE_REDIRECTION = (1<<13),
154
155 /**
156 * IKEv2 Message ID sync, RFC 6311
157 */
158 EXT_IKE_MESSAGE_ID_SYNC = (1<<14),
159 };
160
161 /**
162 * Conditions of an IKE_SA, change during its lifetime
163 */
164 enum ike_condition_t {
165
166 /**
167 * Connection is natted (or faked) somewhere
168 */
169 COND_NAT_ANY = (1<<0),
170
171 /**
172 * we are behind NAT
173 */
174 COND_NAT_HERE = (1<<1),
175
176 /**
177 * other is behind NAT
178 */
179 COND_NAT_THERE = (1<<2),
180
181 /**
182 * Faking NAT to enforce UDP encapsulation
183 */
184 COND_NAT_FAKE = (1<<3),
185
186 /**
187 * peer has been authenticated using EAP at least once
188 */
189 COND_EAP_AUTHENTICATED = (1<<4),
190
191 /**
192 * received a certificate request from the peer
193 */
194 COND_CERTREQ_SEEN = (1<<5),
195
196 /**
197 * Local peer is the "original" IKE initiator. Unaffected from rekeying.
198 */
199 COND_ORIGINAL_INITIATOR = (1<<6),
200
201 /**
202 * IKE_SA is stale, the peer is currently unreachable (MOBIKE)
203 */
204 COND_STALE = (1<<7),
205
206 /**
207 * Initial contact received
208 */
209 COND_INIT_CONTACT_SEEN = (1<<8),
210
211 /**
212 * Peer has been authenticated using XAuth
213 */
214 COND_XAUTH_AUTHENTICATED = (1<<9),
215
216 /**
217 * This IKE_SA is currently being reauthenticated
218 */
219 COND_REAUTHENTICATING = (1<<10),
220
221 /**
222 * This IKE_SA has been redirected
223 */
224 COND_REDIRECTED = (1<<11),
225
226 /**
227 * Online certificate revocation checking is suspended for this IKE_SA
228 */
229 COND_ONLINE_VALIDATION_SUSPENDED = (1<<12),
230 };
231
232 /**
233 * Timing information and statistics to query from an SA
234 */
235 enum statistic_t {
236 /** Timestamp of SA establishement */
237 STAT_ESTABLISHED = 0,
238 /** Timestamp of scheduled rekeying */
239 STAT_REKEY,
240 /** Timestamp of scheduled reauthentication */
241 STAT_REAUTH,
242 /** Timestamp of scheduled delete */
243 STAT_DELETE,
244 /** Timestamp of last inbound IKE packet */
245 STAT_INBOUND,
246 /** Timestamp of last outbound IKE packet */
247 STAT_OUTBOUND,
248
249 STAT_MAX
250 };
251
252 /**
253 * State of an IKE_SA.
254 *
255 * An IKE_SA passes various states in its lifetime. A newly created
256 * SA is in the state CREATED.
257 * @verbatim
258 +----------------+
259 ¦ SA_CREATED ¦
260 +----------------+
261 ¦
262 on initiate()---> ¦ <----- on IKE_SA_INIT received
263 V
264 +----------------+
265 ¦ SA_CONNECTING ¦
266 +----------------+
267 ¦
268 ¦ <----- on IKE_AUTH successfully completed
269 V
270 +----------------+
271 ¦ SA_ESTABLISHED ¦-------------------------+ <-- on rekeying
272 +----------------+ ¦
273 ¦ V
274 on delete()---> ¦ <----- on IKE_SA +-------------+
275 ¦ delete request ¦ SA_REKEYING ¦
276 ¦ received +-------------+
277 V ¦
278 +----------------+ ¦
279 ¦ SA_DELETING ¦<------------------------+ <-- after rekeying
280 +----------------+
281 ¦
282 ¦ <----- after delete() acknowledged
283 ¦
284 \V/
285 X
286 / \
287 @endverbatim
288 */
289 enum ike_sa_state_t {
290
291 /**
292 * IKE_SA just got created, but is not initiating nor responding yet.
293 */
294 IKE_CREATED,
295
296 /**
297 * IKE_SA gets initiated actively or passively
298 */
299 IKE_CONNECTING,
300
301 /**
302 * IKE_SA is fully established
303 */
304 IKE_ESTABLISHED,
305
306 /**
307 * IKE_SA is managed externally and does not process messages
308 */
309 IKE_PASSIVE,
310
311 /**
312 * IKE_SA rekeying in progress
313 */
314 IKE_REKEYING,
315
316 /**
317 * IKE_SA has been rekeyed (or is redundant)
318 */
319 IKE_REKEYED,
320
321 /**
322 * IKE_SA is in progress of deletion
323 */
324 IKE_DELETING,
325
326 /**
327 * IKE_SA object gets destroyed
328 */
329 IKE_DESTROYING,
330 };
331
332 /**
333 * enum names for ike_sa_state_t.
334 */
335 extern enum_name_t *ike_sa_state_names;
336
337 /**
338 * Class ike_sa_t representing an IKE_SA.
339 *
340 * An IKE_SA contains crypto information related to a connection
341 * with a peer. It contains multiple IPsec CHILD_SA, for which
342 * it is responsible. All traffic is handled by an IKE_SA, using
343 * the task manager and its tasks.
344 */
345 struct ike_sa_t {
346
347 /**
348 * Get the id of the SA.
349 *
350 * Returned ike_sa_id_t object is not getting cloned!
351 *
352 * @return ike_sa's ike_sa_id_t
353 */
354 ike_sa_id_t* (*get_id) (ike_sa_t *this);
355
356 /**
357 * Gets the IKE version of the SA
358 */
359 ike_version_t (*get_version)(ike_sa_t *this);
360
361 /**
362 * Get the numerical ID uniquely defining this IKE_SA.
363 *
364 * @return unique ID
365 */
366 uint32_t (*get_unique_id) (ike_sa_t *this);
367
368 /**
369 * Get the state of the IKE_SA.
370 *
371 * @return state of the IKE_SA
372 */
373 ike_sa_state_t (*get_state) (ike_sa_t *this);
374
375 /**
376 * Set the state of the IKE_SA.
377 *
378 * @param state state to set for the IKE_SA
379 */
380 void (*set_state) (ike_sa_t *this, ike_sa_state_t state);
381
382 /**
383 * Get the name of the connection this IKE_SA uses.
384 *
385 * @return name
386 */
387 char* (*get_name) (ike_sa_t *this);
388
389 /**
390 * Get statistic values from the IKE_SA.
391 *
392 * @param kind kind of requested value
393 * @return value as integer
394 */
395 uint32_t (*get_statistic)(ike_sa_t *this, statistic_t kind);
396
397 /**
398 * Set statistic value of the IKE_SA.
399 *
400 * @param kind kind of value to update
401 * @param value value as integer
402 */
403 void (*set_statistic)(ike_sa_t *this, statistic_t kind, uint32_t value);
404
405 /**
406 * Get the own host address.
407 *
408 * @return host address
409 */
410 host_t* (*get_my_host) (ike_sa_t *this);
411
412 /**
413 * Set the own host address.
414 *
415 * @param me host address
416 */
417 void (*set_my_host) (ike_sa_t *this, host_t *me);
418
419 /**
420 * Get the other peers host address.
421 *
422 * @return host address
423 */
424 host_t* (*get_other_host) (ike_sa_t *this);
425
426 /**
427 * Set the others host address.
428 *
429 * @param other host address
430 */
431 void (*set_other_host) (ike_sa_t *this, host_t *other);
432
433 /**
434 * Float to port 4500 (e.g. if a NAT is detected).
435 *
436 * The port of either endpoint is changed only if it is currently
437 * set to the default value of 500.
438 */
439 void (*float_ports)(ike_sa_t *this);
440
441 /**
442 * Update the IKE_SAs host.
443 *
444 * Hosts may be NULL to use current host.
445 *
446 * @param me new local host address, or NULL
447 * @param other new remote host address, or NULL
448 * @param force force update
449 */
450 void (*update_hosts)(ike_sa_t *this, host_t *me, host_t *other, bool force);
451
452 /**
453 * Get the own identification.
454 *
455 * @return identification
456 */
457 identification_t* (*get_my_id) (ike_sa_t *this);
458
459 /**
460 * Set the own identification.
461 *
462 * @param me identification
463 */
464 void (*set_my_id) (ike_sa_t *this, identification_t *me);
465
466 /**
467 * Get the other peer's identification.
468 *
469 * @return identification
470 */
471 identification_t* (*get_other_id) (ike_sa_t *this);
472
473 /**
474 * Get the others peer identity, but prefer an EAP-Identity.
475 *
476 * @return EAP or IKEv2 identity
477 */
478 identification_t* (*get_other_eap_id)(ike_sa_t *this);
479
480 /**
481 * Set the other peer's identification.
482 *
483 * @param other identification
484 */
485 void (*set_other_id) (ike_sa_t *this, identification_t *other);
486
487 /**
488 * Get the config used to setup this IKE_SA.
489 *
490 * @return ike_config
491 */
492 ike_cfg_t* (*get_ike_cfg) (ike_sa_t *this);
493
494 /**
495 * Set the config to setup this IKE_SA.
496 *
497 * @param config ike_config to use
498 */
499 void (*set_ike_cfg) (ike_sa_t *this, ike_cfg_t* config);
500
501 /**
502 * Get the peer config used by this IKE_SA.
503 *
504 * @return peer_config
505 */
506 peer_cfg_t* (*get_peer_cfg) (ike_sa_t *this);
507
508 /**
509 * Set the peer config to use with this IKE_SA.
510 *
511 * @param config peer_config to use
512 */
513 void (*set_peer_cfg) (ike_sa_t *this, peer_cfg_t *config);
514
515 /**
516 * Get the authentication config with rules of the current auth round.
517 *
518 * @param local TRUE for local rules, FALSE for remote constraints
519 * @return current cfg
520 */
521 auth_cfg_t* (*get_auth_cfg)(ike_sa_t *this, bool local);
522
523 /**
524 * Insert a completed authentication round.
525 *
526 * @param local TRUE for own rules, FALSE for others constraints
527 * @param cfg auth config to append
528 */
529 void (*add_auth_cfg)(ike_sa_t *this, bool local, auth_cfg_t *cfg);
530
531 /**
532 * Create an enumerator over added authentication rounds.
533 *
534 * @param local TRUE for own rules, FALSE for others constraints
535 * @return enumerator over auth_cfg_t
536 */
537 enumerator_t* (*create_auth_cfg_enumerator)(ike_sa_t *this, bool local);
538
539 /**
540 * Verify the trustchains (validity, revocation) in completed public key
541 * auth rounds.
542 *
543 * @return TRUE if certificates were valid, FALSE otherwise
544 */
545 bool (*verify_peer_certificate)(ike_sa_t *this);
546
547 /**
548 * Get the selected proposal of this IKE_SA.
549 *
550 * @return selected proposal
551 */
552 proposal_t* (*get_proposal)(ike_sa_t *this);
553
554 /**
555 * Set the proposal selected for this IKE_SA.
556 *
557 * @param selected proposal
558 */
559 void (*set_proposal)(ike_sa_t *this, proposal_t *proposal);
560
561 /**
562 * Set the message ID of the IKE_SA.
563 *
564 * The IKE_SA stores two message IDs, one for initiating exchanges (send)
565 * and one to respond to exchanges (expect).
566 *
567 * @param initiate TRUE to set message ID for initiating
568 * @param mid message id to set
569 */
570 void (*set_message_id)(ike_sa_t *this, bool initiate, uint32_t mid);
571
572 /**
573 * Get the message ID of the IKE_SA.
574 *
575 * The IKE_SA stores two message IDs, one for initiating exchanges (send)
576 * and one to respond to exchanges (expect).
577 *
578 * @param initiate TRUE to get message ID for initiating
579 * @return current message
580 */
581 uint32_t (*get_message_id)(ike_sa_t *this, bool initiate);
582
583 /**
584 * Add an additional address for the peer.
585 *
586 * In MOBIKE, a peer may transmit additional addresses where it is
587 * reachable. These are stored in the IKE_SA.
588 * The own list of addresses is not stored, they are queried from
589 * the kernel when required.
590 *
591 * @param host host to add to list
592 */
593 void (*add_peer_address)(ike_sa_t *this, host_t *host);
594
595 /**
596 * Create an enumerator over all known addresses of the peer.
597 *
598 * @return enumerator over addresses
599 */
600 enumerator_t* (*create_peer_address_enumerator)(ike_sa_t *this);
601
602 /**
603 * Remove all known addresses of the peer.
604 */
605 void (*clear_peer_addresses)(ike_sa_t *this);
606
607 /**
608 * Check if mappings have changed on a NAT for our source address.
609 *
610 * @param hash received DESTINATION_IP hash
611 * @return TRUE if mappings have changed
612 */
613 bool (*has_mapping_changed)(ike_sa_t *this, chunk_t hash);
614
615 /**
616 * Enable an extension the peer supports.
617 *
618 * If support for an IKE extension is detected, this method is called
619 * to enable that extension and behave accordingly.
620 *
621 * @param extension extension to enable
622 */
623 void (*enable_extension)(ike_sa_t *this, ike_extension_t extension);
624
625 /**
626 * Check if the peer supports an extension.
627 *
628 * @param extension extension to check for support
629 * @return TRUE if peer supports it, FALSE otherwise
630 */
631 bool (*supports_extension)(ike_sa_t *this, ike_extension_t extension);
632
633 /**
634 * Enable/disable a condition flag for this IKE_SA.
635 *
636 * @param condition condition to enable/disable
637 * @param enable TRUE to enable condition, FALSE to disable
638 */
639 void (*set_condition) (ike_sa_t *this, ike_condition_t condition, bool enable);
640
641 /**
642 * Check if a condition flag is set.
643 *
644 * @param condition condition to check
645 * @return TRUE if condition flag set, FALSE otherwise
646 */
647 bool (*has_condition) (ike_sa_t *this, ike_condition_t condition);
648
649 #ifdef ME
650 /**
651 * Activate mediation server functionality for this IKE_SA.
652 */
653 void (*act_as_mediation_server) (ike_sa_t *this);
654
655 /**
656 * Get the server reflexive host.
657 *
658 * @return server reflexive host
659 */
660 host_t* (*get_server_reflexive_host) (ike_sa_t *this);
661
662 /**
663 * Set the server reflexive host.
664 *
665 * @param host server reflexive host
666 */
667 void (*set_server_reflexive_host) (ike_sa_t *this, host_t *host);
668
669 /**
670 * Get the connect ID.
671 *
672 * @return connect ID
673 */
674 chunk_t (*get_connect_id) (ike_sa_t *this);
675
676 /**
677 * Initiate the mediation of a mediated connection (i.e. initiate a
678 * ME_CONNECT exchange to a mediation server).
679 *
680 * @param mediated_cfg peer_cfg of the mediated connection
681 * @return
682 * - SUCCESS if initialization started
683 * - DESTROY_ME if initialization failed
684 */
685 status_t (*initiate_mediation) (ike_sa_t *this, peer_cfg_t *mediated_cfg);
686
687 /**
688 * Initiate the mediated connection
689 *
690 * @param me local endpoint (gets cloned)
691 * @param other remote endpoint (gets cloned)
692 * @param connect_id connect ID (gets cloned)
693 * @return
694 * - SUCCESS if initialization started
695 * - DESTROY_ME if initialization failed
696 */
697 status_t (*initiate_mediated) (ike_sa_t *this, host_t *me, host_t *other,
698 chunk_t connect_id);
699
700 /**
701 * Relay data from one peer to another (i.e. initiate a ME_CONNECT exchange
702 * to a peer).
703 *
704 * Data is cloned.
705 *
706 * @param requester ID of the requesting peer
707 * @param connect_id data of the ME_CONNECTID payload
708 * @param connect_key data of the ME_CONNECTKEY payload
709 * @param endpoints endpoints
710 * @param response TRUE if this is a response
711 * @return
712 * - SUCCESS if relay started
713 * - DESTROY_ME if relay failed
714 */
715 status_t (*relay) (ike_sa_t *this, identification_t *requester,
716 chunk_t connect_id, chunk_t connect_key,
717 linked_list_t *endpoints, bool response);
718
719 /**
720 * Send a callback to a peer.
721 *
722 * Data is cloned.
723 *
724 * @param peer_id ID of the other peer
725 * @return
726 * - SUCCESS if response started
727 * - DESTROY_ME if response failed
728 */
729 status_t (*callback) (ike_sa_t *this, identification_t *peer_id);
730
731 /**
732 * Respond to a ME_CONNECT request.
733 *
734 * Data is cloned.
735 *
736 * @param peer_id ID of the other peer
737 * @param connect_id the connect ID supplied by the initiator
738 * @return
739 * - SUCCESS if response started
740 * - DESTROY_ME if response failed
741 */
742 status_t (*respond) (ike_sa_t *this, identification_t *peer_id,
743 chunk_t connect_id);
744 #endif /* ME */
745
746 /**
747 * Initiate a new connection.
748 *
749 * The configs are owned by the IKE_SA after the call. If the initiate
750 * is triggered by a packet, traffic selectors of the packet can be added
751 * to the CHILD_SA.
752 *
753 * @param child_cfg child config to create CHILD from
754 * @param reqid reqid to use for CHILD_SA, 0 assigne uniquely
755 * @param tsi source of triggering packet
756 * @param tsr destination of triggering packet.
757 * @return
758 * - SUCCESS if initialization started
759 * - DESTROY_ME if initialization failed
760 */
761 status_t (*initiate) (ike_sa_t *this, child_cfg_t *child_cfg,
762 uint32_t reqid, traffic_selector_t *tsi,
763 traffic_selector_t *tsr);
764
765 /**
766 * Retry initiation of this IKE_SA after it got deferred previously.
767 *
768 * @return
769 * - SUCCESS if initiation deferred or started
770 * - DESTROY_ME if initiation failed
771 */
772 status_t (*retry_initiate) (ike_sa_t *this);
773
774 /**
775 * Initiates the deletion of an IKE_SA.
776 *
777 * Sends a delete message to the remote peer and waits for
778 * its response. If the response comes in, or a timeout occurs,
779 * the IKE SA gets destroyed, unless force is TRUE then the IKE_SA is
780 * destroyed immediately without waiting for a response.
781 *
782 * @param force whether to immediately destroy the IKE_SA afterwards
783 * without waiting for a response
784 * @return
785 * - SUCCESS if deletion is initialized
786 * - DESTROY_ME, if destroying is forced, or the IKE_SA
787 * is not in an established state and can not be
788 * deleted (but destroyed)
789 */
790 status_t (*delete) (ike_sa_t *this, bool force);
791
792 /**
793 * Update IKE_SAs after network interfaces have changed.
794 *
795 * Whenever the network interface configuration changes, the kernel
796 * interface calls roam() on each IKE_SA. The IKE_SA then checks if
797 * the new network config requires changes, and handles appropriate.
798 * If MOBIKE is supported, addresses are updated; If not, the tunnel is
799 * restarted.
800 *
801 * @param address TRUE if address list changed, FALSE otherwise
802 * @return SUCCESS, FAILED, DESTROY_ME
803 */
804 status_t (*roam)(ike_sa_t *this, bool address);
805
806 /**
807 * Processes an incoming IKE message.
808 *
809 * Message processing may fail. If a critical failure occurs,
810 * process_message() return DESTROY_ME. Then the caller must
811 * destroy the IKE_SA immediately, as it is unusable.
812 *
813 * @param message message to process
814 * @return
815 * - SUCCESS
816 * - FAILED
817 * - DESTROY_ME if this IKE_SA MUST be deleted
818 */
819 status_t (*process_message)(ike_sa_t *this, message_t *message);
820
821 /**
822 * Generate an IKE message to send it to the peer.
823 *
824 * This method generates all payloads in the message and encrypts/signs
825 * the packet.
826 *
827 * @param message message to generate
828 * @param packet generated output packet
829 * @return
830 * - SUCCESS
831 * - FAILED
832 * - DESTROY_ME if this IKE_SA MUST be deleted
833 */
834 status_t (*generate_message)(ike_sa_t *this, message_t *message,
835 packet_t **packet);
836
837 /**
838 * Generate an IKE message to send it to the peer. If enabled and supported
839 * it will be fragmented.
840 *
841 * This method generates all payloads in the message and encrypts/signs
842 * the packet/fragments.
843 *
844 * @param message message to generate
845 * @param packets enumerator of generated packet_t* (are not destroyed
846 * with the enumerator)
847 * @return
848 * - SUCCESS
849 * - FAILED
850 * - DESTROY_ME if this IKE_SA MUST be deleted
851 */
852 status_t (*generate_message_fragmented)(ike_sa_t *this, message_t *message,
853 enumerator_t **packets);
854
855 /**
856 * Retransmits a request.
857 *
858 * @param message_id ID of the request to retransmit
859 * @return
860 * - SUCCESS
861 * - NOT_FOUND if request doesn't have to be retransmitted
862 */
863 status_t (*retransmit) (ike_sa_t *this, uint32_t message_id);
864
865 /**
866 * Sends a DPD request to the peer.
867 *
868 * To check if a peer is still alive, periodic
869 * empty INFORMATIONAL messages are sent if no
870 * other traffic was received.
871 *
872 * @return
873 * - SUCCESS
874 * - DESTROY_ME, if peer did not respond
875 */
876 status_t (*send_dpd) (ike_sa_t *this);
877
878 /**
879 * Sends a keep alive packet.
880 *
881 * To refresh NAT tables in a NAT router between the peers, periodic empty
882 * UDP packets are sent if no other traffic was sent.
883 *
884 * @param scheduled if this is a scheduled keepalive
885 */
886 void (*send_keepalive) (ike_sa_t *this, bool scheduled);
887
888 /**
889 * Redirect an active IKE_SA.
890 *
891 * @param gateway gateway ID (IP or FQDN) of the target
892 * @return state, including DESTROY_ME, if this IKE_SA MUST be
893 * destroyed
894 */
895 status_t (*redirect)(ike_sa_t *this, identification_t *gateway);
896
897 /**
898 * Handle a redirect request.
899 *
900 * The behavior is different depending on the state of the IKE_SA.
901 *
902 * @param gateway gateway ID (IP or FQDN) of the target
903 * @return FALSE if redirect not possible, TRUE otherwise
904 */
905 bool (*handle_redirect)(ike_sa_t *this, identification_t *gateway);
906
907 /**
908 * Get the address of the gateway that redirected us.
909 *
910 * @return original gateway address
911 */
912 host_t *(*get_redirected_from)(ike_sa_t *this);
913
914 /**
915 * Get the keying material of this IKE_SA.
916 *
917 * @return per IKE_SA keymat instance
918 */
919 keymat_t* (*get_keymat)(ike_sa_t *this);
920
921 /**
922 * Associates a child SA to this IKE SA
923 *
924 * @param child_sa child_sa to add
925 */
926 void (*add_child_sa) (ike_sa_t *this, child_sa_t *child_sa);
927
928 /**
929 * Get a CHILD_SA identified by protocol and SPI.
930 *
931 * @param protocol protocol of the SA
932 * @param spi SPI of the CHILD_SA
933 * @param inbound TRUE if SPI is inbound, FALSE if outbound
934 * @return child_sa, or NULL if none found
935 */
936 child_sa_t* (*get_child_sa) (ike_sa_t *this, protocol_id_t protocol,
937 uint32_t spi, bool inbound);
938
939 /**
940 * Get the number of CHILD_SAs.
941 *
942 * @return number of CHILD_SAs
943 */
944 int (*get_child_count) (ike_sa_t *this);
945
946 /**
947 * Create an enumerator over all CHILD_SAs.
948 *
949 * @return enumerator
950 */
951 enumerator_t* (*create_child_sa_enumerator) (ike_sa_t *this);
952
953 /**
954 * Remove the CHILD_SA the given enumerator points to from this IKE_SA.
955 *
956 * @param enumerator enumerator pointing to CHILD_SA
957 */
958 void (*remove_child_sa) (ike_sa_t *this, enumerator_t *enumerator);
959
960 /**
961 * Rekey the CHILD SA with the specified reqid.
962 *
963 * Looks for a CHILD SA owned by this IKE_SA, and start the rekeing.
964 *
965 * @param protocol protocol of the SA
966 * @param spi inbound SPI of the CHILD_SA
967 * @return
968 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
969 * - SUCCESS, if rekeying initiated
970 */
971 status_t (*rekey_child_sa) (ike_sa_t *this, protocol_id_t protocol, uint32_t spi);
972
973 /**
974 * Close the CHILD SA with the specified protocol/SPI.
975 *
976 * Looks for a CHILD SA owned by this IKE_SA, deletes it and
977 * notify's the remote peer about the delete. The associated
978 * states and policies in the kernel get deleted, if they exist.
979 *
980 * @param protocol protocol of the SA
981 * @param spi inbound SPI of the CHILD_SA
982 * @param expired TRUE if CHILD_SA is expired
983 * @return
984 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
985 * - SUCCESS, if delete message sent
986 */
987 status_t (*delete_child_sa)(ike_sa_t *this, protocol_id_t protocol,
988 uint32_t spi, bool expired);
989
990 /**
991 * Destroy a CHILD SA with the specified protocol/SPI.
992 *
993 * Looks for a CHILD SA owned by this IKE_SA and destroys it.
994 *
995 * @param protocol protocol of the SA
996 * @param spi inbound SPI of the CHILD_SA
997 * @return
998 * - NOT_FOUND, if IKE_SA has no such CHILD_SA
999 * - SUCCESS
1000 */
1001 status_t (*destroy_child_sa) (ike_sa_t *this, protocol_id_t protocol, uint32_t spi);
1002
1003 /**
1004 * Rekey the IKE_SA.
1005 *
1006 * Sets up a new IKE_SA, moves all CHILD_SAs to it and deletes this IKE_SA.
1007 *
1008 * @return - SUCCESS, if IKE_SA rekeying initiated
1009 */
1010 status_t (*rekey) (ike_sa_t *this);
1011
1012 /**
1013 * Reauthenticate the IKE_SA.
1014 *
1015 * Triggers a new IKE_SA that replaces this one. IKEv1 implicitly inherits
1016 * all Quick Modes, while IKEv2 recreates all active and queued CHILD_SAs
1017 * in the new IKE_SA.
1018 *
1019 * @return DESTROY_ME to destroy the IKE_SA
1020 */
1021 status_t (*reauth) (ike_sa_t *this);
1022
1023 /**
1024 * Restablish the IKE_SA.
1025 *
1026 * Reestablish an IKE_SA after it has been closed.
1027 *
1028 * @return DESTROY_ME to destroy the IKE_SA
1029 */
1030 status_t (*reestablish) (ike_sa_t *this);
1031
1032 /**
1033 * Set the lifetime limit received/to send in a AUTH_LIFETIME notify.
1034 *
1035 * If the IKE_SA is already ESTABLISHED, an INFORMATIONAL is sent with
1036 * an AUTH_LIFETIME notify. The call never fails on unestablished SAs.
1037 *
1038 * @param lifetime lifetime in seconds
1039 * @return DESTROY_ME to destroy the IKE_SA
1040 */
1041 status_t (*set_auth_lifetime)(ike_sa_t *this, uint32_t lifetime);
1042
1043 /**
1044 * Add a virtual IP to use for this IKE_SA and its children.
1045 *
1046 * The virtual IP is assigned per IKE_SA, not per CHILD_SA. It has the same
1047 * lifetime as the IKE_SA.
1048 *
1049 * @param local TRUE to set local address, FALSE for remote
1050 * @param ip IP to set as virtual IP
1051 */
1052 void (*add_virtual_ip) (ike_sa_t *this, bool local, host_t *ip);
1053
1054 /**
1055 * Clear all virtual IPs stored on this IKE_SA.
1056 *
1057 * @param local TRUE to clear local addresses, FALSE for remote
1058 */
1059 void (*clear_virtual_ips) (ike_sa_t *this, bool local);
1060
1061 /**
1062 * Create an enumerator over virtual IPs.
1063 *
1064 * @param local TRUE to get local virtual IP, FALSE for remote
1065 * @return enumerator over host_t*
1066 */
1067 enumerator_t* (*create_virtual_ip_enumerator) (ike_sa_t *this, bool local);
1068
1069 /**
1070 * Register a configuration attribute to the IKE_SA.
1071 *
1072 * If an IRAS sends a configuration attribute it is installed and
1073 * registered at the IKE_SA. Attributes are inherit()ed and get released
1074 * when the IKE_SA is closed.
1075 *
1076 * Unhandled attributes are passed as well, but with a NULL handler. They
1077 * do not get released.
1078 *
1079 * @param handler handler installed the attribute, use for release()
1080 * @param type configuration attribute type
1081 * @param data associated attribute data
1082 */
1083 void (*add_configuration_attribute)(ike_sa_t *this,
1084 attribute_handler_t *handler,
1085 configuration_attribute_type_t type, chunk_t data);
1086
1087 /**
1088 * Create an enumerator over received configuration attributes.
1089 *
1090 * The resulting enumerator is over the configuration_attribute_type_t type,
1091 * a value chunk_t followed by a bool flag. The boolean flag indicates if
1092 * the attribute has been handled by an attribute handler.
1093 *
1094 * @return enumerator over type, value and the "handled" flag.
1095 */
1096 enumerator_t* (*create_attribute_enumerator)(ike_sa_t *this);
1097
1098 /**
1099 * Set local and remote host addresses to be used for IKE.
1100 *
1101 * These addresses are communicated via the KMADDRESS field of a MIGRATE
1102 * message sent via the NETLINK or PF _KEY kernel socket interface.
1103 *
1104 * @param local local kmaddress
1105 * @param remote remote kmaddress
1106 */
1107 void (*set_kmaddress) (ike_sa_t *this, host_t *local, host_t *remote);
1108
1109 /**
1110 * Create enumerator over a task queue of this IKE_SA.
1111 *
1112 * @param queue type to enumerate
1113 * @return enumerator over task_t
1114 */
1115 enumerator_t* (*create_task_enumerator)(ike_sa_t *this, task_queue_t queue);
1116
1117 /**
1118 * Flush a task queue, cancelling all tasks in it.
1119 *
1120 * @param queue queue type to flush
1121 */
1122 void (*flush_queue)(ike_sa_t *this, task_queue_t queue);
1123
1124 /**
1125 * Queue a task for initiaton to the task manager.
1126 *
1127 * @param task task to queue
1128 */
1129 void (*queue_task)(ike_sa_t *this, task_t *task);
1130
1131 /**
1132 * Queue a task in the manager, but delay its initiation for at least the
1133 * given number of seconds.
1134 *
1135 * @param task task to queue
1136 * @param delay minimum delay in s before initiating the task
1137 */
1138 void (*queue_task_delayed)(ike_sa_t *this, task_t *task, uint32_t delay);
1139
1140 /**
1141 * Inherit required attributes to new SA before rekeying.
1142 *
1143 * Some properties of the SA must be applied before starting IKE_SA
1144 * rekeying, such as the configuration or support extensions.
1145 *
1146 * @param other other IKE_SA to inherit from
1147 */
1148 void (*inherit_pre)(ike_sa_t *this, ike_sa_t *other);
1149
1150 /**
1151 * Inherit all attributes of other to this after rekeying.
1152 *
1153 * When rekeying is completed, all CHILD_SAs, the virtual IP and all
1154 * outstanding tasks are moved from other to this.
1155 *
1156 * @param other other IKE SA to inherit from
1157 */
1158 void (*inherit_post) (ike_sa_t *this, ike_sa_t *other);
1159
1160 /**
1161 * Reset the IKE_SA, usable when initiating fails.
1162 *
1163 * @param new_spi TRUE to allocate a new initiator SPI
1164 */
1165 void (*reset) (ike_sa_t *this, bool new_spi);
1166
1167 /**
1168 * Destroys a ike_sa_t object.
1169 */
1170 void (*destroy) (ike_sa_t *this);
1171 };
1172
1173 /**
1174 * Creates an ike_sa_t object with a specific ID and IKE version.
1175 *
1176 * @param ike_sa_id ike_sa_id_t to associate with new IKE_SA/ISAKMP_SA
1177 * @param initiator TRUE to create this IKE_SA as initiator
1178 * @param version IKE version of this SA
1179 * @return ike_sa_t object
1180 */
1181 ike_sa_t *ike_sa_create(ike_sa_id_t *ike_sa_id, bool initiator,
1182 ike_version_t version);
1183
1184 #endif /** IKE_SA_H_ @}*/