2005-11-08 13:33:28 +00:00
|
|
|
/*
|
2012-03-09 09:15:21 +00:00
|
|
|
* Copyright (C) 2006-2012 Tobias Brunner
|
2007-10-03 15:10:41 +00:00
|
|
|
* Copyright (C) 2006 Daniel Roethlisberger
|
2009-04-14 10:34:24 +00:00
|
|
|
* Copyright (C) 2005-2009 Martin Willi
|
2006-07-07 08:49:06 +00:00
|
|
|
* Copyright (C) 2005 Jan Hutter
|
2005-11-08 13:33:28 +00:00
|
|
|
* 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
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
2006-06-22 06:36:28 +00:00
|
|
|
|
2006-04-10 08:07:38 +00:00
|
|
|
#include <string.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sys/stat.h>
|
2007-04-12 08:52:36 +00:00
|
|
|
#include <errno.h>
|
2008-11-05 08:32:38 +00:00
|
|
|
#include <time.h>
|
2005-11-08 13:33:28 +00:00
|
|
|
|
2005-11-11 13:52:11 +00:00
|
|
|
#include "ike_sa.h"
|
|
|
|
|
2006-10-31 12:27:59 +00:00
|
|
|
#include <library.h>
|
2010-03-24 16:46:29 +00:00
|
|
|
#include <hydra.h>
|
2010-07-05 11:52:05 +00:00
|
|
|
#include <daemon.h>
|
2005-11-23 09:24:35 +00:00
|
|
|
#include <utils/linked_list.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <utils/lexparser.h>
|
|
|
|
#include <sa/task_manager.h>
|
|
|
|
#include <sa/tasks/ike_init.h>
|
|
|
|
#include <sa/tasks/ike_natd.h>
|
2007-06-21 15:25:28 +00:00
|
|
|
#include <sa/tasks/ike_mobike.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sa/tasks/ike_auth.h>
|
2007-12-03 10:52:18 +00:00
|
|
|
#include <sa/tasks/ike_auth_lifetime.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sa/tasks/ike_config.h>
|
2008-03-13 14:14:44 +00:00
|
|
|
#include <sa/tasks/ike_cert_pre.h>
|
|
|
|
#include <sa/tasks/ike_cert_post.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sa/tasks/ike_rekey.h>
|
2007-06-14 08:13:05 +00:00
|
|
|
#include <sa/tasks/ike_reauth.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sa/tasks/ike_delete.h>
|
|
|
|
#include <sa/tasks/ike_dpd.h>
|
2010-01-07 09:26:58 +00:00
|
|
|
#include <sa/tasks/ike_vendor.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sa/tasks/child_create.h>
|
|
|
|
#include <sa/tasks/child_delete.h>
|
|
|
|
#include <sa/tasks/child_rekey.h>
|
2007-04-10 06:01:03 +00:00
|
|
|
#include <processing/jobs/retransmit_job.h>
|
|
|
|
#include <processing/jobs/delete_ike_sa_job.h>
|
|
|
|
#include <processing/jobs/send_dpd_job.h>
|
|
|
|
#include <processing/jobs/send_keepalive_job.h>
|
|
|
|
#include <processing/jobs/rekey_ike_sa_job.h>
|
2010-11-10 15:47:56 +00:00
|
|
|
#include <encoding/payloads/unknown_payload.h>
|
2005-11-08 13:33:28 +00:00
|
|
|
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
|
|
|
#include <sa/tasks/ike_me.h>
|
2007-12-04 10:48:27 +00:00
|
|
|
#include <processing/jobs/initiate_mediation_job.h>
|
2007-10-03 15:10:41 +00:00
|
|
|
#endif
|
2007-02-28 14:04:36 +00:00
|
|
|
|
2008-10-14 08:52:13 +00:00
|
|
|
ENUM(ike_sa_state_names, IKE_CREATED, IKE_DESTROYING,
|
2006-10-18 11:46:13 +00:00
|
|
|
"CREATED",
|
|
|
|
"CONNECTING",
|
|
|
|
"ESTABLISHED",
|
2008-11-28 10:49:14 +00:00
|
|
|
"PASSIVE",
|
2006-10-18 11:46:13 +00:00
|
|
|
"REKEYING",
|
|
|
|
"DELETING",
|
2008-10-14 08:52:13 +00:00
|
|
|
"DESTROYING",
|
2006-10-18 11:46:13 +00:00
|
|
|
);
|
2005-11-08 13:33:28 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
typedef struct private_ike_sa_t private_ike_sa_t;
|
2009-04-24 14:13:52 +00:00
|
|
|
typedef struct attribute_entry_t attribute_entry_t;
|
2005-11-25 13:42:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data of an ike_sa_t object.
|
|
|
|
*/
|
|
|
|
struct private_ike_sa_t {
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* Public members
|
2006-06-23 14:02:30 +00:00
|
|
|
*/
|
2006-07-05 10:53:20 +00:00
|
|
|
ike_sa_t public;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2005-12-03 16:52:54 +00:00
|
|
|
* Identifier for the current IKE_SA.
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
|
|
|
ike_sa_id_t *ike_sa_id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* unique numerical ID for this IKE_SA.
|
|
|
|
*/
|
|
|
|
u_int32_t unique_id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Current state of the IKE_SA
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2009-04-24 14:13:52 +00:00
|
|
|
ike_sa_state_t state;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-12-01 17:16:10 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* IKE configuration used to set up this IKE_SA
|
2005-12-01 17:16:10 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
ike_cfg_t *ike_cfg;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* Peer and authentication information to establish IKE_SA.
|
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
peer_cfg_t *peer_cfg;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-13 14:14:44 +00:00
|
|
|
/**
|
2009-04-14 10:34:24 +00:00
|
|
|
* currently used authentication ruleset, local (as auth_cfg_t)
|
2008-03-13 14:14:44 +00:00
|
|
|
*/
|
2009-04-14 10:34:24 +00:00
|
|
|
auth_cfg_t *my_auth;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-12-01 10:35:30 +00:00
|
|
|
/**
|
|
|
|
* list of completed local authentication rounds
|
|
|
|
*/
|
|
|
|
linked_list_t *my_auths;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* list of completed remote authentication rounds
|
|
|
|
*/
|
|
|
|
linked_list_t *other_auths;
|
|
|
|
|
2008-03-13 14:14:44 +00:00
|
|
|
/**
|
2009-04-14 10:34:24 +00:00
|
|
|
* currently used authentication constraints, remote (as auth_cfg_t)
|
2008-03-13 14:14:44 +00:00
|
|
|
*/
|
2009-04-14 10:34:24 +00:00
|
|
|
auth_cfg_t *other_auth;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-30 12:58:54 +00:00
|
|
|
/**
|
|
|
|
* Selected IKE proposal
|
|
|
|
*/
|
|
|
|
proposal_t *proposal;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* Juggles tasks to process messages
|
|
|
|
*/
|
|
|
|
task_manager_t *task_manager;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
|
|
|
* Address of local host
|
|
|
|
*/
|
|
|
|
host_t *my_host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
|
|
|
* Address of remote host
|
|
|
|
*/
|
|
|
|
host_t *other_host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2008-04-09 18:12:22 +00:00
|
|
|
/**
|
|
|
|
* Are we mediation server
|
|
|
|
*/
|
|
|
|
bool is_mediation_server;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-10-03 15:10:41 +00:00
|
|
|
/**
|
|
|
|
* Server reflexive host
|
|
|
|
*/
|
|
|
|
host_t *server_reflexive_host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-01 11:38:18 +00:00
|
|
|
/**
|
|
|
|
* Connect ID
|
|
|
|
*/
|
|
|
|
chunk_t connect_id;
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
|
|
|
* Identification used for us
|
|
|
|
*/
|
|
|
|
identification_t *my_id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-12-01 17:16:10 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Identification used for other
|
2005-12-01 17:16:10 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
identification_t *other_id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-18 10:32:01 +00:00
|
|
|
/**
|
|
|
|
* set of extensions the peer supports
|
|
|
|
*/
|
|
|
|
ike_extension_t extensions;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-21 15:25:28 +00:00
|
|
|
/**
|
|
|
|
* set of condition flags currently enabled for this IKE_SA
|
|
|
|
*/
|
|
|
|
ike_condition_t conditions;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Linked List containing the child sa's of the current IKE_SA.
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
linked_list_t *child_sas;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-06-22 11:24:33 +00:00
|
|
|
/**
|
2008-10-28 16:07:06 +00:00
|
|
|
* keymat of this IKE_SA
|
2008-06-22 11:24:33 +00:00
|
|
|
*/
|
2008-10-28 16:07:06 +00:00
|
|
|
keymat_t *keymat;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* Virtual IP on local host, if any
|
2006-07-05 10:53:20 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
host_t *my_virtual_ip;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* Virtual IP on remote host, if any
|
|
|
|
*/
|
|
|
|
host_t *other_virtual_ip;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-01-10 08:18:52 +00:00
|
|
|
/**
|
2009-04-24 14:13:52 +00:00
|
|
|
* List of configuration attributes (attribute_entry_t)
|
2007-01-10 08:18:52 +00:00
|
|
|
*/
|
2009-04-24 14:13:52 +00:00
|
|
|
linked_list_t *attributes;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-21 15:25:28 +00:00
|
|
|
/**
|
2012-03-09 09:15:21 +00:00
|
|
|
* list of peer's addresses, additional ones transmitted via MOBIKE
|
2007-06-21 15:25:28 +00:00
|
|
|
*/
|
2012-03-09 09:15:21 +00:00
|
|
|
linked_list_t *peer_addresses;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-06 13:37:04 +00:00
|
|
|
/**
|
|
|
|
* previously value of received DESTINATION_IP hash
|
|
|
|
*/
|
|
|
|
chunk_t nat_detection_dest;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-07-03 12:32:38 +00:00
|
|
|
/**
|
|
|
|
* number pending UPDATE_SA_ADDRESS (MOBIKE)
|
|
|
|
*/
|
|
|
|
u_int32_t pending_updates;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-09-03 18:49:06 +00:00
|
|
|
/**
|
|
|
|
* NAT keep alive interval
|
|
|
|
*/
|
|
|
|
u_int32_t keepalive_interval;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-06-22 06:36:28 +00:00
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Timestamps for this IKE_SA
|
2006-06-22 06:36:28 +00:00
|
|
|
*/
|
2008-10-27 14:51:00 +00:00
|
|
|
u_int32_t stats[STAT_MAX];
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-20 08:16:16 +00:00
|
|
|
/**
|
|
|
|
* how many times we have retried so far (keyingtries)
|
|
|
|
*/
|
|
|
|
u_int32_t keyingtry;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/**
|
|
|
|
* local host address to be used for IKE, set via MIGRATE kernel message
|
|
|
|
*/
|
|
|
|
host_t *local_host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
/**
|
|
|
|
* remote host address to be used for IKE, set via MIGRATE kernel message
|
|
|
|
*/
|
|
|
|
host_t *remote_host;
|
2005-11-25 13:42:02 +00:00
|
|
|
};
|
|
|
|
|
2009-04-24 14:13:52 +00:00
|
|
|
/**
|
|
|
|
* Entry to maintain install configuration attributes during IKE_SA lifetime
|
|
|
|
*/
|
|
|
|
struct attribute_entry_t {
|
|
|
|
/** handler used to install this attribute */
|
|
|
|
attribute_handler_t *handler;
|
|
|
|
/** attribute type */
|
|
|
|
configuration_attribute_type_t type;
|
|
|
|
/** attribute data */
|
|
|
|
chunk_t data;
|
|
|
|
};
|
|
|
|
|
2005-11-21 10:59:45 +00:00
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* get the time of the latest traffic processed by the kernel
|
2005-11-21 10:59:45 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static time_t get_use_time(private_ike_sa_t* this, bool inbound)
|
2005-11-18 12:01:53 +00:00
|
|
|
{
|
2008-10-24 08:02:35 +00:00
|
|
|
enumerator_t *enumerator;
|
2006-07-05 10:53:20 +00:00
|
|
|
child_sa_t *child_sa;
|
2009-08-06 14:46:02 +00:00
|
|
|
time_t use_time, current;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
if (inbound)
|
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
use_time = this->stats[STAT_INBOUND];
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
use_time = this->stats[STAT_OUTBOUND];
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2008-10-24 08:02:35 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, &child_sa))
|
|
|
|
{
|
2009-08-06 14:46:02 +00:00
|
|
|
child_sa->get_usestats(child_sa, inbound, ¤t, NULL);
|
|
|
|
use_time = max(use_time, current);
|
2008-10-24 08:02:35 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-24 08:02:35 +00:00
|
|
|
return use_time;
|
2005-12-01 17:16:10 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_unique_id, u_int32_t,
|
|
|
|
private_ike_sa_t *this)
|
2005-11-25 13:42:02 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
return this->unique_id;
|
2005-11-25 13:42:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_name, char*,
|
|
|
|
private_ike_sa_t *this)
|
2005-12-02 19:26:01 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
if (this->peer_cfg)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->peer_cfg->get_name(this->peer_cfg);
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
return "(unnamed)";
|
2005-12-02 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_statistic, u_int32_t,
|
|
|
|
private_ike_sa_t *this, statistic_t kind)
|
2007-04-11 12:14:51 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
if (kind < STAT_MAX)
|
2007-04-11 12:14:51 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
return this->stats[kind];
|
2007-04-11 12:14:51 +00:00
|
|
|
}
|
2007-11-20 12:06:40 +00:00
|
|
|
return 0;
|
2007-04-11 12:14:51 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_my_host, host_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->my_host;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_my_host, void,
|
|
|
|
private_ike_sa_t *this, host_t *me)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
DESTROY_IF(this->my_host);
|
|
|
|
this->my_host = me;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_other_host, host_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-09-25 06:38:58 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->other_host;
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_other_host, void,
|
|
|
|
private_ike_sa_t *this, host_t *other)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
DESTROY_IF(this->other_host);
|
|
|
|
this->other_host = other;
|
2006-09-25 06:38:58 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_peer_cfg, peer_cfg_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->peer_cfg;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_peer_cfg, void,
|
|
|
|
private_ike_sa_t *this, peer_cfg_t *peer_cfg)
|
2006-07-27 12:18:40 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
peer_cfg->get_ref(peer_cfg);
|
2011-11-04 08:24:51 +00:00
|
|
|
DESTROY_IF(this->peer_cfg);
|
2007-04-10 06:01:03 +00:00
|
|
|
this->peer_cfg = peer_cfg;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
if (this->ike_cfg == NULL)
|
|
|
|
{
|
|
|
|
this->ike_cfg = peer_cfg->get_ike_cfg(peer_cfg);
|
|
|
|
this->ike_cfg->get_ref(this->ike_cfg);
|
|
|
|
}
|
2008-03-13 14:14:44 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_auth_cfg, auth_cfg_t*,
|
|
|
|
private_ike_sa_t *this, bool local)
|
2008-03-13 14:14:44 +00:00
|
|
|
{
|
2009-04-14 10:34:24 +00:00
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
return this->my_auth;
|
|
|
|
}
|
2008-03-13 14:14:44 +00:00
|
|
|
return this->other_auth;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, add_auth_cfg, void,
|
|
|
|
private_ike_sa_t *this, bool local, auth_cfg_t *cfg)
|
2009-12-01 10:35:30 +00:00
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
this->my_auths->insert_last(this->my_auths, cfg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->other_auths->insert_last(this->other_auths, cfg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, create_auth_cfg_enumerator, enumerator_t*,
|
|
|
|
private_ike_sa_t *this, bool local)
|
2009-12-01 10:35:30 +00:00
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
return this->my_auths->create_enumerator(this->my_auths);
|
|
|
|
}
|
|
|
|
return this->other_auths->create_enumerator(this->other_auths);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush the stored authentication round information
|
|
|
|
*/
|
|
|
|
static void flush_auth_cfgs(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
auth_cfg_t *cfg;
|
|
|
|
|
2010-06-07 12:59:39 +00:00
|
|
|
while (this->my_auths->remove_last(this->my_auths,
|
|
|
|
(void**)&cfg) == SUCCESS)
|
2009-12-01 10:35:30 +00:00
|
|
|
{
|
2010-06-07 12:59:39 +00:00
|
|
|
cfg->destroy(cfg);
|
|
|
|
}
|
|
|
|
while (this->other_auths->remove_last(this->other_auths,
|
|
|
|
(void**)&cfg) == SUCCESS)
|
|
|
|
{
|
|
|
|
cfg->destroy(cfg);
|
2009-12-01 10:35:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_proposal, proposal_t*,
|
|
|
|
private_ike_sa_t *this)
|
2008-10-30 12:58:54 +00:00
|
|
|
{
|
|
|
|
return this->proposal;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_proposal, void,
|
|
|
|
private_ike_sa_t *this, proposal_t *proposal)
|
2008-10-30 12:58:54 +00:00
|
|
|
{
|
|
|
|
DESTROY_IF(this->proposal);
|
|
|
|
this->proposal = proposal->clone(proposal);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_message_id, void,
|
|
|
|
private_ike_sa_t *this, bool initiate, u_int32_t mid)
|
2008-11-24 12:46:06 +00:00
|
|
|
{
|
|
|
|
if (initiate)
|
|
|
|
{
|
2008-11-24 13:59:30 +00:00
|
|
|
this->task_manager->reset(this->task_manager, mid, UINT_MAX);
|
2008-11-24 12:46:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-24 13:59:30 +00:00
|
|
|
this->task_manager->reset(this->task_manager, UINT_MAX, mid);
|
2008-11-24 12:46:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, send_keepalive, void,
|
|
|
|
private_ike_sa_t *this)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
send_keepalive_job_t *job;
|
|
|
|
time_t last_out, now, diff;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-09-03 19:00:08 +00:00
|
|
|
if (!(this->conditions & COND_NAT_HERE) || this->keepalive_interval == 0)
|
2007-07-02 12:55:07 +00:00
|
|
|
{ /* disable keep alives if we are not NATed anymore */
|
|
|
|
return;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
last_out = get_use_time(this, FALSE);
|
2009-08-31 15:59:00 +00:00
|
|
|
now = time_monotonic(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
diff = now - last_out;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-09-03 18:49:06 +00:00
|
|
|
if (diff >= this->keepalive_interval)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
packet_t *packet;
|
|
|
|
chunk_t data;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
packet = packet_create();
|
|
|
|
packet->set_source(packet, this->my_host->clone(this->my_host));
|
|
|
|
packet->set_destination(packet, this->other_host->clone(this->other_host));
|
|
|
|
data.ptr = malloc(1);
|
|
|
|
data.ptr[0] = 0xFF;
|
|
|
|
data.len = 1;
|
|
|
|
packet->set_data(packet, data);
|
|
|
|
DBG1(DBG_IKE, "sending keep alive");
|
2007-07-02 12:55:07 +00:00
|
|
|
charon->sender->send(charon->sender, packet);
|
2007-06-26 13:04:13 +00:00
|
|
|
diff = 0;
|
|
|
|
}
|
|
|
|
job = send_keepalive_job_create(this->ike_sa_id);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, (job_t*)job,
|
|
|
|
this->keepalive_interval - diff);
|
2007-06-26 13:04:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_ike_cfg, ike_cfg_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
return this->ike_cfg;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
2006-02-09 16:25:02 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_ike_cfg, void,
|
|
|
|
private_ike_sa_t *this, ike_cfg_t *ike_cfg)
|
2006-07-27 12:18:40 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
ike_cfg->get_ref(ike_cfg);
|
|
|
|
this->ike_cfg = ike_cfg;
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
2008-04-10 07:24:30 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, enable_extension, void,
|
|
|
|
private_ike_sa_t *this, ike_extension_t extension)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
this->extensions |= extension;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, supports_extension, bool,
|
|
|
|
private_ike_sa_t *this, ike_extension_t extension)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
return (this->extensions & extension) != FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, has_condition, bool,
|
|
|
|
private_ike_sa_t *this, ike_condition_t condition)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
return (this->conditions & condition) != FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_condition, void,
|
|
|
|
private_ike_sa_t *this, ike_condition_t condition, bool enable)
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
if (has_condition(this, condition) != enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
2007-06-27 13:10:55 +00:00
|
|
|
this->conditions |= condition;
|
2007-06-26 13:04:13 +00:00
|
|
|
switch (condition)
|
|
|
|
{
|
|
|
|
case COND_NAT_HERE:
|
|
|
|
DBG1(DBG_IKE, "local host is behind NAT, sending keep alives");
|
|
|
|
this->conditions |= COND_NAT_ANY;
|
|
|
|
send_keepalive(this);
|
|
|
|
break;
|
|
|
|
case COND_NAT_THERE:
|
|
|
|
DBG1(DBG_IKE, "remote host is behind NAT");
|
|
|
|
this->conditions |= COND_NAT_ANY;
|
|
|
|
break;
|
2007-10-01 12:19:39 +00:00
|
|
|
case COND_NAT_FAKE:
|
2007-10-01 16:41:34 +00:00
|
|
|
DBG1(DBG_IKE, "faking NAT situation to enforce UDP encapsulation");
|
2007-10-01 12:19:39 +00:00
|
|
|
this->conditions |= COND_NAT_ANY;
|
|
|
|
break;
|
2007-06-26 13:04:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-27 13:10:55 +00:00
|
|
|
this->conditions &= ~condition;
|
2007-06-26 13:04:13 +00:00
|
|
|
switch (condition)
|
|
|
|
{
|
2007-06-27 13:10:55 +00:00
|
|
|
case COND_NAT_HERE:
|
2007-10-01 12:19:39 +00:00
|
|
|
case COND_NAT_FAKE:
|
2007-06-27 13:10:55 +00:00
|
|
|
case COND_NAT_THERE:
|
|
|
|
set_condition(this, COND_NAT_ANY,
|
|
|
|
has_condition(this, COND_NAT_HERE) ||
|
2007-10-01 12:19:39 +00:00
|
|
|
has_condition(this, COND_NAT_THERE) ||
|
|
|
|
has_condition(this, COND_NAT_FAKE));
|
2007-06-27 13:10:55 +00:00
|
|
|
break;
|
2007-06-26 13:04:13 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-27 12:18:40 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, send_dpd, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2009-04-21 15:16:56 +00:00
|
|
|
job_t *job;
|
2007-03-20 08:16:16 +00:00
|
|
|
time_t diff, delay;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2008-04-11 08:14:48 +00:00
|
|
|
delay = this->peer_cfg->get_dpd(this->peer_cfg);
|
2007-03-20 08:16:16 +00:00
|
|
|
if (this->task_manager->busy(this->task_manager))
|
|
|
|
{
|
|
|
|
/* an exchange is in the air, no need to start a DPD check */
|
|
|
|
diff = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* check if there was any inbound traffic */
|
|
|
|
time_t last_in, now;
|
|
|
|
last_in = get_use_time(this, TRUE);
|
2009-08-31 15:59:00 +00:00
|
|
|
now = time_monotonic(NULL);
|
2007-03-20 08:16:16 +00:00
|
|
|
diff = now - last_in;
|
2010-10-29 13:36:19 +00:00
|
|
|
if (!delay || diff >= delay)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
|
|
|
/* to long ago, initiate dead peer detection */
|
|
|
|
task_t *task;
|
2008-10-06 13:37:04 +00:00
|
|
|
ike_mobike_t *mobike;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-06 13:37:04 +00:00
|
|
|
if (supports_extension(this, EXT_MOBIKE) &&
|
|
|
|
has_condition(this, COND_NAT_HERE))
|
|
|
|
{
|
|
|
|
/* use mobike enabled DPD to detect NAT mapping changes */
|
|
|
|
mobike = ike_mobike_create(&this->public, TRUE);
|
|
|
|
mobike->dpd(mobike);
|
|
|
|
task = &mobike->task;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
task = (task_t*)ike_dpd_create(TRUE);
|
|
|
|
}
|
2007-03-20 08:16:16 +00:00
|
|
|
diff = 0;
|
|
|
|
DBG1(DBG_IKE, "sending DPD request");
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-20 08:16:16 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* recheck in "interval" seconds */
|
2010-10-29 13:36:19 +00:00
|
|
|
if (delay)
|
|
|
|
{
|
|
|
|
job = (job_t*)send_dpd_job_create(this->ike_sa_id);
|
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job, delay - diff);
|
|
|
|
}
|
2007-03-20 08:16:16 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_state, ike_sa_state_t,
|
|
|
|
private_ike_sa_t *this)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_state, void,
|
|
|
|
private_ike_sa_t *this, ike_sa_state_t state)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2012-02-02 09:33:40 +00:00
|
|
|
bool trigger_dpd = FALSE;
|
|
|
|
|
2008-07-28 14:01:45 +00:00
|
|
|
DBG2(DBG_IKE, "IKE_SA %s[%d] state change: %N => %N",
|
2008-07-22 17:10:10 +00:00
|
|
|
get_name(this), this->unique_id,
|
2007-03-20 08:16:16 +00:00
|
|
|
ike_sa_state_names, this->state,
|
|
|
|
ike_sa_state_names, state);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-20 16:13:21 +00:00
|
|
|
switch (state)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2007-03-20 16:13:21 +00:00
|
|
|
case IKE_ESTABLISHED:
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2008-11-28 16:19:19 +00:00
|
|
|
if (this->state == IKE_CONNECTING ||
|
|
|
|
this->state == IKE_PASSIVE)
|
2007-03-20 16:13:21 +00:00
|
|
|
{
|
|
|
|
job_t *job;
|
2007-11-20 12:06:40 +00:00
|
|
|
u_int32_t t;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-11-20 12:06:40 +00:00
|
|
|
/* calculate rekey, reauth and lifetime */
|
2009-08-31 15:59:00 +00:00
|
|
|
this->stats[STAT_ESTABLISHED] = time_monotonic(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-11-20 12:06:40 +00:00
|
|
|
/* schedule rekeying if we have a time which is smaller than
|
|
|
|
* an already scheduled rekeying */
|
|
|
|
t = this->peer_cfg->get_rekey_time(this->peer_cfg);
|
2009-09-02 15:26:36 +00:00
|
|
|
if (t && (this->stats[STAT_REKEY] == 0 ||
|
2008-10-27 14:51:00 +00:00
|
|
|
(this->stats[STAT_REKEY] > t + this->stats[STAT_ESTABLISHED])))
|
2007-03-20 16:13:21 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_REKEY] = t + this->stats[STAT_ESTABLISHED];
|
2007-11-20 12:06:40 +00:00
|
|
|
job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, FALSE);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job, t);
|
2007-11-20 12:06:40 +00:00
|
|
|
DBG1(DBG_IKE, "scheduling rekeying in %ds", t);
|
2007-03-20 16:13:21 +00:00
|
|
|
}
|
2007-11-20 12:06:40 +00:00
|
|
|
t = this->peer_cfg->get_reauth_time(this->peer_cfg);
|
2009-09-02 15:26:36 +00:00
|
|
|
if (t && (this->stats[STAT_REAUTH] == 0 ||
|
2008-10-27 14:51:00 +00:00
|
|
|
(this->stats[STAT_REAUTH] > t + this->stats[STAT_ESTABLISHED])))
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_REAUTH] = t + this->stats[STAT_ESTABLISHED];
|
2007-11-20 12:06:40 +00:00
|
|
|
job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job, t);
|
2007-11-20 12:06:40 +00:00
|
|
|
DBG1(DBG_IKE, "scheduling reauthentication in %ds", t);
|
|
|
|
}
|
|
|
|
t = this->peer_cfg->get_over_time(this->peer_cfg);
|
2008-10-27 14:51:00 +00:00
|
|
|
if (this->stats[STAT_REKEY] || this->stats[STAT_REAUTH])
|
2007-03-20 16:13:21 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
if (this->stats[STAT_REAUTH] == 0)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] = this->stats[STAT_REKEY];
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2008-10-27 14:51:00 +00:00
|
|
|
else if (this->stats[STAT_REKEY] == 0)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] = this->stats[STAT_REAUTH];
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] = min(this->stats[STAT_REKEY],
|
|
|
|
this->stats[STAT_REAUTH]);
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] += t;
|
|
|
|
t = this->stats[STAT_DELETE] - this->stats[STAT_ESTABLISHED];
|
2007-03-20 16:13:21 +00:00
|
|
|
job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job, t);
|
2007-11-20 12:06:40 +00:00
|
|
|
DBG1(DBG_IKE, "maximum IKE_SA lifetime %ds", t);
|
2007-03-20 16:13:21 +00:00
|
|
|
}
|
2012-02-02 09:33:40 +00:00
|
|
|
trigger_dpd = this->peer_cfg->get_dpd(this->peer_cfg);
|
2007-03-20 16:13:21 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
2007-03-20 16:13:21 +00:00
|
|
|
case IKE_DELETING:
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
2007-03-20 16:13:21 +00:00
|
|
|
/* delete may fail if a packet gets lost, so set a timeout */
|
|
|
|
job_t *job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job,
|
|
|
|
HALF_OPEN_IKE_SA_TIMEOUT);
|
2007-03-20 16:13:21 +00:00
|
|
|
break;
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
2007-03-20 16:13:21 +00:00
|
|
|
default:
|
|
|
|
break;
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
2008-10-14 08:52:13 +00:00
|
|
|
charon->bus->ike_state_change(charon->bus, &this->public, state);
|
2007-03-20 08:16:16 +00:00
|
|
|
this->state = state;
|
2012-02-02 09:33:40 +00:00
|
|
|
|
|
|
|
if (trigger_dpd)
|
|
|
|
{
|
|
|
|
send_dpd(this);
|
|
|
|
}
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, reset, void,
|
|
|
|
private_ike_sa_t *this)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
|
|
|
/* the responder ID is reset, as peer may choose another one */
|
|
|
|
if (this->ike_sa_id->is_initiator(this->ike_sa_id))
|
|
|
|
{
|
|
|
|
this->ike_sa_id->set_responder_spi(this->ike_sa_id, 0);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-20 08:16:16 +00:00
|
|
|
set_state(this, IKE_CREATED);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-06-07 12:59:39 +00:00
|
|
|
flush_auth_cfgs(this);
|
|
|
|
|
|
|
|
this->keymat->destroy(this->keymat);
|
|
|
|
this->keymat = keymat_create(this->ike_sa_id->is_initiator(this->ike_sa_id));
|
|
|
|
|
2008-11-24 12:46:06 +00:00
|
|
|
this->task_manager->reset(this->task_manager, 0, 0);
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_keymat, keymat_t*,
|
|
|
|
private_ike_sa_t *this)
|
2008-10-28 16:07:06 +00:00
|
|
|
{
|
|
|
|
return this->keymat;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_virtual_ip, void,
|
|
|
|
private_ike_sa_t *this, bool local, host_t *ip)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
2007-09-24 12:15:25 +00:00
|
|
|
DBG1(DBG_IKE, "installing new virtual IP %H", ip);
|
2010-07-12 09:14:54 +00:00
|
|
|
if (hydra->kernel_interface->add_ip(hydra->kernel_interface, ip,
|
|
|
|
this->my_host) == SUCCESS)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
2007-10-25 07:50:23 +00:00
|
|
|
if (this->my_virtual_ip)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "removing old virtual IP %H", this->my_virtual_ip);
|
2010-07-12 09:14:54 +00:00
|
|
|
hydra->kernel_interface->del_ip(hydra->kernel_interface,
|
|
|
|
this->my_virtual_ip);
|
2007-10-25 07:50:23 +00:00
|
|
|
}
|
|
|
|
DESTROY_IF(this->my_virtual_ip);
|
2007-06-28 15:24:24 +00:00
|
|
|
this->my_virtual_ip = ip->clone(ip);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "installing virtual IP %H failed", ip);
|
|
|
|
this->my_virtual_ip = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DESTROY_IF(this->other_virtual_ip);
|
|
|
|
this->other_virtual_ip = ip->clone(ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_virtual_ip, host_t*,
|
|
|
|
private_ike_sa_t *this, bool local)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
return this->my_virtual_ip;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->other_virtual_ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-09 09:15:21 +00:00
|
|
|
METHOD(ike_sa_t, add_peer_address, void,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this, host_t *host)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
2012-03-09 09:15:21 +00:00
|
|
|
this->peer_addresses->insert_last(this->peer_addresses, host);
|
2007-06-28 15:24:24 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-03-09 09:15:21 +00:00
|
|
|
METHOD(ike_sa_t, create_peer_address_enumerator, enumerator_t*,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this)
|
2007-06-28 15:24:24 +00:00
|
|
|
{
|
2012-03-09 09:15:21 +00:00
|
|
|
return this->peer_addresses->create_enumerator(this->peer_addresses);
|
2011-05-19 16:05:53 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 09:15:21 +00:00
|
|
|
METHOD(ike_sa_t, clear_peer_addresses, void,
|
2011-05-19 16:05:53 +00:00
|
|
|
private_ike_sa_t *this)
|
|
|
|
{
|
2012-03-09 09:15:21 +00:00
|
|
|
enumerator_t *enumerator = create_peer_address_enumerator(this);
|
2011-05-19 16:05:53 +00:00
|
|
|
host_t *host;
|
2012-03-09 09:15:21 +00:00
|
|
|
|
2011-05-19 16:05:53 +00:00
|
|
|
while (enumerator->enumerate(enumerator, (void**)&host))
|
|
|
|
{
|
2012-03-09 09:15:21 +00:00
|
|
|
this->peer_addresses->remove_at(this->peer_addresses,
|
|
|
|
enumerator);
|
2011-05-19 16:05:53 +00:00
|
|
|
host->destroy(host);
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2007-06-28 15:24:24 +00:00
|
|
|
}
|
2008-10-06 13:37:04 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, has_mapping_changed, bool,
|
|
|
|
private_ike_sa_t *this, chunk_t hash)
|
2008-10-06 13:37:04 +00:00
|
|
|
{
|
|
|
|
if (this->nat_detection_dest.ptr == NULL)
|
|
|
|
{
|
|
|
|
this->nat_detection_dest = chunk_clone(hash);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (chunk_equals(hash, this->nat_detection_dest))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
free(this->nat_detection_dest.ptr);
|
|
|
|
this->nat_detection_dest = chunk_clone(hash);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_pending_updates, void,
|
|
|
|
private_ike_sa_t *this, u_int32_t updates)
|
2007-07-03 12:32:38 +00:00
|
|
|
{
|
|
|
|
this->pending_updates = updates;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_pending_updates, u_int32_t,
|
|
|
|
private_ike_sa_t *this)
|
2007-07-03 12:32:38 +00:00
|
|
|
{
|
|
|
|
return this->pending_updates;
|
|
|
|
}
|
2007-06-28 15:24:24 +00:00
|
|
|
|
2010-08-30 10:19:37 +00:00
|
|
|
METHOD(ike_sa_t, float_ports, void,
|
|
|
|
private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
/* do not switch if we have a custom port from MOBIKE/NAT */
|
|
|
|
if (this->my_host->get_port(this->my_host) == IKEV2_UDP_PORT)
|
|
|
|
{
|
|
|
|
this->my_host->set_port(this->my_host, IKEV2_NATT_PORT);
|
|
|
|
}
|
|
|
|
if (this->other_host->get_port(this->other_host) == IKEV2_UDP_PORT)
|
|
|
|
{
|
|
|
|
this->other_host->set_port(this->other_host, IKEV2_NATT_PORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, update_hosts, void,
|
2011-01-12 12:54:46 +00:00
|
|
|
private_ike_sa_t *this, host_t *me, host_t *other, bool force)
|
2005-12-02 19:26:01 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
bool update = FALSE;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
if (me == NULL)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
me = this->my_host;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
2007-06-26 13:04:13 +00:00
|
|
|
if (other == NULL)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
other = this->other_host;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
/* apply hosts on first received message */
|
|
|
|
if (this->my_host->is_anyaddr(this->my_host) ||
|
|
|
|
this->other_host->is_anyaddr(this->other_host))
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
set_my_host(this, me->clone(me));
|
|
|
|
set_other_host(this, other->clone(other));
|
|
|
|
update = TRUE;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
/* update our address in any case */
|
|
|
|
if (!me->equals(me, this->my_host))
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2007-06-26 13:04:13 +00:00
|
|
|
set_my_host(this, me->clone(me));
|
|
|
|
update = TRUE;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
if (!other->equals(other, this->other_host))
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2011-07-20 13:57:53 +00:00
|
|
|
/* update others address if we are NOT NATed */
|
2011-01-12 12:54:46 +00:00
|
|
|
if (force || !has_condition(this, COND_NAT_HERE))
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
|
|
|
set_other_host(this, other->clone(other));
|
|
|
|
update = TRUE;
|
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-06-26 13:04:13 +00:00
|
|
|
/* update all associated CHILD_SAs, if required */
|
|
|
|
if (update)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator_t *enumerator;
|
2007-06-26 13:04:13 +00:00
|
|
|
child_sa_t *child_sa;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)&child_sa))
|
2007-06-26 13:04:13 +00:00
|
|
|
{
|
2008-11-19 15:31:27 +00:00
|
|
|
if (child_sa->update(child_sa, this->my_host,
|
2008-11-11 09:22:00 +00:00
|
|
|
this->other_host, this->my_virtual_ip,
|
|
|
|
has_condition(this, COND_NAT_ANY)) == NOT_SUPPORTED)
|
|
|
|
{
|
|
|
|
this->public.rekey_child_sa(&this->public,
|
|
|
|
child_sa->get_protocol(child_sa),
|
|
|
|
child_sa->get_spi(child_sa, TRUE));
|
|
|
|
}
|
2007-06-26 13:04:13 +00:00
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, generate_message, status_t,
|
|
|
|
private_ike_sa_t *this, message_t *message, packet_t **packet)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2010-11-24 17:09:06 +00:00
|
|
|
if (message->is_encoded(message))
|
|
|
|
{ /* already done */
|
|
|
|
*packet = message->get_packet(message);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2009-08-31 15:59:00 +00:00
|
|
|
this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
|
2007-02-28 14:04:36 +00:00
|
|
|
message->set_ike_sa_id(message, this->ike_sa_id);
|
2010-11-02 14:49:09 +00:00
|
|
|
charon->bus->message(charon->bus, message, FALSE);
|
2008-10-28 16:07:06 +00:00
|
|
|
return message->generate(message,
|
2010-08-17 15:36:09 +00:00
|
|
|
this->keymat->get_aead(this->keymat, FALSE), packet);
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* send a notify back to the sender
|
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static void send_notify_response(private_ike_sa_t *this, message_t *request,
|
2010-11-10 15:47:56 +00:00
|
|
|
notify_type_t type, chunk_t data)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
|
|
|
message_t *response;
|
|
|
|
packet_t *packet;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
response = message_create();
|
|
|
|
response->set_exchange_type(response, request->get_exchange_type(request));
|
|
|
|
response->set_request(response, FALSE);
|
|
|
|
response->set_message_id(response, request->get_message_id(request));
|
2010-11-10 15:47:56 +00:00
|
|
|
response->add_notify(response, FALSE, type, data);
|
2007-02-28 14:04:36 +00:00
|
|
|
if (this->my_host->is_anyaddr(this->my_host))
|
2005-11-28 15:20:51 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
this->my_host->destroy(this->my_host);
|
|
|
|
this->my_host = request->get_destination(request);
|
|
|
|
this->my_host = this->my_host->clone(this->my_host);
|
|
|
|
}
|
|
|
|
if (this->other_host->is_anyaddr(this->other_host))
|
|
|
|
{
|
|
|
|
this->other_host->destroy(this->other_host);
|
|
|
|
this->other_host = request->get_source(request);
|
|
|
|
this->other_host = this->other_host->clone(this->other_host);
|
|
|
|
}
|
2007-11-14 09:41:08 +00:00
|
|
|
response->set_source(response, this->my_host->clone(this->my_host));
|
|
|
|
response->set_destination(response, this->other_host->clone(this->other_host));
|
2007-02-28 14:04:36 +00:00
|
|
|
if (generate_message(this, response, &packet) == SUCCESS)
|
|
|
|
{
|
2007-03-28 13:34:02 +00:00
|
|
|
charon->sender->send(charon->sender, packet);
|
2005-11-28 15:20:51 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
response->destroy(response);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_kmaddress, void,
|
|
|
|
private_ike_sa_t *this, host_t *local, host_t *remote)
|
2008-11-11 06:37:37 +00:00
|
|
|
{
|
|
|
|
DESTROY_IF(this->local_host);
|
|
|
|
DESTROY_IF(this->remote_host);
|
|
|
|
this->local_host = local->clone(local);
|
|
|
|
this->remote_host = remote->clone(remote);
|
|
|
|
}
|
|
|
|
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, act_as_mediation_server, void,
|
|
|
|
private_ike_sa_t *this)
|
2008-04-09 18:12:22 +00:00
|
|
|
{
|
|
|
|
charon->mediation_manager->update_sa_id(charon->mediation_manager,
|
|
|
|
this->other_id, this->ike_sa_id);
|
|
|
|
this->is_mediation_server = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_server_reflexive_host, host_t*,
|
|
|
|
private_ike_sa_t *this)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
|
|
|
return this->server_reflexive_host;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_server_reflexive_host, void,
|
|
|
|
private_ike_sa_t *this, host_t *host)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
|
|
|
DESTROY_IF(this->server_reflexive_host);
|
|
|
|
this->server_reflexive_host = host;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_connect_id, chunk_t,
|
|
|
|
private_ike_sa_t *this)
|
2008-04-01 11:38:18 +00:00
|
|
|
{
|
|
|
|
return this->connect_id;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, respond, status_t,
|
|
|
|
private_ike_sa_t *this, identification_t *peer_id, chunk_t connect_id)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-03-26 18:40:19 +00:00
|
|
|
ike_me_t *task = ike_me_create(&this->public, TRUE);
|
|
|
|
task->respond(task, peer_id, connect_id);
|
2007-10-03 15:10:41 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, callback, status_t,
|
|
|
|
private_ike_sa_t *this, identification_t *peer_id)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-03-26 18:40:19 +00:00
|
|
|
ike_me_t *task = ike_me_create(&this->public, TRUE);
|
2007-10-03 15:10:41 +00:00
|
|
|
task->callback(task, peer_id);
|
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, relay, status_t,
|
|
|
|
private_ike_sa_t *this, identification_t *requester, chunk_t connect_id,
|
|
|
|
chunk_t connect_key, linked_list_t *endpoints, bool response)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-03-26 18:40:19 +00:00
|
|
|
ike_me_t *task = ike_me_create(&this->public, TRUE);
|
|
|
|
task->relay(task, requester, connect_id, connect_key, endpoints, response);
|
2007-10-03 15:10:41 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, initiate_mediation, status_t,
|
|
|
|
private_ike_sa_t *this, peer_cfg_t *mediated_cfg)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-03-26 18:40:19 +00:00
|
|
|
ike_me_t *task = ike_me_create(&this->public, TRUE);
|
2007-10-03 15:10:41 +00:00
|
|
|
task->connect(task, mediated_cfg->get_peer_id(mediated_cfg));
|
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, initiate_mediated, status_t,
|
|
|
|
private_ike_sa_t *this, host_t *me, host_t *other, chunk_t connect_id)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2008-04-03 15:13:25 +00:00
|
|
|
set_my_host(this, me->clone(me));
|
|
|
|
set_other_host(this, other->clone(other));
|
2008-04-10 12:51:04 +00:00
|
|
|
chunk_free(&this->connect_id);
|
2008-04-01 11:38:18 +00:00
|
|
|
this->connect_id = chunk_clone(connect_id);
|
2007-10-03 15:10:41 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2007-10-03 15:10:41 +00:00
|
|
|
|
2008-06-06 15:05:54 +00:00
|
|
|
/**
|
|
|
|
* Resolve DNS host in configuration
|
|
|
|
*/
|
|
|
|
static void resolve_hosts(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
host_t *host;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (this->remote_host)
|
|
|
|
{
|
|
|
|
host = this->remote_host->clone(this->remote_host);
|
|
|
|
host->set_port(host, IKEV2_UDP_PORT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
host = host_create_from_dns(this->ike_cfg->get_other_addr(this->ike_cfg),
|
2010-02-22 17:34:11 +00:00
|
|
|
0, this->ike_cfg->get_other_port(this->ike_cfg));
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
2008-06-06 15:05:54 +00:00
|
|
|
if (host)
|
|
|
|
{
|
2008-07-09 14:16:19 +00:00
|
|
|
set_other_host(this, host);
|
2008-06-06 15:05:54 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (this->local_host)
|
2008-07-09 14:16:19 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
host = this->local_host->clone(this->local_host);
|
|
|
|
host->set_port(host, IKEV2_UDP_PORT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-21 13:19:39 +00:00
|
|
|
int family = 0;
|
|
|
|
|
|
|
|
/* use same address family as for other */
|
|
|
|
if (!this->other_host->is_anyaddr(this->other_host))
|
|
|
|
{
|
|
|
|
family = this->other_host->get_family(this->other_host);
|
|
|
|
}
|
2008-11-11 06:37:37 +00:00
|
|
|
host = host_create_from_dns(this->ike_cfg->get_my_addr(this->ike_cfg),
|
2010-02-22 17:34:11 +00:00
|
|
|
family, this->ike_cfg->get_my_port(this->ike_cfg));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-11 06:37:37 +00:00
|
|
|
if (host && host->is_anyaddr(host) &&
|
|
|
|
!this->other_host->is_anyaddr(this->other_host))
|
2008-07-17 11:06:31 +00:00
|
|
|
{
|
2008-11-11 06:37:37 +00:00
|
|
|
host->destroy(host);
|
2010-07-12 09:14:54 +00:00
|
|
|
host = hydra->kernel_interface->get_source_addr(
|
|
|
|
hydra->kernel_interface, this->other_host, NULL);
|
2008-11-11 06:37:37 +00:00
|
|
|
if (host)
|
|
|
|
{
|
2010-02-22 17:34:11 +00:00
|
|
|
host->set_port(host, this->ike_cfg->get_my_port(this->ike_cfg));
|
2008-11-11 06:37:37 +00:00
|
|
|
}
|
2009-03-16 14:23:36 +00:00
|
|
|
else
|
|
|
|
{ /* fallback to address family specific %any(6), if configured */
|
|
|
|
host = host_create_from_dns(
|
2010-02-22 17:34:11 +00:00
|
|
|
this->ike_cfg->get_my_addr(this->ike_cfg),
|
|
|
|
0, this->ike_cfg->get_my_port(this->ike_cfg));
|
2009-03-16 14:23:36 +00:00
|
|
|
}
|
2008-07-17 11:06:31 +00:00
|
|
|
}
|
2008-07-09 14:16:19 +00:00
|
|
|
}
|
2008-06-06 15:05:54 +00:00
|
|
|
if (host)
|
|
|
|
{
|
2008-07-09 14:16:19 +00:00
|
|
|
set_my_host(this, host);
|
2008-06-06 15:05:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, initiate, status_t,
|
|
|
|
private_ike_sa_t *this, child_cfg_t *child_cfg, u_int32_t reqid,
|
|
|
|
traffic_selector_t *tsi, traffic_selector_t *tsr)
|
2005-11-25 13:42:02 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
task_t *task;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
if (this->state == IKE_CREATED)
|
2006-07-20 14:57:49 +00:00
|
|
|
{
|
2008-06-06 15:05:54 +00:00
|
|
|
resolve_hosts(this);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-10-03 15:10:41 +00:00
|
|
|
if (this->other_host->is_anyaddr(this->other_host)
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2007-10-03 15:10:41 +00:00
|
|
|
&& !this->peer_cfg->get_mediated_by(this->peer_cfg)
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2007-10-03 15:10:41 +00:00
|
|
|
)
|
2007-03-21 07:00:04 +00:00
|
|
|
{
|
2007-06-14 08:44:19 +00:00
|
|
|
child_cfg->destroy(child_cfg);
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "unable to initiate to %%any");
|
2011-08-10 13:45:41 +00:00
|
|
|
charon->bus->alert(charon->bus, ALERT_PEER_ADDR_FAILED);
|
2007-03-21 07:00:04 +00:00
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-12 16:07:17 +00:00
|
|
|
set_condition(this, COND_ORIGINAL_INITIATOR, TRUE);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-01-07 09:26:58 +00:00
|
|
|
task = (task_t*)ike_vendor_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2010-02-26 10:07:56 +00:00
|
|
|
task = (task_t*)ike_init_create(&this->public, TRUE, NULL);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2007-02-28 14:04:36 +00:00
|
|
|
task = (task_t*)ike_natd_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2008-03-13 14:14:44 +00:00
|
|
|
task = (task_t*)ike_cert_pre_create(&this->public, TRUE);
|
2007-02-28 14:04:36 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
task = (task_t*)ike_auth_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2008-03-13 14:14:44 +00:00
|
|
|
task = (task_t*)ike_cert_post_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2007-04-10 06:01:03 +00:00
|
|
|
task = (task_t*)ike_config_create(&this->public, TRUE);
|
2007-03-08 20:21:17 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2007-12-03 10:52:18 +00:00
|
|
|
task = (task_t*)ike_auth_lifetime_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2007-08-29 12:11:25 +00:00
|
|
|
if (this->peer_cfg->use_mobike(this->peer_cfg))
|
|
|
|
{
|
|
|
|
task = (task_t*)ike_mobike_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
}
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
|
|
|
task = (task_t*)ike_me_create(&this->public, TRUE);
|
2007-10-03 15:10:41 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2007-10-03 15:10:41 +00:00
|
|
|
}
|
|
|
|
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2008-04-10 12:51:04 +00:00
|
|
|
if (this->peer_cfg->is_mediation(this->peer_cfg))
|
2008-11-11 13:12:05 +00:00
|
|
|
{
|
|
|
|
if (this->state == IKE_ESTABLISHED)
|
|
|
|
{
|
2009-09-02 15:26:36 +00:00
|
|
|
/* mediation connection is already established, retrigger state
|
|
|
|
* change to notify bus listeners */
|
2008-11-11 13:12:05 +00:00
|
|
|
DBG1(DBG_IKE, "mediation connection is already up");
|
|
|
|
set_state(this, IKE_ESTABLISHED);
|
|
|
|
}
|
2008-04-02 18:21:03 +00:00
|
|
|
DESTROY_IF(child_cfg);
|
2007-10-03 15:10:41 +00:00
|
|
|
}
|
|
|
|
else
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2007-12-04 10:48:27 +00:00
|
|
|
/* normal IKE_SA with CHILD_SA */
|
2009-07-09 11:11:46 +00:00
|
|
|
task = (task_t*)child_create_create(&this->public, child_cfg, FALSE,
|
|
|
|
tsi, tsr);
|
2007-10-03 15:10:41 +00:00
|
|
|
child_cfg->destroy(child_cfg);
|
2008-04-10 12:51:04 +00:00
|
|
|
if (reqid)
|
|
|
|
{
|
|
|
|
child_create_t *child_create = (child_create_t*)task;
|
|
|
|
child_create->use_reqid(child_create, reqid);
|
|
|
|
}
|
2007-10-03 15:10:41 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2008-04-10 12:51:04 +00:00
|
|
|
|
|
|
|
#ifdef ME
|
|
|
|
if (this->peer_cfg->get_mediated_by(this->peer_cfg))
|
|
|
|
{
|
|
|
|
/* mediated connection, initiate mediation process */
|
|
|
|
job_t *job = (job_t*)initiate_mediation_job_create(this->ike_sa_id);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->processor->queue_job(lib->processor, job);
|
2008-04-10 12:51:04 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
#endif /* ME */
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2005-11-25 13:42:02 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, process_message, status_t,
|
|
|
|
private_ike_sa_t *this, message_t *message)
|
2007-08-27 09:10:12 +00:00
|
|
|
{
|
|
|
|
status_t status;
|
|
|
|
bool is_request;
|
2010-11-10 15:47:56 +00:00
|
|
|
u_int8_t type = 0;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-28 10:49:14 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{ /* do not handle messages in passive state */
|
|
|
|
return FAILED;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-08-27 09:10:12 +00:00
|
|
|
is_request = message->get_request(message);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-28 16:07:06 +00:00
|
|
|
status = message->parse_body(message,
|
2010-08-17 15:36:09 +00:00
|
|
|
this->keymat->get_aead(this->keymat, TRUE));
|
2010-11-10 15:47:56 +00:00
|
|
|
if (status == SUCCESS)
|
|
|
|
{ /* check for unsupported critical payloads */
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
unknown_payload_t *unknown;
|
|
|
|
payload_t *payload;
|
|
|
|
|
|
|
|
enumerator = message->create_payload_enumerator(message);
|
|
|
|
while (enumerator->enumerate(enumerator, &payload))
|
|
|
|
{
|
|
|
|
unknown = (unknown_payload_t*)payload;
|
|
|
|
type = payload->get_type(payload);
|
|
|
|
if (!payload_is_known(type) &&
|
|
|
|
unknown->is_critical(unknown))
|
|
|
|
{
|
|
|
|
DBG1(DBG_ENC, "payload type %N is not supported, "
|
|
|
|
"but its critical!", payload_type_names, type);
|
|
|
|
status = NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
}
|
2007-08-27 09:10:12 +00:00
|
|
|
if (status != SUCCESS)
|
|
|
|
{
|
|
|
|
if (is_request)
|
|
|
|
{
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case NOT_SUPPORTED:
|
2008-11-25 13:16:05 +00:00
|
|
|
DBG1(DBG_IKE, "critical unknown payloads found");
|
2007-08-27 09:10:12 +00:00
|
|
|
if (is_request)
|
|
|
|
{
|
2010-11-10 15:47:56 +00:00
|
|
|
send_notify_response(this, message,
|
|
|
|
UNSUPPORTED_CRITICAL_PAYLOAD,
|
|
|
|
chunk_from_thing(type));
|
|
|
|
this->task_manager->incr_mid(this->task_manager, FALSE);
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PARSE_ERROR:
|
|
|
|
DBG1(DBG_IKE, "message parsing failed");
|
|
|
|
if (is_request)
|
|
|
|
{
|
2010-11-10 15:47:56 +00:00
|
|
|
send_notify_response(this, message,
|
|
|
|
INVALID_SYNTAX, chunk_empty);
|
|
|
|
this->task_manager->incr_mid(this->task_manager, FALSE);
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VERIFY_ERROR:
|
|
|
|
DBG1(DBG_IKE, "message verification failed");
|
|
|
|
if (is_request)
|
|
|
|
{
|
2010-11-10 15:47:56 +00:00
|
|
|
send_notify_response(this, message,
|
|
|
|
INVALID_SYNTAX, chunk_empty);
|
|
|
|
this->task_manager->incr_mid(this->task_manager, FALSE);
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FAILED:
|
|
|
|
DBG1(DBG_IKE, "integrity check failed");
|
|
|
|
/* ignored */
|
|
|
|
break;
|
|
|
|
case INVALID_STATE:
|
|
|
|
DBG1(DBG_IKE, "found encrypted message, but no keys available");
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DBG1(DBG_IKE, "%N %s with message ID %d processing failed",
|
|
|
|
exchange_type_names, message->get_exchange_type(message),
|
|
|
|
message->get_request(message) ? "request" : "response",
|
|
|
|
message->get_message_id(message));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-05-07 13:53:45 +00:00
|
|
|
if (this->state == IKE_CREATED)
|
|
|
|
{ /* invalid initiation attempt, close SA */
|
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if this IKE_SA is virgin, we check for a config */
|
|
|
|
if (this->ike_cfg == NULL)
|
|
|
|
{
|
|
|
|
job_t *job;
|
2010-09-07 09:52:16 +00:00
|
|
|
host_t *me = message->get_destination(message),
|
|
|
|
*other = message->get_source(message);
|
2007-08-27 09:10:12 +00:00
|
|
|
this->ike_cfg = charon->backends->get_ike_cfg(charon->backends,
|
|
|
|
me, other);
|
|
|
|
if (this->ike_cfg == NULL)
|
|
|
|
{
|
|
|
|
/* no config found for these hosts, destroy */
|
|
|
|
DBG1(DBG_IKE, "no IKE config found for %H...%H, sending %N",
|
|
|
|
me, other, notify_type_names, NO_PROPOSAL_CHOSEN);
|
2010-11-10 15:47:56 +00:00
|
|
|
send_notify_response(this, message,
|
|
|
|
NO_PROPOSAL_CHOSEN, chunk_empty);
|
2007-08-27 09:10:12 +00:00
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
|
|
|
/* add a timeout if peer does not establish it completely */
|
|
|
|
job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, FALSE);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler, job,
|
2011-05-05 10:34:24 +00:00
|
|
|
lib->settings->get_int(lib->settings,
|
|
|
|
"charon.half_open_timeout", HALF_OPEN_IKE_SA_TIMEOUT));
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
2009-08-31 15:59:00 +00:00
|
|
|
this->stats[STAT_INBOUND] = time_monotonic(NULL);
|
2010-09-07 09:52:16 +00:00
|
|
|
status = this->task_manager->process_message(this->task_manager,
|
|
|
|
message);
|
2009-12-01 10:35:30 +00:00
|
|
|
if (message->get_exchange_type(message) == IKE_AUTH &&
|
2010-06-07 12:59:39 +00:00
|
|
|
this->state == IKE_ESTABLISHED &&
|
|
|
|
lib->settings->get_bool(lib->settings,
|
|
|
|
"charon.flush_auth_cfg", FALSE))
|
2009-12-01 10:35:30 +00:00
|
|
|
{ /* authentication completed */
|
|
|
|
flush_auth_cfgs(this);
|
|
|
|
}
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
2009-12-01 10:35:30 +00:00
|
|
|
return status;
|
2007-08-27 09:10:12 +00:00
|
|
|
}
|
2006-07-20 10:09:32 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_id, ike_sa_id_t*,
|
|
|
|
private_ike_sa_t *this)
|
2005-12-02 14:07:36 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
return this->ike_sa_id;
|
2005-12-02 14:07:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_my_id, identification_t*,
|
|
|
|
private_ike_sa_t *this)
|
2005-12-02 19:26:01 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
return this->my_id;
|
2005-12-03 14:47:58 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_my_id, void,
|
|
|
|
private_ike_sa_t *this, identification_t *me)
|
2005-12-03 14:47:58 +00:00
|
|
|
{
|
2006-07-20 14:57:49 +00:00
|
|
|
DESTROY_IF(this->my_id);
|
2006-07-20 10:09:32 +00:00
|
|
|
this->my_id = me;
|
2005-12-02 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_other_id, identification_t*,
|
|
|
|
private_ike_sa_t *this)
|
2006-02-16 09:55:07 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
return this->other_id;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2006-07-20 10:09:32 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_other_eap_id, identification_t*,
|
|
|
|
private_ike_sa_t *this)
|
2010-03-24 13:23:56 +00:00
|
|
|
{
|
|
|
|
identification_t *id = NULL, *current;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
auth_cfg_t *cfg;
|
|
|
|
|
|
|
|
enumerator = this->other_auths->create_enumerator(this->other_auths);
|
|
|
|
while (enumerator->enumerate(enumerator, &cfg))
|
|
|
|
{
|
|
|
|
/* prefer EAP-Identity of last round */
|
|
|
|
current = cfg->get(cfg, AUTH_RULE_EAP_IDENTITY);
|
|
|
|
if (!current || current->get_type(current) == ID_ANY)
|
|
|
|
{
|
|
|
|
current = cfg->get(cfg, AUTH_RULE_IDENTITY);
|
|
|
|
}
|
|
|
|
if (current && current->get_type(current) != ID_ANY)
|
|
|
|
{
|
|
|
|
id = current;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
return this->other_id;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, set_other_id, void,
|
|
|
|
private_ike_sa_t *this, identification_t *other)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2006-07-20 14:57:49 +00:00
|
|
|
DESTROY_IF(this->other_id);
|
2006-07-20 10:09:32 +00:00
|
|
|
this->other_id = other;
|
2006-02-16 09:55:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, add_child_sa, void,
|
|
|
|
private_ike_sa_t *this, child_sa_t *child_sa)
|
2006-05-31 14:23:15 +00:00
|
|
|
{
|
2006-07-05 10:53:20 +00:00
|
|
|
this->child_sas->insert_last(this->child_sas, child_sa);
|
2006-05-31 14:23:15 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, get_child_sa, child_sa_t*,
|
|
|
|
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi, bool inbound)
|
2006-06-09 15:12:43 +00:00
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator_t *enumerator;
|
2006-06-09 15:12:43 +00:00
|
|
|
child_sa_t *current, *found = NULL;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)¤t))
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2006-07-07 07:04:07 +00:00
|
|
|
if (current->get_spi(current, inbound) == spi &&
|
2006-10-24 14:20:45 +00:00
|
|
|
current->get_protocol(current) == protocol)
|
2006-06-09 15:12:43 +00:00
|
|
|
{
|
|
|
|
found = current;
|
|
|
|
}
|
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2006-06-09 15:12:43 +00:00
|
|
|
return found;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2011-05-19 15:27:32 +00:00
|
|
|
METHOD(ike_sa_t, get_child_count, int,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this)
|
2006-08-23 07:30:43 +00:00
|
|
|
{
|
2011-05-19 15:27:32 +00:00
|
|
|
return this->child_sas->get_count(this->child_sas);
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(ike_sa_t, create_child_sa_enumerator, enumerator_t*,
|
|
|
|
private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(ike_sa_t, remove_child_sa, void,
|
|
|
|
private_ike_sa_t *this, enumerator_t *enumerator)
|
|
|
|
{
|
|
|
|
this->child_sas->remove_at(this->child_sas, enumerator);
|
2006-08-23 07:30:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, rekey_child_sa, status_t,
|
|
|
|
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
child_rekey_t *child_rekey;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
2008-12-01 18:38:28 +00:00
|
|
|
child_rekey = child_rekey_create(&this->public, protocol, spi);
|
|
|
|
this->task_manager->queue_task(this->task_manager, &child_rekey->task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-07-07 07:04:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, delete_child_sa, status_t,
|
|
|
|
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
|
2006-07-07 07:04:07 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
child_delete_t *child_delete;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
|
|
|
|
2008-12-01 18:38:28 +00:00
|
|
|
child_delete = child_delete_create(&this->public, protocol, spi);
|
|
|
|
this->task_manager->queue_task(this->task_manager, &child_delete->task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-07-07 07:04:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, destroy_child_sa, status_t,
|
|
|
|
private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
|
2006-07-07 07:04:07 +00:00
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator_t *enumerator;
|
2006-07-07 07:04:07 +00:00
|
|
|
child_sa_t *child_sa;
|
|
|
|
status_t status = NOT_FOUND;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)&child_sa))
|
2006-07-07 07:04:07 +00:00
|
|
|
{
|
|
|
|
if (child_sa->get_protocol(child_sa) == protocol &&
|
|
|
|
child_sa->get_spi(child_sa, TRUE) == spi)
|
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
this->child_sas->remove_at(this->child_sas, enumerator);
|
2006-07-07 07:04:07 +00:00
|
|
|
child_sa->destroy(child_sa);
|
|
|
|
status = SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2006-07-07 07:04:07 +00:00
|
|
|
return status;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, delete_, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2006-12-19 07:30:07 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
ike_delete_t *ike_delete;
|
|
|
|
|
2006-12-19 07:30:07 +00:00
|
|
|
switch (this->state)
|
|
|
|
{
|
|
|
|
case IKE_ESTABLISHED:
|
2007-02-28 14:04:36 +00:00
|
|
|
case IKE_REKEYING:
|
|
|
|
ike_delete = ike_delete_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, &ike_delete->task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2007-08-27 09:10:12 +00:00
|
|
|
case IKE_CREATED:
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "deleting unestablished IKE_SA");
|
2007-08-27 09:10:12 +00:00
|
|
|
break;
|
2008-11-28 10:49:14 +00:00
|
|
|
case IKE_PASSIVE:
|
|
|
|
break;
|
2006-12-19 07:30:07 +00:00
|
|
|
default:
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "destroying IKE_SA in state %N "
|
2007-08-27 09:10:12 +00:00
|
|
|
"without notification", ike_sa_state_names, this->state);
|
2010-04-06 09:58:29 +00:00
|
|
|
charon->bus->ike_updown(charon->bus, &this->public, FALSE);
|
2007-02-28 14:04:36 +00:00
|
|
|
break;
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
return DESTROY_ME;
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, rekey, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2006-07-27 12:18:40 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
ike_rekey_t *ike_rekey;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
ike_rekey = ike_rekey_create(&this->public, TRUE);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, &ike_rekey->task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, reauth, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2006-12-19 07:30:07 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
task_t *task;
|
2007-11-20 12:06:40 +00:00
|
|
|
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2007-11-20 12:06:40 +00:00
|
|
|
/* we can't reauthenticate as responder when we use EAP or virtual IPs.
|
|
|
|
* If the peer does not support RFC4478, there is no way to keep the
|
|
|
|
* IKE_SA up. */
|
2008-11-12 16:07:17 +00:00
|
|
|
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "initiator did not reauthenticate as requested");
|
|
|
|
if (this->other_virtual_ip != NULL ||
|
2008-04-10 08:42:27 +00:00
|
|
|
has_condition(this, COND_EAP_AUTHENTICATED)
|
|
|
|
#ifdef ME
|
2009-09-02 15:26:36 +00:00
|
|
|
/* as mediation server we too cannot reauth the IKE_SA */
|
2008-04-10 08:42:27 +00:00
|
|
|
|| this->is_mediation_server
|
|
|
|
#endif /* ME */
|
|
|
|
)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2012-02-21 13:05:11 +00:00
|
|
|
time_t del, now;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-02-21 13:05:11 +00:00
|
|
|
del = this->stats[STAT_DELETE];
|
|
|
|
now = time_monotonic(NULL);
|
2012-02-22 15:16:15 +00:00
|
|
|
DBG1(DBG_IKE, "IKE_SA %s[%d] will timeout in %V",
|
|
|
|
get_name(this), this->unique_id, &now, &del);
|
2007-11-20 12:06:40 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-22 15:16:15 +00:00
|
|
|
DBG0(DBG_IKE, "reauthenticating IKE_SA %s[%d] actively",
|
|
|
|
get_name(this), this->unique_id);
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-22 15:16:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG0(DBG_IKE, "reauthenticating IKE_SA %s[%d]",
|
|
|
|
get_name(this), this->unique_id);
|
|
|
|
}
|
2007-06-14 08:13:05 +00:00
|
|
|
task = (task_t*)ike_reauth_create(&this->public);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
2007-11-20 12:06:40 +00:00
|
|
|
|
2007-06-14 08:13:05 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
2007-07-02 09:49:22 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, reestablish, status_t,
|
|
|
|
private_ike_sa_t *this)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
|
|
|
ike_sa_t *new;
|
|
|
|
host_t *host;
|
2008-04-14 08:17:18 +00:00
|
|
|
action_t action;
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator_t *enumerator;
|
2008-04-11 08:14:48 +00:00
|
|
|
child_sa_t *child_sa;
|
|
|
|
child_cfg_t *child_cfg;
|
2009-09-24 12:14:30 +00:00
|
|
|
bool restart = FALSE;
|
2008-04-11 08:14:48 +00:00
|
|
|
status_t status = FAILED;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-09-02 15:26:36 +00:00
|
|
|
/* check if we have children to keep up at all */
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)&child_sa))
|
2008-04-14 07:55:23 +00:00
|
|
|
{
|
2008-04-14 08:17:18 +00:00
|
|
|
if (this->state == IKE_DELETING)
|
|
|
|
{
|
2010-06-02 09:41:46 +00:00
|
|
|
action = child_sa->get_close_action(child_sa);
|
2008-04-14 08:17:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-02 09:41:46 +00:00
|
|
|
action = child_sa->get_dpd_action(child_sa);
|
2008-04-14 08:17:18 +00:00
|
|
|
}
|
|
|
|
switch (action)
|
2008-04-14 07:55:23 +00:00
|
|
|
{
|
|
|
|
case ACTION_RESTART:
|
2009-09-24 12:14:30 +00:00
|
|
|
restart = TRUE;
|
|
|
|
break;
|
2008-04-14 07:55:23 +00:00
|
|
|
case ACTION_ROUTE:
|
2010-06-02 09:41:46 +00:00
|
|
|
charon->traps->install(charon->traps, this->peer_cfg,
|
|
|
|
child_sa->get_config(child_sa));
|
2009-09-24 12:14:30 +00:00
|
|
|
break;
|
2008-04-14 07:55:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2008-04-14 07:55:23 +00:00
|
|
|
#ifdef ME
|
2009-09-02 15:26:36 +00:00
|
|
|
/* mediation connections have no children, keep them up anyway */
|
2008-04-14 07:55:23 +00:00
|
|
|
if (this->peer_cfg->is_mediation(this->peer_cfg))
|
|
|
|
{
|
2009-09-24 12:14:30 +00:00
|
|
|
restart = TRUE;
|
2008-04-14 07:55:23 +00:00
|
|
|
}
|
|
|
|
#endif /* ME */
|
2009-09-24 12:14:30 +00:00
|
|
|
if (!restart)
|
2008-04-14 07:55:23 +00:00
|
|
|
{
|
|
|
|
return FAILED;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-14 07:55:23 +00:00
|
|
|
/* check if we are able to reestablish this IKE_SA */
|
2008-11-12 16:07:17 +00:00
|
|
|
if (!has_condition(this, COND_ORIGINAL_INITIATOR) &&
|
2008-04-11 08:14:48 +00:00
|
|
|
(this->other_virtual_ip != NULL ||
|
|
|
|
has_condition(this, COND_EAP_AUTHENTICATED)
|
|
|
|
#ifdef ME
|
|
|
|
|| this->is_mediation_server
|
|
|
|
#endif /* ME */
|
|
|
|
))
|
|
|
|
{
|
2011-04-28 10:50:30 +00:00
|
|
|
DBG1(DBG_IKE, "unable to reestablish IKE_SA due to asymmetric setup");
|
2008-04-11 08:14:48 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-11 08:14:48 +00:00
|
|
|
new = charon->ike_sa_manager->checkout_new(charon->ike_sa_manager, TRUE);
|
|
|
|
new->set_peer_cfg(new, this->peer_cfg);
|
|
|
|
host = this->other_host;
|
|
|
|
new->set_other_host(new, host->clone(host));
|
|
|
|
host = this->my_host;
|
|
|
|
new->set_my_host(new, host->clone(host));
|
|
|
|
/* if we already have a virtual IP, we reuse it */
|
|
|
|
host = this->my_virtual_ip;
|
|
|
|
if (host)
|
|
|
|
{
|
|
|
|
new->set_virtual_ip(new, TRUE, host);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-11 08:14:48 +00:00
|
|
|
#ifdef ME
|
|
|
|
if (this->peer_cfg->is_mediation(this->peer_cfg))
|
|
|
|
{
|
2009-05-20 09:44:43 +00:00
|
|
|
status = new->initiate(new, NULL, 0, NULL, NULL);
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2008-04-14 07:55:23 +00:00
|
|
|
else
|
2008-04-11 08:14:48 +00:00
|
|
|
#endif /* ME */
|
|
|
|
{
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator = this->child_sas->create_enumerator(this->child_sas);
|
|
|
|
while (enumerator->enumerate(enumerator, (void**)&child_sa))
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2008-04-14 08:17:18 +00:00
|
|
|
if (this->state == IKE_DELETING)
|
|
|
|
{
|
2010-06-02 09:41:46 +00:00
|
|
|
action = child_sa->get_close_action(child_sa);
|
2008-04-14 08:17:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-02 09:41:46 +00:00
|
|
|
action = child_sa->get_dpd_action(child_sa);
|
2008-04-14 08:17:18 +00:00
|
|
|
}
|
|
|
|
switch (action)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2008-04-14 07:55:23 +00:00
|
|
|
case ACTION_RESTART:
|
2010-06-02 09:41:46 +00:00
|
|
|
child_cfg = child_sa->get_config(child_sa);
|
2008-07-22 17:10:10 +00:00
|
|
|
DBG1(DBG_IKE, "restarting CHILD_SA %s",
|
2008-04-14 07:55:23 +00:00
|
|
|
child_cfg->get_name(child_cfg));
|
|
|
|
child_cfg->get_ref(child_cfg);
|
2009-05-20 09:44:43 +00:00
|
|
|
status = new->initiate(new, child_cfg, 0, NULL, NULL);
|
2008-04-11 08:14:48 +00:00
|
|
|
break;
|
2008-04-14 07:55:23 +00:00
|
|
|
default:
|
|
|
|
continue;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2008-04-14 07:55:23 +00:00
|
|
|
if (status == DESTROY_ME)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2008-04-14 07:55:23 +00:00
|
|
|
break;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-19 14:18:30 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-14 07:55:23 +00:00
|
|
|
if (status == DESTROY_ME)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2008-04-14 07:55:23 +00:00
|
|
|
charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, new);
|
2009-06-02 13:26:29 +00:00
|
|
|
status = FAILED;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-14 07:55:23 +00:00
|
|
|
charon->ike_sa_manager->checkin(charon->ike_sa_manager, new);
|
2009-06-02 13:26:29 +00:00
|
|
|
status = SUCCESS;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
2009-06-02 13:26:29 +00:00
|
|
|
charon->bus->set_sa(charon->bus, &this->public);
|
|
|
|
return status;
|
2008-04-11 08:14:48 +00:00
|
|
|
}
|
|
|
|
|
2010-06-30 11:48:47 +00:00
|
|
|
/**
|
|
|
|
* Requeue the IKE_SA_INIT tasks for initiation, if required
|
|
|
|
*/
|
|
|
|
static void requeue_init_tasks(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
bool has_init = FALSE;
|
|
|
|
task_t *task;
|
|
|
|
|
|
|
|
/* if we have advanced to IKE_AUTH, the IKE_INIT and related tasks
|
|
|
|
* have already completed. Recreate them if necessary. */
|
|
|
|
enumerator = this->task_manager->create_task_enumerator(
|
|
|
|
this->task_manager, TASK_QUEUE_QUEUED);
|
|
|
|
while (enumerator->enumerate(enumerator, &task))
|
|
|
|
{
|
|
|
|
if (task->get_type(task) == IKE_INIT)
|
|
|
|
{
|
|
|
|
has_init = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
|
|
|
if (!has_init)
|
|
|
|
{
|
|
|
|
task = (task_t*)ike_vendor_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
task = (task_t*)ike_natd_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
task = (task_t*)ike_init_create(&this->public, TRUE, NULL);
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, retransmit, status_t,
|
|
|
|
private_ike_sa_t *this, u_int32_t message_id)
|
2008-04-11 08:14:48 +00:00
|
|
|
{
|
2012-01-10 12:32:06 +00:00
|
|
|
if (this->state == IKE_PASSIVE)
|
|
|
|
{
|
|
|
|
return INVALID_STATE;
|
|
|
|
}
|
2009-08-31 15:59:00 +00:00
|
|
|
this->stats[STAT_OUTBOUND] = time_monotonic(NULL);
|
2008-04-11 08:14:48 +00:00
|
|
|
if (this->task_manager->retransmit(this->task_manager, message_id) != SUCCESS)
|
|
|
|
{
|
|
|
|
/* send a proper signal to brief interested bus listeners */
|
|
|
|
switch (this->state)
|
|
|
|
{
|
|
|
|
case IKE_CONNECTING:
|
|
|
|
{
|
|
|
|
/* retry IKE_SA_INIT if we have multiple keyingtries */
|
|
|
|
u_int32_t tries = this->peer_cfg->get_keyingtries(this->peer_cfg);
|
|
|
|
this->keyingtry++;
|
|
|
|
if (tries == 0 || tries > this->keyingtry)
|
|
|
|
{
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "peer not responding, trying again (%d/%d)",
|
|
|
|
this->keyingtry + 1, tries);
|
2008-04-11 08:14:48 +00:00
|
|
|
reset(this);
|
2012-02-14 10:29:34 +00:00
|
|
|
resolve_hosts(this);
|
2010-06-30 11:48:47 +00:00
|
|
|
requeue_init_tasks(this);
|
2008-04-11 08:14:48 +00:00
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "establishing IKE_SA failed, peer not responding");
|
2008-04-11 08:14:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IKE_DELETING:
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "proper IKE_SA delete failed, peer not responding");
|
2008-04-11 08:14:48 +00:00
|
|
|
break;
|
2008-04-14 08:17:18 +00:00
|
|
|
case IKE_REKEYING:
|
2008-10-14 08:52:13 +00:00
|
|
|
DBG1(DBG_IKE, "rekeying IKE_SA failed, peer not responding");
|
2008-04-14 08:17:18 +00:00
|
|
|
/* FALL */
|
2008-04-11 08:14:48 +00:00
|
|
|
default:
|
2008-04-14 08:17:18 +00:00
|
|
|
reestablish(this);
|
2008-04-11 08:14:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2012-02-22 15:07:31 +00:00
|
|
|
METHOD(ike_sa_t, set_auth_lifetime, status_t,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this, u_int32_t lifetime)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2012-02-21 13:05:57 +00:00
|
|
|
u_int32_t diff, hard, soft, now;
|
2012-02-22 15:07:31 +00:00
|
|
|
ike_auth_lifetime_t *task;
|
|
|
|
bool send_update;
|
2007-11-20 12:06:40 +00:00
|
|
|
|
2012-02-21 13:05:57 +00:00
|
|
|
diff = this->peer_cfg->get_over_time(this->peer_cfg);
|
|
|
|
now = time_monotonic(NULL);
|
|
|
|
hard = now + lifetime;
|
|
|
|
soft = hard - diff;
|
|
|
|
|
2012-02-22 15:07:31 +00:00
|
|
|
/* check if we have to send an AUTH_LIFETIME to enforce the new lifetime.
|
|
|
|
* We send the notify in IKE_AUTH if not yet ESTABLISHED. */
|
|
|
|
send_update = this->state == IKE_ESTABLISHED &&
|
|
|
|
!has_condition(this, COND_ORIGINAL_INITIATOR) &&
|
|
|
|
(this->other_virtual_ip != NULL ||
|
|
|
|
has_condition(this, COND_EAP_AUTHENTICATED));
|
|
|
|
|
2012-02-21 13:05:57 +00:00
|
|
|
if (lifetime < diff)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2012-02-21 13:05:57 +00:00
|
|
|
this->stats[STAT_REAUTH] = now;
|
2012-02-22 15:07:31 +00:00
|
|
|
|
|
|
|
if (!send_update)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, "
|
|
|
|
"starting reauthentication", lifetime);
|
|
|
|
lib->processor->queue_job(lib->processor,
|
2009-09-04 12:58:05 +00:00
|
|
|
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE));
|
2012-02-22 15:07:31 +00:00
|
|
|
}
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2008-10-27 14:51:00 +00:00
|
|
|
else if (this->stats[STAT_REAUTH] == 0 ||
|
2012-02-21 13:05:57 +00:00
|
|
|
this->stats[STAT_REAUTH] > soft)
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2012-02-21 13:05:57 +00:00
|
|
|
this->stats[STAT_REAUTH] = soft;
|
2012-02-22 15:07:31 +00:00
|
|
|
if (!send_update)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, scheduling "
|
|
|
|
"reauthentication in %ds", lifetime, lifetime - diff);
|
|
|
|
lib->scheduler->schedule_job(lib->scheduler,
|
2009-04-21 15:16:56 +00:00
|
|
|
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE),
|
2012-02-21 13:05:57 +00:00
|
|
|
lifetime - diff);
|
2012-02-22 15:07:31 +00:00
|
|
|
}
|
2008-07-28 13:53:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-31 15:59:00 +00:00
|
|
|
DBG1(DBG_IKE, "received AUTH_LIFETIME of %ds, "
|
|
|
|
"reauthentication already scheduled in %ds", lifetime,
|
|
|
|
this->stats[STAT_REAUTH] - time_monotonic(NULL));
|
2012-02-22 15:07:31 +00:00
|
|
|
send_update = FALSE;
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2012-02-21 13:05:57 +00:00
|
|
|
/* give at least some seconds to reauthenticate */
|
|
|
|
this->stats[STAT_DELETE] = max(hard, now + 10);
|
2012-02-22 15:07:31 +00:00
|
|
|
|
|
|
|
if (send_update)
|
|
|
|
{
|
|
|
|
task = ike_auth_lifetime_create(&this->public, TRUE);
|
|
|
|
this->task_manager->queue_task(this->task_manager, &task->task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
|
|
|
|
2010-10-05 15:49:50 +00:00
|
|
|
/**
|
|
|
|
* Check if the current combination of source and destination address is still
|
|
|
|
* valid.
|
|
|
|
*/
|
|
|
|
static bool is_current_path_valid(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
bool valid = FALSE;
|
|
|
|
host_t *src;
|
|
|
|
src = hydra->kernel_interface->get_source_addr(hydra->kernel_interface,
|
|
|
|
this->other_host, this->my_host);
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
if (src->ip_equals(src, this->my_host))
|
|
|
|
{
|
|
|
|
valid = TRUE;
|
|
|
|
}
|
|
|
|
src->destroy(src);
|
|
|
|
}
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if we have any path avialable for this IKE SA.
|
|
|
|
*/
|
|
|
|
static bool is_any_path_valid(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
bool valid = FALSE;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
host_t *src, *addr;
|
2012-03-09 09:22:21 +00:00
|
|
|
|
2010-10-05 15:49:50 +00:00
|
|
|
DBG1(DBG_IKE, "old path is not available anymore, try to find another");
|
2012-03-09 09:22:21 +00:00
|
|
|
enumerator = this->peer_addresses->create_enumerator(this->peer_addresses);
|
|
|
|
while (enumerator->enumerate(enumerator, &addr))
|
2010-10-05 15:49:50 +00:00
|
|
|
{
|
2012-03-09 09:22:21 +00:00
|
|
|
DBG1(DBG_IKE, "looking for a route to %H ...", addr);
|
|
|
|
src = hydra->kernel_interface->get_source_addr(
|
|
|
|
hydra->kernel_interface, addr, NULL);
|
|
|
|
if (src)
|
2010-10-05 15:49:50 +00:00
|
|
|
{
|
2012-03-09 09:22:21 +00:00
|
|
|
break;
|
2010-10-05 15:49:50 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 09:22:21 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2010-10-05 15:49:50 +00:00
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
valid = TRUE;
|
|
|
|
src->destroy(src);
|
|
|
|
}
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, roam, status_t,
|
|
|
|
private_ike_sa_t *this, bool address)
|
2007-06-21 15:25:28 +00:00
|
|
|
{
|
|
|
|
ike_mobike_t *mobike;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-06-04 14:31:06 +00:00
|
|
|
switch (this->state)
|
|
|
|
{
|
|
|
|
case IKE_CREATED:
|
|
|
|
case IKE_DELETING:
|
2009-07-02 08:56:13 +00:00
|
|
|
case IKE_DESTROYING:
|
2008-11-28 10:49:14 +00:00
|
|
|
case IKE_PASSIVE:
|
2008-06-04 14:31:06 +00:00
|
|
|
return SUCCESS;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-08 08:23:46 +00:00
|
|
|
/* keep existing path if possible */
|
2010-10-05 15:49:50 +00:00
|
|
|
if (is_current_path_valid(this))
|
2007-07-02 09:49:22 +00:00
|
|
|
{
|
2010-10-05 15:49:50 +00:00
|
|
|
DBG2(DBG_IKE, "keeping connection path %H - %H",
|
|
|
|
this->my_host, this->other_host);
|
|
|
|
set_condition(this, COND_STALE, FALSE);
|
2010-10-05 15:55:32 +00:00
|
|
|
|
|
|
|
if (supports_extension(this, EXT_MOBIKE) && address)
|
|
|
|
{ /* if any addresses changed, send an updated list */
|
|
|
|
DBG1(DBG_IKE, "sending address list update using MOBIKE");
|
|
|
|
mobike = ike_mobike_create(&this->public, TRUE);
|
|
|
|
mobike->addresses(mobike);
|
|
|
|
this->task_manager->queue_task(this->task_manager,
|
|
|
|
(task_t*)mobike);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2010-10-05 15:49:50 +00:00
|
|
|
return SUCCESS;
|
2009-07-02 08:56:13 +00:00
|
|
|
}
|
2010-10-05 15:55:32 +00:00
|
|
|
|
2010-10-05 15:49:50 +00:00
|
|
|
if (!is_any_path_valid(this))
|
2009-07-02 08:56:13 +00:00
|
|
|
{
|
2010-10-05 15:49:50 +00:00
|
|
|
DBG1(DBG_IKE, "no route found to reach %H, MOBIKE update deferred",
|
|
|
|
this->other_host);
|
|
|
|
set_condition(this, COND_STALE, TRUE);
|
|
|
|
return SUCCESS;
|
2007-06-21 15:25:28 +00:00
|
|
|
}
|
2009-07-02 08:56:13 +00:00
|
|
|
set_condition(this, COND_STALE, FALSE);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-07-02 09:49:22 +00:00
|
|
|
/* update addresses with mobike, if supported ... */
|
|
|
|
if (supports_extension(this, EXT_MOBIKE))
|
|
|
|
{
|
2010-10-05 16:01:41 +00:00
|
|
|
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
|
|
|
|
{ /* responder updates the peer about changed address config */
|
|
|
|
DBG1(DBG_IKE, "sending address list update using MOBIKE, "
|
|
|
|
"implicitly requesting an address change");
|
|
|
|
address = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "requesting address change using MOBIKE");
|
|
|
|
}
|
2007-07-02 09:49:22 +00:00
|
|
|
mobike = ike_mobike_create(&this->public, TRUE);
|
2007-07-03 12:32:38 +00:00
|
|
|
mobike->roam(mobike, address);
|
2007-07-02 09:49:22 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)mobike);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2010-10-05 16:01:41 +00:00
|
|
|
|
2008-04-11 08:14:48 +00:00
|
|
|
/* ... reauth if not */
|
2010-10-05 16:01:41 +00:00
|
|
|
if (!has_condition(this, COND_ORIGINAL_INITIATOR))
|
|
|
|
{ /* responder does not reauthenticate */
|
|
|
|
set_condition(this, COND_STALE, TRUE);
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
DBG1(DBG_IKE, "reauthenticating IKE_SA due to address change");
|
2008-04-11 08:14:48 +00:00
|
|
|
return reauth(this);
|
2007-06-21 15:25:28 +00:00
|
|
|
}
|
2006-12-19 07:30:07 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, add_configuration_attribute, void,
|
|
|
|
private_ike_sa_t *this, attribute_handler_t *handler,
|
|
|
|
configuration_attribute_type_t type, chunk_t data)
|
2009-04-24 14:13:52 +00:00
|
|
|
{
|
2009-11-17 13:51:50 +00:00
|
|
|
attribute_entry_t *entry = malloc_thing(attribute_entry_t);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-11-17 13:51:50 +00:00
|
|
|
entry->handler = handler;
|
|
|
|
entry->type = type;
|
|
|
|
entry->data = chunk_clone(data);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-11-17 13:51:50 +00:00
|
|
|
this->attributes->insert_last(this->attributes, entry);
|
2009-04-24 14:13:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:37:55 +00:00
|
|
|
METHOD(ike_sa_t, create_task_enumerator, enumerator_t*,
|
|
|
|
private_ike_sa_t *this, task_queue_t queue)
|
|
|
|
{
|
|
|
|
return this->task_manager->create_task_enumerator(this->task_manager, queue);
|
|
|
|
}
|
|
|
|
|
2011-03-15 14:20:09 +00:00
|
|
|
METHOD(ike_sa_t, inherit, void,
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this, ike_sa_t *other_public)
|
2006-08-23 07:30:43 +00:00
|
|
|
{
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *other = (private_ike_sa_t*)other_public;
|
2007-02-28 14:04:36 +00:00
|
|
|
child_sa_t *child_sa;
|
2009-04-24 14:13:52 +00:00
|
|
|
attribute_entry_t *entry;
|
2011-07-25 12:08:18 +00:00
|
|
|
enumerator_t *enumerator;
|
|
|
|
auth_cfg_t *cfg;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/* apply hosts and ids */
|
|
|
|
this->my_host->destroy(this->my_host);
|
|
|
|
this->other_host->destroy(this->other_host);
|
|
|
|
this->my_id->destroy(this->my_id);
|
|
|
|
this->other_id->destroy(this->other_id);
|
|
|
|
this->my_host = other->my_host->clone(other->my_host);
|
|
|
|
this->other_host = other->other_host->clone(other->other_host);
|
|
|
|
this->my_id = other->my_id->clone(other->my_id);
|
|
|
|
this->other_id = other->other_id->clone(other->other_id);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/* apply virtual assigned IPs... */
|
|
|
|
if (other->my_virtual_ip)
|
|
|
|
{
|
|
|
|
this->my_virtual_ip = other->my_virtual_ip;
|
|
|
|
other->my_virtual_ip = NULL;
|
|
|
|
}
|
|
|
|
if (other->other_virtual_ip)
|
|
|
|
{
|
|
|
|
this->other_virtual_ip = other->other_virtual_ip;
|
|
|
|
other->other_virtual_ip = NULL;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-07-25 12:08:18 +00:00
|
|
|
/* authentication information */
|
|
|
|
enumerator = other->my_auths->create_enumerator(other->my_auths);
|
|
|
|
while (enumerator->enumerate(enumerator, &cfg))
|
|
|
|
{
|
|
|
|
this->my_auths->insert_last(this->my_auths, cfg->clone(cfg));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
enumerator = other->other_auths->create_enumerator(other->other_auths);
|
|
|
|
while (enumerator->enumerate(enumerator, &cfg))
|
|
|
|
{
|
|
|
|
this->other_auths->insert_last(this->other_auths, cfg->clone(cfg));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
2009-04-24 14:13:52 +00:00
|
|
|
/* ... and configuration attributes */
|
2009-09-02 15:26:36 +00:00
|
|
|
while (other->attributes->remove_last(other->attributes,
|
2009-04-24 14:13:52 +00:00
|
|
|
(void**)&entry) == SUCCESS)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2009-04-24 14:13:52 +00:00
|
|
|
this->attributes->insert_first(this->attributes, entry);
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2008-01-29 01:41:47 +00:00
|
|
|
|
2008-11-12 16:07:17 +00:00
|
|
|
/* inherit all conditions */
|
2008-01-29 01:41:47 +00:00
|
|
|
this->conditions = other->conditions;
|
|
|
|
if (this->conditions & COND_NAT_HERE)
|
|
|
|
{
|
|
|
|
send_keepalive(this);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-09 18:12:22 +00:00
|
|
|
#ifdef ME
|
|
|
|
if (other->is_mediation_server)
|
|
|
|
{
|
|
|
|
act_as_mediation_server(this);
|
|
|
|
}
|
|
|
|
else if (other->server_reflexive_host)
|
|
|
|
{
|
|
|
|
this->server_reflexive_host = other->server_reflexive_host->clone(
|
|
|
|
other->server_reflexive_host);
|
|
|
|
}
|
|
|
|
#endif /* ME */
|
2008-01-29 01:41:47 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/* adopt all children */
|
|
|
|
while (other->child_sas->remove_last(other->child_sas,
|
2009-09-04 12:58:05 +00:00
|
|
|
(void**)&child_sa) == SUCCESS)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
|
|
|
this->child_sas->insert_first(this->child_sas, (void*)child_sa);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-03-27 13:32:12 +00:00
|
|
|
/* move pending tasks to the new IKE_SA */
|
|
|
|
this->task_manager->adopt_tasks(this->task_manager, other->task_manager);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-11-20 12:06:40 +00:00
|
|
|
/* reauthentication timeout survives a rekeying */
|
2008-10-27 14:51:00 +00:00
|
|
|
if (other->stats[STAT_REAUTH])
|
2007-11-20 12:06:40 +00:00
|
|
|
{
|
2009-08-31 15:59:00 +00:00
|
|
|
time_t reauth, delete, now = time_monotonic(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_REAUTH] = other->stats[STAT_REAUTH];
|
|
|
|
reauth = this->stats[STAT_REAUTH] - now;
|
2007-11-20 12:06:40 +00:00
|
|
|
delete = reauth + this->peer_cfg->get_over_time(this->peer_cfg);
|
2008-10-27 14:51:00 +00:00
|
|
|
this->stats[STAT_DELETE] = this->stats[STAT_REAUTH] + delete;
|
2007-11-20 12:06:40 +00:00
|
|
|
DBG1(DBG_IKE, "rescheduling reauthentication in %ds after rekeying, "
|
|
|
|
"lifetime reduced to %ds", reauth, delete);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler,
|
2009-04-21 15:16:56 +00:00
|
|
|
(job_t*)rekey_ike_sa_job_create(this->ike_sa_id, TRUE), reauth);
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->schedule_job(lib->scheduler,
|
2009-04-21 15:16:56 +00:00
|
|
|
(job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE), delete);
|
2007-11-20 12:06:40 +00:00
|
|
|
}
|
2006-08-23 07:30:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
METHOD(ike_sa_t, destroy, void,
|
|
|
|
private_ike_sa_t *this)
|
2006-10-18 11:46:13 +00:00
|
|
|
{
|
2009-04-24 14:13:52 +00:00
|
|
|
attribute_entry_t *entry;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-11-14 08:38:53 +00:00
|
|
|
charon->bus->set_sa(charon->bus, &this->public);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-14 08:52:13 +00:00
|
|
|
set_state(this, IKE_DESTROYING);
|
2011-02-28 10:31:36 +00:00
|
|
|
this->task_manager->destroy(this->task_manager);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-24 14:13:52 +00:00
|
|
|
/* remove attributes first, as we pass the IKE_SA to the handler */
|
2009-09-02 15:26:36 +00:00
|
|
|
while (this->attributes->remove_last(this->attributes,
|
2009-04-24 14:13:52 +00:00
|
|
|
(void**)&entry) == SUCCESS)
|
|
|
|
{
|
2010-03-24 16:46:29 +00:00
|
|
|
hydra->attributes->release(hydra->attributes, entry->handler,
|
|
|
|
this->other_id, entry->type, entry->data);
|
2009-04-24 14:13:52 +00:00
|
|
|
free(entry->data.ptr);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
this->attributes->destroy(this->attributes);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-10-24 08:46:17 +00:00
|
|
|
this->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-16 11:48:18 +00:00
|
|
|
/* unset SA after here to avoid usage by the listeners */
|
|
|
|
charon->bus->set_sa(charon->bus, NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-28 16:07:06 +00:00
|
|
|
this->keymat->destroy(this->keymat);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
if (this->my_virtual_ip)
|
|
|
|
{
|
2010-07-12 09:14:54 +00:00
|
|
|
hydra->kernel_interface->del_ip(hydra->kernel_interface,
|
|
|
|
this->my_virtual_ip);
|
2007-02-28 14:04:36 +00:00
|
|
|
this->my_virtual_ip->destroy(this->my_virtual_ip);
|
|
|
|
}
|
2008-04-09 12:54:47 +00:00
|
|
|
if (this->other_virtual_ip)
|
|
|
|
{
|
|
|
|
if (this->peer_cfg && this->peer_cfg->get_pool(this->peer_cfg))
|
|
|
|
{
|
2010-03-24 16:46:29 +00:00
|
|
|
hydra->attributes->release_address(hydra->attributes,
|
2010-03-24 13:23:56 +00:00
|
|
|
this->peer_cfg->get_pool(this->peer_cfg),
|
|
|
|
this->other_virtual_ip, get_other_eap_id(this));
|
2008-04-09 12:54:47 +00:00
|
|
|
}
|
|
|
|
this->other_virtual_ip->destroy(this->other_virtual_ip);
|
|
|
|
}
|
2012-03-09 09:15:21 +00:00
|
|
|
this->peer_addresses->destroy_offset(this->peer_addresses,
|
|
|
|
offsetof(host_t, destroy));
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2008-04-09 18:12:22 +00:00
|
|
|
if (this->is_mediation_server)
|
2007-10-03 15:10:41 +00:00
|
|
|
{
|
2009-09-02 15:26:36 +00:00
|
|
|
charon->mediation_manager->remove(charon->mediation_manager,
|
|
|
|
this->ike_sa_id);
|
2007-10-03 15:10:41 +00:00
|
|
|
}
|
|
|
|
DESTROY_IF(this->server_reflexive_host);
|
2008-04-01 11:38:18 +00:00
|
|
|
chunk_free(&this->connect_id);
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2008-10-06 13:37:04 +00:00
|
|
|
free(this->nat_detection_dest.ptr);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
DESTROY_IF(this->my_host);
|
|
|
|
DESTROY_IF(this->other_host);
|
|
|
|
DESTROY_IF(this->my_id);
|
|
|
|
DESTROY_IF(this->other_id);
|
2008-11-11 06:37:37 +00:00
|
|
|
DESTROY_IF(this->local_host);
|
|
|
|
DESTROY_IF(this->remote_host);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
DESTROY_IF(this->ike_cfg);
|
|
|
|
DESTROY_IF(this->peer_cfg);
|
2008-10-30 12:58:54 +00:00
|
|
|
DESTROY_IF(this->proposal);
|
2009-04-14 10:34:24 +00:00
|
|
|
this->my_auth->destroy(this->my_auth);
|
|
|
|
this->other_auth->destroy(this->other_auth);
|
2009-12-01 10:35:30 +00:00
|
|
|
this->my_auths->destroy_offset(this->my_auths,
|
|
|
|
offsetof(auth_cfg_t, destroy));
|
|
|
|
this->other_auths->destroy_offset(this->other_auths,
|
|
|
|
offsetof(auth_cfg_t, destroy));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-03-20 15:43:26 +00:00
|
|
|
this->ike_sa_id->destroy(this->ike_sa_id);
|
2006-04-10 08:07:38 +00:00
|
|
|
free(this);
|
2005-11-08 13:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-12-07 09:03:34 +00:00
|
|
|
* Described in header.
|
2005-11-08 13:33:28 +00:00
|
|
|
*/
|
|
|
|
ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
|
|
|
{
|
2010-06-07 09:30:27 +00:00
|
|
|
private_ike_sa_t *this;
|
2007-02-28 14:04:36 +00:00
|
|
|
static u_int32_t unique_id = 0;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-06-07 09:30:27 +00:00
|
|
|
INIT(this,
|
|
|
|
.public = {
|
|
|
|
.get_state = _get_state,
|
|
|
|
.set_state = _set_state,
|
|
|
|
.get_name = _get_name,
|
|
|
|
.get_statistic = _get_statistic,
|
|
|
|
.process_message = _process_message,
|
|
|
|
.initiate = _initiate,
|
|
|
|
.get_ike_cfg = _get_ike_cfg,
|
|
|
|
.set_ike_cfg = _set_ike_cfg,
|
|
|
|
.get_peer_cfg = _get_peer_cfg,
|
|
|
|
.set_peer_cfg = _set_peer_cfg,
|
|
|
|
.get_auth_cfg = _get_auth_cfg,
|
|
|
|
.create_auth_cfg_enumerator = _create_auth_cfg_enumerator,
|
|
|
|
.add_auth_cfg = _add_auth_cfg,
|
|
|
|
.get_proposal = _get_proposal,
|
|
|
|
.set_proposal = _set_proposal,
|
|
|
|
.get_id = _get_id,
|
|
|
|
.get_my_host = _get_my_host,
|
|
|
|
.set_my_host = _set_my_host,
|
|
|
|
.get_other_host = _get_other_host,
|
|
|
|
.set_other_host = _set_other_host,
|
|
|
|
.set_message_id = _set_message_id,
|
2010-08-30 10:19:37 +00:00
|
|
|
.float_ports = _float_ports,
|
2010-06-07 09:30:27 +00:00
|
|
|
.update_hosts = _update_hosts,
|
|
|
|
.get_my_id = _get_my_id,
|
|
|
|
.set_my_id = _set_my_id,
|
|
|
|
.get_other_id = _get_other_id,
|
|
|
|
.set_other_id = _set_other_id,
|
|
|
|
.get_other_eap_id = _get_other_eap_id,
|
|
|
|
.enable_extension = _enable_extension,
|
|
|
|
.supports_extension = _supports_extension,
|
|
|
|
.set_condition = _set_condition,
|
|
|
|
.has_condition = _has_condition,
|
|
|
|
.set_pending_updates = _set_pending_updates,
|
|
|
|
.get_pending_updates = _get_pending_updates,
|
2012-03-09 09:15:21 +00:00
|
|
|
.create_peer_address_enumerator = _create_peer_address_enumerator,
|
|
|
|
.add_peer_address = _add_peer_address,
|
|
|
|
.clear_peer_addresses = _clear_peer_addresses,
|
2010-06-07 09:30:27 +00:00
|
|
|
.has_mapping_changed = _has_mapping_changed,
|
|
|
|
.retransmit = _retransmit,
|
|
|
|
.delete = _delete_,
|
|
|
|
.destroy = _destroy,
|
|
|
|
.send_dpd = _send_dpd,
|
|
|
|
.send_keepalive = _send_keepalive,
|
|
|
|
.get_keymat = _get_keymat,
|
|
|
|
.add_child_sa = _add_child_sa,
|
|
|
|
.get_child_sa = _get_child_sa,
|
2011-05-19 15:27:32 +00:00
|
|
|
.get_child_count = _get_child_count,
|
|
|
|
.create_child_sa_enumerator = _create_child_sa_enumerator,
|
|
|
|
.remove_child_sa = _remove_child_sa,
|
2010-06-07 09:30:27 +00:00
|
|
|
.rekey_child_sa = _rekey_child_sa,
|
|
|
|
.delete_child_sa = _delete_child_sa,
|
|
|
|
.destroy_child_sa = _destroy_child_sa,
|
|
|
|
.rekey = _rekey,
|
|
|
|
.reauth = _reauth,
|
|
|
|
.reestablish = _reestablish,
|
|
|
|
.set_auth_lifetime = _set_auth_lifetime,
|
|
|
|
.roam = _roam,
|
|
|
|
.inherit = _inherit,
|
|
|
|
.generate_message = _generate_message,
|
|
|
|
.reset = _reset,
|
|
|
|
.get_unique_id = _get_unique_id,
|
|
|
|
.set_virtual_ip = _set_virtual_ip,
|
|
|
|
.get_virtual_ip = _get_virtual_ip,
|
|
|
|
.add_configuration_attribute = _add_configuration_attribute,
|
|
|
|
.set_kmaddress = _set_kmaddress,
|
2010-06-07 09:37:55 +00:00
|
|
|
.create_task_enumerator = _create_task_enumerator,
|
2008-03-26 18:40:19 +00:00
|
|
|
#ifdef ME
|
2010-06-07 09:30:27 +00:00
|
|
|
.act_as_mediation_server = _act_as_mediation_server,
|
|
|
|
.get_server_reflexive_host = _get_server_reflexive_host,
|
|
|
|
.set_server_reflexive_host = _set_server_reflexive_host,
|
|
|
|
.get_connect_id = _get_connect_id,
|
|
|
|
.initiate_mediation = _initiate_mediation,
|
|
|
|
.initiate_mediated = _initiate_mediated,
|
|
|
|
.relay = _relay,
|
|
|
|
.callback = _callback,
|
|
|
|
.respond = _respond,
|
2008-03-26 18:40:19 +00:00
|
|
|
#endif /* ME */
|
2010-06-07 09:30:27 +00:00
|
|
|
},
|
|
|
|
.ike_sa_id = ike_sa_id->clone(ike_sa_id),
|
|
|
|
.child_sas = linked_list_create(),
|
|
|
|
.my_host = host_create_any(AF_INET),
|
|
|
|
.other_host = host_create_any(AF_INET),
|
|
|
|
.my_id = identification_create_from_encoding(ID_ANY, chunk_empty),
|
|
|
|
.other_id = identification_create_from_encoding(ID_ANY, chunk_empty),
|
|
|
|
.keymat = keymat_create(ike_sa_id->is_initiator(ike_sa_id)),
|
|
|
|
.state = IKE_CREATED,
|
|
|
|
.stats[STAT_INBOUND] = time_monotonic(NULL),
|
|
|
|
.stats[STAT_OUTBOUND] = time_monotonic(NULL),
|
|
|
|
.my_auth = auth_cfg_create(),
|
|
|
|
.other_auth = auth_cfg_create(),
|
|
|
|
.my_auths = linked_list_create(),
|
|
|
|
.other_auths = linked_list_create(),
|
|
|
|
.unique_id = ++unique_id,
|
2012-03-09 09:15:21 +00:00
|
|
|
.peer_addresses = linked_list_create(),
|
2010-06-07 09:30:27 +00:00
|
|
|
.attributes = linked_list_create(),
|
|
|
|
.keepalive_interval = lib->settings->get_time(lib->settings,
|
|
|
|
"charon.keep_alive", KEEPALIVE_INTERVAL),
|
|
|
|
);
|
2011-08-01 11:08:15 +00:00
|
|
|
this->task_manager = task_manager_create(&this->public);
|
2008-11-18 10:10:36 +00:00
|
|
|
this->my_host->set_port(this->my_host, IKEV2_UDP_PORT);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
return &this->public;
|
2005-11-08 13:33:28 +00:00
|
|
|
}
|