- reworked configuration framework completly
- configuration is now split up in: connections, policies, credentials and daemon config - further alloc/free fixes needed!
This commit is contained in:
@@ -16,12 +16,12 @@ CONFIG_DIR= $(MAIN_DIR)config/
|
||||
|
||||
|
||||
|
||||
OBJS+= $(BUILD_DIR)init_config.o
|
||||
$(BUILD_DIR)init_config.o : $(CONFIG_DIR)init_config.c $(CONFIG_DIR)init_config.h
|
||||
OBJS+= $(BUILD_DIR)connection.o
|
||||
$(BUILD_DIR)connection.o : $(CONFIG_DIR)connection.c $(CONFIG_DIR)connection.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
OBJS+= $(BUILD_DIR)sa_config.o
|
||||
$(BUILD_DIR)sa_config.o : $(CONFIG_DIR)sa_config.c $(CONFIG_DIR)sa_config.h
|
||||
OBJS+= $(BUILD_DIR)policy.o
|
||||
$(BUILD_DIR)policy.o : $(CONFIG_DIR)policy.c $(CONFIG_DIR)policy.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
OBJS+= $(BUILD_DIR)traffic_selector.o
|
||||
@@ -32,10 +32,6 @@ OBJS+= $(BUILD_DIR)proposal.o
|
||||
$(BUILD_DIR)proposal.o : $(CONFIG_DIR)proposal.c $(CONFIG_DIR)proposal.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
OBJS+= $(BUILD_DIR)static_configuration.o
|
||||
$(BUILD_DIR)static_configuration.o : $(CONFIG_DIR)static_configuration.c $(CONFIG_DIR)static_configuration.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
OBJS+= $(BUILD_DIR)stroke_configuration.o
|
||||
$(BUILD_DIR)stroke_configuration.o : $(CONFIG_DIR)stroke_configuration.c $(CONFIG_DIR)stroke_configuration.h
|
||||
OBJS+= $(BUILD_DIR)configuration.o
|
||||
$(BUILD_DIR)configuration.o : $(CONFIG_DIR)configuration.c $(CONFIG_DIR)configuration.h
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* @file configuration.c
|
||||
*
|
||||
* @brief Implementation of configuration_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "configuration.h"
|
||||
|
||||
#include <types.h>
|
||||
#include <utils/allocator.h>
|
||||
|
||||
/**
|
||||
* First retransmit timeout in milliseconds.
|
||||
* Timeout value is increasing in each retransmit round.
|
||||
*/
|
||||
#define RETRANSMIT_TIMEOUT 3000
|
||||
|
||||
/**
|
||||
* Timeout in milliseconds after that a half open IKE_SA gets deleted.
|
||||
*/
|
||||
#define HALF_OPEN_IKE_SA_TIMEOUT 30000
|
||||
|
||||
/**
|
||||
* Max retransmit count.
|
||||
* 0 for infinite. The max time a half open IKE_SA is alive is set by
|
||||
* RETRANSMIT_TIMEOUT.
|
||||
*/
|
||||
#define MAX_RETRANSMIT_COUNT 0
|
||||
|
||||
|
||||
typedef struct private_configuration_t private_configuration_t;
|
||||
|
||||
/**
|
||||
* Private data of an configuration_t object.
|
||||
*/
|
||||
struct private_configuration_t {
|
||||
|
||||
/**
|
||||
* Public part of configuration_t object.
|
||||
*/
|
||||
configuration_t public;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of configuration_t.get_retransmit_timeout.
|
||||
*/
|
||||
static status_t get_retransmit_timeout (private_configuration_t *this, u_int32_t retransmit_count, u_int32_t *timeout)
|
||||
{
|
||||
int new_timeout = RETRANSMIT_TIMEOUT, i;
|
||||
if (retransmit_count > MAX_RETRANSMIT_COUNT && MAX_RETRANSMIT_COUNT != 0)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
for (i = 0; i < retransmit_count; i++)
|
||||
{
|
||||
new_timeout *= 2;
|
||||
}
|
||||
|
||||
*timeout = new_timeout;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of configuration_t.get_half_open_ike_sa_timeout.
|
||||
*/
|
||||
static u_int32_t get_half_open_ike_sa_timeout (private_configuration_t *this)
|
||||
{
|
||||
return HALF_OPEN_IKE_SA_TIMEOUT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of configuration_t.destroy.
|
||||
*/
|
||||
static void destroy(private_configuration_t *this)
|
||||
{
|
||||
allocator_free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header-file
|
||||
*/
|
||||
configuration_t *configuration_create()
|
||||
{
|
||||
private_configuration_t *this = allocator_alloc_thing(private_configuration_t);
|
||||
|
||||
/* public functions */
|
||||
this->public.destroy = (void(*)(configuration_t*))destroy;
|
||||
this->public.get_retransmit_timeout = (status_t (*) (configuration_t *, u_int32_t retransmit_count, u_int32_t *timeout))get_retransmit_timeout;
|
||||
this->public.get_half_open_ike_sa_timeout = (u_int32_t (*) (configuration_t *)) get_half_open_ike_sa_timeout;
|
||||
|
||||
return (&this->public);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
@@ -24,22 +24,12 @@
|
||||
#define CONFIGURATION_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <config/init_config.h>
|
||||
#include <config/sa_config.h>
|
||||
#include <transforms/rsa/rsa_private_key.h>
|
||||
#include <transforms/rsa/rsa_public_key.h>
|
||||
|
||||
|
||||
typedef struct configuration_t configuration_t;
|
||||
|
||||
/**
|
||||
* @brief The interface for a configuration backend.
|
||||
*
|
||||
* Multiple backends for the configuration are conceivable:
|
||||
* - ipsec starter from pluto
|
||||
* - own file backend
|
||||
* - multiple database backends
|
||||
* - LDAP backend?
|
||||
* @brief The interface for various daemon related configs.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - configuration_create()
|
||||
@@ -48,81 +38,11 @@ typedef struct configuration_t configuration_t;
|
||||
*/
|
||||
struct configuration_t {
|
||||
|
||||
/**
|
||||
* @brief Returns the configuration information needed for IKE_SA_INIT exchange
|
||||
* for a specific configuration name.
|
||||
*
|
||||
* The returned init_config_t object MUST NOT be destroyed cause it's managed by
|
||||
* this configuration_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param name name of the configuration
|
||||
* @param[out] init_config the init_config_t object is stored at this location
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_init_config_for_name) (configuration_t *this, char *name, init_config_t **init_config);
|
||||
|
||||
/**
|
||||
* @brief Returns the configuration information needed for IKE_SA_INIT exchange
|
||||
* for specific host informations.
|
||||
*
|
||||
* The returned init_config_t object MUST NOT be destroyed cause it's managed by
|
||||
* this configuration_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param my_host my host informations
|
||||
* @param other_host other host informations
|
||||
* @param[out] init_config the init_config_t object is stored at this location
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_init_config_for_host) (configuration_t *this, host_t *my_host, host_t *other_host,init_config_t **init_config);
|
||||
|
||||
/**
|
||||
* @brief Returns the configuration information needed after IKE_SA_INIT exchange
|
||||
* for a specific configuration name.
|
||||
*
|
||||
* The returned sa_config_t object MUST NOT be destroyed cause it's managed by
|
||||
* this configuration_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param name name of the configuration
|
||||
* @param[out] sa_config the sa_config_t object is stored at this location
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_sa_config_for_name) (configuration_t *this, char *name, sa_config_t **sa_config);
|
||||
|
||||
/**
|
||||
* @brief Returns the configuration information needed after IKE_SA_INIT exchange
|
||||
* for specific init_config_t and ID data.
|
||||
*
|
||||
* The returned sa_config_t object MUST NOT be destroyed cause it's managed by
|
||||
* this configuration_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param init_config init_config_t object
|
||||
* @param other_id identification of other one
|
||||
* @param my_id my identification (can be NULL)
|
||||
* @param[out] sa_config the sa_config_t object is stored at this location
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_sa_config_for_init_config_and_id) (configuration_t *this, init_config_t *init_config, identification_t *other_id, identification_t *my_id,sa_config_t **sa_config);
|
||||
|
||||
/**
|
||||
* @brief Returns the retransmit timeout.
|
||||
*
|
||||
* The timeout values are managed by the configuration.
|
||||
* The timeout values are managed by the configuration, so
|
||||
* another backoff algorithm may be implemented here.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param retransmit_count number of times a message was retransmitted so far
|
||||
@@ -148,54 +68,6 @@ struct configuration_t {
|
||||
* @return timeout in milliseconds (ms)
|
||||
*/
|
||||
u_int32_t (*get_half_open_ike_sa_timeout) (configuration_t *this);
|
||||
|
||||
/**
|
||||
* @brief Returns the preshared secret of a specific ID.
|
||||
*
|
||||
* The returned preshared secret MUST NOT be destroyed cause it's managed by
|
||||
* this configuration_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param identification identification_t object identifiying the ID.
|
||||
* @param[out] preshared_secret the preshared secret will be written there.
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND if no preshared secrets for specific ID could be found
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_shared_secret) (configuration_t *this, identification_t *identification, chunk_t *preshared_secret);
|
||||
|
||||
/**
|
||||
* @brief Returns the RSA public key of a specific ID.
|
||||
*
|
||||
* The returned rsa_public_key_t object MUST NOT be destroyed cause it's managed by
|
||||
* this configuration_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param identification identification_t object identifiying the ID.
|
||||
* @param[out] public_key the public key will be written there
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND if no key is configured for specific id
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_rsa_public_key) (configuration_t *this, identification_t *identification, rsa_public_key_t **public_key);
|
||||
|
||||
/**
|
||||
* @brief Returns the RSA private key of a specific ID.
|
||||
*
|
||||
* The returned rsa_private_key_t object MUST NOT be destroyed cause it's managed by
|
||||
* this configuration_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param identification identification_t object identifiying the ID.
|
||||
* @param[out] private_key the private key will be written there
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND if no key is configured for specific id
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_rsa_private_key) (configuration_t *this, identification_t *identification, rsa_private_key_t **private_key);
|
||||
|
||||
/**
|
||||
* @brief Destroys a configuration_t object.
|
||||
@@ -205,4 +77,13 @@ struct configuration_t {
|
||||
void (*destroy) (configuration_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates a configuration backend.
|
||||
*
|
||||
* @return static_configuration_t object
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
configuration_t *configuration_create();
|
||||
|
||||
#endif /*CONFIGURATION_H_*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file init_config.c
|
||||
* @file connection.c
|
||||
*
|
||||
* @brief Implementation of init_config_t.
|
||||
* @brief Implementation of connection_t.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -20,23 +20,44 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "init_config.h"
|
||||
#include "connection.h"
|
||||
|
||||
#include <utils/allocator.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
typedef struct private_init_config_t private_init_config_t;
|
||||
/**
|
||||
* String mappings for auth_method_t.
|
||||
*/
|
||||
mapping_t auth_method_m[] = {
|
||||
{RSA_DIGITAL_SIGNATURE, "RSA"},
|
||||
{SHARED_KEY_MESSAGE_INTEGRITY_CODE, "SHARED_KEY"},
|
||||
{DSS_DIGITAL_SIGNATURE, "DSS"},
|
||||
{MAPPING_END, NULL}
|
||||
};
|
||||
|
||||
|
||||
typedef struct private_connection_t private_connection_t;
|
||||
|
||||
/**
|
||||
* Private data of an init_config_t object
|
||||
* Private data of an connection_t object
|
||||
*/
|
||||
struct private_init_config_t {
|
||||
struct private_connection_t {
|
||||
|
||||
/**
|
||||
* Public part
|
||||
*/
|
||||
init_config_t public;
|
||||
connection_t public;
|
||||
|
||||
/**
|
||||
* ID of us
|
||||
*/
|
||||
identification_t *my_id;
|
||||
|
||||
/**
|
||||
* ID of remote peer
|
||||
*/
|
||||
identification_t *other_id;
|
||||
|
||||
/**
|
||||
* Host information of my host.
|
||||
@@ -48,6 +69,11 @@ struct private_init_config_t {
|
||||
*/
|
||||
host_t *other_host;
|
||||
|
||||
/**
|
||||
* Method to use for own authentication data
|
||||
*/
|
||||
auth_method_t auth_method;
|
||||
|
||||
/**
|
||||
* Supported proposals
|
||||
*/
|
||||
@@ -55,49 +81,58 @@ struct private_init_config_t {
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.get_my_host.
|
||||
* Implementation of connection_t.get_my_id.
|
||||
*/
|
||||
static host_t * get_my_host (private_init_config_t *this)
|
||||
static identification_t *get_my_id (private_connection_t *this)
|
||||
{
|
||||
return this->my_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of connection_t.get_other_id.
|
||||
*/
|
||||
static identification_t *get_other_id(private_connection_t *this)
|
||||
{
|
||||
return this->other_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of connection_t.get_my_host.
|
||||
*/
|
||||
static host_t * get_my_host (private_connection_t *this)
|
||||
{
|
||||
return this->my_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.get_other_host.
|
||||
* Implementation of connection_t.update_my_host.
|
||||
*/
|
||||
static host_t * get_other_host (private_init_config_t *this)
|
||||
static void update_my_host(private_connection_t *this, host_t *my_host)
|
||||
{
|
||||
this->my_host->destroy(this->my_host);
|
||||
this->my_host = my_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of connection_t.get_other_host.
|
||||
*/
|
||||
static host_t * get_other_host (private_connection_t *this)
|
||||
{
|
||||
return this->other_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.get_my_host_clone.
|
||||
* Implementation of connection_t.get_proposals.
|
||||
*/
|
||||
static host_t * get_my_host_clone (private_init_config_t *this)
|
||||
{
|
||||
return this->my_host->clone(this->my_host);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.get_other_host_clone.
|
||||
*/
|
||||
static host_t * get_other_host_clone (private_init_config_t *this)
|
||||
{
|
||||
return this->other_host->clone(this->other_host);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.get_proposals.
|
||||
*/
|
||||
static linked_list_t* get_proposals (private_init_config_t *this)
|
||||
static linked_list_t* get_proposals (private_connection_t *this)
|
||||
{
|
||||
return this->proposals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.select_proposal.
|
||||
* Implementation of connection_t.select_proposal.
|
||||
*/
|
||||
static proposal_t *select_proposal(private_init_config_t *this, linked_list_t *proposals)
|
||||
static proposal_t *select_proposal(private_connection_t *this, linked_list_t *proposals)
|
||||
{
|
||||
iterator_t *stored_iter, *supplied_iter;
|
||||
proposal_t *stored, *supplied, *selected;
|
||||
@@ -133,17 +168,25 @@ static proposal_t *select_proposal(private_init_config_t *this, linked_list_t *p
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.add_proposal.
|
||||
* Implementation of connection_t.add_proposal.
|
||||
*/
|
||||
static void add_proposal (private_init_config_t *this, proposal_t *proposal)
|
||||
static void add_proposal (private_connection_t *this, proposal_t *proposal)
|
||||
{
|
||||
this->proposals->insert_last(this->proposals, proposal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.get_dh_group.
|
||||
* Implementation of connection_t.auth_method_t.
|
||||
*/
|
||||
static diffie_hellman_group_t get_dh_group(private_init_config_t *this)
|
||||
static auth_method_t get_auth_method(private_connection_t *this)
|
||||
{
|
||||
return this->auth_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of connection_t.get_dh_group.
|
||||
*/
|
||||
static diffie_hellman_group_t get_dh_group(private_connection_t *this)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
proposal_t *proposal;
|
||||
@@ -165,9 +208,9 @@ static diffie_hellman_group_t get_dh_group(private_init_config_t *this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.check_dh_group.
|
||||
* Implementation of connection_t.check_dh_group.
|
||||
*/
|
||||
static bool check_dh_group(private_init_config_t *this, diffie_hellman_group_t dh_group)
|
||||
static bool check_dh_group(private_connection_t *this, diffie_hellman_group_t dh_group)
|
||||
{
|
||||
iterator_t *prop_iter, *alg_iter;
|
||||
proposal_t *proposal;
|
||||
@@ -195,9 +238,9 @@ static bool check_dh_group(private_init_config_t *this, diffie_hellman_group_t d
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of init_config_t.destroy.
|
||||
* Implementation of connection_t.destroy.
|
||||
*/
|
||||
static void destroy (private_init_config_t *this)
|
||||
static void destroy (private_connection_t *this)
|
||||
{
|
||||
proposal_t *proposal;
|
||||
|
||||
@@ -209,31 +252,38 @@ static void destroy (private_init_config_t *this)
|
||||
|
||||
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);
|
||||
allocator_free(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
init_config_t * init_config_create(host_t *me, host_t *other)
|
||||
connection_t * connection_create(host_t *my_host, host_t *other_host, identification_t *my_id, identification_t *other_id, auth_method_t auth_method)
|
||||
{
|
||||
private_init_config_t *this = allocator_alloc_thing(private_init_config_t);
|
||||
private_connection_t *this = allocator_alloc_thing(private_connection_t);
|
||||
|
||||
/* public functions */
|
||||
this->public.get_my_host = (host_t*(*)(init_config_t*))get_my_host;
|
||||
this->public.get_other_host = (host_t*(*)(init_config_t*))get_other_host;
|
||||
this->public.get_my_host_clone = (host_t*(*)(init_config_t*))get_my_host_clone;
|
||||
this->public.get_other_host_clone = (host_t*(*)(init_config_t*))get_other_host_clone;
|
||||
this->public.get_proposals = (linked_list_t*(*)(init_config_t*))get_proposals;
|
||||
this->public.select_proposal = (proposal_t*(*)(init_config_t*,linked_list_t*))select_proposal;
|
||||
this->public.add_proposal = (void(*)(init_config_t*, proposal_t*)) add_proposal;
|
||||
this->public.get_dh_group = (diffie_hellman_group_t(*)(init_config_t*)) get_dh_group;
|
||||
this->public.check_dh_group = (bool(*)(init_config_t*,diffie_hellman_group_t)) check_dh_group;
|
||||
this->public.destroy = (void(*)(init_config_t*))destroy;
|
||||
this->public.get_my_id = (identification_t*(*)(connection_t*))get_my_id;
|
||||
this->public.get_other_id = (identification_t*(*)(connection_t*))get_other_id;
|
||||
this->public.get_my_host = (host_t*(*)(connection_t*))get_my_host;
|
||||
this->public.update_my_host = (void(*)(connection_t*,host_t*))update_my_host;
|
||||
this->public.get_other_host = (host_t*(*)(connection_t*))get_other_host;
|
||||
this->public.get_proposals = (linked_list_t*(*)(connection_t*))get_proposals;
|
||||
this->public.select_proposal = (proposal_t*(*)(connection_t*,linked_list_t*))select_proposal;
|
||||
this->public.add_proposal = (void(*)(connection_t*, proposal_t*)) add_proposal;
|
||||
this->public.get_auth_method = (auth_method_t(*)(connection_t*)) get_auth_method;
|
||||
this->public.get_dh_group = (diffie_hellman_group_t(*)(connection_t*)) get_dh_group;
|
||||
this->public.check_dh_group = (bool(*)(connection_t*,diffie_hellman_group_t)) check_dh_group;
|
||||
this->public.destroy = (void(*)(connection_t*))destroy;
|
||||
|
||||
/* private variables */
|
||||
this->my_host = me;
|
||||
this->other_host = other;
|
||||
this->my_host = my_host;
|
||||
this->other_host = other_host;
|
||||
this->my_id = my_id;
|
||||
this->other_id = other_id;
|
||||
this->auth_method = auth_method;
|
||||
|
||||
this->proposals = linked_list_create();
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
/**
|
||||
* @file connection.h
|
||||
*
|
||||
* @brief Interface of connection_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef CONNECTION_H_
|
||||
#define CONNECTION_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <network/host.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/identification.h>
|
||||
#include <config/proposal.h>
|
||||
#include <transforms/diffie_hellman.h>
|
||||
|
||||
|
||||
typedef enum auth_method_t auth_method_t;
|
||||
|
||||
/**
|
||||
* AUTH Method to use.
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
enum auth_method_t {
|
||||
/**
|
||||
* Computed as specified in section 2.15 of RFC using
|
||||
* an RSA private key over a PKCS#1 padded hash.
|
||||
*/
|
||||
RSA_DIGITAL_SIGNATURE = 1,
|
||||
|
||||
/**
|
||||
* Computed as specified in section 2.15 of RFC using the
|
||||
* shared key associated with the identity in the ID payload
|
||||
* and the negotiated prf function
|
||||
*/
|
||||
SHARED_KEY_MESSAGE_INTEGRITY_CODE = 2,
|
||||
|
||||
/**
|
||||
* Computed as specified in section 2.15 of RFC using a
|
||||
* DSS private key over a SHA-1 hash.
|
||||
*/
|
||||
DSS_DIGITAL_SIGNATURE = 3,
|
||||
};
|
||||
|
||||
/**
|
||||
* string mappings for auth method.
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
extern mapping_t auth_method_m[];
|
||||
|
||||
|
||||
typedef struct connection_t connection_t;
|
||||
|
||||
/**
|
||||
* @brief A connection_t defines the rules to set up an IKE_SA.
|
||||
*
|
||||
*
|
||||
* @b Constructors:
|
||||
* - connection_create()
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
struct connection_t {
|
||||
|
||||
/**
|
||||
* @brief Get my ID for this connection.
|
||||
*
|
||||
* Object is NOT getting cloned.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return host information as identification_t object
|
||||
*/
|
||||
identification_t *(*get_my_id) (connection_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get others ID for this connection.
|
||||
*
|
||||
* Object is NOT getting cloned.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return host information as identification_t object
|
||||
*/
|
||||
identification_t *(*get_other_id) (connection_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get my address as host_t object.
|
||||
*
|
||||
* Object is NOT getting cloned.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return host information as host_t object
|
||||
*/
|
||||
host_t *(*get_my_host) (connection_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get others address as host_t object.
|
||||
*
|
||||
* Object is NOT getting cloned.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return host information as host_t object
|
||||
*/
|
||||
host_t *(*get_other_host) (connection_t *this);
|
||||
|
||||
/**
|
||||
* @brief Update address of my host.
|
||||
*
|
||||
* It may be necessary to uptdate this address, as it
|
||||
* is set to the default route (0.0.0.0) in some cases.
|
||||
* Old host is destroyed, new one NOT cloned.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param my_host new host to set as my_host
|
||||
*/
|
||||
void (*update_my_host) (connection_t *this, host_t *my_host);
|
||||
|
||||
/**
|
||||
* @brief Returns a list of all supported proposals.
|
||||
*
|
||||
* Returned list is still owned by connection and MUST NOT
|
||||
* modified or destroyed.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return list containing all the proposals
|
||||
*/
|
||||
linked_list_t *(*get_proposals) (connection_t *this);
|
||||
|
||||
/**
|
||||
* @brief Adds a proposal to the list..
|
||||
*
|
||||
* The first added proposal has the highest priority, the last
|
||||
* added the lowest.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param proposal proposal to add
|
||||
*/
|
||||
void (*add_proposal) (connection_t *this, proposal_t *proposal);
|
||||
|
||||
/**
|
||||
* @brief Select a proposed from suggested proposals.
|
||||
*
|
||||
* Returned proposal must be destroyed after usage.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param proposals list of proposals to select from
|
||||
* @return selected proposal, or NULL if none matches.
|
||||
*/
|
||||
proposal_t *(*select_proposal) (connection_t *this, linked_list_t *proposals);
|
||||
|
||||
/**
|
||||
* @brief Get the authentication method to use
|
||||
*
|
||||
* @param this calling object
|
||||
* @return authentication method
|
||||
*/
|
||||
auth_method_t (*get_auth_method) (connection_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get the DH group to use for connection initialization.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return dh group to use for initialization
|
||||
*/
|
||||
diffie_hellman_group_t (*get_dh_group) (connection_t *this);
|
||||
|
||||
/**
|
||||
* @brief Check if a suggested dh group is acceptable.
|
||||
*
|
||||
* If we guess a wrong DH group for IKE_SA_INIT, the other
|
||||
* peer will send us a offer. But is this acceptable for us?
|
||||
*
|
||||
* @param this calling object
|
||||
* @return TRUE if group acceptable
|
||||
*/
|
||||
bool (*check_dh_group) (connection_t *this, diffie_hellman_group_t dh_group);
|
||||
|
||||
/**
|
||||
* @brief Destroys a connection_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (connection_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates a connection_t object.
|
||||
*
|
||||
* Supplied hosts/IDs become owned by connection, so
|
||||
* do not modify or destroy them after a call to
|
||||
* connection_create().
|
||||
*
|
||||
* @param my_host host_t representing local address
|
||||
* @param other_host host_t representing remote address
|
||||
* @param my_id identification_t for me
|
||||
* @param other_id identification_t for other
|
||||
* @param auth_method Authentication method to use for our(!) auth data
|
||||
* @return connection_t object.
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
connection_t * connection_create(host_t *my_host, host_t *other_host,
|
||||
identification_t *my_id,
|
||||
identification_t *other_id,
|
||||
auth_method_t auth_method);
|
||||
|
||||
#endif /* CONNECTION_H_ */
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @file connection_store.h
|
||||
*
|
||||
* @brief Interface connection_store_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef CONNECTION_STORE_H_
|
||||
#define CONNECTION_STORE_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <config/connection.h>
|
||||
|
||||
|
||||
typedef struct connection_store_t connection_store_t;
|
||||
|
||||
/**
|
||||
* @brief The interface for a store of connection_t's.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - connection_store_create()
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
struct connection_store_t {
|
||||
|
||||
/**
|
||||
* @brief Returns a connection definition identified by two IDs.
|
||||
*
|
||||
* The returned connection gets created/cloned and therefore must
|
||||
* be destroyed after usage.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param my_id own ID of connection
|
||||
* @param other_id others ID of connection
|
||||
* @return
|
||||
* - connection_t, if found
|
||||
* - NULL otherwise
|
||||
*/
|
||||
connection_t *(*get_connection_by_ids) (connection_store_t *this, identification_t *my_id, identification_t *other_id);
|
||||
|
||||
/**
|
||||
* @brief Returns a connection definition identified by two hosts.
|
||||
*
|
||||
* The returned connection gets created/cloned and therefore must
|
||||
* be destroyed after usage.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param my_id own address of connection
|
||||
* @param other_id others address of connection
|
||||
* @return
|
||||
* - connection_t, if found
|
||||
* - NULL otherwise
|
||||
*/
|
||||
connection_t *(*get_connection_by_hosts) (connection_store_t *this, host_t *my_host, host_t *other_host);
|
||||
|
||||
/**
|
||||
* @brief Destroys a connection_store_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (connection_store_t *this);
|
||||
};
|
||||
|
||||
#endif /*CONNECTION_STORE_H_*/
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* @file credential_store.h
|
||||
*
|
||||
* @brief Interface credential_store_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef CREDENTIAL_STORE_H_
|
||||
#define CREDENTIAL_STORE_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <transforms/rsa/rsa_private_key.h>
|
||||
#include <transforms/rsa/rsa_public_key.h>
|
||||
|
||||
|
||||
typedef struct credential_store_t credential_store_t;
|
||||
|
||||
/**
|
||||
* @brief The interface for a credential_store backend.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - credential_store_create()
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
struct credential_store_t {
|
||||
|
||||
/**
|
||||
* @brief Returns the preshared secret of a specific ID.
|
||||
*
|
||||
* The returned preshared secret MUST NOT be destroyed cause it's managed by
|
||||
* this credential_store_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param identification identification_t object identifiying the secret.
|
||||
* @param[out] preshared_secret the preshared secret will be written there.
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND if no preshared secrets for specific ID could be found
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_shared_secret) (credential_store_t *this, identification_t *identification, chunk_t *preshared_secret);
|
||||
|
||||
/**
|
||||
* @brief Returns the RSA public key of a specific ID.
|
||||
*
|
||||
* The returned rsa_public_key_t object MUST NOT be destroyed cause it's managed by
|
||||
* this credential_store_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param identification identification_t object identifiying the key.
|
||||
* @param[out] public_key the public key will be written there
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND if no key is configured for specific id
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_rsa_public_key) (credential_store_t *this, identification_t *identification, rsa_public_key_t **public_key);
|
||||
|
||||
/**
|
||||
* @brief Returns the RSA private key of a specific ID.
|
||||
*
|
||||
* The returned rsa_private_key_t object MUST NOT be destroyed cause it's managed by
|
||||
* this credential_store_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param identification identification_t object identifiying the key
|
||||
* @param[out] private_key the private key will be written there
|
||||
*
|
||||
* @return
|
||||
* - NOT_FOUND if no key is configured for specific id
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*get_rsa_private_key) (credential_store_t *this, identification_t *identification, rsa_private_key_t **private_key);
|
||||
|
||||
/**
|
||||
* @brief Destroys a credential_store_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (credential_store_t *this);
|
||||
};
|
||||
|
||||
#endif /*CREDENTIAL_STORE_H_*/
|
||||
@@ -1,165 +0,0 @@
|
||||
/**
|
||||
* @file init_config.h
|
||||
*
|
||||
* @brief Interface of init_config_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _INIT_CONFIG_H_
|
||||
#define _INIT_CONFIG_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <network/host.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <config/proposal.h>
|
||||
#include <transforms/crypters/crypter.h>
|
||||
#include <transforms/prfs/prf.h>
|
||||
#include <transforms/signers/signer.h>
|
||||
#include <transforms/diffie_hellman.h>
|
||||
|
||||
|
||||
|
||||
typedef struct init_config_t init_config_t;
|
||||
|
||||
/**
|
||||
* @brief Represents a configuration class holding all needed informations for IKE_SA_INIT phase.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - init_config_create()
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
struct init_config_t {
|
||||
|
||||
/**
|
||||
* @brief Get my host information as host_t object.
|
||||
*
|
||||
* Object is NOT getting cloned.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return host information as host_t object
|
||||
*/
|
||||
host_t *(*get_my_host) (init_config_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get other host information as host_t object.
|
||||
*
|
||||
* Object is NOT getting cloned.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return host information as host_t object
|
||||
*/
|
||||
host_t *(*get_other_host) (init_config_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get my host information as host_t object.
|
||||
*
|
||||
* Object is getting cloned and has to get destroyed by caller.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return host information as host_t object
|
||||
*/
|
||||
host_t *(*get_my_host_clone) (init_config_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get other host information as host_t object.
|
||||
*
|
||||
* @warning Object is getting cloned and has to get destroyed by caller.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return host information as host_t object
|
||||
*/
|
||||
host_t *(*get_other_host_clone) (init_config_t *this);
|
||||
|
||||
/**
|
||||
* @brief Returns a list of all supported proposals.
|
||||
*
|
||||
* Returned list is still owned by init_config and MUST NOT
|
||||
* modified or destroyed.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return list containing all the proposals
|
||||
*/
|
||||
linked_list_t *(*get_proposals) (init_config_t *this);
|
||||
|
||||
/**
|
||||
* @brief Adds a proposal to the list..
|
||||
*
|
||||
* The first added proposal has the highest priority, the last
|
||||
* added the lowest.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param priority priority of adding proposal
|
||||
* @param proposal proposal to add
|
||||
*/
|
||||
void (*add_proposal) (init_config_t *this, proposal_t *proposal);
|
||||
|
||||
/**
|
||||
* @brief Select a proposed from suggested proposals.
|
||||
*
|
||||
* Returned proposal must be destroyed after usage.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param proposals list of proposals to select from
|
||||
* @return selected proposal, or NULL if none matches.
|
||||
*/
|
||||
proposal_t *(*select_proposal) (init_config_t *this, linked_list_t *proposals);
|
||||
|
||||
/**
|
||||
* @brief Get the DH group to use for connection initialization.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return dh group to use for initialization
|
||||
*/
|
||||
diffie_hellman_group_t (*get_dh_group) (init_config_t *this);
|
||||
|
||||
/**
|
||||
* @brief Check if a suggested dh group is acceptable.
|
||||
*
|
||||
* If we guess a wrong DH group for IKE_SA_INIT, the other
|
||||
* peer will send us a offer. But is this acceptable for us?
|
||||
*
|
||||
* @param this calling object
|
||||
* @return dh group to use for initialization
|
||||
*/
|
||||
bool (*check_dh_group) (init_config_t *this, diffie_hellman_group_t dh_group);
|
||||
|
||||
/**
|
||||
* @brief Destroys a init_config_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (init_config_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates a init_config_t object from two host_t's.
|
||||
*
|
||||
* Supplied hosts become owned by init_config, so
|
||||
* do not modify or destroy them after a call to
|
||||
* init_config_create_from_hosts().
|
||||
*
|
||||
* @param me host_t object representing local address
|
||||
* @param other host_t object representing remote address
|
||||
* @return init_config_t object.
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
init_config_t * init_config_create(host_t *me, host_t *other);
|
||||
|
||||
#endif /* _INIT_CONFIG_H_ */
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file sa_config.c
|
||||
* @file policy.c
|
||||
*
|
||||
* @brief Implementation of sa_config_t.
|
||||
* @brief Implementation of policy_t.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -20,24 +20,24 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "sa_config.h"
|
||||
#include "policy.h"
|
||||
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/allocator.h>
|
||||
#include <utils/identification.h>
|
||||
#include <utils/logger.h>
|
||||
|
||||
typedef struct private_sa_config_t private_sa_config_t;
|
||||
typedef struct private_policy_t private_policy_t;
|
||||
|
||||
/**
|
||||
* Private data of an sa_config_t object
|
||||
* Private data of an policy_t object
|
||||
*/
|
||||
struct private_sa_config_t {
|
||||
struct private_policy_t {
|
||||
|
||||
/**
|
||||
* Public part
|
||||
*/
|
||||
sa_config_t public;
|
||||
policy_t public;
|
||||
|
||||
/**
|
||||
* id to use to identify us
|
||||
@@ -49,16 +49,6 @@ struct private_sa_config_t {
|
||||
*/
|
||||
identification_t *other_id;
|
||||
|
||||
/**
|
||||
* authentification method to use
|
||||
*/
|
||||
auth_method_t auth_method;
|
||||
|
||||
/**
|
||||
* Lifetime of IKE_SA in milliseconds.
|
||||
*/
|
||||
u_int32_t ike_sa_lifetime;
|
||||
|
||||
/**
|
||||
* list for all proposals
|
||||
*/
|
||||
@@ -77,76 +67,60 @@ struct private_sa_config_t {
|
||||
/**
|
||||
* select_traffic_selectors for both
|
||||
*/
|
||||
linked_list_t *(*select_traffic_selectors) (private_sa_config_t *,linked_list_t*,linked_list_t*);
|
||||
linked_list_t *(*select_traffic_selectors) (private_policy_t *,linked_list_t*,linked_list_t*);
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.get_my_id
|
||||
* Implementation of policy_t.get_my_id
|
||||
*/
|
||||
static identification_t *get_my_id(private_sa_config_t *this)
|
||||
static identification_t *get_my_id(private_policy_t *this)
|
||||
{
|
||||
return this->my_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.get_other_id
|
||||
* Implementation of policy_t.get_other_id
|
||||
*/
|
||||
static identification_t *get_other_id(private_sa_config_t *this)
|
||||
static identification_t *get_other_id(private_policy_t *this)
|
||||
{
|
||||
return this->other_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.get_auth_method.
|
||||
* Implementation of policy_t.get_my_traffic_selectors
|
||||
*/
|
||||
static auth_method_t get_auth_method(private_sa_config_t *this)
|
||||
{
|
||||
return this->auth_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.get_ike_sa_lifetime.
|
||||
*/
|
||||
static u_int32_t get_ike_sa_lifetime (private_sa_config_t *this)
|
||||
{
|
||||
return this->ike_sa_lifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.get_my_traffic_selectors
|
||||
*/
|
||||
static linked_list_t *get_my_traffic_selectors(private_sa_config_t *this)
|
||||
static linked_list_t *get_my_traffic_selectors(private_policy_t *this)
|
||||
{
|
||||
return this->my_ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.get_other_traffic_selectors
|
||||
* Implementation of policy_t.get_other_traffic_selectors
|
||||
*/
|
||||
static linked_list_t *get_other_traffic_selectors(private_sa_config_t *this, traffic_selector_t **traffic_selectors[])
|
||||
static linked_list_t *get_other_traffic_selectors(private_policy_t *this, traffic_selector_t **traffic_selectors[])
|
||||
{
|
||||
return this->other_ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_sa_config_t.select_my_traffic_selectors
|
||||
* Implementation of private_policy_t.select_my_traffic_selectors
|
||||
*/
|
||||
static linked_list_t *select_my_traffic_selectors(private_sa_config_t *this, linked_list_t *supplied)
|
||||
static linked_list_t *select_my_traffic_selectors(private_policy_t *this, linked_list_t *supplied)
|
||||
{
|
||||
return this->select_traffic_selectors(this, this->my_ts, supplied);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_sa_config_t.select_other_traffic_selectors
|
||||
* Implementation of private_policy_t.select_other_traffic_selectors
|
||||
*/
|
||||
static linked_list_t *select_other_traffic_selectors(private_sa_config_t *this, linked_list_t *supplied)
|
||||
static linked_list_t *select_other_traffic_selectors(private_policy_t *this, linked_list_t *supplied)
|
||||
{
|
||||
return this->select_traffic_selectors(this, this->other_ts, supplied);
|
||||
}
|
||||
/**
|
||||
* Implementation of private_sa_config_t.select_traffic_selectors
|
||||
* Implementation of private_policy_t.select_traffic_selectors
|
||||
*/
|
||||
static linked_list_t *select_traffic_selectors(private_sa_config_t *this, linked_list_t *stored, linked_list_t *supplied)
|
||||
static linked_list_t *select_traffic_selectors(private_policy_t *this, linked_list_t *stored, linked_list_t *supplied)
|
||||
{
|
||||
iterator_t *supplied_iter, *stored_iter;
|
||||
traffic_selector_t *supplied_ts, *stored_ts, *selected_ts;
|
||||
@@ -182,17 +156,17 @@ static linked_list_t *select_traffic_selectors(private_sa_config_t *this, linked
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.get_proposal_iterator
|
||||
* Implementation of policy_t.get_proposal_iterator
|
||||
*/
|
||||
static linked_list_t *get_proposals(private_sa_config_t *this)
|
||||
static linked_list_t *get_proposals(private_policy_t *this)
|
||||
{
|
||||
return this->proposals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.select_proposal
|
||||
* Implementation of policy_t.select_proposal
|
||||
*/
|
||||
static proposal_t *select_proposal(private_sa_config_t *this, linked_list_t *proposals)
|
||||
static proposal_t *select_proposal(private_policy_t *this, linked_list_t *proposals)
|
||||
{
|
||||
iterator_t *stored_iter, *supplied_iter;
|
||||
proposal_t *stored, *supplied, *selected;
|
||||
@@ -228,33 +202,33 @@ static proposal_t *select_proposal(private_sa_config_t *this, linked_list_t *pro
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.add_my_traffic_selector
|
||||
* Implementation of policy_t.add_my_traffic_selector
|
||||
*/
|
||||
static void add_my_traffic_selector(private_sa_config_t *this, traffic_selector_t *traffic_selector)
|
||||
static void add_my_traffic_selector(private_policy_t *this, traffic_selector_t *traffic_selector)
|
||||
{
|
||||
this->my_ts->insert_last(this->my_ts, (void*)traffic_selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.add_other_traffic_selector
|
||||
* Implementation of policy_t.add_other_traffic_selector
|
||||
*/
|
||||
static void add_other_traffic_selector(private_sa_config_t *this, traffic_selector_t *traffic_selector)
|
||||
static void add_other_traffic_selector(private_policy_t *this, traffic_selector_t *traffic_selector)
|
||||
{
|
||||
this->other_ts->insert_last(this->other_ts, (void*)traffic_selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of sa_config_t.add_proposal
|
||||
* Implementation of policy_t.add_proposal
|
||||
*/
|
||||
static void add_proposal(private_sa_config_t *this, proposal_t *proposal)
|
||||
static void add_proposal(private_policy_t *this, proposal_t *proposal)
|
||||
{
|
||||
this->proposals->insert_last(this->proposals, (void*)proposal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements sa_config_t.destroy.
|
||||
* Implements policy_t.destroy.
|
||||
*/
|
||||
static status_t destroy(private_sa_config_t *this)
|
||||
static status_t destroy(private_policy_t *this)
|
||||
{
|
||||
proposal_t *proposal;
|
||||
traffic_selector_t *traffic_selector;
|
||||
@@ -292,48 +266,33 @@ static status_t destroy(private_sa_config_t *this)
|
||||
/*
|
||||
* Described in header-file
|
||||
*/
|
||||
sa_config_t *sa_config_create(id_type_t my_id_type, char *my_id, id_type_t other_id_type, char *other_id, auth_method_t auth_method, u_int32_t ike_sa_lifetime)
|
||||
policy_t *policy_create(identification_t *my_id, identification_t *other_id)
|
||||
{
|
||||
private_sa_config_t *this = allocator_alloc_thing(private_sa_config_t);
|
||||
private_policy_t *this = allocator_alloc_thing(private_policy_t);
|
||||
|
||||
/* public functions */
|
||||
this->public.get_my_id = (identification_t*(*)(sa_config_t*))get_my_id;
|
||||
this->public.get_other_id = (identification_t*(*)(sa_config_t*))get_other_id;
|
||||
this->public.get_auth_method = (auth_method_t(*)(sa_config_t*))get_auth_method;
|
||||
this->public.get_ike_sa_lifetime = (u_int32_t(*)(sa_config_t*))get_ike_sa_lifetime;
|
||||
this->public.get_my_traffic_selectors = (linked_list_t*(*)(sa_config_t*))get_my_traffic_selectors;
|
||||
this->public.select_my_traffic_selectors = (linked_list_t*(*)(sa_config_t*,linked_list_t*))select_my_traffic_selectors;
|
||||
this->public.get_other_traffic_selectors = (linked_list_t*(*)(sa_config_t*))get_other_traffic_selectors;
|
||||
this->public.select_other_traffic_selectors = (linked_list_t*(*)(sa_config_t*,linked_list_t*))select_other_traffic_selectors;
|
||||
this->public.get_proposals = (linked_list_t*(*)(sa_config_t*))get_proposals;
|
||||
this->public.select_proposal = (proposal_t*(*)(sa_config_t*,linked_list_t*))select_proposal;
|
||||
this->public.add_my_traffic_selector = (void(*)(sa_config_t*,traffic_selector_t*))add_my_traffic_selector;
|
||||
this->public.add_other_traffic_selector = (void(*)(sa_config_t*,traffic_selector_t*))add_other_traffic_selector;
|
||||
this->public.add_proposal = (void(*)(sa_config_t*,proposal_t*))add_proposal;
|
||||
this->public.destroy = (void(*)(sa_config_t*))destroy;
|
||||
this->public.get_my_id = (identification_t*(*)(policy_t*))get_my_id;
|
||||
this->public.get_other_id = (identification_t*(*)(policy_t*))get_other_id;
|
||||
this->public.get_my_traffic_selectors = (linked_list_t*(*)(policy_t*))get_my_traffic_selectors;
|
||||
this->public.select_my_traffic_selectors = (linked_list_t*(*)(policy_t*,linked_list_t*))select_my_traffic_selectors;
|
||||
this->public.get_other_traffic_selectors = (linked_list_t*(*)(policy_t*))get_other_traffic_selectors;
|
||||
this->public.select_other_traffic_selectors = (linked_list_t*(*)(policy_t*,linked_list_t*))select_other_traffic_selectors;
|
||||
this->public.get_proposals = (linked_list_t*(*)(policy_t*))get_proposals;
|
||||
this->public.select_proposal = (proposal_t*(*)(policy_t*,linked_list_t*))select_proposal;
|
||||
this->public.add_my_traffic_selector = (void(*)(policy_t*,traffic_selector_t*))add_my_traffic_selector;
|
||||
this->public.add_other_traffic_selector = (void(*)(policy_t*,traffic_selector_t*))add_other_traffic_selector;
|
||||
this->public.add_proposal = (void(*)(policy_t*,proposal_t*))add_proposal;
|
||||
this->public.destroy = (void(*)(policy_t*))destroy;
|
||||
|
||||
/* apply init values */
|
||||
this->my_id = identification_create_from_string(my_id_type, my_id);
|
||||
if (this->my_id == NULL)
|
||||
{
|
||||
allocator_free(this);
|
||||
return NULL;
|
||||
}
|
||||
this->other_id = identification_create_from_string(other_id_type, other_id);
|
||||
if (this->my_id == NULL)
|
||||
{
|
||||
this->other_id->destroy(this->other_id);
|
||||
allocator_free(this);
|
||||
return NULL;
|
||||
}
|
||||
this->my_id = my_id;
|
||||
this->other_id = other_id;
|
||||
|
||||
/* init private members*/
|
||||
this->select_traffic_selectors = select_traffic_selectors;
|
||||
this->proposals = linked_list_create();
|
||||
this->my_ts = linked_list_create();
|
||||
this->other_ts = linked_list_create();
|
||||
this->auth_method = auth_method;
|
||||
this->ike_sa_lifetime = ike_sa_lifetime;
|
||||
|
||||
return (&this->public);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file sa_config.h
|
||||
* @file policy.h
|
||||
*
|
||||
* @brief Interface of sa_config_t.
|
||||
* @brief Interface of policy_t.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -20,38 +20,30 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef _SA_CONFIG_H_
|
||||
#define _SA_CONFIG_H_
|
||||
#ifndef POLICY_H_
|
||||
#define POLICY_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <utils/identification.h>
|
||||
#include <encoding/payloads/auth_payload.h>
|
||||
#include <encoding/payloads/transform_substructure.h>
|
||||
#include <network/host.h>
|
||||
#include <transforms/crypters/crypter.h>
|
||||
#include <transforms/signers/signer.h>
|
||||
#include <transforms/diffie_hellman.h>
|
||||
#include <config/traffic_selector.h>
|
||||
#include <config/proposal.h>
|
||||
#include <encoding/payloads/auth_payload.h>
|
||||
|
||||
|
||||
|
||||
typedef struct sa_config_t sa_config_t;
|
||||
typedef struct policy_t policy_t;
|
||||
|
||||
/**
|
||||
* @brief Stores configuration of an initialized connection.
|
||||
* @brief A policy_t defines the policies to apply to CHILD_SAs.
|
||||
*
|
||||
* During the IKE_AUTH phase, we have enough data to specify a
|
||||
* configuration.
|
||||
*
|
||||
* @warning This config is not thread save.
|
||||
* The given two IDs identify a policy. These rules define how
|
||||
* child SAs may be set up and which traffic may be IPsec'ed.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - sa_config_create()
|
||||
* - policy_create()
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
struct sa_config_t {
|
||||
struct policy_t {
|
||||
|
||||
/**
|
||||
* @brief Get own id to use for identification.
|
||||
@@ -61,7 +53,7 @@ struct sa_config_t {
|
||||
* @param this calling object
|
||||
* @return own id
|
||||
*/
|
||||
identification_t *(*get_my_id) (sa_config_t *this);
|
||||
identification_t *(*get_my_id) (policy_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get id of communication partner.
|
||||
@@ -71,22 +63,7 @@ struct sa_config_t {
|
||||
* @param this calling object
|
||||
* @return other id
|
||||
*/
|
||||
identification_t *(*get_other_id) (sa_config_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get authentication method to use for IKE_AUTH.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return authentication methood
|
||||
*/
|
||||
auth_method_t (*get_auth_method) (sa_config_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get lifetime of IKE_SA in milliseconds.
|
||||
*
|
||||
* @return IKE_SA lifetime in milliseconds.
|
||||
*/
|
||||
u_int32_t (*get_ike_sa_lifetime) (sa_config_t *this);
|
||||
identification_t *(*get_other_id) (policy_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get configured traffic selectors for our site.
|
||||
@@ -97,7 +74,7 @@ struct sa_config_t {
|
||||
* @param this calling object
|
||||
* @return list with traffic selectors
|
||||
*/
|
||||
linked_list_t *(*get_my_traffic_selectors) (sa_config_t *this);
|
||||
linked_list_t *(*get_my_traffic_selectors) (policy_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get configured traffic selectors for others site.
|
||||
@@ -108,7 +85,7 @@ struct sa_config_t {
|
||||
* @param this calling object
|
||||
* @return list with traffic selectors
|
||||
*/
|
||||
linked_list_t *(*get_other_traffic_selectors) (sa_config_t *this);
|
||||
linked_list_t *(*get_other_traffic_selectors) (policy_t *this);
|
||||
|
||||
/**
|
||||
* @brief Select traffic selectors from a supplied list for local site.
|
||||
@@ -119,7 +96,7 @@ struct sa_config_t {
|
||||
* @param supplied linked list with traffic selectors
|
||||
* @return list containing the selected traffic selectors
|
||||
*/
|
||||
linked_list_t *(*select_my_traffic_selectors) (sa_config_t *this, linked_list_t *supplied);
|
||||
linked_list_t *(*select_my_traffic_selectors) (policy_t *this, linked_list_t *supplied);
|
||||
|
||||
/**
|
||||
* @brief Select traffic selectors from a supplied list for remote site.
|
||||
@@ -130,21 +107,21 @@ struct sa_config_t {
|
||||
* @param supplied linked list with traffic selectors
|
||||
* @return list containing the selected traffic selectors
|
||||
*/
|
||||
linked_list_t *(*select_other_traffic_selectors) (sa_config_t *this, linked_list_t *supplied);
|
||||
linked_list_t *(*select_other_traffic_selectors) (policy_t *this, linked_list_t *supplied);
|
||||
|
||||
/**
|
||||
* @brief Get the list of internally stored proposals.
|
||||
*
|
||||
* Rembember: sa_config_t does store proposals for AH/ESP,
|
||||
* IKE proposals are in the init_config_t
|
||||
* Rembember: policy_t does store proposals for AH/ESP,
|
||||
* IKE proposals are in the connection_t
|
||||
*
|
||||
* @warning List and Items are still owned by sa_config and MUST NOT
|
||||
* @warning List and Items are still owned by policy and MUST NOT
|
||||
* be manipulated or freed!
|
||||
*
|
||||
* @param this calling object
|
||||
* @return lists with proposals
|
||||
*/
|
||||
linked_list_t *(*get_proposals) (sa_config_t *this);
|
||||
linked_list_t *(*get_proposals) (policy_t *this);
|
||||
|
||||
/**
|
||||
* @brief Select a proposal from a supplied list.
|
||||
@@ -153,31 +130,31 @@ struct sa_config_t {
|
||||
* @param proposals list from from wich proposals are selected
|
||||
* @return selected proposal, or NULL if nothing matches
|
||||
*/
|
||||
proposal_t *(*select_proposal) (sa_config_t *this, linked_list_t *proposals);
|
||||
proposal_t *(*select_proposal) (policy_t *this, linked_list_t *proposals);
|
||||
|
||||
/**
|
||||
* @brief Add a traffic selector to the list for local site.
|
||||
*
|
||||
* After add, proposal is owned by sa_config.
|
||||
* After add, proposal is owned by policy.
|
||||
*
|
||||
* @warning Do not add while other threads are reading.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param traffic_selector traffic_selector to add
|
||||
*/
|
||||
void (*add_my_traffic_selector) (sa_config_t *this, traffic_selector_t *traffic_selector);
|
||||
void (*add_my_traffic_selector) (policy_t *this, traffic_selector_t *traffic_selector);
|
||||
|
||||
/**
|
||||
* @brief Add a traffic selector to the list for remote site.
|
||||
*
|
||||
* After add, proposal is owned by sa_config.
|
||||
* After add, proposal is owned by policy.
|
||||
*
|
||||
* @warning Do not add while other threads are reading.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param traffic_selector traffic_selector to add
|
||||
*/
|
||||
void (*add_other_traffic_selector) (sa_config_t *this, traffic_selector_t *traffic_selector);
|
||||
void (*add_other_traffic_selector) (policy_t *this, traffic_selector_t *traffic_selector);
|
||||
|
||||
/**
|
||||
* @brief Add a proposal to the list.
|
||||
@@ -190,30 +167,25 @@ struct sa_config_t {
|
||||
* @param this calling object
|
||||
* @param proposal proposal to add
|
||||
*/
|
||||
void (*add_proposal) (sa_config_t *this, proposal_t *proposal);
|
||||
void (*add_proposal) (policy_t *this, proposal_t *proposal);
|
||||
|
||||
/**
|
||||
* @brief Destroys the config object
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (sa_config_t *this);
|
||||
void (*destroy) (policy_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create a configuration object for IKE_AUTH and later.
|
||||
*
|
||||
* @param my_id_type type of my identification
|
||||
* @param my_id my identification as string
|
||||
* @param other_id_type type of other identification
|
||||
* @param other_id other identification as string
|
||||
* @param auth_method Method of authentication
|
||||
* @param ike_sa_lifetime lifetime of this IKE_SA in milliseconds. IKE_SA will be deleted
|
||||
* after this lifetime!
|
||||
* @return sa_config_t object
|
||||
* @param my_id identification_t for ourselves
|
||||
* @param other_id identification_t for the remote guy
|
||||
* @return policy_t object
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
sa_config_t *sa_config_create(id_type_t my_id_type, char *my_id, id_type_t other_id_type, char *other_id, auth_method_t auth_method, u_int32_t ike_sa_lifetime);
|
||||
policy_t *policy_create(identification_t *my_id, identification_t *other_id);
|
||||
|
||||
#endif //_SA_CONFIG_H_
|
||||
#endif /* POLICY_H_ */
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @file policy_store.h
|
||||
*
|
||||
* @brief Interface policy_store_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef POLICY_STORE_H_
|
||||
#define POLICY_STORE_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <config/policy.h>
|
||||
|
||||
|
||||
typedef struct policy_store_t policy_store_t;
|
||||
|
||||
/**
|
||||
* @brief The interface for a store of polcy_t's.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - policy_store_create()
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
struct policy_store_t {
|
||||
|
||||
/**
|
||||
* @brief Returns a policy identified by two IDs.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param my_id own ID of the policy
|
||||
* @param other_id others ID of the policy
|
||||
* @return
|
||||
* - matching policy_t, if found
|
||||
* - NULL otherwise
|
||||
*/
|
||||
policy_t *(*get_policy) (policy_store_t *this, identification_t *my_id, identification_t *other_id);
|
||||
|
||||
/**
|
||||
* @brief Destroys a policy_store_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (policy_store_t *this);
|
||||
};
|
||||
|
||||
#endif /*POLICY_STORE_H_*/
|
||||
@@ -20,8 +20,8 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef _PROPOSAL_H_
|
||||
#define _PROPOSAL_H_
|
||||
#ifndef PROPOSAL_H_
|
||||
#define PROPOSAL_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <utils/identification.h>
|
||||
@@ -258,4 +258,4 @@ struct proposal_t {
|
||||
*/
|
||||
proposal_t *proposal_create(u_int8_t number);
|
||||
|
||||
#endif //_PROPOSAL_H_
|
||||
#endif /* PROPOSAL_H_ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
* @file static_configuration_t.h
|
||||
*
|
||||
* @brief Interface of static_configuration_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef STATIC_CONFIGURATION_H_
|
||||
#define STATIC_CONFIGURATION_H_
|
||||
|
||||
#include <config/configuration.h>
|
||||
|
||||
|
||||
typedef struct static_configuration_t static_configuration_t;
|
||||
|
||||
/**
|
||||
* @brief A static hardcoded config for testing purposes.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - static_configuration_create()
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
struct static_configuration_t {
|
||||
|
||||
/**
|
||||
* Implements configuration_t interface
|
||||
*/
|
||||
configuration_t configuration_interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an static configuration
|
||||
*
|
||||
* @return static_configuration_t object
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
static_configuration_t *static_configuration_create();
|
||||
|
||||
#endif /*STATIC_CONFIGURATION_H_*/
|
||||
@@ -1,992 +0,0 @@
|
||||
/**
|
||||
* @file stroke_configuration.c
|
||||
*
|
||||
* @brief Implementation of stroke_configuration_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "stroke_configuration.h"
|
||||
|
||||
#include <types.h>
|
||||
#include <daemon.h>
|
||||
#include <utils/allocator.h>
|
||||
#include <queues/jobs/initiate_ike_sa_job.h>
|
||||
|
||||
/**
|
||||
* First retransmit timeout in milliseconds.
|
||||
*
|
||||
* Timeout value is increasing in each retransmit round.
|
||||
*/
|
||||
#define RETRANSMIT_TIMEOUT 3000
|
||||
|
||||
/**
|
||||
* Timeout in milliseconds after that a half open IKE_SA gets deleted.
|
||||
*/
|
||||
#define HALF_OPEN_IKE_SA_TIMEOUT 30000
|
||||
|
||||
/**
|
||||
* Max retransmit count.
|
||||
* 0 for infinite. The max time a half open IKE_SA is alive is set by
|
||||
* RETRANSMIT_TIMEOUT.
|
||||
*/
|
||||
#define MAX_RETRANSMIT_COUNT 0
|
||||
|
||||
|
||||
struct sockaddr_un socket_addr = { AF_UNIX, "/var/run/charon.ctl"};
|
||||
|
||||
|
||||
typedef struct preshared_secret_entry_t preshared_secret_entry_t;
|
||||
|
||||
/**
|
||||
* A preshared secret entry combines an identifier and a
|
||||
* preshared secret.
|
||||
*/
|
||||
struct preshared_secret_entry_t {
|
||||
|
||||
/**
|
||||
* Identification.
|
||||
*/
|
||||
identification_t *identification;
|
||||
|
||||
/**
|
||||
* Preshared secret as chunk_t. The NULL termination is not included.
|
||||
*/
|
||||
chunk_t preshared_secret;
|
||||
};
|
||||
|
||||
|
||||
typedef struct rsa_private_key_entry_t rsa_private_key_entry_t;
|
||||
|
||||
/**
|
||||
* Entry for a rsa private key.
|
||||
*/
|
||||
struct rsa_private_key_entry_t {
|
||||
|
||||
/**
|
||||
* Identification.
|
||||
*/
|
||||
identification_t *identification;
|
||||
|
||||
/**
|
||||
* Private key.
|
||||
*/
|
||||
rsa_private_key_t* private_key;
|
||||
};
|
||||
|
||||
typedef struct rsa_public_key_entry_t rsa_public_key_entry_t;
|
||||
|
||||
/**
|
||||
* Entry for a rsa private key.
|
||||
*/
|
||||
struct rsa_public_key_entry_t {
|
||||
|
||||
/**
|
||||
* Identification.
|
||||
*/
|
||||
identification_t *identification;
|
||||
|
||||
/**
|
||||
* Private key.
|
||||
*/
|
||||
rsa_public_key_t* public_key;
|
||||
};
|
||||
|
||||
typedef struct configuration_entry_t configuration_entry_t;
|
||||
|
||||
/**
|
||||
* A configuration entry combines a configuration name with a init and sa
|
||||
* configuration represented as init_config_t and sa_config_t objects.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - configuration_entry_create()
|
||||
*/
|
||||
struct configuration_entry_t {
|
||||
|
||||
/**
|
||||
* Configuration name.
|
||||
*
|
||||
*/
|
||||
char *name;
|
||||
|
||||
/**
|
||||
* Configuration for IKE_SA_INIT exchange.
|
||||
*/
|
||||
init_config_t *init_config;
|
||||
|
||||
/**
|
||||
* Configuration for all phases after IKE_SA_INIT exchange.
|
||||
*/
|
||||
sa_config_t *sa_config;
|
||||
|
||||
/**
|
||||
* Destroys a configuration_entry_t
|
||||
*
|
||||
* @param this calling object
|
||||
*/
|
||||
void (*destroy) (configuration_entry_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of configuration_entry_t.destroy.
|
||||
*/
|
||||
static void configuration_entry_destroy (configuration_entry_t *this)
|
||||
{
|
||||
allocator_free(this->name);
|
||||
allocator_free(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates a configuration_entry_t object.
|
||||
*
|
||||
* @param name name of the configuration entry (gets copied)
|
||||
* @param init_config object of type init_config_t
|
||||
* @param sa_config object of type sa_config_t
|
||||
*/
|
||||
static configuration_entry_t * configuration_entry_create(char * name, init_config_t * init_config, sa_config_t * sa_config)
|
||||
{
|
||||
configuration_entry_t *entry = allocator_alloc_thing(configuration_entry_t);
|
||||
|
||||
/* functions */
|
||||
entry->destroy = configuration_entry_destroy;
|
||||
|
||||
/* private data */
|
||||
entry->init_config = init_config;
|
||||
entry->sa_config = sa_config;
|
||||
entry->name = allocator_alloc(strlen(name) + 1);
|
||||
strcpy(entry->name,name);
|
||||
return entry;
|
||||
}
|
||||
|
||||
typedef struct private_stroke_configuration_t private_stroke_configuration_t;
|
||||
|
||||
/**
|
||||
* Private data of an stroke_configuration_t object.
|
||||
*/
|
||||
struct private_stroke_configuration_t {
|
||||
|
||||
/**
|
||||
* Public part of stroke_configuration_t object.
|
||||
*/
|
||||
stroke_configuration_t public;
|
||||
|
||||
/**
|
||||
* Holding all configurations.
|
||||
*/
|
||||
linked_list_t *configurations;
|
||||
|
||||
/**
|
||||
* Holding all managed init_configs.
|
||||
*/
|
||||
linked_list_t *init_configs;
|
||||
|
||||
/**
|
||||
* Holding all managed init_configs.
|
||||
*/
|
||||
linked_list_t *sa_configs;
|
||||
|
||||
/**
|
||||
* Holding all managed preshared secrets.
|
||||
*/
|
||||
linked_list_t *preshared_secrets;
|
||||
|
||||
/**
|
||||
* Holding all managed private secrets.
|
||||
*/
|
||||
linked_list_t *rsa_private_keys;
|
||||
|
||||
/**
|
||||
* Holding all managed public secrets.
|
||||
*/
|
||||
linked_list_t *rsa_public_keys;
|
||||
|
||||
/**
|
||||
* Assigned logger_t object.
|
||||
*/
|
||||
logger_t *logger;
|
||||
|
||||
/**
|
||||
* Max number of requests to be retransmitted.
|
||||
* 0 for infinite.
|
||||
*/
|
||||
u_int32_t max_retransmit_count;
|
||||
|
||||
/**
|
||||
* First retransmit timeout in ms.
|
||||
*/
|
||||
u_int32_t first_retransmit_timeout;
|
||||
|
||||
/**
|
||||
* Timeout in ms after that time a IKE_SA gets deleted.
|
||||
*/
|
||||
u_int32_t half_open_ike_sa_timeout;
|
||||
|
||||
int socket;
|
||||
|
||||
pthread_t assigned_thread;
|
||||
|
||||
/**
|
||||
* Adds a new IKE_SA configuration.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param name name for the configuration
|
||||
* @param init_config init_config_t object
|
||||
* @param sa_config sa_config_t object
|
||||
*/
|
||||
void (*add_new_configuration) (private_stroke_configuration_t *this, char *name, init_config_t *init_config, sa_config_t *sa_config);
|
||||
|
||||
/**
|
||||
* Adds a new preshared secret.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param type type of identification
|
||||
* @param id_string identification as string
|
||||
* @param preshared_secret preshared secret as string
|
||||
*/
|
||||
void (*add_new_preshared_secret) (private_stroke_configuration_t *this,id_type_t type, char *id_string, char *preshared_secret);
|
||||
|
||||
/**
|
||||
* Adds a new rsa private key.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param type type of identification
|
||||
* @param id_string identification as string
|
||||
* @param key_pos location of key
|
||||
* @param key_len length of key
|
||||
*/
|
||||
void (*add_new_rsa_private_key) (private_stroke_configuration_t *this,id_type_t type, char *id_string, u_int8_t *key_pos, size_t key_len);
|
||||
|
||||
/**
|
||||
* Adds a new rsa public key.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param type type of identification
|
||||
* @param id_string identification as string
|
||||
* @param key_pos location of key
|
||||
* @param key_len length of key
|
||||
*/
|
||||
void (*add_new_rsa_public_key) (private_stroke_configuration_t *this,id_type_t type, char *id_string, u_int8_t *key_pos, size_t key_len);
|
||||
|
||||
void (*whack_receive) (private_stroke_configuration_t *this);
|
||||
};
|
||||
|
||||
extern u_int8_t public_key_1[];
|
||||
extern u_int8_t private_key_1[];
|
||||
extern u_int8_t public_key_2[];
|
||||
extern u_int8_t private_key_2[];
|
||||
|
||||
static void fix_string(stroke_msg_t *msg, char **string)
|
||||
{
|
||||
/* check for sanity of string pointer and string */
|
||||
if (string < (char**)msg ||
|
||||
string > (char**)msg + sizeof(stroke_msg_t) ||
|
||||
*string < (char*)msg->buffer - (u_int)msg ||
|
||||
*string > (char*)(u_int)msg->length)
|
||||
{
|
||||
*string = "(invalid char* in stroke msg)";
|
||||
}
|
||||
else
|
||||
{
|
||||
*string = (char*)msg + (u_int)*string;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_stroke_configuration_t.listen.
|
||||
*/
|
||||
static void whack_receive(private_stroke_configuration_t *this)
|
||||
{
|
||||
stroke_msg_t *msg;
|
||||
u_int16_t msg_length;
|
||||
struct sockaddr_un whackaddr;
|
||||
int whackaddrlen = sizeof(whackaddr);
|
||||
ssize_t n;
|
||||
int whackfd;
|
||||
|
||||
while (1)
|
||||
{
|
||||
whackfd = accept(this->socket, (struct sockaddr *)&whackaddr, &whackaddrlen);
|
||||
|
||||
if (whackfd < 0)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "accepting stroke connection failed");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* peek the length */
|
||||
n = recv(whackfd, &msg_length, sizeof(msg_length), MSG_PEEK);
|
||||
if (n != sizeof(msg_length))
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "reading lenght of stroke message failed");
|
||||
close(whackfd);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* read message */
|
||||
msg = allocator_alloc(msg_length);
|
||||
n = recv(whackfd, msg, msg_length, 0);
|
||||
if (n != msg_length)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "reading stroke message failed");
|
||||
close(whackfd);
|
||||
continue;
|
||||
}
|
||||
|
||||
this->logger->log_bytes(this->logger, RAW|LEVEL1, "Whackinput", (void*)msg, msg_length);
|
||||
|
||||
switch (msg->type)
|
||||
{
|
||||
case STR_INITIATE:
|
||||
{
|
||||
initiate_ike_sa_job_t *job;
|
||||
fix_string(msg, &(msg->initiate.name));
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "received stroke: initiate \"%s\"", msg->initiate.name);
|
||||
job = initiate_ike_sa_job_create(msg->initiate.name);
|
||||
charon->job_queue->add(charon->job_queue, (job_t*)job);
|
||||
break;
|
||||
}
|
||||
case STR_INSTALL:
|
||||
{
|
||||
fix_string(msg, &(msg->install.name));
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "received stroke: install \"%s\"", msg->install.name);
|
||||
break;
|
||||
}
|
||||
case STR_ADD_CONN:
|
||||
{
|
||||
sa_config_t *sa_config;
|
||||
init_config_t *init_config;
|
||||
host_t *me, *other;
|
||||
proposal_t *proposal;
|
||||
traffic_selector_t *ts;
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "my id is: \"%p\"", msg->add_conn.me.id);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "other id is: \"%p\"", msg->add_conn.other.id);
|
||||
fix_string(msg, &msg->add_conn.name);
|
||||
fix_string(msg, &msg->add_conn.me.id);
|
||||
fix_string(msg, &msg->add_conn.other.id);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "received stroke: add connection \"%s\"", msg->add_conn.name);
|
||||
|
||||
msg->add_conn.me.address.v4.sin_port = htons(500);
|
||||
msg->add_conn.other.address.v4.sin_port = htons(500);
|
||||
me = host_create_from_sockaddr(&msg->add_conn.me.address.saddr);
|
||||
other = host_create_from_sockaddr(&msg->add_conn.other.address.saddr);
|
||||
|
||||
init_config = init_config_create(me, other);
|
||||
proposal = proposal_create(1);
|
||||
proposal->add_algorithm(proposal, IKE, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
|
||||
proposal->add_algorithm(proposal, IKE, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
|
||||
proposal->add_algorithm(proposal, IKE, PSEUDO_RANDOM_FUNCTION, PRF_HMAC_SHA1, 0);
|
||||
proposal->add_algorithm(proposal, IKE, DIFFIE_HELLMAN_GROUP, MODP_1024_BIT, 0);
|
||||
init_config->add_proposal(init_config, proposal);
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "my id is: \"%s\"", msg->add_conn.me.id);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "other id is: \"%s\"", msg->add_conn.other.id);
|
||||
|
||||
sa_config = sa_config_create(ID_IPV4_ADDR, msg->add_conn.me.id,
|
||||
ID_IPV4_ADDR, msg->add_conn.other.id,
|
||||
SHARED_KEY_MESSAGE_INTEGRITY_CODE, 30000);
|
||||
|
||||
this->add_new_preshared_secret(this, ID_IPV4_ADDR, "192.168.0.1","verschluesselt");
|
||||
this->add_new_preshared_secret(this, ID_IPV4_ADDR, "192.168.0.2","verschluesselt");
|
||||
|
||||
proposal = proposal_create(1);
|
||||
proposal->add_algorithm(proposal, ESP, ENCRYPTION_ALGORITHM, ENCR_AES_CBC, 16);
|
||||
proposal->add_algorithm(proposal, ESP, INTEGRITY_ALGORITHM, AUTH_HMAC_SHA1_96, 0);
|
||||
sa_config->add_proposal(sa_config, proposal);
|
||||
|
||||
me = host_create_from_sockaddr(&msg->add_conn.me.subnet.saddr);
|
||||
ts = traffic_selector_create_from_subnet(me, msg->add_conn.me.subnet_netbits);
|
||||
sa_config->add_my_traffic_selector(sa_config,ts);
|
||||
chunk_t chunk = ts->get_to_address(ts);
|
||||
this->logger->log_chunk(this->logger, CONTROL|LEVEL1, "my toaddr", &chunk);
|
||||
other = host_create_from_sockaddr(&msg->add_conn.other.subnet.saddr);
|
||||
ts = traffic_selector_create_from_subnet(other, msg->add_conn.other.subnet_netbits);
|
||||
sa_config->add_other_traffic_selector(sa_config,ts);
|
||||
chunk = ts->get_to_address(ts);
|
||||
this->logger->log_chunk(this->logger, CONTROL|LEVEL1, "other toaddr", &chunk);
|
||||
|
||||
this->add_new_configuration(this, msg->add_conn.name, init_config, sa_config);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "connection added \"%s\"", msg->add_conn.name);
|
||||
|
||||
break;
|
||||
}
|
||||
case STR_DEL_CONN:
|
||||
default:
|
||||
this->logger->log(this->logger, ERROR, "received invalid stroke");
|
||||
}
|
||||
|
||||
allocator_free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_init_config_for_host.
|
||||
*/
|
||||
static status_t get_init_config_for_host (private_stroke_configuration_t *this, host_t *my_host, host_t *other_host,init_config_t **init_config)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
status_t status = NOT_FOUND;
|
||||
|
||||
iterator = this->configurations->create_iterator(this->configurations,TRUE);
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL1, "getting config for hosts %s - %s",
|
||||
my_host->get_address(my_host), other_host->get_address(other_host));
|
||||
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
configuration_entry_t *entry;
|
||||
host_t *config_my_host;
|
||||
host_t *config_other_host;
|
||||
|
||||
iterator->current(iterator,(void **) &entry);
|
||||
|
||||
config_my_host = entry->init_config->get_my_host(entry->init_config);
|
||||
config_other_host = entry->init_config->get_other_host(entry->init_config);
|
||||
|
||||
/* first check if ip is equal */
|
||||
if(config_other_host->ip_is_equal(config_other_host,other_host))
|
||||
{
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "config entry with remote host %s",
|
||||
config_other_host->get_address(config_other_host));
|
||||
/* could be right one, check my_host for default route*/
|
||||
if (config_my_host->is_default_route(config_my_host))
|
||||
{
|
||||
*init_config = entry->init_config;
|
||||
status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
/* check now if host informations are the same */
|
||||
else if (config_my_host->ip_is_equal(config_my_host,my_host))
|
||||
{
|
||||
*init_config = entry->init_config;
|
||||
status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
/* Then check for wildcard hosts!
|
||||
* TODO
|
||||
* actually its only checked if other host with default route can be found! */
|
||||
else if (config_other_host->is_default_route(config_other_host))
|
||||
{
|
||||
/* could be right one, check my_host for default route*/
|
||||
if (config_my_host->is_default_route(config_my_host))
|
||||
{
|
||||
*init_config = entry->init_config;
|
||||
status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
/* check now if host informations are the same */
|
||||
else if (config_my_host->ip_is_equal(config_my_host,my_host))
|
||||
{
|
||||
*init_config = entry->init_config;
|
||||
status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iterator->destroy(iterator);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_init_config_for_name.
|
||||
*/
|
||||
static status_t get_init_config_for_name (private_stroke_configuration_t *this, char *name, init_config_t **init_config)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
status_t status = NOT_FOUND;
|
||||
|
||||
iterator = this->configurations->create_iterator(this->configurations,TRUE);
|
||||
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
configuration_entry_t *entry;
|
||||
iterator->current(iterator,(void **) &entry);
|
||||
|
||||
if (strcmp(entry->name,name) == 0)
|
||||
{
|
||||
|
||||
/* found configuration */
|
||||
*init_config = entry->init_config;
|
||||
status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
iterator->destroy(iterator);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_sa_config_for_name.
|
||||
*/
|
||||
static status_t get_sa_config_for_name (private_stroke_configuration_t *this, char *name, sa_config_t **sa_config)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
status_t status = NOT_FOUND;
|
||||
|
||||
iterator = this->configurations->create_iterator(this->configurations,TRUE);
|
||||
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
configuration_entry_t *entry;
|
||||
iterator->current(iterator,(void **) &entry);
|
||||
|
||||
if (strcmp(entry->name,name) == 0)
|
||||
{
|
||||
/* found configuration */
|
||||
*sa_config = entry->sa_config;
|
||||
status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
iterator->destroy(iterator);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_sa_config_for_init_config_and_id.
|
||||
*/
|
||||
static status_t get_sa_config_for_init_config_and_id (private_stroke_configuration_t *this, init_config_t *init_config, identification_t *other_id, identification_t *my_id,sa_config_t **sa_config)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
status_t status = NOT_FOUND;
|
||||
|
||||
iterator = this->configurations->create_iterator(this->configurations,TRUE);
|
||||
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
configuration_entry_t *entry;
|
||||
iterator->current(iterator,(void **) &entry);
|
||||
|
||||
if (entry->init_config == init_config)
|
||||
{
|
||||
identification_t *config_my_id = entry->sa_config->get_my_id(entry->sa_config);
|
||||
identification_t *config_other_id = entry->sa_config->get_other_id(entry->sa_config);
|
||||
|
||||
/* host informations seem to be the same */
|
||||
if (config_other_id->equals(config_other_id,other_id))
|
||||
{
|
||||
/* other ids seems to match */
|
||||
|
||||
if (my_id == NULL)
|
||||
{
|
||||
/* first matching one is selected */
|
||||
|
||||
/* TODO priorize found entries */
|
||||
*sa_config = entry->sa_config;
|
||||
status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
if (config_my_id->equals(config_my_id,my_id))
|
||||
{
|
||||
*sa_config = entry->sa_config;
|
||||
status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iterator->destroy(iterator);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_stroke_configuration_t.add_new_configuration.
|
||||
*/
|
||||
static void add_new_configuration (private_stroke_configuration_t *this, char *name, init_config_t *init_config, sa_config_t *sa_config)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
bool found;
|
||||
|
||||
iterator = this->init_configs->create_iterator(this->init_configs,TRUE);
|
||||
found = FALSE;
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
init_config_t *found_init_config;
|
||||
iterator->current(iterator,(void **) &found_init_config);
|
||||
if (init_config == found_init_config)
|
||||
{
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
if (!found)
|
||||
{
|
||||
this->init_configs->insert_first(this->init_configs,init_config);
|
||||
}
|
||||
|
||||
iterator = this->sa_configs->create_iterator(this->sa_configs,TRUE);
|
||||
found = FALSE;
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
sa_config_t *found_sa_config;
|
||||
iterator->current(iterator,(void **) &found_sa_config);
|
||||
if (sa_config == found_sa_config)
|
||||
{
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
if (!found)
|
||||
{
|
||||
this->sa_configs->insert_first(this->sa_configs,sa_config);
|
||||
}
|
||||
|
||||
this->configurations->insert_last(this->configurations,configuration_entry_create(name,init_config,sa_config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_stroke_configuration_t.add_new_preshared_secret.
|
||||
*/
|
||||
static void add_new_preshared_secret (private_stroke_configuration_t *this,id_type_t type, char *id_string, char *preshared_secret)
|
||||
{
|
||||
preshared_secret_entry_t *entry = allocator_alloc_thing(preshared_secret_entry_t);
|
||||
|
||||
entry->identification = identification_create_from_string(type,id_string);
|
||||
entry->preshared_secret.len = strlen(preshared_secret) + 1;
|
||||
entry->preshared_secret.ptr = allocator_alloc(entry->preshared_secret.len);
|
||||
memcpy(entry->preshared_secret.ptr,preshared_secret,entry->preshared_secret.len);
|
||||
|
||||
this->preshared_secrets->insert_last(this->preshared_secrets,entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_stroke_configuration_t.add_new_preshared_secret.
|
||||
*/
|
||||
static void add_new_rsa_public_key (private_stroke_configuration_t *this, id_type_t type, char *id_string, u_int8_t* key_pos, size_t key_len)
|
||||
{
|
||||
chunk_t key;
|
||||
key.ptr = key_pos;
|
||||
key.len = key_len;
|
||||
|
||||
rsa_public_key_entry_t *entry = allocator_alloc_thing(rsa_public_key_entry_t);
|
||||
|
||||
entry->identification = identification_create_from_string(type,id_string);
|
||||
entry->public_key = rsa_public_key_create();
|
||||
entry->public_key->set_key(entry->public_key, key);
|
||||
|
||||
this->rsa_public_keys->insert_last(this->rsa_public_keys, entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of private_stroke_configuration_t.add_new_preshared_secret.
|
||||
*/
|
||||
static void add_new_rsa_private_key (private_stroke_configuration_t *this, id_type_t type, char *id_string, u_int8_t* key_pos, size_t key_len)
|
||||
{
|
||||
chunk_t key;
|
||||
key.ptr = key_pos;
|
||||
key.len = key_len;
|
||||
|
||||
rsa_private_key_entry_t *entry = allocator_alloc_thing(rsa_private_key_entry_t);
|
||||
|
||||
entry->identification = identification_create_from_string(type,id_string);
|
||||
entry->private_key = rsa_private_key_create();
|
||||
entry->private_key->set_key(entry->private_key, key);
|
||||
|
||||
this->rsa_private_keys->insert_last(this->rsa_private_keys, entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_shared_secret.
|
||||
*/
|
||||
static status_t get_shared_secret(private_stroke_configuration_t *this, identification_t *identification, chunk_t *preshared_secret)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
|
||||
iterator = this->preshared_secrets->create_iterator(this->preshared_secrets,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
preshared_secret_entry_t *entry;
|
||||
iterator->current(iterator,(void **) &entry);
|
||||
if (entry->identification->equals(entry->identification,identification))
|
||||
{
|
||||
*preshared_secret = entry->preshared_secret;
|
||||
iterator->destroy(iterator);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_shared_secret.
|
||||
*/
|
||||
static status_t get_rsa_public_key(private_stroke_configuration_t *this, identification_t *identification, rsa_public_key_t **public_key)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
|
||||
iterator = this->rsa_public_keys->create_iterator(this->rsa_public_keys,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
rsa_public_key_entry_t *entry;
|
||||
iterator->current(iterator,(void **) &entry);
|
||||
if (entry->identification->equals(entry->identification,identification))
|
||||
{
|
||||
*public_key = entry->public_key;
|
||||
iterator->destroy(iterator);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_shared_secret.
|
||||
*/
|
||||
static status_t get_rsa_private_key(private_stroke_configuration_t *this, identification_t *identification, rsa_private_key_t **private_key)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
|
||||
iterator = this->rsa_private_keys->create_iterator(this->rsa_private_keys,TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
rsa_private_key_entry_t *entry;
|
||||
iterator->current(iterator,(void **) &entry);
|
||||
if (entry->identification->equals(entry->identification,identification))
|
||||
{
|
||||
*private_key = entry->private_key;
|
||||
iterator->destroy(iterator);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_retransmit_timeout.
|
||||
*/
|
||||
static status_t get_retransmit_timeout (private_stroke_configuration_t *this, u_int32_t retransmit_count, u_int32_t *timeout)
|
||||
{
|
||||
int new_timeout = this->first_retransmit_timeout, i;
|
||||
if ((retransmit_count > this->max_retransmit_count) && (this->max_retransmit_count != 0))
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < retransmit_count; i++)
|
||||
{
|
||||
new_timeout *= 2;
|
||||
}
|
||||
|
||||
*timeout = new_timeout;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.get_half_open_ike_sa_timeout.
|
||||
*/
|
||||
static u_int32_t get_half_open_ike_sa_timeout (private_stroke_configuration_t *this)
|
||||
{
|
||||
return this->half_open_ike_sa_timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of stroke_configuration_t.destroy.
|
||||
*/
|
||||
static void destroy(private_stroke_configuration_t *this)
|
||||
{
|
||||
this->logger->log(this->logger,CONTROL | LEVEL1, "Going to destroy configuration backend ");
|
||||
|
||||
this->logger->log(this->logger,CONTROL | LEVEL2, "Destroy configuration entries");
|
||||
while (this->configurations->get_count(this->configurations) > 0)
|
||||
{
|
||||
configuration_entry_t *entry;
|
||||
this->configurations->remove_first(this->configurations,(void **) &entry);
|
||||
entry->destroy(entry);
|
||||
}
|
||||
this->configurations->destroy(this->configurations);
|
||||
|
||||
this->logger->log(this->logger,CONTROL | LEVEL2, "Destroy sa_config_t objects");
|
||||
while (this->sa_configs->get_count(this->sa_configs) > 0)
|
||||
{
|
||||
sa_config_t *sa_config;
|
||||
this->sa_configs->remove_first(this->sa_configs,(void **) &sa_config);
|
||||
sa_config->destroy(sa_config);
|
||||
}
|
||||
|
||||
this->sa_configs->destroy(this->sa_configs);
|
||||
|
||||
this->logger->log(this->logger,CONTROL | LEVEL2, "Destroy init_config_t objects");
|
||||
while (this->init_configs->get_count(this->init_configs) > 0)
|
||||
{
|
||||
init_config_t *init_config;
|
||||
this->init_configs->remove_first(this->init_configs,(void **) &init_config);
|
||||
init_config->destroy(init_config);
|
||||
}
|
||||
this->init_configs->destroy(this->init_configs);
|
||||
|
||||
while (this->preshared_secrets->get_count(this->preshared_secrets) > 0)
|
||||
{
|
||||
preshared_secret_entry_t *entry;
|
||||
this->preshared_secrets->remove_first(this->preshared_secrets,(void **) &entry);
|
||||
entry->identification->destroy(entry->identification);
|
||||
allocator_free_chunk(&(entry->preshared_secret));
|
||||
allocator_free(entry);
|
||||
}
|
||||
this->preshared_secrets->destroy(this->preshared_secrets);
|
||||
|
||||
this->logger->log(this->logger,CONTROL | LEVEL2, "Destroy rsa private keys");
|
||||
while (this->rsa_private_keys->get_count(this->rsa_private_keys) > 0)
|
||||
{
|
||||
rsa_private_key_entry_t *entry;
|
||||
this->rsa_private_keys->remove_first(this->rsa_private_keys,(void **) &entry);
|
||||
entry->identification->destroy(entry->identification);
|
||||
entry->private_key->destroy(entry->private_key);
|
||||
allocator_free(entry);
|
||||
}
|
||||
this->rsa_private_keys->destroy(this->rsa_private_keys);
|
||||
|
||||
this->logger->log(this->logger,CONTROL | LEVEL2, "Destroy rsa public keys");
|
||||
while (this->rsa_public_keys->get_count(this->rsa_public_keys) > 0)
|
||||
{
|
||||
rsa_public_key_entry_t *entry;
|
||||
this->rsa_public_keys->remove_first(this->rsa_public_keys,(void **) &entry);
|
||||
entry->identification->destroy(entry->identification);
|
||||
entry->public_key->destroy(entry->public_key);
|
||||
allocator_free(entry);
|
||||
}
|
||||
this->rsa_public_keys->destroy(this->rsa_public_keys);
|
||||
|
||||
this->logger->log(this->logger,CONTROL | LEVEL2, "Destroy assigned logger");
|
||||
charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
|
||||
close(this->socket);
|
||||
unlink(socket_addr.sun_path);
|
||||
allocator_free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header-file
|
||||
*/
|
||||
stroke_configuration_t *stroke_configuration_create()
|
||||
{
|
||||
private_stroke_configuration_t *this = allocator_alloc_thing(private_stroke_configuration_t);
|
||||
mode_t old;
|
||||
bool on = TRUE;
|
||||
|
||||
/* public functions */
|
||||
this->public.configuration_interface.destroy = (void(*)(configuration_t*))destroy;
|
||||
this->public.configuration_interface.get_init_config_for_name = (status_t (*) (configuration_t *, char *, init_config_t **)) get_init_config_for_name;
|
||||
this->public.configuration_interface.get_init_config_for_host = (status_t (*) (configuration_t *, host_t *, host_t *,init_config_t **)) get_init_config_for_host;
|
||||
this->public.configuration_interface.get_sa_config_for_name =(status_t (*) (configuration_t *, char *, sa_config_t **)) get_sa_config_for_name;
|
||||
this->public.configuration_interface.get_sa_config_for_init_config_and_id =(status_t (*) (configuration_t *, init_config_t *, identification_t *, identification_t *,sa_config_t **)) get_sa_config_for_init_config_and_id;
|
||||
this->public.configuration_interface.get_retransmit_timeout = (status_t (*) (configuration_t *, u_int32_t retransmit_count, u_int32_t *timeout))get_retransmit_timeout;
|
||||
this->public.configuration_interface.get_half_open_ike_sa_timeout = (u_int32_t (*) (configuration_t *)) get_half_open_ike_sa_timeout;
|
||||
this->public.configuration_interface.get_shared_secret = (status_t (*) (configuration_t *, identification_t *, chunk_t *))get_shared_secret;
|
||||
this->public.configuration_interface.get_rsa_private_key = (status_t (*) (configuration_t *, identification_t *, rsa_private_key_t**))get_rsa_private_key;
|
||||
this->public.configuration_interface.get_rsa_public_key = (status_t (*) (configuration_t *, identification_t *, rsa_public_key_t**))get_rsa_public_key;
|
||||
|
||||
/* private functions */
|
||||
this->add_new_configuration = add_new_configuration;
|
||||
this->add_new_preshared_secret = add_new_preshared_secret;
|
||||
this->add_new_rsa_public_key = add_new_rsa_public_key;
|
||||
this->add_new_rsa_private_key = add_new_rsa_private_key;
|
||||
this->whack_receive = whack_receive;
|
||||
|
||||
this->logger = charon->logger_manager->create_logger(charon->logger_manager,CONFIG,NULL);
|
||||
|
||||
/* set up unix socket */
|
||||
this->socket = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (this->socket == -1)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "could not create whack socket");
|
||||
charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
|
||||
allocator_free(this);
|
||||
return NULL;
|
||||
}
|
||||
if (fcntl(this->socket, F_SETFD, FD_CLOEXEC) < 0)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "could not FD_CLOEXEC on whack socket");
|
||||
charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
|
||||
close(this->socket);
|
||||
allocator_free(this);
|
||||
return NULL;
|
||||
}
|
||||
if (setsockopt(this->socket, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) < 0)
|
||||
|
||||
old = umask(~S_IRWXU);
|
||||
if (bind(this->socket, (struct sockaddr *)&socket_addr, sizeof(socket_addr)) < 0)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "could not bind whack socket: %s", strerror(errno));
|
||||
charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
|
||||
close(this->socket);
|
||||
allocator_free(this);
|
||||
return NULL;
|
||||
}
|
||||
umask(old);
|
||||
|
||||
if (listen(this->socket, 0) < 0)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "could not listen on whack socket: %s", strerror(errno));
|
||||
charon->logger_manager->destroy_logger(charon->logger_manager,this->logger);
|
||||
close(this->socket);
|
||||
unlink(socket_addr.sun_path);
|
||||
allocator_free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* start a thread reading from the socket */
|
||||
if (pthread_create(&(this->assigned_thread), NULL, (void*(*)(void*))this->whack_receive, this) != 0)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "Could not spawn whack thread");
|
||||
charon->logger_manager->destroy_logger(charon->logger_manager, this->logger);
|
||||
close(this->socket);
|
||||
unlink(socket_addr.sun_path);
|
||||
allocator_free(this);
|
||||
}
|
||||
|
||||
/* private variables */
|
||||
this->configurations = linked_list_create();
|
||||
this->sa_configs = linked_list_create();
|
||||
this->init_configs = linked_list_create();
|
||||
this->preshared_secrets = linked_list_create();
|
||||
this->rsa_private_keys = linked_list_create();
|
||||
this->rsa_public_keys = linked_list_create();
|
||||
this->max_retransmit_count = MAX_RETRANSMIT_COUNT;
|
||||
this->first_retransmit_timeout = RETRANSMIT_TIMEOUT;
|
||||
this->half_open_ike_sa_timeout = HALF_OPEN_IKE_SA_TIMEOUT;
|
||||
|
||||
return (&this->public);
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
/**
|
||||
* @file stroke_configuration_t.h
|
||||
*
|
||||
* @brief Interface of stroke_configuration_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef STROKE_CONFIGURATION_H
|
||||
#define STROKE_CONFIGURATION_H
|
||||
|
||||
#include <config/configuration.h>
|
||||
|
||||
/**
|
||||
* @brief A message sent over the unix socket.
|
||||
*
|
||||
*/
|
||||
typedef struct stroke_msg_t stroke_msg_t;
|
||||
|
||||
struct stroke_msg_t {
|
||||
/* length of this message with all strings */
|
||||
u_int16_t length;
|
||||
/* type of the message */
|
||||
enum {
|
||||
/* initiate a connection */
|
||||
STR_INITIATE,
|
||||
/* install SPD entries for a connection */
|
||||
STR_INSTALL,
|
||||
/* add a connection */
|
||||
STR_ADD_CONN,
|
||||
/* delete a connection */
|
||||
STR_DEL_CONN,
|
||||
/* more to come */
|
||||
} type;
|
||||
union {
|
||||
/* data for STR_INITIATE, STR_INSTALL */
|
||||
struct {
|
||||
char *name;
|
||||
} initiate, install;
|
||||
/* data for STR_ADD_CONN */
|
||||
struct {
|
||||
char *name;
|
||||
struct {
|
||||
union {
|
||||
u_int16_t family;
|
||||
struct sockaddr saddr;
|
||||
struct sockaddr_in v4;
|
||||
struct sockaddr_in6 v6;
|
||||
} address;
|
||||
char *id;
|
||||
union {
|
||||
u_int16_t family;
|
||||
struct sockaddr saddr;
|
||||
struct sockaddr_in v4;
|
||||
struct sockaddr_in6 v6;
|
||||
} subnet;
|
||||
u_int8_t subnet_netbits;
|
||||
} me, other;
|
||||
} add_conn;
|
||||
};
|
||||
u_int8_t buffer[];
|
||||
};
|
||||
|
||||
|
||||
typedef struct stroke_configuration_t stroke_configuration_t;
|
||||
|
||||
/**
|
||||
* @brief A config backend which uses a unix socket.
|
||||
*
|
||||
* Allows config manipulation (as whack in pluto). This config
|
||||
* is used by the ipsec_starter utility. This configuration
|
||||
* implementation opens a socket at /var/run/charon.ctl and
|
||||
* waits for input from ipsec starter.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - stroke_configuration_create()
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
struct stroke_configuration_t {
|
||||
|
||||
/**
|
||||
* Implements configuration_t interface
|
||||
*/
|
||||
configuration_t configuration_interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an configuration with a unix socket interface.
|
||||
*
|
||||
* @return stroke_configuration_t object
|
||||
*
|
||||
* @ingroup config
|
||||
*/
|
||||
stroke_configuration_t *stroke_configuration_create();
|
||||
|
||||
#endif /*STROKE_CONFIGURATION_H*/
|
||||
@@ -218,7 +218,6 @@ static u_int8_t get_netmask(private_traffic_selector_t *this)
|
||||
u_int32_t from, to, bit;
|
||||
from = htonl(this->from_addr_ipv4);
|
||||
to = htonl(this->to_addr_ipv4);
|
||||
printf("%x - %x\n", from, to);
|
||||
for (bit = 0; bit < 32; bit++)
|
||||
{
|
||||
if ((1<<bit & from) != (1<<bit & to))
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef _TRAFFIC_SELECTOR_H_
|
||||
#define _TRAFFIC_SELECTOR_H_
|
||||
#ifndef TRAFFIC_SELECTOR_H_
|
||||
#define TRAFFIC_SELECTOR_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <network/host.h>
|
||||
@@ -224,4 +224,4 @@ traffic_selector_t *traffic_selector_create_from_bytes(u_int8_t protocol, ts_typ
|
||||
|
||||
traffic_selector_t *traffic_selector_create_from_subnet(host_t *net, u_int8_t netbits);
|
||||
|
||||
#endif //_TRAFFIC_SELECTOR_H_
|
||||
#endif /* TRAFFIC_SELECTOR_H_ */
|
||||
|
||||
Reference in New Issue
Block a user