This commit is contained in:
@@ -31,7 +31,6 @@
|
|||||||
#include "payloads/nonce_payload.h"
|
#include "payloads/nonce_payload.h"
|
||||||
#include "payloads/proposal_substructure.h"
|
#include "payloads/proposal_substructure.h"
|
||||||
#include "payloads/ke_payload.h"
|
#include "payloads/ke_payload.h"
|
||||||
#include "payloads/transform_substructure.h"
|
|
||||||
#include "payloads/transform_attribute.h"
|
#include "payloads/transform_attribute.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,6 +237,17 @@ static status_t select_proposals_for_host(private_configuration_manager_t *this,
|
|||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static status_t is_dh_group_allowed_for_host(private_configuration_manager_t *this, host_t *host, diffie_hellman_group_t group, bool *allowed)
|
||||||
|
{
|
||||||
|
if (group == MODP_768_BIT ||
|
||||||
|
group == MODP_1024_BIT)
|
||||||
|
{
|
||||||
|
*allowed = TRUE;
|
||||||
|
}
|
||||||
|
*allowed = FALSE;
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements function destroy of configuration_t.
|
* Implements function destroy of configuration_t.
|
||||||
@@ -266,7 +276,7 @@ configuration_manager_t *configuration_manager_create()
|
|||||||
this->public.get_local_host = (status_t(*)(configuration_manager_t*,char*,host_t**))get_local_host;
|
this->public.get_local_host = (status_t(*)(configuration_manager_t*,char*,host_t**))get_local_host;
|
||||||
this->public.get_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,linked_list_iterator_t*))get_proposals_for_host;
|
this->public.get_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,linked_list_iterator_t*))get_proposals_for_host;
|
||||||
this->public.select_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,linked_list_iterator_t*,linked_list_iterator_t*))select_proposals_for_host;
|
this->public.select_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,linked_list_iterator_t*,linked_list_iterator_t*))select_proposals_for_host;
|
||||||
|
this->public.is_dh_group_allowed_for_host = (status_t(*)(configuration_manager_t*,host_t*,diffie_hellman_group_t,bool*)) is_dh_group_allowed_for_host;
|
||||||
|
|
||||||
return (&this->public);
|
return (&this->public);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "utils/linked_list.h"
|
#include "utils/linked_list.h"
|
||||||
#include "utils/host.h"
|
#include "utils/host.h"
|
||||||
|
#include "payloads/transform_substructure.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Manages all configuration aspects of the daemon.
|
* @brief Manages all configuration aspects of the daemon.
|
||||||
@@ -41,7 +42,9 @@ struct configuration_manager_s {
|
|||||||
|
|
||||||
status_t (*get_proposals_for_host) (configuration_manager_t *this, host_t *host, linked_list_iterator_t *list);
|
status_t (*get_proposals_for_host) (configuration_manager_t *this, host_t *host, linked_list_iterator_t *list);
|
||||||
|
|
||||||
status_t (*select_proposals_for_host) (configuration_manager_t *this, host_t *host, linked_list_iterator_t *in, linked_list_iterator_t *out);
|
status_t (*select_proposals_for_host) (configuration_manager_t *this, host_t *host, linked_list_iterator_t *in, linked_list_iterator_t *out);
|
||||||
|
|
||||||
|
status_t (*is_dh_group_allowed_for_host) (configuration_manager_t *this, host_t *host, diffie_hellman_group_t group, bool *allowed);
|
||||||
|
|
||||||
status_t (*destroy) (configuration_manager_t *this);
|
status_t (*destroy) (configuration_manager_t *this);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -141,11 +141,11 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i<10; i++)
|
for(i = 0; i<1; i++)
|
||||||
{
|
{
|
||||||
initiate_ike_sa_job_t *initiate_job;
|
initiate_ike_sa_job_t *initiate_job;
|
||||||
|
|
||||||
initiate_job = initiate_ike_sa_job_create("pinflb31");
|
initiate_job = initiate_ike_sa_job_create("pinflb30");
|
||||||
global_event_queue->add_relative(global_event_queue, (job_t*)initiate_job, i * 1000);
|
global_event_queue->add_relative(global_event_queue, (job_t*)initiate_job, i * 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+148
-42
@@ -25,10 +25,12 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "definitions.h"
|
||||||
#include "utils/allocator.h"
|
#include "utils/allocator.h"
|
||||||
#include "utils/linked_list.h"
|
#include "utils/linked_list.h"
|
||||||
#include "utils/logger_manager.h"
|
#include "utils/logger_manager.h"
|
||||||
#include "utils/randomizer.h"
|
#include "utils/randomizer.h"
|
||||||
|
#include "transforms/diffie_hellman.h"
|
||||||
#include "payloads/sa_payload.h"
|
#include "payloads/sa_payload.h"
|
||||||
#include "payloads/nonce_payload.h"
|
#include "payloads/nonce_payload.h"
|
||||||
#include "payloads/ke_payload.h"
|
#include "payloads/ke_payload.h"
|
||||||
@@ -72,6 +74,18 @@ enum ike_sa_state_e {
|
|||||||
IKE_SA_INITIALIZED = 5
|
IKE_SA_INITIALIZED = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* string mappings for ike_sa_state
|
||||||
|
*/
|
||||||
|
mapping_t ike_sa_state_m[] = {
|
||||||
|
{NO_STATE, "NO_STATE"},
|
||||||
|
{IKE_SA_INIT_REQUESTED, "IKE_SA_INIT_REQUESTED"},
|
||||||
|
{IKE_SA_INIT_RESPONDED, "IKE_SA_INIT_RESPONDED"},
|
||||||
|
{IKE_AUTH_REQUESTED, "IKE_AUTH_REQUESTED"},
|
||||||
|
{IKE_SA_INITIALIZED, "IKE_SA_INITIALIZED"},
|
||||||
|
{MAPPING_END, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data of an message_t object
|
* Private data of an message_t object
|
||||||
@@ -89,6 +103,9 @@ struct private_ike_sa_s {
|
|||||||
status_t (*build_nonce_payload) (private_ike_sa_t *this, nonce_payload_t **payload);
|
status_t (*build_nonce_payload) (private_ike_sa_t *this, nonce_payload_t **payload);
|
||||||
status_t (*build_ke_payload) (private_ike_sa_t *this, ke_payload_t **payload);
|
status_t (*build_ke_payload) (private_ike_sa_t *this, ke_payload_t **payload);
|
||||||
|
|
||||||
|
status_t (*transto_ike_sa_init_responded) (private_ike_sa_t *this, message_t *message);
|
||||||
|
status_t (*transto_ike_auth_requested) (private_ike_sa_t *this, message_t *message);
|
||||||
|
|
||||||
/* Private values */
|
/* Private values */
|
||||||
/**
|
/**
|
||||||
* Identifier for the current IKE_SA
|
* Identifier for the current IKE_SA
|
||||||
@@ -103,7 +120,7 @@ struct private_ike_sa_s {
|
|||||||
/**
|
/**
|
||||||
* Current state of the IKE_SA
|
* Current state of the IKE_SA
|
||||||
*/
|
*/
|
||||||
ike_sa_state_t current_state;
|
ike_sa_state_t state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* is this IKE_SA the original initiator of this IKE_SA
|
* is this IKE_SA the original initiator of this IKE_SA
|
||||||
@@ -125,6 +142,8 @@ struct private_ike_sa_s {
|
|||||||
host_t *host;
|
host_t *host;
|
||||||
} other;
|
} other;
|
||||||
|
|
||||||
|
diffie_hellman_t *diffie_hellman;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a logger for this IKE_SA
|
* a logger for this IKE_SA
|
||||||
*/
|
*/
|
||||||
@@ -136,53 +155,135 @@ struct private_ike_sa_s {
|
|||||||
*/
|
*/
|
||||||
static status_t process_message (private_ike_sa_t *this, message_t *message)
|
static status_t process_message (private_ike_sa_t *this, message_t *message)
|
||||||
{
|
{
|
||||||
status_t status;
|
this->logger->log(this->logger, CONTROL|MORE, "Process message of exchange type %s",
|
||||||
/* @TODO Add Message Processing here */
|
mapping_find(exchange_type_m,message->get_exchange_type(message)));
|
||||||
|
|
||||||
this->logger->log(this->logger, CONTROL|MORE, "Process message of exchange type %s",mapping_find(exchange_type_m,message->get_exchange_type(message)));
|
switch (message->get_exchange_type(message))
|
||||||
|
|
||||||
/* parse body */
|
|
||||||
status = message->parse_body(message);
|
|
||||||
switch (status)
|
|
||||||
{
|
{
|
||||||
case SUCCESS:
|
case IKE_SA_INIT:
|
||||||
{
|
{
|
||||||
break;
|
if (message->get_request(message)) {
|
||||||
}
|
if (this->state == NO_STATE)
|
||||||
|
{
|
||||||
|
/* state transission NO_STATE => IKE_SA_INIT_RESPONDED */
|
||||||
|
return this->transto_ike_sa_init_responded(this, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (this->state == IKE_SA_INIT_REQUESTED)
|
||||||
|
{
|
||||||
|
/* state transission IKE_SA_INIT_REQUESTED => IKE_AUTH_REQUESTED*/
|
||||||
|
return this->transto_ike_auth_requested(this, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case IKE_AUTH:
|
||||||
|
{
|
||||||
|
/* break; */
|
||||||
|
}
|
||||||
|
case CREATE_CHILD_SA:
|
||||||
|
{
|
||||||
|
/* break; */
|
||||||
|
}
|
||||||
|
case INFORMATIONAL:
|
||||||
|
{
|
||||||
|
/* break; */
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
this->logger->log(this->logger, ERROR, "Error of type %s while parsing message body",mapping_find(status_m,status));
|
this->logger->log(this->logger, ERROR, "processing %s-message not supported.",
|
||||||
switch (this->current_state)
|
mapping_find(exchange_type_m,message->get_exchange_type(message)));
|
||||||
{
|
return NOT_SUPPORTED;
|
||||||
case NO_STATE:
|
}
|
||||||
{
|
}
|
||||||
job_t *delete_job;
|
this->logger->log(this->logger, ERROR, "received %s-message in state %s, rejected.",
|
||||||
/* create delete job for this ike_sa */
|
mapping_find(exchange_type_m, message->get_exchange_type(message)),
|
||||||
delete_job = (job_t *) delete_ike_sa_job_create(this->ike_sa_id);
|
mapping_find(ike_sa_state_m, this->state));
|
||||||
if (delete_job == NULL)
|
return INVALID_STATE;
|
||||||
{
|
}
|
||||||
this->logger->log(this->logger, ERROR, "Job to delete IKE SA could not be created");
|
|
||||||
}
|
|
||||||
|
|
||||||
status = global_job_queue->add(global_job_queue,delete_job);
|
|
||||||
if (status != SUCCESS)
|
|
||||||
{
|
|
||||||
this->logger->log(this->logger, ERROR, "%s Job to delete IKE SA could not be added to job queue",mapping_find(status_m,status));
|
|
||||||
delete_job->destroy_all(delete_job);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
static status_t transto_ike_sa_init_responded(private_ike_sa_t *this, message_t *message)
|
||||||
default:
|
{
|
||||||
{
|
status_t status;
|
||||||
break;
|
linked_list_iterator_t *payloads;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return FAILED;
|
status = message->parse_body(message);
|
||||||
}
|
if (status != SUCCESS)
|
||||||
|
{
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
status = message->get_payload_iterator(message, &payloads);
|
||||||
|
if (status != SUCCESS)
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
while (payloads->has_next(payloads))
|
||||||
|
{
|
||||||
|
payload_t *payload;
|
||||||
|
payloads->current(payloads, (void**)payload);
|
||||||
|
switch (payload->get_type(payload))
|
||||||
|
{
|
||||||
|
case SECURITY_ASSOCIATION:
|
||||||
|
{
|
||||||
|
sa_payload_t *sa_payload;
|
||||||
|
linked_list_iterator_t *proposals;
|
||||||
|
|
||||||
|
sa_payload = (sa_payload_t*)payload;
|
||||||
|
status = sa_payload->create_proposal_substructure_iterator(sa_payload, &proposals, TRUE);
|
||||||
|
if (status != SUCCESS)
|
||||||
|
{
|
||||||
|
payloads->destroy(payloads);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
//global_configuration_manager->select_prop
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KEY_EXCHANGE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NONCE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
job_t *delete_job;
|
||||||
|
delete_job = (job_t *) delete_ike_sa_job_create(this->ike_sa_id);
|
||||||
|
if (delete_job == NULL)
|
||||||
|
{
|
||||||
|
this->logger->log(this->logger, ERROR, "Job to delete IKE SA could not be created");
|
||||||
|
}
|
||||||
|
|
||||||
|
status = global_job_queue->add(global_job_queue,delete_job);
|
||||||
|
if (status != SUCCESS)
|
||||||
|
{
|
||||||
|
this->logger->log(this->logger, ERROR, "%s Job to delete IKE SA could not be added to job queue",mapping_find(status_m,status));
|
||||||
|
delete_job->destroy_all(delete_job);
|
||||||
|
}*/
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static status_t transto_ike_auth_requested(private_ike_sa_t *this, message_t *message)
|
||||||
|
{
|
||||||
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,7 +372,7 @@ static status_t initialize_connection(private_ike_sa_t *this, char *name)
|
|||||||
|
|
||||||
message->destroy(message);
|
message->destroy(message);
|
||||||
|
|
||||||
this->current_state = IKE_SA_INIT_REQUESTED;
|
this->state = IKE_SA_INIT_REQUESTED;
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -427,6 +528,10 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
|||||||
this->build_nonce_payload = build_nonce_payload;
|
this->build_nonce_payload = build_nonce_payload;
|
||||||
|
|
||||||
|
|
||||||
|
this->transto_ike_sa_init_responded = transto_ike_sa_init_responded;
|
||||||
|
this->transto_ike_auth_requested = transto_ike_auth_requested;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* initialize private fields */
|
/* initialize private fields */
|
||||||
if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
|
if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
|
||||||
@@ -468,10 +573,11 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
|
|||||||
|
|
||||||
this->me.host = NULL;
|
this->me.host = NULL;
|
||||||
this->other.host = NULL;
|
this->other.host = NULL;
|
||||||
|
this->diffie_hellman = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* at creation time, IKE_SA isn't in a specific state */
|
/* at creation time, IKE_SA isn't in a specific state */
|
||||||
this->current_state = NO_STATE;
|
this->state = NO_STATE;
|
||||||
|
|
||||||
return (&this->public);
|
return (&this->public);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,6 +430,12 @@ static status_t get_destination(private_message_t *this, host_t **host)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static status_t get_payload_iterator(private_message_t *this, linked_list_iterator_t **iterator)
|
||||||
|
{
|
||||||
|
return this->payloads->create_iterator(this->payloads, iterator, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements message_t's generate function.
|
* Implements message_t's generate function.
|
||||||
* See #message_s.generate.
|
* See #message_s.generate.
|
||||||
@@ -776,6 +782,7 @@ message_t *message_create_from_packet(packet_t *packet)
|
|||||||
this->public.get_source = (status_t (*) (message_t*,host_t**)) get_source;
|
this->public.get_source = (status_t (*) (message_t*,host_t**)) get_source;
|
||||||
this->public.set_destination = (status_t (*) (message_t*,host_t*)) set_destination;
|
this->public.set_destination = (status_t (*) (message_t*,host_t*)) set_destination;
|
||||||
this->public.get_destination = (status_t (*) (message_t*,host_t**)) get_destination;
|
this->public.get_destination = (status_t (*) (message_t*,host_t**)) get_destination;
|
||||||
|
this->public.get_payload_iterator = (status_t (*) (message_t *, linked_list_iterator_t **)) get_payload_iterator;
|
||||||
this->public.parse_header = (status_t (*) (message_t *)) parse_header;
|
this->public.parse_header = (status_t (*) (message_t *)) parse_header;
|
||||||
this->public.parse_body = (status_t (*) (message_t *)) parse_body;
|
this->public.parse_body = (status_t (*) (message_t *)) parse_body;
|
||||||
this->public.destroy = (status_t(*)(message_t*))destroy;
|
this->public.destroy = (status_t(*)(message_t*))destroy;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "ike_sa_id.h"
|
#include "ike_sa_id.h"
|
||||||
#include "payloads/ike_header.h"
|
#include "payloads/ike_header.h"
|
||||||
|
#include "utils/linked_list.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -223,6 +224,7 @@ struct message_s {
|
|||||||
status_t (*set_source) (message_t *this, host_t *host);
|
status_t (*set_source) (message_t *this, host_t *host);
|
||||||
status_t (*get_destination) (message_t *this, host_t **host);
|
status_t (*get_destination) (message_t *this, host_t **host);
|
||||||
status_t (*set_destination) (message_t *this, host_t *host);
|
status_t (*set_destination) (message_t *this, host_t *host);
|
||||||
|
status_t (*get_payload_iterator) (message_t *this, linked_list_iterator_t **iterator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroys a message and all including objects
|
* @brief Destroys a message and all including objects
|
||||||
|
|||||||
Reference in New Issue
Block a user