]> git.ipfire.org Git - thirdparty/strongswan.git/blobdiff - src/libcharon/sa/ike_sa.h
ike-sa: Add property for interface ID
[thirdparty/strongswan.git] / src / libcharon / sa / ike_sa.h
index de9e0ede4829dd854242aefb30068fe39d846345..c7ef1fe3c349ef9de1e9d9831509cd9b072071ec 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * Copyright (C) 2006-2012 Tobias Brunner
+ * Copyright (C) 2006-2019 Tobias Brunner
  * Copyright (C) 2006 Daniel Roethlisberger
  * Copyright (C) 2005-2009 Martin Willi
  * Copyright (C) 2005 Jan Hutter
- * Hochschule fuer Technik Rapperswil
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -43,7 +43,7 @@ typedef struct ike_sa_t ike_sa_t;
 #include <config/peer_cfg.h>
 #include <config/ike_cfg.h>
 #include <credentials/auth_cfg.h>
-#include <utils/packet.h>
+#include <networking/packet.h>
 
 /**
  * Timeout in seconds after that a half open IKE_SA gets deleted.
@@ -58,12 +58,22 @@ typedef struct ike_sa_t ike_sa_t;
 /**
  * After which time rekeying should be retried if it failed, in seconds.
  */
-#define RETRY_INTERVAL 30
+#define RETRY_INTERVAL 15
 
 /**
  * Jitter to subtract from RETRY_INTERVAL to randomize rekey retry.
  */
-#define RETRY_JITTER 20
+#define RETRY_JITTER 10
+
+/**
+ * Number of redirects allowed within REDIRECT_LOOP_DETECT_PERIOD.
+ */
+#define MAX_REDIRECTS 5
+
+/**
+ * Time period in seconds in which at most MAX_REDIRECTS are allowed.
+ */
+#define REDIRECT_LOOP_DETECT_PERIOD 300
 
 /**
  * Extensions (or optional features) the peer supports
@@ -72,6 +82,7 @@ enum ike_extension_t {
 
        /**
         * peer supports NAT traversal as specified in RFC4306 or RFC3947
+        * including some RFC3947 drafts
         */
        EXT_NATT = (1<<0),
 
@@ -101,7 +112,7 @@ enum ike_extension_t {
        EXT_EAP_ONLY_AUTHENTICATION = (1<<5),
 
        /**
-        * peer is probably a Windows RAS client
+        * peer is probably a Windows RAS client
         */
        EXT_MS_WINDOWS = (1<<6),
 
@@ -119,6 +130,37 @@ enum ike_extension_t {
         * peer supports Cisco Unity configuration attributes
         */
        EXT_CISCO_UNITY = (1<<9),
+
+       /**
+        * peer supports NAT traversal as specified in
+        * draft-ietf-ipsec-nat-t-ike-02 .. -03
+        */
+       EXT_NATT_DRAFT_02_03 = (1<<10),
+
+       /**
+        * peer supports proprietary IKEv1 or standardized IKEv2 fragmentation
+        */
+       EXT_IKE_FRAGMENTATION = (1<<11),
+
+       /**
+        * Signature Authentication, RFC 7427
+        */
+       EXT_SIGNATURE_AUTH = (1<<12),
+
+       /**
+        * IKEv2 Redirect Mechanism, RFC 5685
+        */
+       EXT_IKE_REDIRECTION = (1<<13),
+
+       /**
+        * IKEv2 Message ID sync, RFC 6311
+        */
+       EXT_IKE_MESSAGE_ID_SYNC = (1<<14),
+
+       /**
+        * Postquantum Preshared Keys, draft-ietf-ipsecme-qr-ikev2
+        */
+       EXT_PPK = (1<<15),
 };
 
 /**
@@ -175,6 +217,26 @@ enum ike_condition_t {
         * Peer has been authenticated using XAuth
         */
        COND_XAUTH_AUTHENTICATED = (1<<9),
+
+       /**
+        * This IKE_SA is currently being reauthenticated
+        */
+       COND_REAUTHENTICATING = (1<<10),
+
+       /**
+        * This IKE_SA has been redirected
+        */
+       COND_REDIRECTED = (1<<11),
+
+       /**
+        * Online certificate revocation checking is suspended for this IKE_SA
+        */
+       COND_ONLINE_VALIDATION_SUSPENDED = (1<<12),
+
+       /**
+        * A Postquantum Preshared Key was used when this IKE_SA was created
+        */
+       COND_PPK = (1<<13),
 };
 
 /**
@@ -183,11 +245,11 @@ enum ike_condition_t {
 enum statistic_t {
        /** Timestamp of SA establishement */
        STAT_ESTABLISHED = 0,
