From 55f90b5d518845509a1cbadbe12f097fa44c7133 Mon Sep 17 00:00:00 2001 From: Jan Hutter Date: Mon, 21 Nov 2005 17:50:56 +0000 Subject: [PATCH] - allready partly working --- Source/charon/configuration_manager.c | 2 +- Source/charon/ike_sa.c | 53 ++++++++++++-------- Source/charon/message.c | 12 +---- Source/charon/states/ike_sa_init_requested.c | 34 ++++++++++--- Source/charon/states/initiator_init.c | 4 ++ Source/charon/states/responder_init.c | 43 +++++++++++++++- Source/charon/thread_pool.c | 8 +-- Source/charon/utils/logger_manager.c | 1 + 8 files changed, 111 insertions(+), 46 deletions(-) diff --git a/Source/charon/configuration_manager.c b/Source/charon/configuration_manager.c index b7ffbc0a9..df6f9af22 100644 --- a/Source/charon/configuration_manager.c +++ b/Source/charon/configuration_manager.c @@ -52,7 +52,7 @@ static status_t get_remote_host(private_configuration_manager_t *this, char *nam /* some hard coded users for testing */ host_t *remote; if (strcmp(name, "pinflb30") == 0) { - remote = host_create(AF_INET, "152.96.193.130", 500); + remote = host_create(AF_INET, "152.96.193.131", 500); if (remote == NULL) { return OUT_OF_RES; } diff --git a/Source/charon/ike_sa.c b/Source/charon/ike_sa.c index 3d0a5c165..ab4d3e577 100644 --- a/Source/charon/ike_sa.c +++ b/Source/charon/ike_sa.c @@ -95,6 +95,7 @@ static status_t process_message (protected_ike_sa_t *this, message_t *message) /* now the message is processed by the current state object */ status = this->current_state->process_message(this->current_state,message,&new_state); + if (status == SUCCESS) { this->current_state = new_state; @@ -285,25 +286,27 @@ static status_t destroy (protected_ike_sa_t *this) this->logger->log(this->logger, CONTROL | MOST, "Destroy randomizer"); this->randomizer->destroy(this->randomizer); -// if (this->me.host != NULL) -// { -// this->logger->log(this->logger, CONTROL | MOST, "Destroy host informations of me"); -// this->me.host->destroy(this->me.host); -// } -// -// if (this->other.host != NULL) -// { -// this->logger->log(this->logger, CONTROL | MOST, "Destroy host informations of other"); -// this->other.host->destroy(this->other.host); -// } -// -// this->logger->log(this->logger, CONTROL | MOST, "Destroy current state object"); -// this->current_state->destroy(this->current_state); -// -// this->logger->log(this->logger, CONTROL | MOST, "Destroy logger of IKE_SA"); -// global_logger_manager->destroy_logger(global_logger_manager, this->logger); -// -// allocator_free(this); + if (this->me.host != NULL) + { + this->logger->log(this->logger, CONTROL | MOST, "Destroy host informations of me"); + this->me.host->destroy(this->me.host); + } + + if (this->other.host != NULL) + { + this->logger->log(this->logger, CONTROL | MOST, "Destroy host informations of other"); + this->other.host->destroy(this->other.host); + } + + this->logger->log(this->logger, CONTROL | MOST, "Destroy current state object"); + this->current_state->destroy(this->current_state); + + this->logger->log(this->logger, CONTROL | MOST, "Destroy logger of IKE_SA"); + + + global_logger_manager->destroy_logger(global_logger_manager, this->logger); + + allocator_free(this); return SUCCESS; } @@ -379,7 +382,17 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id) { this->current_state = (state_t *) responder_init_create(this); } + + if (this->current_state == NULL) + { + this->logger->log(this->logger, ERROR, "Fatal error: Could not create state object"); + this->child_sas->destroy(this->child_sas); + this->ike_sa_id->destroy(this->ike_sa_id); + global_logger_manager->destroy_logger(global_logger_manager,this->logger); + this->randomizer->destroy(this->randomizer); + allocator_free(this); + } - return (&this->public); + return &(this->public); } diff --git a/Source/charon/message.c b/Source/charon/message.c index 607585615..a97d182df 100644 --- a/Source/charon/message.c +++ b/Source/charon/message.c @@ -458,12 +458,6 @@ static status_t generate(private_message_t *this, packet_t **packet) this->logger->log(this->logger, CONTROL, "generating message, contains %d payloads", this->payloads->get_count(this->payloads)); - if (this->packet != NULL) - { - /* already generated packet is just cloned */ - this->packet->clone(this->packet, packet); - } - if (this->exchange_type == EXCHANGE_TYPE_UNDEFINED) { this->logger->log(this->logger, ERROR, "exchange type is not defined"); @@ -754,10 +748,8 @@ static status_t destroy (private_message_t *this) { linked_list_iterator_t *iterator; - if (this->packet != NULL) - { - this->packet->destroy(this->packet); - } + this->packet->destroy(this->packet); + if (this->ike_sa_id != NULL) { this->ike_sa_id->destroy(this->ike_sa_id); diff --git a/Source/charon/states/ike_sa_init_requested.c b/Source/charon/states/ike_sa_init_requested.c index 81a10043e..6ac8777b8 100644 --- a/Source/charon/states/ike_sa_init_requested.c +++ b/Source/charon/states/ike_sa_init_requested.c @@ -165,9 +165,11 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t } status = dh->get_shared_secret(dh, &shared_secret); - + this->logger->log_chunk(this->logger, RAW, "Shared secret", &shared_secret); + allocator_free_chunk(shared_secret); + break; } case NONCE: @@ -196,14 +198,17 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t } payloads->destroy(payloads); - /* set up the reply */ - status = this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, FALSE, &response); - if (status != SUCCESS) - { - return status; - } - response->destroy(response); + /* set up the reply */ +// status = this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, FALSE, &response); +// if (status != SUCCESS) +// { +// return status; +// } + +// response->destroy(response); + + *new_state = this; return SUCCESS; } @@ -221,6 +226,19 @@ static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this) */ static status_t destroy(private_ike_sa_init_requested_t *this) { + this->logger->log(this->logger, CONTROL | MORE, "Going to destroy state of type ike_sa_init_requested_t"); + this->diffie_hellman->destroy(this->diffie_hellman); + if (this->sent_nonce.ptr != NULL) + { + this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce"); + allocator_free(this->sent_nonce.ptr); + } + if (this->received_nonce.ptr != NULL) + { + this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce"); + allocator_free(this->received_nonce.ptr); + } + allocator_free(this); return SUCCESS; } diff --git a/Source/charon/states/initiator_init.c b/Source/charon/states/initiator_init.c index 8fc6f4dd4..b2e6f93c2 100644 --- a/Source/charon/states/initiator_init.c +++ b/Source/charon/states/initiator_init.c @@ -304,6 +304,7 @@ static status_t build_sa_payload(private_initiator_init_t *this, payload_t **pay if (status != SUCCESS) { this->logger->log(this->logger, ERROR, "Could not get current proposal needed to copy"); + proposal_iterator->destroy(proposal_iterator); sa_payload->destroy(sa_payload); return status; } @@ -311,6 +312,7 @@ static status_t build_sa_payload(private_initiator_init_t *this, payload_t **pay if (status != SUCCESS) { this->logger->log(this->logger, ERROR, "Could not clone current proposal"); + proposal_iterator->destroy(proposal_iterator); sa_payload->destroy(sa_payload); return status; } @@ -319,11 +321,13 @@ static status_t build_sa_payload(private_initiator_init_t *this, payload_t **pay if (status != SUCCESS) { this->logger->log(this->logger, ERROR, "Could not add cloned proposal to SA payload"); + proposal_iterator->destroy(proposal_iterator); sa_payload->destroy(sa_payload); return status; } } + proposal_iterator->destroy(proposal_iterator); this->logger->log(this->logger, CONTROL|MORE, "sa payload builded"); diff --git a/Source/charon/states/responder_init.c b/Source/charon/states/responder_init.c index 9fc744f2e..b0cfd9e52 100644 --- a/Source/charon/states/responder_init.c +++ b/Source/charon/states/responder_init.c @@ -255,6 +255,17 @@ static status_t process_message(private_responder_init_t *this, message_t *messa } /* iterator can be destroyed */ payloads->destroy(payloads); + + /********************/ + diffie_hellman_t *dh = this->diffie_hellman; + chunk_t shared_secret; + + status = dh->get_shared_secret(dh, &shared_secret); + this->logger->log_chunk(this->logger, RAW, "Shared secret", &shared_secret); + + allocator_free_chunk(shared_secret); + /********************/ + this->logger->log(this->logger, CONTROL | MORE, "Request successfully handled. Going to create reply."); @@ -350,7 +361,8 @@ static status_t process_message(private_responder_init_t *this, message_t *messa /* state has NOW changed :-) */ // this ->logger->log(this->logger, CONTROL|MORE, "Change state of IKE_SA from %s to %s",mapping_find(ike_sa_state_m,this->state),mapping_find(ike_sa_state_m,IKE_SA_INIT_REQUESTED) ); - + + *new_state = &(this->public.state_interface); return SUCCESS; } @@ -391,6 +403,7 @@ static status_t build_sa_payload(private_responder_init_t *this, payload_t **pay if (status != SUCCESS) { this->logger->log(this->logger, ERROR, "Could not get current proposal needed to copy"); + proposal_iterator->destroy(proposal_iterator); sa_payload->destroy(sa_payload); return status; } @@ -398,6 +411,7 @@ static status_t build_sa_payload(private_responder_init_t *this, payload_t **pay if (status != SUCCESS) { this->logger->log(this->logger, ERROR, "Could not clone current proposal"); + proposal_iterator->destroy(proposal_iterator); sa_payload->destroy(sa_payload); return status; } @@ -406,11 +420,14 @@ static status_t build_sa_payload(private_responder_init_t *this, payload_t **pay if (status != SUCCESS) { this->logger->log(this->logger, ERROR, "Could not add cloned proposal to SA payload"); + proposal_iterator->destroy(proposal_iterator); sa_payload->destroy(sa_payload); return status; } } + + proposal_iterator->destroy(proposal_iterator); this->logger->log(this->logger, CONTROL|MORE, "sa payload builded"); @@ -505,6 +522,8 @@ static ike_sa_state_t get_state(private_responder_init_t *this) */ static status_t destroy(private_responder_init_t *this) { + this->logger->log(this->logger, CONTROL | MORE, "Going to destroy responder init state object"); + /* destroy stored proposal */ this->logger->log(this->logger, CONTROL | MOST, "Destroy stored proposals"); while (this->proposals->get_count(this->proposals) > 0) @@ -514,8 +533,30 @@ static status_t destroy(private_responder_init_t *this) current_proposal->destroy(current_proposal); } this->proposals->destroy(this->proposals); + + if (this->sent_nonce.ptr != NULL) + { + this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce"); + allocator_free(this->sent_nonce.ptr); + } + + if (this->received_nonce.ptr != NULL) + { + this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce"); + allocator_free(this->received_nonce.ptr); + } + + /* destroy diffie hellman object */ + if (this->diffie_hellman != NULL) + { + this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie_hellman_t object"); + this->diffie_hellman->destroy(this->diffie_hellman); + } + allocator_free(this); + return SUCCESS; + } /* diff --git a/Source/charon/thread_pool.c b/Source/charon/thread_pool.c index 63a084940..d98b621a2 100644 --- a/Source/charon/thread_pool.c +++ b/Source/charon/thread_pool.c @@ -143,12 +143,8 @@ static void job_processing(private_thread_pool_t *this) message->destroy(message); break; } - /* we must switch the initiator flag when receiving a request - */ - if (message->get_request(message)) - { - ike_sa_id->switch_initiator(ike_sa_id); - } + + ike_sa_id->switch_initiator(ike_sa_id); this->worker_logger->log(this->worker_logger, CONTROL|MOST, "checking out IKE SA %lld:%lld, role %s", ike_sa_id->get_initiator_spi(ike_sa_id), diff --git a/Source/charon/utils/logger_manager.c b/Source/charon/utils/logger_manager.c index d00761dc0..2d1587cac 100644 --- a/Source/charon/utils/logger_manager.c +++ b/Source/charon/utils/logger_manager.c @@ -263,6 +263,7 @@ static status_t destroy_logger (private_logger_manager_t *this,logger_t *logger) } } iterator->destroy(iterator); + pthread_mutex_unlock(&(this->mutex)); return status; }