4 * @brief Class ike_sa_t. An object of this type is managed by an
5 * ike_sa_manager_t object and represents an IKE_SA
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 #include "definitions.h"
29 #include "utils/allocator.h"
30 #include "utils/linked_list.h"
31 #include "utils/logger_manager.h"
32 #include "utils/randomizer.h"
33 #include "transforms/diffie_hellman.h"
34 #include "payloads/sa_payload.h"
35 #include "payloads/nonce_payload.h"
36 #include "payloads/ke_payload.h"
37 #include "payloads/transform_substructure.h"
38 #include "payloads/transform_attribute.h"
42 * States in which a IKE_SA can actually be
44 typedef enum ike_sa_state_e ike_sa_state_t
;
49 * IKE_SA is is not in a state
54 * A IKE_SA_INIT-message was sent: role initiator
56 IKE_SA_INIT_REQUESTED
= 2,
59 * A IKE_SA_INIT-message was replied: role responder
61 IKE_SA_INIT_RESPONDED
= 3,
64 * An IKE_AUTH-message was sent after a successful
65 * IKE_SA_INIT-exchange: role initiator
67 IKE_AUTH_REQUESTED
= 4,
70 * An IKE_AUTH-message was replied: role responder.
71 * In this state, all the informations for an IKE_SA
72 * and one CHILD_SA are known.
74 IKE_SA_INITIALIZED
= 5
78 * string mappings for ike_sa_state
80 mapping_t ike_sa_state_m
[] = {
81 {NO_STATE
, "NO_STATE"},
82 {IKE_SA_INIT_REQUESTED
, "IKE_SA_INIT_REQUESTED"},
83 {IKE_SA_INIT_RESPONDED
, "IKE_SA_INIT_RESPONDED"},
84 {IKE_AUTH_REQUESTED
, "IKE_AUTH_REQUESTED"},
85 {IKE_SA_INITIALIZED
, "IKE_SA_INITIALIZED"},
91 * Private data of an message_t object
93 typedef struct private_ike_sa_s private_ike_sa_t
;
95 struct private_ike_sa_s
{
98 * Public part of a ike_sa_t object
102 status_t (*build_sa_payload
) (private_ike_sa_t
*this, sa_payload_t
**payload
);
103 status_t (*build_ke_payload
) (private_ike_sa_t
*this, ke_payload_t
**payload
);
104 status_t (*build_nonce_payload
) (private_ike_sa_t
*this, nonce_payload_t
**payload
);
106 status_t (*build_message
) (private_ike_sa_t
*this, exchange_type_t type
, bool request
, message_t
**message
);
109 status_t (*transto_ike_sa_init_requested
) (private_ike_sa_t
*this, char *name
);
110 status_t (*transto_ike_sa_init_responded
) (private_ike_sa_t
*this, message_t
*message
);
111 status_t (*transto_ike_auth_requested
) (private_ike_sa_t
*this, message_t
*message
);
115 * Identifier for the current IKE_SA
117 ike_sa_id_t
*ike_sa_id
;
120 * Linked List containing the child sa's of the current IKE_SA
122 linked_list_t
*child_sas
;
125 * Current state of the IKE_SA
127 ike_sa_state_t state
;
130 * this SA's source for random data
132 randomizer_t
*randomizer
;
135 * contains the last responded message
138 message_t
*last_responded_message
;
141 * contains the last requested message
144 message_t
*last_requested_message
;
147 * Informations of this host
154 * Informations of the other host
163 * Diffie Hellman object used to compute shared secret
165 diffie_hellman_t
*diffie_hellman
;
167 * Diffie Hellman group number
169 u_int16_t dh_group_number
;
172 * Priority used get matching dh_group number
174 u_int16_t dh_group_priority
;
179 linked_list_t
*proposals
;
185 * received nonce value
187 chunk_t received_nonce
;
192 * next message id to receive
194 u_int32_t message_id_in
;
197 * next message id to send
199 u_int32_t message_id_out
;
202 * a logger for this IKE_SA
208 * @brief implements function process_message of private_ike_sa_t
210 static status_t
process_message (private_ike_sa_t
*this, message_t
*message
)
212 u_int32_t message_id
;
214 is_request
= message
->get_request(message
);
215 this->logger
->log(this->logger
, CONTROL
|MORE
, "Process %s message of exchange type %s",(is_request
) ?
"REQUEST" : "RESPONSE",
216 mapping_find(exchange_type_m
,message
->get_exchange_type(message
)));
219 //message->get_exchange_type(message);
222 switch (message
->get_exchange_type(message
))
226 if (message
->get_request(message
)) {
227 if (this->state
== NO_STATE
)
229 /* state transission NO_STATE => IKE_SA_INIT_RESPONDED */
230 return this->transto_ike_sa_init_responded(this, message
);
235 if (this->state
== IKE_SA_INIT_REQUESTED
)
237 /* state transission IKE_SA_INIT_REQUESTED => IKE_AUTH_REQUESTED*/
238 return this->transto_ike_auth_requested(this, message
);
247 case CREATE_CHILD_SA
:
257 this->logger
->log(this->logger
, ERROR
, "processing %s-message not supported.",
258 mapping_find(exchange_type_m
,message
->get_exchange_type(message
)));
259 return NOT_SUPPORTED
;
262 this->logger
->log(this->logger
, ERROR
, "received %s-message in state %s, rejected.",
263 mapping_find(exchange_type_m
, message
->get_exchange_type(message
)),
264 mapping_find(ike_sa_state_m
, this->state
));
265 return INVALID_STATE
;
269 static status_t
build_message(private_ike_sa_t
*this, exchange_type_t type
, bool request
, message_t
**message
)
272 message_t
*new_message
;
273 host_t
*source
, *destination
;
275 new_message
= message_create();
276 if (new_message
== NULL
)
281 status
= this->me
.host
->clone(this->me
.host
, &source
);
282 status
|= this->other
.host
->clone(this->other
.host
, &destination
);
283 if (status
!= SUCCESS
)
285 new_message
->destroy(new_message
);
288 new_message
->set_source(new_message
, source
);
289 new_message
->set_destination(new_message
, destination
);
291 new_message
->set_exchange_type(new_message
, type
);
292 new_message
->set_request(new_message
, request
);
296 new_message
->set_message_id(new_message
, this->message_id_out
);
299 new_message
->set_message_id(new_message
, this->message_id_in
);
302 new_message
->set_ike_sa_id(new_message
, this->ike_sa_id
);
304 *message
= new_message
;
310 static status_t
transto_ike_sa_init_requested(private_ike_sa_t
*this, char *name
)
317 this->logger
->log(this->logger
, CONTROL
, "initializing connection");
319 status
= global_configuration_manager
->get_local_host(global_configuration_manager
, name
, &(this->me
.host
));
320 if (status
!= SUCCESS
)
325 status
= global_configuration_manager
->get_remote_host(global_configuration_manager
, name
, &(this->other
.host
));
326 if (status
!= SUCCESS
)
331 status
= global_configuration_manager
->get_dh_group_number(global_configuration_manager
, name
, &(this->ike_sa_init_data
.dh_group_number
), this->ike_sa_init_data
.dh_group_priority
);
332 if (status
!= SUCCESS
)
337 this ->logger
->log(this->logger
, CONTROL
|MORE
, "create diffie hellman object");
338 if (this->ike_sa_init_data
.diffie_hellman
!= NULL
)
340 this->logger
->log(this->logger
, ERROR
, "Object of type diffie_hellman_t already existing!");
343 this->ike_sa_init_data
.diffie_hellman
= diffie_hellman_create(this->ike_sa_init_data
.dh_group_number
);
344 if (this->ike_sa_init_data
.diffie_hellman
== NULL
)
346 this->logger
->log(this->logger
, ERROR
, "Object of type diffie_hellman_t could not be created!");
350 if (this->ike_sa_init_data
.sent_nonce
.ptr
!= NULL
)
352 this->logger
->log(this->logger
, ERROR
, "Nonce for IKE_SA_INIT phase already existing!");
356 if (this->randomizer
->allocate_pseudo_random_bytes(this->randomizer
, 16, &(this->ike_sa_init_data
.sent_nonce
)) != SUCCESS
)
358 this->logger
->log(this->logger
, ERROR
, "Could not create nonce!");
363 /* going to build message */
365 status
= this->build_message(this, IKE_SA_INIT
, TRUE
, &message
);
366 if (status
!= SUCCESS
)
368 this->logger
->log(this->logger
, ERROR
, "Could not build message");
372 /* build SA payload */
373 status
= this->build_sa_payload(this, (sa_payload_t
**)&payload
);
374 if (status
!= SUCCESS
)
376 this->logger
->log(this->logger
, ERROR
, "Could not build SA payload");
377 message
->destroy(message
);
380 message
->add_payload(message
, payload
);
382 /* build KE payload */
383 status
= this->build_ke_payload(this,(ke_payload_t
**) &payload
);
384 if (status
!= SUCCESS
)
386 this->logger
->log(this->logger
, ERROR
, "Could not build KE payload");
387 message
->destroy(message
);
390 message
->add_payload(message
, payload
);
392 /* build Nonce payload */
393 status
= this->build_nonce_payload(this, (nonce_payload_t
**)&payload
);
394 if (status
!= SUCCESS
)
396 this->logger
->log(this->logger
, ERROR
, "Could not build NONCE payload");
397 message
->destroy(message
);
400 message
->add_payload(message
, payload
);
403 status
= message
->generate(message
, &packet
);
404 if (status
!= SUCCESS
)
406 this->logger
->log(this->logger
, ERROR
, "Could not generate message");
407 message
->destroy(message
);
411 status
= global_send_queue
->add(global_send_queue
, packet
);
412 if (status
!= SUCCESS
)
414 this->logger
->log(this->logger
, ERROR
, "Could not add packet to send queue");
415 message
->destroy(message
);
419 if ( this->last_requested_message
!= NULL
)
421 /* destroy message */
422 this->last_requested_message
->destroy(this->last_requested_message
);
425 this->last_requested_message
= message
;
427 /* message counter can now be increased */
428 this->message_id_out
++;
430 /* states has NOW changed :-) */
431 this->state
= IKE_SA_INIT_REQUESTED
;
436 static status_t
transto_ike_sa_init_responded(private_ike_sa_t
*this, message_t
*request
)
439 linked_list_iterator_t
*payloads
;
441 host_t
*source
, *destination
;
443 /* this is the first message we process, so copy host infos */
444 request
->get_source(request
, &source
);
445 request
->get_destination(request
, &destination
);
446 /* we need to clone them, since we destroy the message later */
447 destination
->clone(destination
, &(this->me
.host
));
448 source
->clone(source
, &(this->other
.host
));
450 /* parse incoming message */
451 status
= request
->parse_body(request
);
452 if (status
!= SUCCESS
)
454 this->logger
->log(this->logger
, ERROR
, "Could not parse body");
457 /* iterate over incoming payloads */
458 status
= request
->get_payload_iterator(request
, &payloads
);
459 if (status
!= SUCCESS
)
461 request
->destroy(request
);
464 while (payloads
->has_next(payloads
))
467 payloads
->current(payloads
, (void**)&payload
);
469 this->logger
->log(this->logger
, CONTROL
|MORE
, "Processing payload %s", mapping_find(payload_type_m
, payload
->get_type(payload
)));
470 switch (payload
->get_type(payload
))
472 case SECURITY_ASSOCIATION
:
474 sa_payload_t
*sa_payload
= (sa_payload_t
*)payload
;
475 linked_list_iterator_t
*suggested_proposals
, *accepted_proposals
;
476 /* create a list for accepted proposals */
477 if (this->ike_sa_init_data
.proposals
== NULL
) {
478 this->ike_sa_init_data
.proposals
= linked_list_create();
482 /** @todo destroy list contents */
484 if (this->ike_sa_init_data
.proposals
== NULL
)
486 payloads
->destroy(payloads
);
489 status
= this->ike_sa_init_data
.proposals
->create_iterator(this->ike_sa_init_data
.proposals
, &accepted_proposals
, FALSE
);
490 if (status
!= SUCCESS
)
492 payloads
->destroy(payloads
);
496 /* get the list of suggested proposals */
497 status
= sa_payload
->create_proposal_substructure_iterator(sa_payload
, &suggested_proposals
, TRUE
);
498 if (status
!= SUCCESS
)
500 accepted_proposals
->destroy(accepted_proposals
);
501 payloads
->destroy(payloads
);
505 /* now let the configuration-manager select a subset of the proposals */
506 status
= global_configuration_manager
->select_proposals_for_host(global_configuration_manager
,
507 this->other
.host
, suggested_proposals
, accepted_proposals
);
508 if (status
!= SUCCESS
)
510 suggested_proposals
->destroy(suggested_proposals
);
511 accepted_proposals
->destroy(accepted_proposals
);
512 payloads
->destroy(payloads
);
516 suggested_proposals
->destroy(suggested_proposals
);
517 accepted_proposals
->destroy(accepted_proposals
);
519 /* ok, we have what we need for sa_payload */
524 ke_payload_t
*ke_payload
= (ke_payload_t
*)payload
;
525 diffie_hellman_t
*dh
;
526 diffie_hellman_group_t group
;
529 group
= ke_payload
->get_dh_group_number(ke_payload
);
531 status
= global_configuration_manager
->is_dh_group_allowed_for_host(global_configuration_manager
,
532 this->other
.host
, group
, &allowed_group
);
533 if (status
!= SUCCESS
)
535 payloads
->destroy(payloads
);
540 /** @todo info reply */
543 dh
= diffie_hellman_create(group
);
546 payloads
->destroy(payloads
);
550 status
= dh
->set_other_public_value(dh
, ke_payload
->get_key_exchange_data(ke_payload
));
551 if (status
!= SUCCESS
)
554 payloads
->destroy(payloads
);
557 /** @todo destroy if there is already one */
558 this->ike_sa_init_data
.diffie_hellman
= dh
;
563 nonce_payload_t
*nonce_payload
= (nonce_payload_t
*)payload
;
566 nonce_payload
->get_nonce(nonce_payload
, &nonce
);
567 /** @todo free if there is already one */
568 this->ike_sa_init_data
.received_nonce
.ptr
= allocator_clone_bytes(nonce
.ptr
, nonce
.len
);
569 this->ike_sa_init_data
.received_nonce
.len
= nonce
.len
;
570 if (this->ike_sa_init_data
.received_nonce
.ptr
== NULL
)
572 payloads
->destroy(payloads
);
585 payloads
->destroy(payloads
);
589 /* set up the reply */
590 status
= this->build_message(this, IKE_SA_INIT
, FALSE
, &response
);
591 if (status
!= SUCCESS
)
601 delete_job = (job_t *) delete_ike_sa_job_create(this->ike_sa_id);
602 if (delete_job == NULL)
604 this->logger->log(this->logger, ERROR, "Job to delete IKE SA could not be created");
607 status = global_job_queue->add(global_job_queue,delete_job);
608 if (status != SUCCESS)
610 this->logger->log(this->logger, ERROR, "%s Job to delete IKE SA could not be added to job queue",mapping_find(status_m,status));
611 delete_job->destroy_all(delete_job);
616 static status_t
transto_ike_auth_requested(private_ike_sa_t
*this, message_t
*response
)
619 linked_list_iterator_t
*payloads
;
622 /* parse incoming message */
623 status
= response
->parse_body(response
);
624 if (status
!= SUCCESS
)
626 this->logger
->log(this->logger
, ERROR
, "Could not parse body");
629 /* iterate over incoming payloads */
630 status
= response
->get_payload_iterator(response
, &payloads
);
631 if (status
!= SUCCESS
)
633 response
->destroy(response
);
636 while (payloads
->has_next(payloads
))
639 payloads
->current(payloads
, (void**)&payload
);
641 this->logger
->log(this->logger
, CONTROL
|MORE
, "Processing payload %s", mapping_find(payload_type_m
, payload
->get_type(payload
)));
642 switch (payload
->get_type(payload
))
644 // case SECURITY_ASSOCIATION:
646 // sa_payload_t *sa_payload = (sa_payload_t*)payload;
647 // linked_list_iterator_t *suggested_proposals, *accepted_proposals;
648 // /* create a list for accepted proposals */
649 // if (this->ike_sa_init_data.proposals == NULL) {
650 // this->ike_sa_init_data.proposals = linked_list_create();
654 // /** @todo destroy list contents */
656 // if (this->ike_sa_init_data.proposals == NULL)
658 // payloads->destroy(payloads);
659 // return OUT_OF_RES;
661 // status = this->ike_sa_init_data.proposals->create_iterator(this->ike_sa_init_data.proposals, &accepted_proposals, FALSE);
662 // if (status != SUCCESS)
664 // payloads->destroy(payloads);
668 // /* get the list of suggested proposals */
669 // status = sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE);
670 // if (status != SUCCESS)
672 // accepted_proposals->destroy(accepted_proposals);
673 // payloads->destroy(payloads);
677 // /* now let the configuration-manager select a subset of the proposals */
678 // status = global_configuration_manager->select_proposals_for_host(global_configuration_manager,
679 // this->other.host, suggested_proposals, accepted_proposals);
680 // if (status != SUCCESS)
682 // suggested_proposals->destroy(suggested_proposals);
683 // accepted_proposals->destroy(accepted_proposals);
684 // payloads->destroy(payloads);
688 // suggested_proposals->destroy(suggested_proposals);
689 // accepted_proposals->destroy(accepted_proposals);
691 // /* ok, we have what we need for sa_payload */
696 ke_payload_t
*ke_payload
= (ke_payload_t
*)payload
;
697 diffie_hellman_t
*dh
;
698 chunk_t shared_secret
;
700 dh
= this->ike_sa_init_data
.diffie_hellman
;
705 status
= dh
->set_other_public_value(dh
, ke_payload
->get_key_exchange_data(ke_payload
));
706 if (status
!= SUCCESS
)
709 payloads
->destroy(payloads
);
713 status
= dh
->get_shared_secret(dh
, &shared_secret
);
715 this->logger
->log_chunk(this->logger
, RAW
, "Shared secret", &shared_secret
);
721 nonce_payload_t
*nonce_payload
= (nonce_payload_t
*)payload
;
724 nonce_payload
->get_nonce(nonce_payload
, &nonce
);
725 /** @todo free if there is already one */
726 this->ike_sa_init_data
.received_nonce
.ptr
= allocator_clone_bytes(nonce
.ptr
, nonce
.len
);
727 this->ike_sa_init_data
.received_nonce
.len
= nonce
.len
;
728 if (this->ike_sa_init_data
.received_nonce
.ptr
== NULL
)
730 payloads
->destroy(payloads
);
743 payloads
->destroy(payloads
);
747 /* set up the reply */
748 status
= this->build_message(this, IKE_SA_INIT
, FALSE
, &response
);
749 if (status
!= SUCCESS
)
759 * @brief implements function process_configuration of private_ike_sa_t
761 static status_t
initialize_connection(private_ike_sa_t
*this, char *name
)
763 /* work is done in transto_ike_sa_init_requested */
764 return (this->transto_ike_sa_init_requested(this,name
));
768 * @brief implements function private_ike_sa_t.get_id
770 static ike_sa_id_t
* get_id(private_ike_sa_t
*this)
772 return this->ike_sa_id
;
776 * implements private_ike_sa_t.build_sa_payload
778 static status_t
build_sa_payload(private_ike_sa_t
*this, sa_payload_t
**payload
)
780 sa_payload_t
* sa_payload
;
781 linked_list_iterator_t
*iterator
;
784 this->logger
->log(this->logger
, CONTROL
|MORE
, "building sa payload");
786 sa_payload
= sa_payload_create();
787 if (sa_payload
== NULL
)
791 status
= sa_payload
->create_proposal_substructure_iterator(sa_payload
, &iterator
, FALSE
);
792 if (status
!= SUCCESS
)
794 sa_payload
->destroy(sa_payload
);
797 status
= global_configuration_manager
->get_proposals_for_host(global_configuration_manager
, this->other
.host
, iterator
);
798 if (status
!= SUCCESS
)
800 sa_payload
->destroy(sa_payload
);
804 *payload
= sa_payload
;
809 static status_t
build_ke_payload(private_ike_sa_t
*this, ke_payload_t
**payload
)
811 ke_payload_t
*ke_payload
;
815 this->logger
->log(this->logger
, CONTROL
|MORE
, "building ke payload");
817 if (this->state
!= NO_STATE
)
819 this->logger
->log(this->logger
, ERROR
, "KE payload in state %s not supported",mapping_find(ike_sa_state_m
,this->state
));
823 switch(this->ike_sa_id
->is_initiator(this->ike_sa_id
))
827 this ->logger
->log(this->logger
, CONTROL
|MORE
, "get public dh value to send in ke payload");
828 status
= this->ike_sa_init_data
.diffie_hellman
->get_my_public_value(this->ike_sa_init_data
.diffie_hellman
,&key_data
);
829 if (status
!= SUCCESS
)
831 this->logger
->log(this->logger
, ERROR
, "Could not get my DH public value");
835 ke_payload
= ke_payload_create();
836 if (ke_payload
== NULL
)
838 this->logger
->log(this->logger
, ERROR
, "Could not create KE payload");
839 allocator_free_chunk(key_data
);
842 ke_payload
->set_dh_group_number(ke_payload
, MODP_1024_BIT
);
843 if (ke_payload
->set_key_exchange_data(ke_payload
, key_data
) != SUCCESS
)
845 this->logger
->log(this->logger
, ERROR
, "Could not set key exchange data of KE payload");
846 ke_payload
->destroy(ke_payload
);
847 allocator_free_chunk(key_data
);
850 allocator_free_chunk(key_data
);
852 *payload
= ke_payload
;
865 * implements private_ike_sa_t.build_nonce_payload
867 static status_t
build_nonce_payload(private_ike_sa_t
*this, nonce_payload_t
**payload
)
869 nonce_payload_t
*nonce_payload
;
871 this->logger
->log(this->logger
, CONTROL
|MORE
, "building nonce payload");
872 nonce_payload
= nonce_payload_create();
873 if (nonce_payload
== NULL
)
878 nonce_payload
->set_nonce(nonce_payload
, this->ike_sa_init_data
.sent_nonce
);
880 *payload
= nonce_payload
;
886 * @brief implements function destroy of private_ike_sa_t
888 static status_t
destroy (private_ike_sa_t
*this)
891 this->logger
->log(this->logger
, CONTROL
| MORE
, "Going to destroy IKE_SA");
893 /* destroy child sa's */
894 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy all child_sa's");
895 while (this->child_sas
->get_count(this->child_sas
) > 0)
898 if (this->child_sas
->remove_first(this->child_sas
,&child_sa
) != SUCCESS
)
902 /* destroy child sa */
904 this->child_sas
->destroy(this->child_sas
);
906 /* destroy ike_sa_id */
907 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy assigned ike_sa_id");
908 this->ike_sa_id
->destroy(this->ike_sa_id
);
910 /* destroy stored requested message */
911 if (this->last_requested_message
!= NULL
)
913 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy last requested message");
914 this->last_requested_message
->destroy(this->last_requested_message
);
917 /* destroy stored responded messages */
918 if (this->last_responded_message
!= NULL
)
920 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy last responded message");
921 this->last_responded_message
->destroy(this->last_responded_message
);
924 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy randomizer");
925 this->randomizer
->destroy(this->randomizer
);
927 this->logger
->log(this->logger
, CONTROL
| MOST
, "Going to destroy ike_sa_init data");
928 if (this->ike_sa_init_data
.diffie_hellman
!= NULL
)
930 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy diffie hellman object");
931 this->ike_sa_init_data
.diffie_hellman
->destroy(this->ike_sa_init_data
.diffie_hellman
);
933 if (this->ike_sa_init_data
.sent_nonce
.ptr
!= NULL
)
935 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy sent nonce data");
936 allocator_free_chunk(this->ike_sa_init_data
.sent_nonce
);
938 if (this->ike_sa_init_data
.received_nonce
.ptr
!= NULL
)
940 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy received nonce data");
941 allocator_free_chunk(this->ike_sa_init_data
.received_nonce
);
944 this->logger
->log(this->logger
, CONTROL
| MOST
, "Destroy logger of IKE_SA");
945 global_logger_manager
->destroy_logger(global_logger_manager
, this->logger
);
947 allocator_free(this);
953 * Described in Header
955 ike_sa_t
* ike_sa_create(ike_sa_id_t
*ike_sa_id
)
957 private_ike_sa_t
*this = allocator_alloc_thing(private_ike_sa_t
);
964 /* Public functions */
965 this->public.process_message
= (status_t(*)(ike_sa_t
*, message_t
*)) process_message
;
966 this->public.initialize_connection
= (status_t(*)(ike_sa_t
*, char*)) initialize_connection
;
967 this->public.get_id
= (ike_sa_id_t
*(*)(ike_sa_t
*)) get_id
;
968 this->public.destroy
= (status_t(*)(ike_sa_t
*))destroy
;
970 /* private functions */
971 this->build_sa_payload
= build_sa_payload
;
972 this->build_nonce_payload
= build_nonce_payload
;
973 this->build_ke_payload
= build_ke_payload
;
974 this->build_message
= build_message
;
975 this->transto_ike_sa_init_requested
= transto_ike_sa_init_requested
;
976 this->transto_ike_sa_init_responded
= transto_ike_sa_init_responded
;
977 this->transto_ike_auth_requested
= transto_ike_auth_requested
;
981 /* initialize private fields */
982 this->logger
= global_logger_manager
->create_logger(global_logger_manager
, IKE_SA
, NULL
);
983 if (this->logger
== NULL
)
985 allocator_free(this);
988 if (ike_sa_id
->clone(ike_sa_id
,&(this->ike_sa_id
)) != SUCCESS
)
990 this->logger
->log(this->logger
, ERROR
, "Fatal error: Could not clone ike_sa_id");
991 global_logger_manager
->destroy_logger(global_logger_manager
,this->logger
);
992 allocator_free(this);
995 this->child_sas
= linked_list_create();
996 if (this->child_sas
== NULL
)
998 this->logger
->log(this->logger
, ERROR
, "Fatal error: Could not create list for child_sa's");
999 this->ike_sa_id
->destroy(this->ike_sa_id
);
1000 global_logger_manager
->destroy_logger(global_logger_manager
,this->logger
);
1001 allocator_free(this);
1004 this->randomizer
= randomizer_create();
1005 if (this->randomizer
== NULL
)
1007 this->logger
->log(this->logger
, ERROR
, "Fatal error: Could not create list for child_sa's");
1008 this->child_sas
->destroy(this->child_sas
);
1009 this->ike_sa_id
->destroy(this->ike_sa_id
);
1010 global_logger_manager
->destroy_logger(global_logger_manager
,this->logger
);
1011 allocator_free(this);
1014 this->me
.host
= NULL
;
1015 this->other
.host
= NULL
;
1016 this->ike_sa_init_data
.diffie_hellman
= NULL
;
1017 this->ike_sa_init_data
.dh_group_number
= 0;
1018 /* 1 means highest priority */
1019 this->ike_sa_init_data
.dh_group_priority
= 1;
1020 this->ike_sa_init_data
.sent_nonce
.len
= 0;
1021 this->ike_sa_init_data
.sent_nonce
.ptr
= NULL
;
1022 this->ike_sa_init_data
.received_nonce
.len
= 0;
1023 this->ike_sa_init_data
.received_nonce
.ptr
= NULL
;
1024 this->ike_sa_init_data
.proposals
= NULL
;
1025 this->last_requested_message
= NULL
;
1026 this->last_responded_message
= NULL
;
1027 this->message_id_out
= 0;
1028 this->message_id_in
= 0;
1031 /* at creation time, IKE_SA isn't in a specific state */
1032 this->state
= NO_STATE
;
1034 return (&this->public);