-       /** Timestamp of scheudled rekeying */
+       /** Timestamp of scheduled rekeying */
        STAT_REKEY,
-       /** Timestamp of scheudled reauthentication */
+       /** Timestamp of scheduled reauthentication */
        STAT_REAUTH,
-       /** Timestamp of scheudled delete */
+       /** Timestamp of scheduled delete */
        STAT_DELETE,
        /** Timestamp of last inbound IKE packet */
        STAT_INBOUND,
@@ -261,6 +323,11 @@ enum ike_sa_state_t {
         */
        IKE_REKEYING,
 
+       /**
+        * IKE_SA has been rekeyed (or is redundant)
+        */
+       IKE_REKEYED,
+
        /**
         * IKE_SA is in progress of deletion
         */
@@ -306,7 +373,7 @@ struct ike_sa_t {
         *
         * @return                              unique ID
         */
-       u_int32_t (*get_unique_id) (ike_sa_t *this);
+       uint32_t (*get_unique_id) (ike_sa_t *this);
 
        /**
         * Get the state of the IKE_SA.
@@ -335,7 +402,7 @@ struct ike_sa_t {
         * @param kind                  kind of requested value
         * @return                              value as integer
         */
-       u_int32_t (*get_statistic)(ike_sa_t *this, statistic_t kind);
+       uint32_t (*get_statistic)(ike_sa_t *this, statistic_t kind);
 
        /**
         * Set statistic value of the IKE_SA.
@@ -343,7 +410,7 @@ struct ike_sa_t {
         * @param kind                  kind of value to update
         * @param value                 value as integer
         */
-       void (*set_statistic)(ike_sa_t *this, statistic_t kind, u_int32_t value);
+       void (*set_statistic)(ike_sa_t *this, statistic_t kind, uint32_t value);
 
        /**
         * Get the own host address.
@@ -479,6 +546,14 @@ struct ike_sa_t {
         */
        enumerator_t* (*create_auth_cfg_enumerator)(ike_sa_t *this, bool local);
 
+       /**
+        * Verify the trustchains (validity, revocation) in completed public key
+        * auth rounds.
+        *
+        * @return                              TRUE if certificates were valid, FALSE otherwise
+        */
+       bool (*verify_peer_certificate)(ike_sa_t *this);
+
        /**
         * Get the selected proposal of this IKE_SA.
         *
@@ -494,7 +569,7 @@ struct ike_sa_t {
        void (*set_proposal)(ike_sa_t *this, proposal_t *proposal);
 
        /**
-        * Set the message id of the IKE_SA.
+        * Set the message ID of the IKE_SA.
         *
         * The IKE_SA stores two message IDs, one for initiating exchanges (send)
         * and one to respond to exchanges (expect).
@@ -502,7 +577,18 @@ struct ike_sa_t {
         * @param initiate              TRUE to set message ID for initiating
         * @param mid                   message id to set
         */
-       void (*set_message_id)(ike_sa_t *this, bool initiate, u_int32_t mid);
+       void (*set_message_id)(ike_sa_t *this, bool initiate, uint32_t mid);
+
+       /**
+        * Get the message ID of the IKE_SA.
+        *
+        * The IKE_SA stores two message IDs, one for initiating exchanges (send)
+        * and one to respond to exchanges (expect).
+        *
+        * @param initiate              TRUE to get message ID for initiating
+        * @return                              current message
+        */
+       uint32_t (*get_message_id)(ike_sa_t *this, bool initiate);
 
        /**
         * Add an additional address for the peer.
@@ -570,20 +656,6 @@ struct ike_sa_t {
         */
        bool (*has_condition) (ike_sa_t *this, ike_condition_t condition);
 
-       /**
-        * Get the number of queued MOBIKE address updates.
-        *
-        * @return                              number of pending updates
-        */
-       u_int32_t (*get_pending_updates)(ike_sa_t *this);
-
-       /**
-        * Set the number of queued MOBIKE address updates.
-        *
-        * @param updates               number of pending updates
-        */
-       void (*set_pending_updates)(ike_sa_t *this, u_int32_t updates);
-
 #ifdef ME
        /**
         * Activate mediation server functionality for this IKE_SA.
@@ -697,7 +769,7 @@ struct ike_sa_t {
         *                                              - DESTROY_ME if initialization failed
         */
        status_t (*initiate) (ike_sa_t *this, child_cfg_t *child_cfg,
-                                                 u_int32_t reqid, traffic_selector_t *tsi,
+                                                 uint32_t reqid, traffic_selector_t *tsi,
                                                  traffic_selector_t *tsr);
 
        /**
@@ -714,15 +786,18 @@ struct ike_sa_t {
         *
         * Sends a delete message to the remote peer and waits for
         * its response. If the response comes in, or a timeout occurs,
-        * the IKE SA gets deleted.
+        * the IKE SA gets destroyed, unless force is TRUE then the IKE_SA is
+        * destroyed immediately without waiting for a response.
         *
+        * @param force                 whether to immediately destroy the IKE_SA afterwards
+        *                                              without waiting for a response
         * @return
         *                                              - SUCCESS if deletion is initialized
-        *                                              - DESTROY_ME, if the IKE_SA is not in
-        *                                                an established state and can not be
-        *                                                deleted (but destroyed).
+        *                                              - DESTROY_ME, if destroying is forced, or the IKE_SA
+        *                                                is not in an established state and can not be
+        *                                                deleted (but destroyed)
         */
-       status_t (*delete) (ike_sa_t *this);
+       status_t (*delete) (ike_sa_t *this, bool force);
 
        /**
         * Update IKE_SAs after network interfaces have changed.
@@ -739,7 +814,7 @@ struct ike_sa_t {
        status_t (*roam)(ike_sa_t *this, bool address);
 
        /**
-        * Processes a incoming IKEv2-Message.
+        * Processes an incoming IKE message.
         *
         * Message processing may fail. If a critical failure occurs,
         * process_message() return DESTROY_ME. Then the caller must
@@ -751,10 +826,10 @@ struct ike_sa_t {
         *                                              - FAILED
         *                                              - DESTROY_ME if this IKE_SA MUST be deleted
         */
-       status_t (*process_message) (ike_sa_t *this, message_t *message);
+       status_t (*process_message)(ike_sa_t *this, message_t *message);
 
        /**
-        * Generate a IKE message to send it to the peer.
+        * Generate an IKE message to send it to the peer.
         *
         * This method generates all payloads in the message and encrypts/signs
         * the packet.
@@ -766,8 +841,26 @@ struct ike_sa_t {
         *                                              - FAILED
         *                                              - DESTROY_ME if this IKE_SA MUST be deleted
         */
-       status_t (*generate_message) (ike_sa_t *this, message_t *message,
-                                                                 packet_t **packet);
+       status_t (*generate_message)(ike_sa_t *this, message_t *message,
+                                                                packet_t **packet);
+
+       /**
+        * Generate an IKE message to send it to the peer. If enabled and supported
+        * it will be fragmented.
+        *
+        * This method generates all payloads in the message and encrypts/signs
+        * the packet/fragments.
+        *
+        * @param message               message to generate
+        * @param packets               enumerator of generated packet_t* (are not destroyed
+        *                                              with the enumerator)
+        * @return
+        *                                              - SUCCESS
+        *                                              - FAILED
+        *                                              - DESTROY_ME if this IKE_SA MUST be deleted
+        */
+       status_t (*generate_message_fragmented)(ike_sa_t *this, message_t *message,
+                                                                                       enumerator_t **packets);
 
        /**
         * Retransmits a request.
@@ -775,9 +868,9 @@ struct ike_sa_t {
         * @param message_id    ID of the request to retransmit
         * @return
         *                                              - SUCCESS
-        *                                              - NOT_FOUND if request doesn't have to be retransmited
+        *                                              - NOT_FOUND if request doesn't have to be retransmitted
         */
-       status_t (*retransmit) (ike_sa_t *this, u_int32_t message_id);
+       status_t (*retransmit) (ike_sa_t *this, uint32_t message_id);
 
        /**
         * Sends a DPD request to the peer.
@@ -795,12 +888,38 @@ struct ike_sa_t {
        /**
         * Sends a keep alive packet.
         *
-        * To refresh NAT tables in a NAT router
-        * between the peers, periodic empty
-        * UDP packets are sent if no other traffic
-        * was sent.
+        * To refresh NAT tables in a NAT router between the peers, periodic empty
+        * UDP packets are sent if no other traffic was sent.
+        *
+        * @param scheduled             if this is a scheduled keepalive
+        */
+       void (*send_keepalive) (ike_sa_t *this, bool scheduled);
+
+       /**
+        * Redirect an active IKE_SA.
+        *
+        * @param gateway               gateway ID (IP or FQDN) of the target
+        * @return                              state, including DESTROY_ME, if this IKE_SA MUST be
+        *                                              destroyed
         */
-       void (*send_keepalive) (ike_sa_t *this);
+       status_t (*redirect)(ike_sa_t *this, identification_t *gateway);
+
+       /**
+        * Handle a redirect request.
+        *
+        * The behavior is different depending on the state of the IKE_SA.
+        *
+        * @param gateway               gateway ID (IP or FQDN) of the target
+        * @return                              FALSE if redirect not possible, TRUE otherwise
+        */
+       bool (*handle_redirect)(ike_sa_t *this, identification_t *gateway);
+
+       /**
+        * Get the address of the gateway that redirected us.
+        *
+        * @return                              original gateway address
+        */
+       host_t *(*get_redirected_from)(ike_sa_t *this);
 
        /**
         * Get the keying material of this IKE_SA.
@@ -825,7 +944,7 @@ struct ike_sa_t {
         * @return                              child_sa, or NULL if none found
         */
        child_sa_t* (*get_child_sa) (ike_sa_t *this, protocol_id_t protocol,
-                                                                u_int32_t spi, bool inbound);
+                                                                uint32_t spi, bool inbound);
 
        /**
         * Get the number of CHILD_SAs.
@@ -859,7 +978,7 @@ struct ike_sa_t {
         *                                              - NOT_FOUND, if IKE_SA has no such CHILD_SA
         *                                              - SUCCESS, if rekeying initiated
         */
-       status_t (*rekey_child_sa) (ike_sa_t *this, protocol_id_t protocol, u_int32_t spi);
+       status_t (*rekey_child_sa) (ike_sa_t *this, protocol_id_t protocol, uint32_t spi);
 
        /**
         * Close the CHILD SA with the specified protocol/SPI.
@@ -876,7 +995,7 @@ struct ike_sa_t {
         *                                              - SUCCESS, if delete message sent
         */
        status_t (*delete_child_sa)(ike_sa_t *this, protocol_id_t protocol,
-                                                               u_int32_t spi, bool expired);
+                                                               uint32_t spi, bool expired);
 
        /**
         * Destroy a CHILD SA with the specified protocol/SPI.
@@ -889,12 +1008,12 @@ struct ike_sa_t {
         *                                              - NOT_FOUND, if IKE_SA has no such CHILD_SA
         *                                              - SUCCESS
         */
