/*
- * 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
#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.
/**
* 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
/**
* peer supports NAT traversal as specified in RFC4306 or RFC3947
+ * including some RFC3947 drafts
*/
EXT_NATT = (1<<0),
EXT_EAP_ONLY_AUTHENTICATION = (1<<5),
/**
- * peer is probably a Windows 7 RAS client
+ * peer is probably a Windows RAS client
*/
EXT_MS_WINDOWS = (1<<6),
* 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),
};
/**
* 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),
};
/**
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,
*/
IKE_REKEYING,
+ /**
+ * IKE_SA has been rekeyed (or is redundant)
+ */
+ IKE_REKEYED,
+
/**
* IKE_SA is in progress of deletion
*/
*
* @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.
* @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.
* @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.
*/
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.
*
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).
* @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.
*/
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.
* - 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);
/**
*
* 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.
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
* - 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.
* - 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.
* @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.
/**
* 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.
* @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.
* - 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.
* - 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.
* - 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
*/
/**
* 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
*/
* @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.
* @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.
* 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
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.
*
*/
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.
*
*/
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.