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