-       status_t (*destroy_child_sa) (ike_sa_t *this, protocol_id_t protocol, u_int32_t spi);
+       status_t (*destroy_child_sa) (ike_sa_t *this, protocol_id_t protocol, uint32_t spi);
 
        /**
         * Rekey the IKE_SA.
         *
-        * Sets up a new IKE_SA, moves all CHILDs to it and deletes this IKE_SA.
+        * Sets up a new IKE_SA, moves all CHILD_SAs to it and deletes this IKE_SA.
         *
         * @return                              - SUCCESS, if IKE_SA rekeying initiated
         */
@@ -903,8 +1022,9 @@ struct ike_sa_t {
        /**
         * Reauthenticate the IKE_SA.
         *
-        * Create a completely new IKE_SA with authentication, recreates all children
-        * within the IKE_SA, closes this IKE_SA.
+        * Triggers a new IKE_SA that replaces this one. IKEv1 implicitly inherits
+        * all Quick Modes, while IKEv2 recreates all active and queued CHILD_SAs
+        * in the new IKE_SA.
         *
         * @return                              DESTROY_ME to destroy the IKE_SA
         */
@@ -928,10 +1048,10 @@ struct ike_sa_t {
         * @param lifetime              lifetime in seconds
         * @return                              DESTROY_ME to destroy the IKE_SA
         */
-       status_t (*set_auth_lifetime)(ike_sa_t *this, u_int32_t lifetime);
+       status_t (*set_auth_lifetime)(ike_sa_t *this, uint32_t lifetime);
 
        /**
-        * Set the virtual IP to use for this IKE_SA and its children.
+        * Add a virtual IP to use for this IKE_SA and its children.
         *
         * The virtual IP is assigned per IKE_SA, not per CHILD_SA. It has the same
         * lifetime as the IKE_SA.
@@ -939,15 +1059,30 @@ struct ike_sa_t {
         * @param local                 TRUE to set local address, FALSE for remote
         * @param ip                    IP to set as virtual IP
         */
-       void (*set_virtual_ip) (ike_sa_t *this, bool local, host_t *ip);
+       void (*add_virtual_ip) (ike_sa_t *this, bool local, host_t *ip);
+
+       /**
+        * Clear all virtual IPs stored on this IKE_SA.
+        *
+        * @param local                 TRUE to clear local addresses, FALSE for remote
+        */
+       void (*clear_virtual_ips) (ike_sa_t *this, bool local);
+
+       /**
+        * Get interface ID to use as default for children of this IKE_SA.
+        *
+        * @param inbound               TRUE for inbound interface ID
+        * @return                              interface ID
+        */
+       uint32_t (*get_if_id)(ike_sa_t *this, bool inbound);
 
        /**
-        * Get the virtual IP configured.
+        * Create an enumerator over virtual IPs.
         *
         * @param local                 TRUE to get local virtual IP, FALSE for remote
-        * @return                              host_t *virtual IP
+        * @return                              enumerator over host_t*
         */
-       host_t* (*get_virtual_ip) (ike_sa_t *this, bool local);
+       enumerator_t* (*create_virtual_ip_enumerator) (ike_sa_t *this, bool local);
 
        /**
         * Register a configuration attribute to the IKE_SA.
@@ -956,6 +1091,9 @@ struct ike_sa_t {
         * registered at the IKE_SA. Attributes are inherit()ed and get released
         * when the IKE_SA is closed.
         *
+        * Unhandled attributes are passed as well, but with a NULL handler. They
+        * do not get released.
+        *
         * @param handler               handler installed the attribute, use for release()
         * @param type                  configuration attribute type
         * @param data                  associated attribute data
@@ -964,6 +1102,17 @@ struct ike_sa_t {
                                                        attribute_handler_t *handler,
                                                        configuration_attribute_type_t type, chunk_t data);
 
+       /**
+        * Create an enumerator over received configuration attributes.
+        *
+        * The resulting enumerator is over the configuration_attribute_type_t type,
+        * a value chunk_t followed by a bool flag. The boolean flag indicates if
+        * the attribute has been handled by an attribute handler.
+        *
+        * @return                              enumerator over type, value and the "handled" flag.
+        */
+       enumerator_t* (*create_attribute_enumerator)(ike_sa_t *this);
+
        /**
         * Set local and remote host addresses to be used for IKE.
         *
@@ -983,6 +1132,16 @@ struct ike_sa_t {
         */
        enumerator_t* (*create_task_enumerator)(ike_sa_t *this, task_queue_t queue);
 
+       /**
+        * Remove the task the given enumerator points to.
+        *
+        * @note This should be used with caution, in partciular, for tasks in the
+        * active and passive queues.
+        *
+        * @param enumerator    enumerator created with the method above
+        */
+       void (*remove_task)(ike_sa_t *this, enumerator_t *enumerator);
+
        /**
         * Flush a task queue, cancelling all tasks in it.
         *
@@ -997,21 +1156,48 @@ struct ike_sa_t {
         */
        void (*queue_task)(ike_sa_t *this, task_t *task);
 
+       /**
+        * Queue a task in the manager, but delay its initiation for at least the
+        * given number of seconds.
+        *
+        * @param task                  task to queue
+        * @param delay                 minimum delay in s before initiating the task
+        */
+       void (*queue_task_delayed)(ike_sa_t *this, task_t *task, uint32_t delay);
+
+       /**
+        * Adopt child creating tasks from the given IKE_SA.
+        *
+        * @param other                 other IKE_SA to adopt tasks from
+        */
+       void (*adopt_child_tasks)(ike_sa_t *this, ike_sa_t *other);
+
+       /**
+        * Inherit required attributes to new SA before rekeying.
+        *
+        * Some properties of the SA must be applied before starting IKE_SA
+        * rekeying, such as the configuration or support extensions.
+        *
+        * @param other                 other IKE_SA to inherit from
+        */
+       void (*inherit_pre)(ike_sa_t *this, ike_sa_t *other);
+
        /**
         * Inherit all attributes of other to this after rekeying.
         *
         * When rekeying is completed, all CHILD_SAs, the virtual IP and all
         * outstanding tasks are moved from other to this.
-        * As this call may initiate inherited tasks, a status is returned.
         *
-        * @param other                 other task to inherit from
+        * @param other                 other IKE SA to inherit from
         */
-       void (*inherit) (ike_sa_t *this, ike_sa_t *other);
+       void (*inherit_post) (ike_sa_t *this, ike_sa_t *other);
 
        /**
-        * Reset the IKE_SA, useable when initiating fails
+        * Reset the IKE_SA, usable when initiating fails.
+        *
+        * @param new_spi               TRUE to allocate a new initiator SPI
         */
-       void (*reset) (ike_sa_t *this);
+       void (*reset) (ike_sa_t *this, bool new_spi);
 
        /**
         * Destroys a ike_sa_t object.