2005-11-08 13:33:28 +00:00
|
|
|
/**
|
|
|
|
* @file ike_sa.c
|
2005-11-09 09:11:06 +00:00
|
|
|
*
|
2005-11-29 08:08:03 +00:00
|
|
|
* @brief Implementation of ike_sa_t.
|
2005-11-09 09:11:06 +00:00
|
|
|
*
|
2005-11-08 13:33:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2006-06-22 06:36:28 +00:00
|
|
|
* Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
|
2006-07-07 08:49:06 +00:00
|
|
|
* Copyright (C) 2005-2006 Martin Willi
|
|
|
|
* 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
|
|
|
|
|
|
|
#include <sys/time.h>
|
2006-04-10 08:07:38 +00:00
|
|
|
#include <string.h>
|
2006-10-18 11:46:13 +00:00
|
|
|
#include <printf.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sys/stat.h>
|
2007-04-12 08:52:36 +00:00
|
|
|
#include <errno.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>
|
2005-11-29 10:25:07 +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>
|
2006-04-05 12:10:50 +00:00
|
|
|
#include <crypto/diffie_hellman.h>
|
|
|
|
#include <crypto/prf_plus.h>
|
|
|
|
#include <crypto/crypters/crypter.h>
|
2006-06-22 06:36:28 +00:00
|
|
|
#include <crypto/hashers/hasher.h>
|
2005-11-23 09:57:18 +00:00
|
|
|
#include <encoding/payloads/sa_payload.h>
|
|
|
|
#include <encoding/payloads/nonce_payload.h>
|
|
|
|
#include <encoding/payloads/ke_payload.h>
|
2005-12-12 14:14:52 +00:00
|
|
|
#include <encoding/payloads/delete_payload.h>
|
2005-11-23 09:57:18 +00:00
|
|
|
#include <encoding/payloads/transform_substructure.h>
|
|
|
|
#include <encoding/payloads/transform_attribute.h>
|
2006-06-07 13:26:23 +00:00
|
|
|
#include <encoding/payloads/ts_payload.h>
|
2007-02-28 14:04:36 +00:00
|
|
|
#include <sa/task_manager.h>
|
|
|
|
#include <sa/tasks/ike_init.h>
|
|
|
|
#include <sa/tasks/ike_natd.h>
|
|
|
|
#include <sa/tasks/ike_auth.h>
|
|
|
|
#include <sa/tasks/ike_config.h>
|
|
|
|
#include <sa/tasks/ike_cert.h>
|
|
|
|
#include <sa/tasks/ike_rekey.h>
|
|
|
|
#include <sa/tasks/ike_delete.h>
|
|
|
|
#include <sa/tasks/ike_dpd.h>
|
|
|
|
#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>
|
2005-11-08 13:33:28 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
|
|
|
|
#ifndef RESOLV_CONF
|
|
|
|
#define RESOLV_CONF "/etc/resolv.conf"
|
|
|
|
#endif
|
|
|
|
|
2006-10-18 11:46:13 +00:00
|
|
|
ENUM(ike_sa_state_names, IKE_CREATED, IKE_DELETING,
|
|
|
|
"CREATED",
|
|
|
|
"CONNECTING",
|
|
|
|
"ESTABLISHED",
|
|
|
|
"REKEYING",
|
|
|
|
"DELETING",
|
|
|
|
);
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private data of an ike_sa_t object.
|
|
|
|
*/
|
|
|
|
struct private_ike_sa_t {
|
|
|
|
|
|
|
|
/**
|
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;
|
2006-06-23 14:02:30 +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;
|
2006-06-07 13:26:23 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* unique numerical ID for this IKE_SA.
|
|
|
|
*/
|
|
|
|
u_int32_t unique_id;
|
|
|
|
|
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
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
ike_sa_state_t state;
|
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;
|
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;
|
2007-02-28 14:04:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Juggles tasks to process messages
|
|
|
|
*/
|
|
|
|
task_manager_t *task_manager;
|
2006-07-20 10:09:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Address of local host
|
|
|
|
*/
|
|
|
|
host_t *my_host;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Address of remote host
|
|
|
|
*/
|
|
|
|
host_t *other_host;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Identification used for us
|
|
|
|
*/
|
|
|
|
identification_t *my_id;
|
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;
|
2005-12-03 16:52:54 +00:00
|
|
|
|
2007-05-17 17:55:29 +00:00
|
|
|
/**
|
|
|
|
* CA that issued the certificate of other
|
|
|
|
*/
|
|
|
|
ca_info_t *other_ca;
|
|
|
|
|
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;
|
2005-11-25 13:42:02 +00:00
|
|
|
|
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* crypter for inbound traffic
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2006-07-05 10:53:20 +00:00
|
|
|
crypter_t *crypter_in;
|
2005-11-25 13:42:02 +00:00
|
|
|
|
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* crypter for outbound traffic
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2006-07-05 10:53:20 +00:00
|
|
|
crypter_t *crypter_out;
|
2005-11-25 13:42:02 +00:00
|
|
|
|
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* Signer for inbound traffic
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2006-07-05 10:53:20 +00:00
|
|
|
signer_t *signer_in;
|
2005-11-25 13:42:02 +00:00
|
|
|
|
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* Signer for outbound traffic
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2006-07-05 10:53:20 +00:00
|
|
|
signer_t *signer_out;
|
2005-11-25 13:42:02 +00:00
|
|
|
|
|
|
|
/**
|
2006-02-14 14:52:00 +00:00
|
|
|
* Multi purpose prf, set key, use it, forget it
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
|
|
|
prf_t *prf;
|
|
|
|
|
2006-02-09 16:25:02 +00:00
|
|
|
/**
|
|
|
|
* Prf function for derivating keymat child SAs
|
|
|
|
*/
|
|
|
|
prf_t *child_prf;
|
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2007-04-19 12:37:48 +00:00
|
|
|
* Key to build outging authentication data (SKp)
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2007-04-19 12:37:48 +00:00
|
|
|
chunk_t skp_build;
|
2005-11-25 13:42:02 +00:00
|
|
|
|
2006-02-14 14:52:00 +00:00
|
|
|
/**
|
2007-04-19 12:37:48 +00:00
|
|
|
* Key to verify incoming authentication data (SKp)
|
2006-02-14 14:52:00 +00:00
|
|
|
*/
|
2007-04-19 12:37:48 +00:00
|
|
|
chunk_t skp_verify;
|
2005-12-02 14:07:36 +00:00
|
|
|
|
2006-06-22 06:36:28 +00:00
|
|
|
/**
|
|
|
|
* NAT status of local host.
|
|
|
|
*/
|
|
|
|
bool nat_here;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NAT status of remote host.
|
|
|
|
*/
|
|
|
|
bool nat_there;
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual IP on remote host, if any
|
|
|
|
*/
|
|
|
|
host_t *other_virtual_ip;
|
|
|
|
|
2007-01-10 08:18:52 +00:00
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* List of DNS servers installed by us
|
2007-01-10 08:18:52 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
linked_list_t *dns_servers;
|
2007-01-10 08:18:52 +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
|
|
|
*/
|
2006-07-27 12:18:40 +00:00
|
|
|
struct {
|
|
|
|
/** last IKE message received */
|
|
|
|
u_int32_t inbound;
|
|
|
|
/** last IKE message sent */
|
|
|
|
u_int32_t outbound;
|
|
|
|
/** when IKE_SA became established */
|
|
|
|
u_int32_t established;
|
|
|
|
/** when IKE_SA gets rekeyed */
|
|
|
|
u_int32_t rekey;
|
|
|
|
/** when IKE_SA gets deleted */
|
|
|
|
u_int32_t delete;
|
|
|
|
} time;
|
2007-03-20 08:16:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* how many times we have retried so far (keyingtries)
|
|
|
|
*/
|
|
|
|
u_int32_t keyingtry;
|
2005-11-25 13:42:02 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2006-07-05 10:53:20 +00:00
|
|
|
iterator_t *iterator;
|
|
|
|
child_sa_t *child_sa;
|
|
|
|
time_t latest = 0, use_time;
|
2006-03-16 15:25:06 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
|
|
|
while (iterator->iterate(iterator, (void**)&child_sa))
|
|
|
|
{
|
|
|
|
if (child_sa->get_use_time(child_sa, inbound, &use_time) == SUCCESS)
|
|
|
|
{
|
|
|
|
latest = max(latest, use_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
2005-12-02 13:20:20 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
if (inbound)
|
|
|
|
{
|
|
|
|
return max(this->time.inbound, latest);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return max(this->time.outbound, latest);
|
|
|
|
}
|
2005-12-01 17:16:10 +00:00
|
|
|
}
|
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* Implementation of ike_sa_t.get_unique_id
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static u_int32_t get_unique_id(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
|
|
|
}
|
|
|
|
|
2005-12-02 19:26:01 +00:00
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* Implementation of ike_sa_t.get_name.
|
2005-12-02 19:26:01 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static char *get_name(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
|
|
|
}
|
|
|
|
|
2007-04-11 12:14:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.get_stats.
|
|
|
|
*/
|
|
|
|
static void get_stats(private_ike_sa_t *this, u_int32_t *next_rekeying)
|
|
|
|
{
|
|
|
|
if (next_rekeying)
|
|
|
|
{
|
|
|
|
*next_rekeying = this->time.rekey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Implementation of ike_sa_t.get_my_host.
|
2006-07-20 10:09:32 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static host_t *get_my_host(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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Implementation of ike_sa_t.set_my_host.
|
2006-07-20 10:09:32 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static void set_my_host(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
|
|
|
}
|
|
|
|
|
2006-09-25 06:38:58 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Implementation of ike_sa_t.get_other_host.
|
2006-09-25 06:38:58 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static host_t *get_other_host(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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Implementation of ike_sa_t.set_other_host.
|
2007-02-28 14:04:36 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static void set_other_host(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
|
|
|
}
|
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Implementation of ike_sa_t.get_peer_cfg
|
2006-07-20 10:09:32 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static peer_cfg_t* get_peer_cfg(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
|
|
|
}
|
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Implementation of ike_sa_t.set_peer_cfg
|
2006-07-27 12:18:40 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static void set_peer_cfg(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);
|
|
|
|
this->peer_cfg = peer_cfg;
|
2007-04-10 22:39: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply values, so we are ready to initate/acquire */
|
|
|
|
if (this->my_host->is_anyaddr(this->my_host))
|
|
|
|
{
|
2007-04-10 22:39:09 +00:00
|
|
|
host_t *me = this->ike_cfg->get_my_host(this->ike_cfg);
|
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
set_my_host(this, me->clone(me));
|
|
|
|
}
|
|
|
|
if (this->other_host->is_anyaddr(this->other_host))
|
|
|
|
{
|
2007-04-10 22:39:09 +00:00
|
|
|
host_t *other = this->ike_cfg->get_other_host(this->ike_cfg);
|
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
set_other_host(this, other->clone(other));
|
|
|
|
}
|
2007-04-25 06:06:13 +00:00
|
|
|
/* apply IDs if they are not already set */
|
|
|
|
if (this->my_id->contains_wildcards(this->my_id))
|
2007-04-10 22:39:09 +00:00
|
|
|
{
|
|
|
|
identification_t *my_id = this->peer_cfg->get_my_id(this->peer_cfg);
|
2007-04-25 06:06:13 +00:00
|
|
|
|
2007-04-10 22:39:09 +00:00
|
|
|
DESTROY_IF(this->my_id);
|
|
|
|
this->my_id = my_id->clone(my_id);
|
|
|
|
}
|
2007-04-25 06:06:13 +00:00
|
|
|
if (this->other_id->contains_wildcards(this->other_id))
|
2007-04-10 22:39:09 +00:00
|
|
|
{
|
|
|
|
identification_t *other_id = this->peer_cfg->get_other_id(this->peer_cfg);
|
|
|
|
|
|
|
|
DESTROY_IF(this->other_id);
|
|
|
|
this->other_id = other_id->clone(other_id);
|
|
|
|
}
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Implementation of ike_sa_t.get_ike_cfg
|
2006-07-20 10:09:32 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static ike_cfg_t *get_ike_cfg(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
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Implementation of ike_sa_t.set_ike_cfg
|
2006-07-27 12:18:40 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static void set_ike_cfg(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
|
|
|
}
|
|
|
|
|
2007-03-20 08:16:16 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.send_dpd
|
|
|
|
*/
|
|
|
|
static status_t send_dpd(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
send_dpd_job_t *job;
|
|
|
|
time_t diff, delay;
|
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
delay = this->peer_cfg->get_dpd_delay(this->peer_cfg);
|
2007-03-20 08:16:16 +00:00
|
|
|
|
|
|
|
if (delay == 0)
|
|
|
|
{
|
|
|
|
/* DPD disabled */
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
now = time(NULL);
|
|
|
|
diff = now - last_in;
|
|
|
|
if (diff >= delay)
|
|
|
|
{
|
|
|
|
/* to long ago, initiate dead peer detection */
|
|
|
|
task_t *task;
|
|
|
|
|
|
|
|
task = (task_t*)ike_dpd_create(TRUE);
|
|
|
|
diff = 0;
|
|
|
|
DBG1(DBG_IKE, "sending DPD request");
|
|
|
|
|
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* recheck in "interval" seconds */
|
|
|
|
job = send_dpd_job_create(this->ike_sa_id);
|
2007-06-11 10:57:19 +00:00
|
|
|
charon->scheduler->schedule_job(charon->scheduler, (job_t*)job,
|
|
|
|
(delay - diff) * 1000);
|
2007-03-20 08:16:16 +00:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.send_keepalive
|
|
|
|
*/
|
|
|
|
static void send_keepalive(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
send_keepalive_job_t *job;
|
2007-04-11 07:20:39 +00:00
|
|
|
time_t last_out, now, diff;
|
2007-03-20 08:16:16 +00:00
|
|
|
|
|
|
|
last_out = get_use_time(this, FALSE);
|
|
|
|
now = time(NULL);
|
|
|
|
|
|
|
|
diff = now - last_out;
|
|
|
|
|
2007-04-11 07:20:39 +00:00
|
|
|
if (diff >= KEEPALIVE_INTERVAL)
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
|
|
|
packet_t *packet;
|
|
|
|
chunk_t data;
|
|
|
|
|
|
|
|
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);
|
2007-03-28 13:34:02 +00:00
|
|
|
charon->sender->send(charon->sender, packet);
|
2007-03-20 08:16:16 +00:00
|
|
|
DBG1(DBG_IKE, "sending keep alive");
|
|
|
|
diff = 0;
|
|
|
|
}
|
|
|
|
job = send_keepalive_job_create(this->ike_sa_id);
|
2007-06-11 10:57:19 +00:00
|
|
|
charon->scheduler->schedule_job(charon->scheduler, (job_t*)job,
|
|
|
|
(KEEPALIVE_INTERVAL - diff) * 1000);
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.get_state.
|
|
|
|
*/
|
|
|
|
static ike_sa_state_t get_state(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.set_state.
|
|
|
|
*/
|
|
|
|
static void set_state(private_ike_sa_t *this, ike_sa_state_t state)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "IKE_SA state change: %N => %N",
|
|
|
|
ike_sa_state_names, this->state,
|
|
|
|
ike_sa_state_names, state);
|
|
|
|
|
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
|
|
|
{
|
2007-03-20 16:13:21 +00:00
|
|
|
if (this->state == IKE_CONNECTING)
|
|
|
|
{
|
|
|
|
job_t *job;
|
|
|
|
u_int32_t now = time(NULL);
|
|
|
|
u_int32_t soft, hard;
|
|
|
|
bool reauth;
|
|
|
|
|
|
|
|
this->time.established = now;
|
|
|
|
/* start DPD checks */
|
|
|
|
send_dpd(this);
|
|
|
|
|
|
|
|
/* schedule rekeying/reauthentication */
|
2007-04-10 06:01:03 +00:00
|
|
|
soft = this->peer_cfg->get_lifetime(this->peer_cfg, TRUE);
|
|
|
|
hard = this->peer_cfg->get_lifetime(this->peer_cfg, FALSE);
|
|
|
|
reauth = this->peer_cfg->use_reauth(this->peer_cfg);
|
2007-03-20 16:13:21 +00:00
|
|
|
DBG1(DBG_IKE, "scheduling %s in %ds, maximum lifetime %ds",
|
|
|
|
reauth ? "reauthentication": "rekeying", soft, hard);
|
|
|
|
|
|
|
|
if (soft)
|
|
|
|
{
|
|
|
|
this->time.rekey = now + soft;
|
|
|
|
job = (job_t*)rekey_ike_sa_job_create(this->ike_sa_id, reauth);
|
2007-06-11 10:57:19 +00:00
|
|
|
charon->scheduler->schedule_job(charon->scheduler, job,
|
|
|
|
soft * 1000);
|
2007-03-20 16:13:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hard)
|
|
|
|
{
|
|
|
|
this->time.delete = now + hard;
|
|
|
|
job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
|
2007-06-11 10:57:19 +00:00
|
|
|
charon->scheduler->schedule_job(charon->scheduler, job,
|
|
|
|
hard * 1000);
|
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);
|
2007-06-11 10:57:19 +00:00
|
|
|
charon->scheduler->schedule_job(charon->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
|
|
|
}
|
|
|
|
|
|
|
|
this->state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.reset
|
|
|
|
*/
|
|
|
|
static void reset(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_state(this, IKE_CREATED);
|
|
|
|
|
|
|
|
this->task_manager->reset(this->task_manager);
|
|
|
|
}
|
|
|
|
|
2005-12-02 19:26:01 +00:00
|
|
|
/**
|
2007-04-10 06:01:03 +00:00
|
|
|
* Update hosts, as addresses may change (NAT)
|
2005-12-02 19:26:01 +00:00
|
|
|
*/
|
2006-07-05 10:53:20 +00:00
|
|
|
static void update_hosts(private_ike_sa_t *this, host_t *me, host_t *other)
|
2005-12-02 19:26:01 +00:00
|
|
|
{
|
2006-07-05 10:53:20 +00:00
|
|
|
iterator_t *iterator = NULL;
|
|
|
|
child_sa_t *child_sa = NULL;
|
2006-07-20 10:09:32 +00:00
|
|
|
host_diff_t my_diff, other_diff;
|
|
|
|
|
2006-07-21 13:31:53 +00:00
|
|
|
if (this->my_host->is_anyaddr(this->my_host) ||
|
|
|
|
this->other_host->is_anyaddr(this->other_host))
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
|
|
|
/* on first received message */
|
2006-07-21 13:31:53 +00:00
|
|
|
this->my_host->destroy(this->my_host);
|
2006-07-20 10:09:32 +00:00
|
|
|
this->my_host = me->clone(me);
|
2006-07-21 13:31:53 +00:00
|
|
|
this->other_host->destroy(this->other_host);
|
2006-07-20 10:09:32 +00:00
|
|
|
this->other_host = other->clone(other);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
my_diff = me->get_differences(me, this->my_host);
|
|
|
|
other_diff = other->get_differences(other, this->other_host);
|
|
|
|
|
|
|
|
if (!my_diff && !other_diff)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
if (my_diff)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
this->my_host->destroy(this->my_host);
|
|
|
|
this->my_host = me->clone(me);
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!this->nat_here)
|
|
|
|
{
|
|
|
|
/* update without restrictions if we are not NATted */
|
2006-07-20 10:09:32 +00:00
|
|
|
if (other_diff)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
this->other_host->destroy(this->other_host);
|
|
|
|
this->other_host = other->clone(other);
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if we are natted, only port may change */
|
2006-07-20 10:09:32 +00:00
|
|
|
if (other_diff & HOST_DIFF_ADDR)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2006-07-20 10:09:32 +00:00
|
|
|
else if (other_diff & HOST_DIFF_PORT)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
this->other_host->set_port(this->other_host, other->get_port(other));
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
|
|
|
while (iterator->iterate(iterator, (void**)&child_sa))
|
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
child_sa->update_hosts(child_sa, this->my_host, this->other_host,
|
|
|
|
my_diff, other_diff);
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* Implementation of ike_sa_t.generate
|
2006-06-07 13:26:23 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static status_t generate_message(private_ike_sa_t *this, message_t *message,
|
|
|
|
packet_t **packet)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2006-07-27 12:18:40 +00:00
|
|
|
this->time.outbound = time(NULL);
|
2007-02-28 14:04:36 +00:00
|
|
|
message->set_ike_sa_id(message, this->ike_sa_id);
|
|
|
|
message->set_destination(message, this->other_host->clone(this->other_host));
|
|
|
|
message->set_source(message, this->my_host->clone(this->my_host));
|
|
|
|
return message->generate(message, this->crypter_out, this->signer_out, 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,
|
2006-07-05 10:53:20 +00:00
|
|
|
notify_type_t type)
|
|
|
|
{
|
|
|
|
message_t *response;
|
|
|
|
packet_t *packet;
|
|
|
|
|
|
|
|
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));
|
2007-02-28 14:04:36 +00:00
|
|
|
response->add_notify(response, FALSE, type, chunk_empty);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.process_message.
|
|
|
|
*/
|
|
|
|
static status_t process_message(private_ike_sa_t *this, message_t *message)
|
|
|
|
{
|
|
|
|
status_t status;
|
|
|
|
bool is_request;
|
2006-02-14 14:52:00 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
is_request = message->get_request(message);
|
2006-02-14 14:52:00 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
status = message->parse_body(message, this->crypter_in, this->signer_in);
|
|
|
|
if (status != SUCCESS)
|
2005-11-28 15:20:51 +00:00
|
|
|
{
|
2006-10-18 11:46:13 +00:00
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
if (is_request)
|
2006-07-05 10:53:20 +00:00
|
|
|
{
|
2006-07-27 12:18:40 +00:00
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case NOT_SUPPORTED:
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "ciritcal unknown payloads found");
|
2006-07-27 12:18:40 +00:00
|
|
|
if (is_request)
|
|
|
|
{
|
|
|
|
send_notify_response(this, message, UNSUPPORTED_CRITICAL_PAYLOAD);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PARSE_ERROR:
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "message parsing failed");
|
2006-07-27 12:18:40 +00:00
|
|
|
if (is_request)
|
|
|
|
{
|
|
|
|
send_notify_response(this, message, INVALID_SYNTAX);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VERIFY_ERROR:
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "message verification failed");
|
2006-07-27 12:18:40 +00:00
|
|
|
if (is_request)
|
|
|
|
{
|
|
|
|
send_notify_response(this, message, INVALID_SYNTAX);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FAILED:
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "integrity check failed");
|
2006-07-27 12:18:40 +00:00
|
|
|
/* ignored */
|
|
|
|
break;
|
|
|
|
case INVALID_STATE:
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "found encrypted message, but no keys available");
|
2006-07-27 12:18:40 +00:00
|
|
|
if (is_request)
|
|
|
|
{
|
|
|
|
send_notify_response(this, message, INVALID_SYNTAX);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "%N %s with message ID %d processing failed",
|
2006-10-18 11:46:13 +00:00
|
|
|
exchange_type_names, message->get_exchange_type(message),
|
|
|
|
message->get_request(message) ? "request" : "response",
|
|
|
|
message->get_message_id(message));
|
2007-02-28 14:04:36 +00:00
|
|
|
return status;
|
2005-11-28 15:20:51 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
else
|
2006-02-14 14:52:00 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
host_t *me, *other;
|
|
|
|
|
|
|
|
me = message->get_destination(message);
|
|
|
|
other = message->get_source(message);
|
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
/* if this IKE_SA is virgin, we check for a config */
|
|
|
|
if (this->ike_cfg == NULL)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2007-03-20 16:13:21 +00:00
|
|
|
job_t *job;
|
2007-04-27 14:25:08 +00:00
|
|
|
this->ike_cfg = charon->backends->get_ike_cfg(charon->backends,
|
|
|
|
me, other);
|
2007-04-10 06:01:03 +00:00
|
|
|
if (this->ike_cfg == NULL)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
/* no config found for these hosts, destroy */
|
|
|
|
DBG1(DBG_IKE, "no IKE config found for %H...%H, sending %N",
|
2007-03-08 00:15:15 +00:00
|
|
|
me, other, notify_type_names, NO_PROPOSAL_CHOSEN);
|
2007-02-28 14:04:36 +00:00
|
|
|
send_notify_response(this, message, NO_PROPOSAL_CHOSEN);
|
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
2007-03-20 16:13:21 +00:00
|
|
|
/* add a timeout if peer does not establish it completely */
|
|
|
|
job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, FALSE);
|
2007-06-11 10:57:19 +00:00
|
|
|
charon->scheduler->schedule_job(charon->scheduler, job,
|
|
|
|
HALF_OPEN_IKE_SA_TIMEOUT);
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2007-04-11 07:20:39 +00:00
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
/* check if message is trustworthy, and update host information */
|
2006-07-20 10:09:32 +00:00
|
|
|
if (this->state == IKE_CREATED ||
|
2006-07-05 10:53:20 +00:00
|
|
|
message->get_exchange_type(message) != IKE_SA_INIT)
|
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
update_hosts(this, me, other);
|
2006-07-27 12:18:40 +00:00
|
|
|
this->time.inbound = time(NULL);
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
return this->task_manager->process_message(this->task_manager, message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2006-07-05 10:53:20 +00:00
|
|
|
* Implementation of ike_sa_t.initiate.
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static status_t initiate(private_ike_sa_t *this, child_cfg_t *child_cfg)
|
2005-11-25 13:42:02 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
task_t *task;
|
|
|
|
|
|
|
|
if (this->state == IKE_CREATED)
|
2006-07-20 14:57:49 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
|
2007-03-21 07:00:04 +00:00
|
|
|
if (this->other_host->is_anyaddr(this->other_host))
|
|
|
|
{
|
|
|
|
SIG(IKE_UP_START, "initiating IKE_SA");
|
|
|
|
SIG(IKE_UP_FAILED, "unable to initiate to %%any");
|
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
task = (task_t*)ike_init_create(&this->public, TRUE, NULL);
|
|
|
|
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_cert_create(&this->public, TRUE);
|
|
|
|
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);
|
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-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
task = (task_t*)child_create_create(&this->public, child_cfg);
|
2007-05-23 09:08:13 +00:00
|
|
|
child_cfg->destroy(child_cfg);
|
2007-02-28 14:04:36 +00:00
|
|
|
this->task_manager->queue_task(this->task_manager, task);
|
|
|
|
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2005-11-25 13:42:02 +00:00
|
|
|
}
|
|
|
|
|
2006-07-20 10:09:32 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.acquire.
|
|
|
|
*/
|
|
|
|
static status_t acquire(private_ike_sa_t *this, u_int32_t reqid)
|
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
child_cfg_t *child_cfg;
|
2006-07-21 13:31:53 +00:00
|
|
|
iterator_t *iterator;
|
|
|
|
child_sa_t *current, *child_sa = NULL;
|
2007-02-28 14:04:36 +00:00
|
|
|
task_t *task;
|
|
|
|
child_create_t *child_create;
|
2006-07-21 13:31:53 +00:00
|
|
|
|
|
|
|
if (this->state == IKE_DELETING)
|
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
SIG(CHILD_UP_START, "acquiring CHILD_SA on kernel request");
|
|
|
|
SIG(CHILD_UP_FAILED, "acquiring CHILD_SA (reqid %d) failed: "
|
2006-10-18 11:46:13 +00:00
|
|
|
"IKE_SA is deleting", reqid);
|
2006-07-21 13:31:53 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find CHILD_SA */
|
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
|
|
|
while (iterator->iterate(iterator, (void**)¤t))
|
|
|
|
{
|
|
|
|
if (current->get_reqid(current) == reqid)
|
2007-02-28 14:04:36 +00:00
|
|
|
{
|
|
|
|
child_sa = current;
|
2006-07-21 13:31:53 +00:00
|
|
|
break;
|
2007-02-28 14:04:36 +00:00
|
|
|
}
|
2006-07-21 13:31:53 +00:00
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
iterator->destroy(iterator);
|
|
|
|
if (!child_sa)
|
|
|
|
{
|
|
|
|
SIG(CHILD_UP_START, "acquiring CHILD_SA on kernel request");
|
|
|
|
SIG(CHILD_UP_FAILED, "acquiring CHILD_SA (reqid %d) failed: "
|
|
|
|
"CHILD_SA not found", reqid);
|
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this->state == IKE_CREATED)
|
|
|
|
{
|
|
|
|
task = (task_t*)ike_init_create(&this->public, TRUE, NULL);
|
|
|
|
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_cert_create(&this->public, TRUE);
|
|
|
|
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);
|
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-02-28 14:04:36 +00:00
|
|
|
}
|
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
child_cfg = child_sa->get_config(child_sa);
|
|
|
|
child_create = child_create_create(&this->public, child_cfg);
|
2007-02-28 14:04:36 +00:00
|
|
|
child_create->use_reqid(child_create, reqid);
|
|
|
|
this->task_manager->queue_task(this->task_manager, (task_t*)child_create);
|
|
|
|
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-07-21 13:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.route.
|
|
|
|
*/
|
2007-04-10 06:01:03 +00:00
|
|
|
static status_t route(private_ike_sa_t *this, child_cfg_t *child_cfg)
|
2006-07-21 13:31:53 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
child_sa_t *child_sa;
|
2006-07-21 13:31:53 +00:00
|
|
|
iterator_t *iterator;
|
|
|
|
linked_list_t *my_ts, *other_ts;
|
|
|
|
status_t status;
|
|
|
|
|
2006-10-26 09:46:56 +00:00
|
|
|
SIG(CHILD_ROUTE_START, "routing CHILD_SA");
|
|
|
|
|
2006-07-21 13:31:53 +00:00
|
|
|
/* check if not already routed*/
|
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
|
|
|
while (iterator->iterate(iterator, (void**)&child_sa))
|
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
if (child_sa->get_state(child_sa) == CHILD_ROUTED &&
|
|
|
|
streq(child_sa->get_name(child_sa), child_cfg->get_name(child_cfg)))
|
2006-07-21 13:31:53 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
iterator->destroy(iterator);
|
|
|
|
SIG(CHILD_ROUTE_FAILED, "CHILD_SA with such a config already routed");
|
|
|
|
return FAILED;
|
2006-07-21 13:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
|
|
|
|
|
|
|
switch (this->state)
|
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
case IKE_DELETING:
|
|
|
|
case IKE_REKEYING:
|
|
|
|
SIG(CHILD_ROUTE_FAILED,
|
|
|
|
"unable to route CHILD_SA, as its IKE_SA gets deleted");
|
|
|
|
return FAILED;
|
2006-07-21 13:31:53 +00:00
|
|
|
case IKE_CREATED:
|
2007-02-28 14:04:36 +00:00
|
|
|
case IKE_CONNECTING:
|
2006-07-20 10:09:32 +00:00
|
|
|
case IKE_ESTABLISHED:
|
2007-02-28 14:04:36 +00:00
|
|
|
default:
|
2006-07-20 10:09:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-09-25 06:10:28 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/* install kernel policies */
|
2007-04-10 06:01:03 +00:00
|
|
|
child_sa = child_sa_create(this->my_host, this->other_host, this->my_id,
|
|
|
|
this->other_id, child_cfg, FALSE, 0);
|
2007-02-28 14:04:36 +00:00
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
my_ts = child_cfg->get_traffic_selectors(child_cfg, TRUE, NULL,
|
|
|
|
this->my_host);
|
|
|
|
other_ts = child_cfg->get_traffic_selectors(child_cfg, FALSE, NULL,
|
|
|
|
this->other_host);
|
2006-12-21 14:35:17 +00:00
|
|
|
status = child_sa->add_policies(child_sa, my_ts, other_ts,
|
2007-04-10 06:01:03 +00:00
|
|
|
child_cfg->get_mode(child_cfg));
|
2006-10-24 08:46:17 +00:00
|
|
|
my_ts->destroy_offset(my_ts, offsetof(traffic_selector_t, destroy));
|
|
|
|
other_ts->destroy_offset(other_ts, offsetof(traffic_selector_t, destroy));
|
2007-04-10 06:01:03 +00:00
|
|
|
if (status == SUCCESS)
|
|
|
|
{
|
|
|
|
this->child_sas->insert_last(this->child_sas, child_sa);
|
|
|
|
SIG(CHILD_ROUTE_SUCCESS, "CHILD_SA routed");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SIG(CHILD_ROUTE_FAILED, "routing CHILD_SA failed");
|
|
|
|
}
|
2006-07-21 13:31:53 +00:00
|
|
|
return status;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-21 13:31:53 +00:00
|
|
|
* Implementation of ike_sa_t.unroute.
|
2006-07-20 10:09:32 +00:00
|
|
|
*/
|
2007-05-16 08:32:15 +00:00
|
|
|
static status_t unroute(private_ike_sa_t *this, u_int32_t reqid)
|
2006-07-20 10:09:32 +00:00
|
|
|
{
|
2006-07-21 13:31:53 +00:00
|
|
|
iterator_t *iterator;
|
2007-04-10 06:01:03 +00:00
|
|
|
child_sa_t *child_sa;
|
2006-10-26 09:46:56 +00:00
|
|
|
bool found = FALSE;
|
2006-07-21 13:31:53 +00:00
|
|
|
|
2006-10-26 09:46:56 +00:00
|
|
|
SIG(CHILD_UNROUTE_START, "unrouting CHILD_SA");
|
|
|
|
|
2006-07-21 13:31:53 +00:00
|
|
|
/* find CHILD_SA in ROUTED state */
|
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
|
|
|
while (iterator->iterate(iterator, (void**)&child_sa))
|
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
if (child_sa->get_state(child_sa) == CHILD_ROUTED &&
|
2007-05-16 08:32:15 +00:00
|
|
|
child_sa->get_reqid(child_sa) == reqid)
|
2006-07-21 13:31:53 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
iterator->remove(iterator);
|
|
|
|
SIG(CHILD_UNROUTE_SUCCESS, "CHILD_SA unrouted");
|
|
|
|
child_sa->destroy(child_sa);
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
2006-07-21 13:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
2006-10-26 09:46:56 +00:00
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
SIG(CHILD_UNROUTE_FAILED, "CHILD_SA to unroute not found");
|
|
|
|
return FAILED;
|
|
|
|
}
|
2006-07-21 13:31:53 +00:00
|
|
|
/* if we are not established, and we have no more routed childs, remove whole SA */
|
|
|
|
if (this->state == IKE_CREATED &&
|
|
|
|
this->child_sas->get_count(this->child_sas) == 0)
|
|
|
|
{
|
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
2006-07-20 10:09:32 +00:00
|
|
|
}
|
|
|
|
|
2007-03-14 11:07:12 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.retransmit.
|
|
|
|
*/
|
|
|
|
static status_t retransmit(private_ike_sa_t *this, u_int32_t message_id)
|
|
|
|
{
|
|
|
|
this->time.outbound = time(NULL);
|
|
|
|
if (this->task_manager->retransmit(this->task_manager, message_id) != SUCCESS)
|
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
child_cfg_t *child_cfg;
|
2007-03-14 11:07:12 +00:00
|
|
|
child_sa_t* child_sa;
|
|
|
|
linked_list_t *to_route, *to_restart;
|
|
|
|
iterator_t *iterator;
|
|
|
|
|
|
|
|
/* send a proper signal to brief interested bus listeners */
|
|
|
|
switch (this->state)
|
|
|
|
{
|
|
|
|
case IKE_CONNECTING:
|
2007-03-20 08:16:16 +00:00
|
|
|
{
|
|
|
|
/* retry IKE_SA_INIT if we have multiple keyingtries */
|
2007-04-10 06:01:03 +00:00
|
|
|
u_int32_t tries = this->peer_cfg->get_keyingtries(this->peer_cfg);
|
2007-03-20 08:16:16 +00:00
|
|
|
this->keyingtry++;
|
|
|
|
if (tries == 0 || tries > this->keyingtry)
|
|
|
|
{
|
|
|
|
SIG(IKE_UP_FAILED, "peer not responding, trying again "
|
|
|
|
"(%d/%d) in background ", this->keyingtry + 1, tries);
|
|
|
|
reset(this);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
|
|
|
}
|
2007-03-14 11:07:12 +00:00
|
|
|
SIG(IKE_UP_FAILED, "establishing IKE_SA failed, peer not responding");
|
|
|
|
break;
|
2007-03-20 08:16:16 +00:00
|
|
|
}
|
2007-03-14 11:07:12 +00:00
|
|
|
case IKE_REKEYING:
|
|
|
|
SIG(IKE_REKEY_FAILED, "rekeying IKE_SA failed, peer not responding");
|
|
|
|
break;
|
|
|
|
case IKE_DELETING:
|
|
|
|
SIG(IKE_DOWN_FAILED, "proper IKE_SA delete failed, peer not responding");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* summarize how we have to handle each child */
|
|
|
|
to_route = linked_list_create();
|
|
|
|
to_restart = linked_list_create();
|
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
|
|
|
while (iterator->iterate(iterator, (void**)&child_sa))
|
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
child_cfg = child_sa->get_config(child_sa);
|
2007-03-14 11:07:12 +00:00
|
|
|
|
|
|
|
if (child_sa->get_state(child_sa) == CHILD_ROUTED)
|
|
|
|
{
|
|
|
|
/* reroute routed CHILD_SAs */
|
2007-04-10 06:01:03 +00:00
|
|
|
to_route->insert_last(to_route, child_cfg);
|
2007-03-14 11:07:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* use DPD action for established CHILD_SAs */
|
2007-04-10 06:01:03 +00:00
|
|
|
switch (this->peer_cfg->get_dpd_action(this->peer_cfg))
|
2007-03-14 11:07:12 +00:00
|
|
|
{
|
|
|
|
case DPD_ROUTE:
|
2007-04-10 06:01:03 +00:00
|
|
|
to_route->insert_last(to_route, child_cfg);
|
2007-03-14 11:07:12 +00:00
|
|
|
break;
|
|
|
|
case DPD_RESTART:
|
2007-04-10 06:01:03 +00:00
|
|
|
to_restart->insert_last(to_restart, child_cfg);
|
2007-03-14 11:07:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
|
|
|
|
|
|
|
/* create a new IKE_SA if we have to route or to restart */
|
|
|
|
if (to_route->get_count(to_route) || to_restart->get_count(to_restart))
|
|
|
|
{
|
|
|
|
private_ike_sa_t *new;
|
|
|
|
task_t *task;
|
|
|
|
|
2007-03-29 14:20:10 +00:00
|
|
|
new = (private_ike_sa_t*)charon->ike_sa_manager->checkout_new(
|
|
|
|
charon->ike_sa_manager, TRUE);
|
2007-03-14 11:07:12 +00:00
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
set_peer_cfg(new, this->peer_cfg);
|
|
|
|
/* use actual used host, not the wildcarded one in config */
|
2007-03-14 11:07:12 +00:00
|
|
|
new->other_host->destroy(new->other_host);
|
|
|
|
new->other_host = this->other_host->clone(this->other_host);
|
|
|
|
|
|
|
|
/* install routes */
|
2007-04-10 06:01:03 +00:00
|
|
|
while (to_route->remove_last(to_route, (void**)&child_cfg) == SUCCESS)
|
2007-03-14 11:07:12 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
route(new, child_cfg);
|
2007-03-14 11:07:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* restart children */
|
|
|
|
if (to_restart->get_count(to_restart))
|
|
|
|
{
|
|
|
|
task = (task_t*)ike_init_create(&new->public, TRUE, NULL);
|
|
|
|
new->task_manager->queue_task(new->task_manager, task);
|
|
|
|
task = (task_t*)ike_natd_create(&new->public, TRUE);
|
|
|
|
new->task_manager->queue_task(new->task_manager, task);
|
|
|
|
task = (task_t*)ike_cert_create(&new->public, TRUE);
|
|
|
|
new->task_manager->queue_task(new->task_manager, task);
|
2007-04-10 06:01:03 +00:00
|
|
|
task = (task_t*)ike_config_create(&new->public, TRUE);
|
2007-03-14 11:07:12 +00:00
|
|
|
new->task_manager->queue_task(new->task_manager, task);
|
|
|
|
task = (task_t*)ike_auth_create(&new->public, TRUE);
|
|
|
|
new->task_manager->queue_task(new->task_manager, task);
|
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
while (to_restart->remove_last(to_restart, (void**)&child_cfg) == SUCCESS)
|
2007-03-14 11:07:12 +00:00
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
task = (task_t*)child_create_create(&new->public, child_cfg);
|
2007-03-14 11:07:12 +00:00
|
|
|
new->task_manager->queue_task(new->task_manager, task);
|
|
|
|
}
|
|
|
|
new->task_manager->initiate(new->task_manager);
|
|
|
|
}
|
|
|
|
charon->ike_sa_manager->checkin(charon->ike_sa_manager, &new->public);
|
|
|
|
}
|
|
|
|
to_route->destroy(to_route);
|
|
|
|
to_restart->destroy(to_restart);
|
|
|
|
return DESTROY_ME;
|
|
|
|
}
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-06-23 14:02:30 +00:00
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Implementation of ike_sa_t.get_prf.
|
2006-06-23 14:02:30 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
static prf_t *get_prf(private_ike_sa_t *this)
|
2006-06-23 14:02:30 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
return this->prf;
|
2006-06-23 14:02:30 +00:00
|
|
|
}
|
|
|
|
|
2005-11-25 13:42:02 +00:00
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Implementation of ike_sa_t.get_prf.
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
static prf_t *get_child_prf(private_ike_sa_t *this)
|
2005-11-25 13:42:02 +00:00
|
|
|
{
|
2006-07-20 10:09:32 +00:00
|
|
|
return this->child_prf;
|
2005-11-25 13:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-04-19 12:37:48 +00:00
|
|
|
* Implementation of ike_sa_t.get_skp_bild
|
2005-11-25 13:42:02 +00:00
|
|
|
*/
|
2007-04-19 12:37:48 +00:00
|
|
|
static chunk_t get_skp_build(private_ike_sa_t *this)
|
2005-11-25 13:42:02 +00:00
|
|
|
{
|
2007-04-19 12:37:48 +00:00
|
|
|
return this->skp_build;
|
2005-11-25 13:42:02 +00:00
|
|
|
}
|
|
|
|
|
2005-12-07 09:53:33 +00:00
|
|
|
/**
|
2007-04-19 12:37:48 +00:00
|
|
|
* Implementation of ike_sa_t.get_skp_verify
|
2005-12-07 09:53:33 +00:00
|
|
|
*/
|
2007-04-19 12:37:48 +00:00
|
|
|
static chunk_t get_skp_verify(private_ike_sa_t *this)
|
2005-12-07 09:53:33 +00:00
|
|
|
{
|
2007-04-19 12:37:48 +00:00
|
|
|
return this->skp_verify;
|
2005-12-07 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
2005-12-02 11:38:56 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Implementation of ike_sa_t.get_id.
|
2005-12-02 14:07:36 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
static ike_sa_id_t* get_id(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
|
|
|
}
|
|
|
|
|
2005-12-02 19:26:01 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Implementation of ike_sa_t.get_my_id.
|
2005-12-02 19:26:01 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
static identification_t* get_my_id(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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Implementation of ike_sa_t.set_my_id.
|
2005-12-03 14:47:58 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
static void set_my_id(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
|
|
|
}
|
|
|
|
|
2006-02-16 09:55:07 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Implementation of ike_sa_t.get_other_id.
|
2006-02-16 09:55:07 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
static identification_t* get_other_id(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
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
/**
|
2006-07-20 10:09:32 +00:00
|
|
|
* Implementation of ike_sa_t.set_other_id.
|
2006-07-05 10:53:20 +00:00
|
|
|
*/
|
2006-07-20 10:09:32 +00:00
|
|
|
static void set_other_id(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
|
|
|
}
|
|
|
|
|
2007-05-17 17:55:29 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.get_other_ca.
|
|
|
|
*/
|
|
|
|
static ca_info_t* get_other_ca(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->other_ca;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.set_other_ca.
|
|
|
|
*/
|
|
|
|
static void set_other_ca(private_ike_sa_t *this, ca_info_t *other_ca)
|
|
|
|
{
|
|
|
|
this->other_ca = other_ca;
|
|
|
|
}
|
|
|
|
|
2007-04-10 15:02:57 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.set_virtual_ip
|
|
|
|
*/
|
|
|
|
static void set_virtual_ip(private_ike_sa_t *this, bool local, host_t *ip)
|
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "installing new virtual IP %H", ip);
|
|
|
|
if (this->my_virtual_ip)
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "removing old virtual IP %H", this->my_virtual_ip);
|
|
|
|
charon->kernel_interface->del_ip(charon->kernel_interface,
|
|
|
|
this->my_virtual_ip,
|
|
|
|
this->my_host);
|
|
|
|
this->my_virtual_ip->destroy(this->my_virtual_ip);
|
|
|
|
}
|
|
|
|
if (charon->kernel_interface->add_ip(charon->kernel_interface, ip,
|
|
|
|
this->my_host) == SUCCESS)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.get_virtual_ip
|
|
|
|
*/
|
|
|
|
static host_t* get_virtual_ip(private_ike_sa_t *this, bool local)
|
|
|
|
{
|
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
return this->my_virtual_ip;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->other_virtual_ip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-07 13:26:23 +00:00
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Implementation of ike_sa_t.derive_keys.
|
2006-06-07 13:26:23 +00:00
|
|
|
*/
|
2006-07-27 12:18:40 +00:00
|
|
|
static status_t derive_keys(private_ike_sa_t *this,
|
2007-02-28 14:04:36 +00:00
|
|
|
proposal_t *proposal, chunk_t secret,
|
2006-07-27 12:18:40 +00:00
|
|
|
chunk_t nonce_i, chunk_t nonce_r,
|
2006-08-23 07:30:43 +00:00
|
|
|
bool initiator, prf_t *child_prf, prf_t *old_prf)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2006-07-05 10:53:20 +00:00
|
|
|
prf_plus_t *prf_plus;
|
2007-02-28 14:04:36 +00:00
|
|
|
chunk_t skeyseed, key, nonces, prf_plus_seed;
|
2006-07-05 10:53:20 +00:00
|
|
|
algorithm_t *algo;
|
|
|
|
size_t key_size;
|
|
|
|
crypter_t *crypter_i, *crypter_r;
|
|
|
|
signer_t *signer_i, *signer_r;
|
2006-07-27 12:18:40 +00:00
|
|
|
u_int8_t spi_i_buf[sizeof(u_int64_t)], spi_r_buf[sizeof(u_int64_t)];
|
|
|
|
chunk_t spi_i = chunk_from_buf(spi_i_buf);
|
|
|
|
chunk_t spi_r = chunk_from_buf(spi_r_buf);
|
2006-06-07 13:26:23 +00:00
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
/* Create SAs general purpose PRF first, we may use it here */
|
2006-07-05 10:53:20 +00:00
|
|
|
if (!proposal->get_algorithm(proposal, PSEUDO_RANDOM_FUNCTION, &algo))
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "key derivation failed: no PSEUDO_RANDOM_FUNCTION");;
|
2006-07-05 10:53:20 +00:00
|
|
|
return FAILED;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
this->prf = prf_create(algo->algorithm);
|
|
|
|
if (this->prf == NULL)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "key derivation failed: PSEUDO_RANDOM_FUNCTION "
|
2006-10-18 11:46:13 +00:00
|
|
|
"%N not supported!", pseudo_random_function_names, algo->algorithm);
|
2006-07-05 10:53:20 +00:00
|
|
|
return FAILED;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "shared Diffie Hellman secret %B", &secret);
|
2006-07-27 12:18:40 +00:00
|
|
|
nonces = chunk_cat("cc", nonce_i, nonce_r);
|
|
|
|
*((u_int64_t*)spi_i.ptr) = this->ike_sa_id->get_initiator_spi(this->ike_sa_id);
|
|
|
|
*((u_int64_t*)spi_r.ptr) = this->ike_sa_id->get_responder_spi(this->ike_sa_id);
|
|
|
|
prf_plus_seed = chunk_cat("ccc", nonces, spi_i, spi_r);
|
2006-06-07 13:26:23 +00:00
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
/* KEYMAT = prf+ (SKEYSEED, Ni | Nr | SPIi | SPIr)
|
|
|
|
*
|
2006-10-26 09:46:56 +00:00
|
|
|
* if we are rekeying, SKEYSEED is built on another way
|
2006-07-27 12:18:40 +00:00
|
|
|
*/
|
2006-08-23 07:30:43 +00:00
|
|
|
if (child_prf == NULL) /* not rekeying */
|
2006-10-18 11:46:13 +00:00
|
|
|
{
|
2006-07-27 12:18:40 +00:00
|
|
|
/* SKEYSEED = prf(Ni | Nr, g^ir) */
|
|
|
|
this->prf->set_key(this->prf, nonces);
|
|
|
|
this->prf->allocate_bytes(this->prf, secret, &skeyseed);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "SKEYSEED %B", &skeyseed);
|
2006-07-27 12:18:40 +00:00
|
|
|
this->prf->set_key(this->prf, skeyseed);
|
|
|
|
chunk_free(&skeyseed);
|
|
|
|
chunk_free(&secret);
|
|
|
|
prf_plus = prf_plus_create(this->prf, prf_plus_seed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-23 07:30:43 +00:00
|
|
|
/* SKEYSEED = prf(SK_d (old), [g^ir (new)] | Ni | Nr)
|
|
|
|
* use OLD SAs PRF functions for both prf_plus and prf */
|
2006-07-27 12:18:40 +00:00
|
|
|
secret = chunk_cat("mc", secret, nonces);
|
2006-08-23 07:30:43 +00:00
|
|
|
child_prf->allocate_bytes(child_prf, secret, &skeyseed);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "SKEYSEED %B", &skeyseed);
|
2006-08-23 07:30:43 +00:00
|
|
|
old_prf->set_key(old_prf, skeyseed);
|
2006-07-27 12:18:40 +00:00
|
|
|
chunk_free(&skeyseed);
|
|
|
|
chunk_free(&secret);
|
2006-08-23 07:30:43 +00:00
|
|
|
prf_plus = prf_plus_create(old_prf, prf_plus_seed);
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
chunk_free(&nonces);
|
2006-07-27 12:18:40 +00:00
|
|
|
chunk_free(&prf_plus_seed);
|
|
|
|
|
|
|
|
/* KEYMAT = SK_d | SK_ai | SK_ar | SK_ei | SK_er | SK_pi | SK_pr */
|
2006-07-05 10:53:20 +00:00
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
/* SK_d is used for generating CHILD_SA key mat => child_prf */
|
|
|
|
proposal->get_algorithm(proposal, PSEUDO_RANDOM_FUNCTION, &algo);
|
2006-07-05 10:53:20 +00:00
|
|
|
this->child_prf = prf_create(algo->algorithm);
|
|
|
|
key_size = this->child_prf->get_key_size(this->child_prf);
|
|
|
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "Sk_d secret %B", &key);
|
2006-07-05 10:53:20 +00:00
|
|
|
this->child_prf->set_key(this->child_prf, key);
|
|
|
|
chunk_free(&key);
|
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
/* SK_ai/SK_ar used for integrity protection => signer_in/signer_out */
|
2006-07-05 10:53:20 +00:00
|
|
|
if (!proposal->get_algorithm(proposal, INTEGRITY_ALGORITHM, &algo))
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "key derivation failed: no INTEGRITY_ALGORITHM");
|
2006-06-07 13:26:23 +00:00
|
|
|
return FAILED;
|
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
signer_i = signer_create(algo->algorithm);
|
|
|
|
signer_r = signer_create(algo->algorithm);
|
|
|
|
if (signer_i == NULL || signer_r == NULL)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "key derivation failed: INTEGRITY_ALGORITHM "
|
2006-10-18 11:46:13 +00:00
|
|
|
"%N not supported!", integrity_algorithm_names ,algo->algorithm);
|
2006-07-05 10:53:20 +00:00
|
|
|
return FAILED;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
key_size = signer_i->get_key_size(signer_i);
|
|
|
|
|
|
|
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "Sk_ai secret %B", &key);
|
2006-07-05 10:53:20 +00:00
|
|
|
signer_i->set_key(signer_i, key);
|
|
|
|
chunk_free(&key);
|
2006-07-27 12:18:40 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "Sk_ar secret %B", &key);
|
2006-07-05 10:53:20 +00:00
|
|
|
signer_r->set_key(signer_r, key);
|
|
|
|
chunk_free(&key);
|
2006-06-22 06:36:28 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
if (initiator)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2006-07-12 14:08:13 +00:00
|
|
|
this->signer_in = signer_r;
|
|
|
|
this->signer_out = signer_i;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-12 14:08:13 +00:00
|
|
|
this->signer_in = signer_i;
|
|
|
|
this->signer_out = signer_r;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
/* SK_ei/SK_er used for encryption => crypter_in/crypter_out */
|
2006-07-05 10:53:20 +00:00
|
|
|
if (!proposal->get_algorithm(proposal, ENCRYPTION_ALGORITHM, &algo))
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "key derivation failed: no ENCRYPTION_ALGORITHM");
|
2006-07-05 10:53:20 +00:00
|
|
|
return FAILED;
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
crypter_i = crypter_create(algo->algorithm, algo->key_size / 8);
|
|
|
|
crypter_r = crypter_create(algo->algorithm, algo->key_size / 8);
|
|
|
|
if (crypter_i == NULL || crypter_r == NULL)
|
|
|
|
{
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG1(DBG_IKE, "key derivation failed: ENCRYPTION_ALGORITHM "
|
2006-10-18 11:46:13 +00:00
|
|
|
"%N (key size %d) not supported!",
|
|
|
|
encryption_algorithm_names, algo->algorithm, algo->key_size);
|
2006-07-05 10:53:20 +00:00
|
|
|
return FAILED;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
key_size = crypter_i->get_key_size(crypter_i);
|
2006-06-22 06:36:28 +00:00
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "Sk_ei secret %B", &key);
|
2006-07-05 10:53:20 +00:00
|
|
|
crypter_i->set_key(crypter_i, key);
|
|
|
|
chunk_free(&key);
|
|
|
|
|
|
|
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "Sk_er secret %B", &key);
|
2006-07-05 10:53:20 +00:00
|
|
|
crypter_r->set_key(crypter_r, key);
|
|
|
|
chunk_free(&key);
|
|
|
|
|
|
|
|
if (initiator)
|
2006-06-22 06:36:28 +00:00
|
|
|
{
|
2006-07-12 14:08:13 +00:00
|
|
|
this->crypter_in = crypter_r;
|
|
|
|
this->crypter_out = crypter_i;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
else
|
|
|
|
{
|
2006-07-12 14:08:13 +00:00
|
|
|
this->crypter_in = crypter_i;
|
|
|
|
this->crypter_out = crypter_r;
|
2006-07-05 10:53:20 +00:00
|
|
|
}
|
|
|
|
|
2007-04-19 12:37:48 +00:00
|
|
|
/* SK_pi/SK_pr used for authentication => stored for later */
|
|
|
|
key_size = this->prf->get_key_size(this->prf);
|
2006-07-05 10:53:20 +00:00
|
|
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "Sk_pi secret %B", &key);
|
2007-04-19 12:37:48 +00:00
|
|
|
if (initiator)
|
|
|
|
{
|
|
|
|
this->skp_build = key;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->skp_verify = key;
|
|
|
|
}
|
2006-07-05 10:53:20 +00:00
|
|
|
prf_plus->allocate_bytes(prf_plus, key_size, &key);
|
2006-10-26 09:46:56 +00:00
|
|
|
DBG4(DBG_IKE, "Sk_pr secret %B", &key);
|
2006-10-30 14:07:05 +00:00
|
|
|
if (initiator)
|
|
|
|
{
|
2007-04-19 12:37:48 +00:00
|
|
|
this->skp_verify = key;
|
2006-10-30 14:07:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-04-19 12:37:48 +00:00
|
|
|
this->skp_build = key;
|
2006-10-30 14:07:05 +00:00
|
|
|
}
|
|
|
|
|
2006-07-05 10:53:20 +00:00
|
|
|
/* all done, prf_plus not needed anymore */
|
|
|
|
prf_plus->destroy(prf_plus);
|
|
|
|
|
|
|
|
return SUCCESS;
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
|
|
|
|
2006-05-31 14:23:15 +00:00
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Implementation of ike_sa_t.add_child_sa.
|
2006-05-31 14:23:15 +00:00
|
|
|
*/
|
2006-07-05 10:53:20 +00:00
|
|
|
static void add_child_sa(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
|
|
|
}
|
|
|
|
|
2006-06-09 15:12:43 +00:00
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Implementation of ike_sa_t.get_child_sa.
|
2006-06-09 15:12:43 +00:00
|
|
|
*/
|
2006-07-07 07:04:07 +00:00
|
|
|
static child_sa_t* get_child_sa(private_ike_sa_t *this, protocol_id_t protocol,
|
|
|
|
u_int32_t spi, bool inbound)
|
2006-06-09 15:12:43 +00:00
|
|
|
{
|
|
|
|
iterator_t *iterator;
|
|
|
|
child_sa_t *current, *found = NULL;
|
|
|
|
|
2006-07-21 13:31:53 +00:00
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
2006-10-24 14:20:45 +00:00
|
|
|
while (iterator->iterate(iterator, (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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
|
|
|
return found;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-23 07:30:43 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.create_child_sa_iterator.
|
|
|
|
*/
|
|
|
|
static iterator_t* create_child_sa_iterator(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
return this->child_sas->create_iterator(this->child_sas, TRUE);
|
|
|
|
}
|
|
|
|
|
2006-06-07 13:26:23 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.rekey_child_sa.
|
|
|
|
*/
|
2006-07-07 07:04:07 +00:00
|
|
|
static status_t rekey_child_sa(private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
|
|
|
child_sa_t *child_sa;
|
2007-02-28 14:04:36 +00:00
|
|
|
child_rekey_t *child_rekey;
|
2006-06-07 13:26:23 +00:00
|
|
|
|
2006-07-07 07:04:07 +00:00
|
|
|
child_sa = get_child_sa(this, protocol, spi, TRUE);
|
2007-02-28 14:04:36 +00:00
|
|
|
if (child_sa)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
child_rekey = child_rekey_create(&this->public, child_sa);
|
|
|
|
this->task_manager->queue_task(this->task_manager, &child_rekey->task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
return FAILED;
|
2006-07-07 07:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.delete_child_sa.
|
|
|
|
*/
|
|
|
|
static status_t delete_child_sa(private_ike_sa_t *this, protocol_id_t protocol, u_int32_t spi)
|
|
|
|
{
|
|
|
|
child_sa_t *child_sa;
|
2007-02-28 14:04:36 +00:00
|
|
|
child_delete_t *child_delete;
|
2006-07-07 07:04:07 +00:00
|
|
|
|
|
|
|
child_sa = get_child_sa(this, protocol, spi, TRUE);
|
2007-02-28 14:04:36 +00:00
|
|
|
if (child_sa)
|
2006-06-07 13:26:23 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
child_delete = child_delete_create(&this->public, child_sa);
|
|
|
|
this->task_manager->queue_task(this->task_manager, &child_delete->task);
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
return FAILED;
|
2006-07-07 07:04:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Implementation of ike_sa_t.destroy_child_sa.
|
2006-07-07 07:04:07 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static status_t destroy_child_sa(private_ike_sa_t *this, protocol_id_t protocol,
|
|
|
|
u_int32_t spi)
|
2006-07-07 07:04:07 +00:00
|
|
|
{
|
|
|
|
iterator_t *iterator;
|
|
|
|
child_sa_t *child_sa;
|
|
|
|
status_t status = NOT_FOUND;
|
2006-06-07 13:26:23 +00:00
|
|
|
|
2006-07-07 07:04:07 +00:00
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
|
|
|
while (iterator->iterate(iterator, (void**)&child_sa))
|
|
|
|
{
|
|
|
|
if (child_sa->get_protocol(child_sa) == protocol &&
|
|
|
|
child_sa->get_spi(child_sa, TRUE) == spi)
|
|
|
|
{
|
|
|
|
child_sa->destroy(child_sa);
|
|
|
|
iterator->remove(iterator);
|
|
|
|
status = SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
2006-07-07 07:04:07 +00:00
|
|
|
iterator->destroy(iterator);
|
|
|
|
return status;
|
2006-06-07 13:26:23 +00:00
|
|
|
}
|
|
|
|
|
2006-12-19 07:30:07 +00:00
|
|
|
/**
|
|
|
|
* Implementation of public_ike_sa_t.delete.
|
|
|
|
*/
|
|
|
|
static status_t delete_(private_ike_sa_t *this)
|
|
|
|
{
|
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);
|
2006-12-19 07:30:07 +00:00
|
|
|
default:
|
2007-02-28 14:04:36 +00:00
|
|
|
DBG1(DBG_IKE, "destroying IKE_SA in state %N without notification",
|
|
|
|
ike_sa_state_names, this->state);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-04-26 12:28:02 +00:00
|
|
|
/**
|
2006-07-27 12:18:40 +00:00
|
|
|
* Implementation of ike_sa_t.rekey.
|
|
|
|
*/
|
|
|
|
static status_t rekey(private_ike_sa_t *this)
|
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
ike_rekey_t *ike_rekey;
|
2006-07-27 12:18:40 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
ike_rekey = ike_rekey_create(&this->public, TRUE);
|
2006-07-27 12:18:40 +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
|
|
|
}
|
|
|
|
|
2006-12-19 07:30:07 +00:00
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* Implementation of ike_sa_t.reestablish
|
2006-12-19 07:30:07 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static void reestablish(private_ike_sa_t *this)
|
2006-12-19 07:30:07 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
private_ike_sa_t *other;
|
2006-12-19 07:30:07 +00:00
|
|
|
iterator_t *iterator;
|
2007-02-28 14:04:36 +00:00
|
|
|
child_sa_t *child_sa;
|
2007-04-10 06:01:03 +00:00
|
|
|
child_cfg_t *child_cfg;
|
2007-02-28 14:04:36 +00:00
|
|
|
task_t *task;
|
|
|
|
job_t *job;
|
2006-12-19 07:30:07 +00:00
|
|
|
|
2007-03-29 14:20:10 +00:00
|
|
|
other = (private_ike_sa_t*)charon->ike_sa_manager->checkout_new(
|
|
|
|
charon->ike_sa_manager, TRUE);
|
2006-12-19 07:30:07 +00:00
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
set_peer_cfg(other, this->peer_cfg);
|
2007-02-28 14:17:31 +00:00
|
|
|
other->other_host->destroy(other->other_host);
|
|
|
|
other->other_host = this->other_host->clone(this->other_host);
|
2007-04-10 15:02:57 +00:00
|
|
|
if (this->my_virtual_ip)
|
|
|
|
{
|
|
|
|
/* if we already have a virtual IP, we reuse it */
|
|
|
|
set_virtual_ip(other, TRUE, this->my_virtual_ip);
|
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
|
|
|
|
if (this->state == IKE_ESTABLISHED)
|
2006-12-19 07:30:07 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
task = (task_t*)ike_init_create(&other->public, TRUE, NULL);
|
|
|
|
other->task_manager->queue_task(other->task_manager, task);
|
|
|
|
task = (task_t*)ike_natd_create(&other->public, TRUE);
|
|
|
|
other->task_manager->queue_task(other->task_manager, task);
|
|
|
|
task = (task_t*)ike_cert_create(&other->public, TRUE);
|
|
|
|
other->task_manager->queue_task(other->task_manager, task);
|
2007-04-10 06:01:03 +00:00
|
|
|
task = (task_t*)ike_config_create(&other->public, TRUE);
|
2007-02-28 14:04:36 +00:00
|
|
|
other->task_manager->queue_task(other->task_manager, task);
|
|
|
|
task = (task_t*)ike_auth_create(&other->public, TRUE);
|
|
|
|
other->task_manager->queue_task(other->task_manager, task);
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
other->task_manager->adopt_tasks(other->task_manager, this->task_manager);
|
|
|
|
|
|
|
|
/* Create task for established children, adopt routed children directly */
|
2006-12-19 07:30:07 +00:00
|
|
|
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
|
2007-02-28 14:04:36 +00:00
|
|
|
while(iterator->iterate(iterator, (void**)&child_sa))
|
2006-12-19 07:30:07 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
switch (child_sa->get_state(child_sa))
|
2006-12-19 07:30:07 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
case CHILD_ROUTED:
|
|
|
|
{
|
|
|
|
iterator->remove(iterator);
|
|
|
|
other->child_sas->insert_first(other->child_sas, child_sa);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2007-04-10 06:01:03 +00:00
|
|
|
child_cfg = child_sa->get_config(child_sa);
|
|
|
|
task = (task_t*)child_create_create(&other->public, child_cfg);
|
2007-02-28 14:04:36 +00:00
|
|
|
other->task_manager->queue_task(other->task_manager, task);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
other->task_manager->initiate(other->task_manager);
|
|
|
|
|
|
|
|
charon->ike_sa_manager->checkin(charon->ike_sa_manager, &other->public);
|
|
|
|
|
|
|
|
job = (job_t*)delete_ike_sa_job_create(this->ike_sa_id, TRUE);
|
2007-06-11 10:57:19 +00:00
|
|
|
charon->processor->queue_job(charon->processor, job);
|
2006-12-19 07:30:07 +00:00
|
|
|
}
|
|
|
|
|
2006-08-23 07:30:43 +00:00
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* Implementation of ike_sa_t.inherit.
|
2006-08-23 07:30:43 +00:00
|
|
|
*/
|
2007-03-27 13:32:12 +00:00
|
|
|
static status_t inherit(private_ike_sa_t *this, private_ike_sa_t *other)
|
2006-08-23 07:30:43 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
child_sa_t *child_sa;
|
|
|
|
host_t *ip;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ... and DNS servers */
|
|
|
|
while (other->dns_servers->remove_last(other->dns_servers,
|
|
|
|
(void**)&ip) == SUCCESS)
|
|
|
|
{
|
|
|
|
this->dns_servers->insert_first(this->dns_servers, ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adopt all children */
|
|
|
|
while (other->child_sas->remove_last(other->child_sas,
|
|
|
|
(void**)&child_sa) == SUCCESS)
|
|
|
|
{
|
|
|
|
this->child_sas->insert_first(this->child_sas, (void*)child_sa);
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
/* we have to initate here, there may be new tasks to handle */
|
|
|
|
return this->task_manager->initiate(this->task_manager);
|
2006-08-23 07:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* Implementation of ike_sa_t.is_natt_enabled.
|
2006-08-23 07:30:43 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static bool is_natt_enabled(private_ike_sa_t *this)
|
2006-08-23 07:30:43 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
return this->nat_here || this->nat_there;
|
2006-08-23 07:30:43 +00:00
|
|
|
}
|
|
|
|
|
2006-07-27 12:18:40 +00:00
|
|
|
/**
|
2007-02-28 14:04:36 +00:00
|
|
|
* Implementation of ike_sa_t.enable_natt.
|
2006-07-27 12:18:40 +00:00
|
|
|
*/
|
2007-02-28 14:04:36 +00:00
|
|
|
static void enable_natt(private_ike_sa_t *this, bool local)
|
2006-07-27 12:18:40 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
if (local)
|
2006-07-27 12:18:40 +00:00
|
|
|
{
|
2007-02-28 14:04:36 +00:00
|
|
|
DBG1(DBG_IKE, "local host is behind NAT, scheduling keep alives");
|
|
|
|
this->nat_here = TRUE;
|
|
|
|
send_keepalive(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG1(DBG_IKE, "remote host is behind NAT");
|
|
|
|
this->nat_there = TRUE;
|
2006-07-27 12:18:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.remove_dns_server
|
|
|
|
*/
|
|
|
|
static void remove_dns_servers(private_ike_sa_t *this)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
struct stat stats;
|
|
|
|
chunk_t contents, line, orig_line, token;
|
|
|
|
char string[INET6_ADDRSTRLEN];
|
|
|
|
host_t *ip;
|
|
|
|
iterator_t *iterator;
|
|
|
|
|
|
|
|
if (this->dns_servers->get_count(this->dns_servers) == 0)
|
|
|
|
{
|
|
|
|
/* don't touch anything if we have no nameservers installed */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = fopen(RESOLV_CONF, "r");
|
|
|
|
if (file == NULL || stat(RESOLV_CONF, &stats) != 0)
|
|
|
|
{
|
2007-04-12 08:52:36 +00:00
|
|
|
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %s",
|
|
|
|
RESOLV_CONF, strerror(errno));
|
2007-02-28 14:04:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
contents = chunk_alloca((size_t)stats.st_size);
|
|
|
|
|
|
|
|
if (fread(contents.ptr, 1, contents.len, file) != contents.len)
|
|
|
|
{
|
2007-04-12 08:52:36 +00:00
|
|
|
DBG1(DBG_IKE, "unable to read DNS configuration file: %s", strerror(errno));
|
2007-02-28 14:04:36 +00:00
|
|
|
fclose(file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
file = fopen(RESOLV_CONF, "w");
|
|
|
|
if (file == NULL)
|
|
|
|
{
|
2007-04-12 08:52:36 +00:00
|
|
|
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %s",
|
|
|
|
RESOLV_CONF, strerror(errno));
|
2007-02-28 14:04:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator = this->dns_servers->create_iterator(this->dns_servers, TRUE);
|
|
|
|
while (fetchline(&contents, &line))
|
|
|
|
{
|
|
|
|
bool found = FALSE;
|
|
|
|
orig_line = line;
|
|
|
|
if (extract_token(&token, ' ', &line) &&
|
|
|
|
strncasecmp(token.ptr, "nameserver", token.len) == 0)
|
|
|
|
{
|
|
|
|
if (!extract_token(&token, ' ', &line))
|
|
|
|
{
|
|
|
|
token = line;
|
|
|
|
}
|
|
|
|
iterator->reset(iterator);
|
|
|
|
while (iterator->iterate(iterator, (void**)&ip))
|
|
|
|
{
|
|
|
|
snprintf(string, sizeof(string), "%H", ip);
|
|
|
|
if (strlen(string) == token.len &&
|
|
|
|
strncmp(token.ptr, string, token.len) == 0)
|
|
|
|
{
|
|
|
|
iterator->remove(iterator);
|
|
|
|
ip->destroy(ip);
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
/* write line untouched back to file */
|
|
|
|
fwrite(orig_line.ptr, orig_line.len, 1, file);
|
|
|
|
fprintf(file, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iterator->destroy(iterator);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.add_dns_server
|
|
|
|
*/
|
|
|
|
static void add_dns_server(private_ike_sa_t *this, host_t *dns)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
struct stat stats;
|
|
|
|
chunk_t contents;
|
|
|
|
|
|
|
|
DBG1(DBG_IKE, "installing DNS server %H", dns);
|
|
|
|
|
|
|
|
file = fopen(RESOLV_CONF, "a+");
|
|
|
|
if (file == NULL || stat(RESOLV_CONF, &stats) != 0)
|
|
|
|
{
|
2007-04-12 08:52:36 +00:00
|
|
|
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %s",
|
|
|
|
RESOLV_CONF, strerror(errno));
|
2007-02-28 14:04:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
contents = chunk_alloca(stats.st_size);
|
|
|
|
|
|
|
|
if (fread(contents.ptr, 1, contents.len, file) != contents.len)
|
|
|
|
{
|
2007-04-12 08:52:36 +00:00
|
|
|
DBG1(DBG_IKE, "unable to read DNS configuration file: %s", strerror(errno));
|
2007-02-28 14:04:36 +00:00
|
|
|
fclose(file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
file = fopen(RESOLV_CONF, "w");
|
|
|
|
if (file == NULL)
|
|
|
|
{
|
2007-04-12 08:52:36 +00:00
|
|
|
DBG1(DBG_IKE, "unable to open DNS configuration file %s: %s",
|
|
|
|
RESOLV_CONF, strerror(errno));
|
2007-02-28 14:04:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fprintf(file, "nameserver %H # added by strongSwan, assigned by %D\n",
|
|
|
|
dns, this->other_id) < 0)
|
|
|
|
{
|
2007-04-12 08:52:36 +00:00
|
|
|
DBG1(DBG_IKE, "unable to write DNS configuration: %s", strerror(errno));
|
2006-06-23 14:02:30 +00:00
|
|
|
}
|
2007-02-28 14:04:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
this->dns_servers->insert_last(this->dns_servers, dns->clone(dns));
|
|
|
|
}
|
|
|
|
fwrite(contents.ptr, contents.len, 1, file);
|
|
|
|
|
|
|
|
fclose(file);
|
2006-06-22 06:36:28 +00:00
|
|
|
}
|
|
|
|
|
2006-10-18 11:46:13 +00:00
|
|
|
/**
|
|
|
|
* Implementation of ike_sa_t.destroy.
|
|
|
|
*/
|
|
|
|
static void destroy(private_ike_sa_t *this)
|
|
|
|
{
|
2006-10-24 08:46:17 +00:00
|
|
|
this->child_sas->destroy_offset(this->child_sas, offsetof(child_sa_t, destroy));
|
2006-07-20 10:09:32 +00:00
|
|
|
|
|
|
|
DESTROY_IF(this->crypter_in);
|
|
|
|
DESTROY_IF(this->crypter_out);
|
|
|
|
DESTROY_IF(this->signer_in);
|
|
|
|
DESTROY_IF(this->signer_out);
|
|
|
|
DESTROY_IF(this->prf);
|
|
|
|
DESTROY_IF(this->child_prf);
|
2007-04-19 12:37:48 +00:00
|
|
|
chunk_free(&this->skp_verify);
|
|
|
|
chunk_free(&this->skp_build);
|
2006-07-20 10:09:32 +00:00
|
|
|
|
2007-02-28 14:04:36 +00:00
|
|
|
if (this->my_virtual_ip)
|
|
|
|
{
|
|
|
|
charon->kernel_interface->del_ip(charon->kernel_interface,
|
2007-03-02 17:08:38 +00:00
|
|
|
this->my_virtual_ip, this->my_host);
|
2007-02-28 14:04:36 +00:00
|
|
|
this->my_virtual_ip->destroy(this->my_virtual_ip);
|
|
|
|
}
|
|
|
|
DESTROY_IF(this->other_virtual_ip);
|
|
|
|
|
|
|
|
remove_dns_servers(this);
|
|
|
|
this->dns_servers->destroy_offset(this->dns_servers, offsetof(host_t, destroy));
|
|
|
|
|
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);
|
|
|
|
|
2007-04-10 06:01:03 +00:00
|
|
|
DESTROY_IF(this->ike_cfg);
|
|
|
|
DESTROY_IF(this->peer_cfg);
|
2007-02-28 14:04:36 +00:00
|
|
|
|
2006-03-20 15:43:26 +00:00
|
|
|
this->ike_sa_id->destroy(this->ike_sa_id);
|
2007-02-28 14:04:36 +00:00
|
|
|
this->task_manager->destroy(this->task_manager);
|
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)
|
|
|
|
{
|
2006-04-10 08:07:38 +00:00
|
|
|
private_ike_sa_t *this = malloc_thing(private_ike_sa_t);
|
2007-02-28 14:04:36 +00:00
|
|
|
static u_int32_t unique_id = 0;
|
2006-06-07 13:26:23 +00:00
|
|
|
|
2005-11-08 13:33:28 +00:00
|
|
|
/* Public functions */
|
2007-05-17 17:55:29 +00:00
|
|
|
this->public.get_state = (ike_sa_state_t (*)(ike_sa_t*)) get_state;
|
|
|
|
this->public.set_state = (void (*)(ike_sa_t*,ike_sa_state_t)) set_state;
|
|
|
|
this->public.get_stats = (void (*)(ike_sa_t*,u_int32_t*))get_stats;
|
|
|
|
this->public.get_name = (char* (*)(ike_sa_t*))get_name;
|
|
|
|
this->public.process_message = (status_t (*)(ike_sa_t*, message_t*)) process_message;
|
|
|
|
this->public.initiate = (status_t (*)(ike_sa_t*,child_cfg_t*)) initiate;
|
|
|
|
this->public.route = (status_t (*)(ike_sa_t*,child_cfg_t*)) route;
|
|
|
|
this->public.unroute = (status_t (*)(ike_sa_t*,u_int32_t)) unroute;
|
|
|
|
this->public.acquire = (status_t (*)(ike_sa_t*,u_int32_t)) acquire;
|
|
|
|
this->public.get_ike_cfg = (ike_cfg_t* (*)(ike_sa_t*))get_ike_cfg;
|
|
|
|
this->public.set_ike_cfg = (void (*)(ike_sa_t*,ike_cfg_t*))set_ike_cfg;
|
|
|
|
this->public.get_peer_cfg = (peer_cfg_t* (*)(ike_sa_t*))get_peer_cfg;
|
|
|
|
this->public.set_peer_cfg = (void (*)(ike_sa_t*,peer_cfg_t*))set_peer_cfg;
|
|
|
|
this->public.get_id = (ike_sa_id_t* (*)(ike_sa_t*)) get_id;
|
|
|
|
this->public.get_my_host = (host_t* (*)(ike_sa_t*)) get_my_host;
|
|
|
|
this->public.set_my_host = (void (*)(ike_sa_t*,host_t*)) set_my_host;
|
|
|
|
this->public.get_other_host = (host_t* (*)(ike_sa_t*)) get_other_host;
|
|
|
|
this->public.set_other_host = (void (*)(ike_sa_t*,host_t*)) set_other_host;
|
|
|
|
this->public.get_my_id = (identification_t* (*)(ike_sa_t*)) get_my_id;
|
|
|
|
this->public.set_my_id = (void (*)(ike_sa_t*,identification_t*)) set_my_id;
|
|
|
|
this->public.get_other_id = (identification_t* (*)(ike_sa_t*)) get_other_id;
|
|
|
|
this->public.set_other_id = (void (*)(ike_sa_t*,identification_t*)) set_other_id;
|
|
|
|
this->public.get_other_ca = (ca_info_t* (*)(ike_sa_t*)) get_other_ca;
|
|
|
|
this->public.set_other_ca = (void (*)(ike_sa_t*,ca_info_t*)) set_other_ca;
|
|
|
|
this->public.retransmit = (status_t (*)(ike_sa_t *, u_int32_t)) retransmit;
|
|
|
|
this->public.delete = (status_t (*)(ike_sa_t*))delete_;
|
|
|
|
this->public.destroy = (void (*)(ike_sa_t*))destroy;
|
2006-07-05 10:53:20 +00:00
|
|
|
this->public.send_dpd = (status_t (*)(ike_sa_t*)) send_dpd;
|
|
|
|
this->public.send_keepalive = (void (*)(ike_sa_t*)) send_keepalive;
|
2007-05-17 17:55:29 +00:00
|
|
|
this->public.get_prf = (prf_t* (*)(ike_sa_t*)) get_prf;
|
|
|
|
this->public.get_child_prf = (prf_t* (*)(ike_sa_t *)) get_child_prf;
|
|
|
|
this->public.get_skp_verify = (chunk_t (*)(ike_sa_t *)) get_skp_verify;
|
|
|
|
this->public.get_skp_build = (chunk_t (*)(ike_sa_t *)) get_skp_build;
|
|
|
|
this->public.derive_keys = (status_t (*)(ike_sa_t *,proposal_t*,chunk_t,chunk_t,chunk_t,bool,prf_t*,prf_t*)) derive_keys;
|
|
|
|
this->public.add_child_sa = (void (*)(ike_sa_t*,child_sa_t*)) add_child_sa;
|
2006-07-07 07:04:07 +00:00
|
|
|
this->public.get_child_sa = (child_sa_t* (*)(ike_sa_t*,protocol_id_t,u_int32_t,bool)) get_child_sa;
|
2006-08-23 07:30:43 +00:00
|
|
|
this->public.create_child_sa_iterator = (iterator_t* (*)(ike_sa_t*)) create_child_sa_iterator;
|
2007-05-17 17:55:29 +00:00
|
|
|
this->public.rekey_child_sa = (status_t (*)(ike_sa_t*,protocol_id_t,u_int32_t)) rekey_child_sa;
|
|
|
|
this->public.delete_child_sa = (status_t (*)(ike_sa_t*,protocol_id_t,u_int32_t)) delete_child_sa;
|
2006-07-07 07:04:07 +00:00
|
|
|
this->public.destroy_child_sa = (status_t (*)(ike_sa_t*,protocol_id_t,u_int32_t))destroy_child_sa;
|
2007-05-17 17:55:29 +00:00
|
|
|
this->public.enable_natt = (void (*)(ike_sa_t*, bool)) enable_natt;
|
|
|
|
this->public.is_natt_enabled = (bool (*)(ike_sa_t*)) is_natt_enabled;
|
|
|
|
this->public.rekey = (status_t (*)(ike_sa_t*))rekey;
|
|
|
|
this->public.reestablish = (void (*)(ike_sa_t*))reestablish;
|
|
|
|
this->public.inherit = (status_t (*)(ike_sa_t*,ike_sa_t*))inherit;
|
|
|
|
this->public.generate_message = (status_t (*)(ike_sa_t*,message_t*,packet_t**))generate_message;
|
|
|
|
this->public.reset = (void (*)(ike_sa_t*))reset;
|
|
|
|
this->public.get_unique_id = (u_int32_t (*)(ike_sa_t*))get_unique_id;
|
|
|
|
this->public.set_virtual_ip = (void (*)(ike_sa_t*,bool,host_t*))set_virtual_ip;
|
|
|
|
this->public.get_virtual_ip = (host_t* (*)(ike_sa_t*,bool))get_virtual_ip;
|
|
|
|
this->public.add_dns_server = (void (*)(ike_sa_t*,host_t*))add_dns_server;
|
2006-07-05 10:53:20 +00:00
|
|
|
|
2005-11-08 13:33:28 +00:00
|
|
|
/* initialize private fields */
|
2005-11-28 20:29:47 +00:00
|
|
|
this->ike_sa_id = ike_sa_id->clone(ike_sa_id);
|
2005-11-08 13:33:28 +00:00
|
|
|
this->child_sas = linked_list_create();
|
2007-02-28 14:04:36 +00:00
|
|
|
this->my_host = host_create_any(AF_INET);
|
|
|
|
this->other_host = host_create_any(AF_INET);
|
2006-10-31 12:27:59 +00:00
|
|
|
this->my_id = identification_create_from_encoding(ID_ANY, chunk_empty);
|
|
|
|
this->other_id = identification_create_from_encoding(ID_ANY, chunk_empty);
|
2007-05-17 17:55:29 +00:00
|
|
|
this->other_ca = NULL;
|
2006-07-05 10:53:20 +00:00
|
|
|
this->crypter_in = NULL;
|
|
|
|
this->crypter_out = NULL;
|
|
|
|
this->signer_in = NULL;
|
|
|
|
this->signer_out = NULL;
|
2005-11-22 15:38:41 +00:00
|
|
|
this->prf = NULL;
|
2007-04-19 12:37:48 +00:00
|
|
|
this->skp_verify = chunk_empty;
|
|
|
|
this->skp_build = chunk_empty;
|
2006-07-03 06:27:45 +00:00
|
|
|
this->child_prf = NULL;
|
2006-06-22 06:36:28 +00:00
|
|
|
this->nat_here = FALSE;
|
|
|
|
this->nat_there = FALSE;
|
2006-07-13 08:26:54 +00:00
|
|
|
this->state = IKE_CREATED;
|
2006-07-27 12:18:40 +00:00
|
|
|
this->time.inbound = this->time.outbound = time(NULL);
|
|
|
|
this->time.established = 0;
|
|
|
|
this->time.rekey = 0;
|
|
|
|
this->time.delete = 0;
|
2007-04-10 06:01:03 +00:00
|
|
|
this->ike_cfg = NULL;
|
|
|
|
this->peer_cfg = NULL;
|
2007-02-28 14:04:36 +00:00
|
|
|
this->task_manager = task_manager_create(&this->public);
|
|
|
|
this->unique_id = ++unique_id;
|
|
|
|
this->my_virtual_ip = NULL;
|
|
|
|
this->other_virtual_ip = NULL;
|
|
|
|
this->dns_servers = linked_list_create();
|
2007-03-20 08:16:16 +00:00
|
|
|
this->keyingtry = 0;
|
2006-07-05 10:53:20 +00:00
|
|
|
|
|
|
|
return &this->public;
|
2005-11-08 13:33:28 +00:00
|
|
|
}
|