- allready partly working
authorJan Hutter <jhutter@hsr.ch>
Mon, 21 Nov 2005 17:50:56 +0000 (17:50 -0000)
committerJan Hutter <jhutter@hsr.ch>
Mon, 21 Nov 2005 17:50:56 +0000 (17:50 -0000)
Source/charon/configuration_manager.c
Source/charon/ike_sa.c
Source/charon/message.c
Source/charon/states/ike_sa_init_requested.c
Source/charon/states/initiator_init.c
Source/charon/states/responder_init.c
Source/charon/thread_pool.c
Source/charon/utils/logger_manager.c

index b7ffbc0..df6f9af 100644 (file)
@@ -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;      
                }
index 3d0a5c1..ab4d3e5 100644 (file)
@@ -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);
 }
index 6075856..a97d182 100644 (file)
@@ -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);
index 81a1004..6ac8777 100644 (file)
@@ -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;  
-       }
+//     status = this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, FALSE, &response);
+//     if (status != SUCCESS)
+//     {
+//             return status;  
+//     }
 
-       response->destroy(response);
+//     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;
 }
index 8fc6f4d..b2e6f93 100644 (file)
@@ -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");
        
index 9fc744f..b0cfd9e 100644 (file)
@@ -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;
+       
 }
 
 /* 
index 63a0849..d98b621 100644 (file)
@@ -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),
index d00761d..2d1587c 100644 (file)
@@ -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;
 }