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"
43 * This implementation supports only window size 1
48 * States in which a IKE_SA can actually be
50 typedef enum ike_sa_state_e ike_sa_state_t
;
55 * IKE_SA is is not in a state
60 * A IKE_SA_INIT-message was sent: role initiator
62 IKE_SA_INIT_REQUESTED
= 2,
65 * A IKE_SA_INIT-message was replied: role responder
67 IKE_SA_INIT_RESPONDED
= 3,
70 * An IKE_AUTH-message was sent after a successful
71 * IKE_SA_INIT-exchange: role initiator
73 IKE_AUTH_REQUESTED
= 4,
76 * An IKE_AUTH-message was replied: role responder.
77 * In this state, all the informations for an IKE_SA
78 * and one CHILD_SA are known.
80 IKE_SA_INITIALIZED
= 5
84 * string mappings for ike_sa_state
86 mapping_t ike_sa_state_m
[] = {
87 {NO_STATE
, "NO_STATE"},
88 {IKE_SA_INIT_REQUESTED
, "IKE_SA_INIT_REQUESTED"},
89 {IKE_SA_INIT_RESPONDED
, "IKE_SA_INIT_RESPONDED"},
90 {IKE_AUTH_REQUESTED
, "IKE_AUTH_REQUESTED"},
91 {IKE_SA_INITIALIZED
, "IKE_SA_INITIALIZED"},
97 * Private data of an message_t object
99 typedef struct private_ike_sa_s private_ike_sa_t
;
101 struct private_ike_sa_s
{
104 * Public part of a ike_sa_t object
108 status_t (*build_sa_payload
) (private_ike_sa_t
*this, sa_payload_t
**payload
);
109 status_t (*build_ke_payload
) (private_ike_sa_t
*this, ke_payload_t
**payload
);
110 status_t (*build_nonce_payload
) (private_ike_sa_t
*this, nonce_payload_t
**payload
);
112 status_t (*build_message
) (private_ike_sa_t
*this, exchange_type_t type
, bool request
, message_t
**message
);
115 status_t (*transto_ike_sa_init_requested
) (private_ike_sa_t
*this, char *name
);
116 status_t (*transto_ike_sa_init_responded
) (private_ike_sa_t
*this, message_t
*message
);
117 status_t (*transto_ike_auth_requested
) (private_ike_sa_t
*this, message_t
*message
);
121 * Identifier for the current IKE_SA
123 ike_sa_id_t
*ike_sa_id
;
126 * Linked List containing the child sa's of the current IKE_SA
128 linked_list_t
*child_sas
;
131 * Current state of the IKE_SA
133 ike_sa_state_t state
;
136 * this SA's source for random data
138 randomizer_t
*randomizer
;
141 * contains the last X responded messages
143 * X is windows size (here 1)
145 linked_list_t
*responded_messages
;
148 * contains the last X requested messages
150 * X is windows size (here 1)
152 linked_list_t
*requested_messages
;
165 * Diffie Hellman object used to compute shared secret
167 diffie_hellman_t
*diffie_hellman
;
169 * Diffie Hellman group number
171 u_int16_t dh_group_number
;
174 * Priority used get matching dh_group number
176 u_int16_t dh_group_priority
;
181 linked_list_t
*proposals
;
189 chunk_t received_nonce
;
194 * next message id to receive
196 u_int32_t message_id_in
;
199 * next message id to send
201 u_int32_t message_id_out
;
204 * a logger for this IKE_SA
210 * @brief implements function process_message of private_ike_sa_t
212 static status_t
process_message (private_ike_sa_t
*this, message_t
*message
)
214 u_int32_t message_id
;
216 is_request
= message
->get_request(message
);
217 this->logger
->log(this->logger
, CONTROL
|MORE
, "Process %s message of exchange type %s",(is_request
) ?
"REQUEST" : "RESPONSE",
218 mapping_find(exchange_type_m
,message
->get_exchange_type(message
)));
221 //message->get_exchange_type(message);
224 switch (message
->get_exchange_type(message
))
228 if (message
->get_request(message
)) {
229 if (this->state
== NO_STATE
)
231 /* state transission NO_STATE => IKE_SA_INIT_RESPONDED */
232 return this->transto_ike_sa_init_responded(this, message
);
237 if (this->state
== IKE_SA_INIT_REQUESTED
)
239 /* state transission IKE_SA_INIT_REQUESTED => IKE_AUTH_REQUESTED*/
240 return this->transto_ike_auth_requested(this, message
);
249 case CREATE_CHILD_SA
:
259 this->logger
->log(this->logger
, ERROR
, "processing %s-message not supported.",
260 mapping_find(exchange_type_m
,message
->get_exchange_type(message
)));
261 return NOT_SUPPORTED
;
264 this->logger
->log(this->logger
, ERROR
, "received %s-message in state %s, rejected.",
265 mapping_find(exchange_type_m
, message
->get_exchange_type(message
)),
266 mapping_find(ike_sa_state_m
, this->state
));
267 return INVALID_STATE
;
271 static status_t
build_message(private_ike_sa_t
*this, exchange_type_t type
, bool request
, message_t
**message
)
274 message_t
*new_message
;
275 host_t
*source
, *destination
;
277 new_message
= message_create();
278 if (new_message
== NULL
)
283 status
= this->me
.host
->clone(this->me
.host
, &source
);
284 status
|= this->other
.host
->clone(this->other
.host
, &destination
);
285 if (status
!= SUCCESS
)
287 new_message
->destroy(new_message
);
290 new_message
->set_source(new_message
, source
);
291 new_message
->set_destination(new_message
, destination
);
293 new_message
->set_exchange_type(new_message
, type
);
294 new_message
->set_request(new_message
, request
);
298 new_message
->set_message_id(new_message
, this->message_id_out
);
301 new_message
->set_message_id(new_message
, this->message_id_in
);
304 new_message
->set_ike_sa_id(new_message
, this->ike_sa_id
);
306 *message
= new_message
;
312 static status_t
transto_ike_sa_init_requested(private_ike_sa_t
*this, char *name
)
319 this->logger
->log(this->logger
, CONTROL
, "initializing connection");
321 status
= global_configuration_manager
->get_local_host(global_configuration_manager
, name
, &(this->me
.host
));
322 if (status
!= SUCCESS
)
327 status
= global_configuration_manager
->get_remote_host(global_configuration_manager
, name
, &(this->other
.host
));
328 if (status
!= SUCCESS
)
333 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
);
334 if (status
!= SUCCESS
)
339 this ->logger
->log(this->logger
, CONTROL
|MORE
, "create diffie hellman object");
340 if (this->ike_sa_init_data
.diffie_hellman
!= NULL
)
342 this->logger
->log(this->logger
, ERROR
, "Object of type diffie_hellman_t already existing!");
345 this->ike_sa_init_data
.diffie_hellman
= diffie_hellman_create(this->ike_sa_init_data
.dh_group_number
);
346 if (this->ike_sa_init_data
.diffie_hellman
== NULL
)
348 this->logger
->log(this->logger
, ERROR
, "Object of type diffie_hellman_t could not be created!");
352 if (this->ike_sa_init_data
.sent_nonce
.ptr
!= NULL
)
354 this->logger
->log(this->logger
, ERROR
, "Nonce for IKE_SA_INIT phase already existing!");
358 if (this->randomizer
->allocate_pseudo_random_bytes(this->randomizer
, 16, &(this->ike_sa_init_data
.sent_nonce
)) != SUCCESS
)
360 this->logger
->log(this->logger
, ERROR
, "Could not create nonce!");
365 /* going to build message */
367 status
= this->build_message(this, IKE_SA_INIT
, TRUE
, &message
);
368 if (status
!= SUCCESS
)
370 this->logger
->log(this->logger
, ERROR
, "Could not build message");
374 /* build SA payload */
375 status
= this->build_sa_payload(this, (sa_payload_t
**)&payload
);
376 if (status
!= SUCCESS
)
378 this->logger
->log(this->logger
, ERROR
, "Could not build SA payload");
379 message
->destroy(message
);
382 message
->add_payload(message
, payload
);
384 /* build KE payload */
385 status
= this->build_ke_payload(this,(ke_payload_t
**) &payload
);
386 if (status
!= SUCCESS
)
388 this->logger
->log(this->logger
, ERROR
, "Could not build KE payload");
389 message
->destroy(message
);
392 message
->add_payload(message
, payload
);
394 /* build Nonce payload */
395 status
= this->build_nonce_payload(this, (nonce_payload_t
**)&payload
);
396 if (status
!= SUCCESS
)
398 this->logger
->log(this->logger
, ERROR
, "Could not build NONCE payload");
399 message
->destroy(message
);
402 message
->add_payload(message
, payload
);
405 status
= message
->generate(message
, &packet
);
406 if (status
!= SUCCESS
)
408 this->logger
->log(this->logger
, ERROR
, "Could not generate message");
409 message
->destroy(message
);
413 status
= global_send_queue
->add(global_send_queue
, packet
);
414 if (status
!= SUCCESS
)
416 this->logger
->log(this->logger
, ERROR
, "Could not add packet to send queue");
417 message
->destroy(message
);
421 if ( this->requested_messages
->get_count(this->requested_messages
) >= WINDOW_SIZE
)
423 message_t
*removed_message
;
424 /* destroy message */
425 this->requested_messages
->remove_last(this->requested_messages
,(void **)&removed_message
);
426 removed_message
->destroy(removed_message
);
429 status
= this->requested_messages
->insert_first(this->requested_messages
,(void *) message
);
430 if (status
!= SUCCESS
)
432 this->logger
->log(this->logger
, ERROR
, "Could not store last received message");
433 message
->destroy(message
);
437 /* message counter can now be increased */
438 this->message_id_out
++;
440 /* states has NOW changed :-) */
441 this->state
= IKE_SA_INIT_REQUESTED
;
446 static status_t
transto_ike_sa_init_responded(private_ike_sa_t
*this, message_t
*request
)
449 linked_list_iterator_t
*payloads
;
451 host_t
*source
, *destination
;
453 /* this is the first message we process, so copy host infos */
454 request
->get_source(request
, &source
);
455 request
->get_destination(request
, &destination
);
456 /* we need to clone them, since we destroy the message later */
457 destination
->clone(destination
, &(this->me
.host
));
458 source
->clone(source
, &(this->other
.host
));
460 /* parse incoming message */
461 status
= request
->parse_body(request
);
462 if (status
!= SUCCESS
)
464 this->logger
->log(this->logger
, ERROR
, "Could not parse body");
467 /* iterate over incoming payloads */
468 status
= request
->get_payload_iterator(request
, &payloads
);
469 if (status
!= SUCCESS
)
471 request
->destroy(request
);
474 while (payloads
->has_next(payloads
))
477 payloads
->current(payloads
, (void**)&payload
);
479 this->logger
->log(this->logger
, CONTROL
|MORE
, "Processing payload %s", mapping_find(payload_type_m
, payload
->get_type(payload
)));
480 switch (payload
->get_type(payload
))
482 case SECURITY_ASSOCIATION
:
484 sa_payload_t
*sa_payload
= (sa_payload_t
*)payload
;
485 linked_list_iterator_t
*suggested_proposals
, *accepted_proposals
;
486 /* create a list for accepted proposals */
487 if (this->ike_sa_init_data
.proposals
== NULL
) {
488 this->ike_sa_init_data
.proposals
= linked_list_create();
492 /** @todo destroy list contents */
494 if (this->ike_sa_init_data
.proposals
== NULL
)
496 payloads
->destroy(payloads
);
499 status
= this->ike_sa_init_data
.proposals
->create_iterator(this->ike_sa_init_data
.proposals
, &accepted_proposals
, FALSE
);
500 if (status
!= SUCCESS
)
502 payloads
->destroy(payloads
);
506 /* get the list of suggested proposals */
507 status
= sa_payload
->create_proposal_substructure_iterator(sa_payload
, &suggested_proposals
, TRUE
);
508 if (status
!= SUCCESS
)
510 accepted_proposals
->destroy(accepted_proposals
);
511 payloads
->destroy(payloads
);
515 /* now let the configuration-manager select a subset of the proposals */
516 status
= global_configuration_manager
->select_proposals_for_host(global_configuration_manager
,
517 this->other
.host
, suggested_proposals
, accepted_proposals
);
518 if (status
!= SUCCESS
)
520 suggested_proposals
->destroy(suggested_proposals
);
521 accepted_proposals
->destroy(accepted_proposals
);
522 payloads
->destroy(payloads
);
526 suggested_proposals
->destroy(suggested_proposals
);
527 accepted_proposals
->destroy(accepted_proposals
);
529 /* ok, we have what we need for sa_payload */
534 ke_payload_t
*ke_payload
= (ke_payload_t
*)payload
;
535 diffie_hellman_t
*dh
;
536 diffie_hellman_group_t group
;
539 group
= ke_payload
->get_dh_group_number(ke_payload
);
541 status
= global_configuration_manager
->is_dh_group_allowed_for_host(global_configuration_manager
,
542 this->other
.host
, group
, &allowed_group
);
543 if (status
!= SUCCESS
)
545 payloads
->destroy(payloads
);
550 /** @todo info reply */
553 dh
= diffie_hellman_create(group
);
556 payloads
->destroy(payloads
);
560 status
= dh
->set_other_public_value(dh
, ke_payload
->get_key_exchange_data(ke_payload
));
561 if (status
!= SUCCESS
)
564 payloads
->destroy(payloads
);
567 /** @todo destroy if there is already one */
568 this->ike_sa_init_data
.diffie_hellman
= dh
;
573 nonce_payload_t
*nonce_payload
= (nonce_payload_t
*)payload
;
576 nonce_payload
->get_nonce(nonce_payload
, &nonce
);
577 /** @todo free if there is already one */
578 this->ike_sa_init_data
.received_nonce
.ptr
= allocator_clone_bytes(nonce
.ptr
, nonce
.len
);
579 this->ike_sa_init_data
.received_nonce
.len
= nonce
.len
;
580 if (this->ike_sa_init_data
.received_nonce
.ptr
== NULL
)
582 payloads
->destroy(payloads
);
595 payloads
->destroy(payloads
);
599 /* set up the reply */
600 status
= this->build_message(this, IKE_SA_INIT
, FALSE
, &response
);
601 if (status
!= SUCCESS
)
611 delete_job = (job_t *) delete_ike_sa_job_create(this->ike_sa_id);
612 if (delete_job == NULL)
614 this->logger->log(this->logger, ERROR, "Job to delete IKE SA could not be created");
617 status = global_job_queue->add(global_job_queue,delete_job);
618 if (status != SUCCESS)
620 this->logger->log(this->logger, ERROR, "%s Job to delete IKE SA could not be added to job queue",mapping_find(status_m,status));
621 delete_job->destroy_all(delete_job);
626 static status_t
transto_ike_auth_requested(private_ike_sa_t
*this, message_t
*response
)
629 linked_list_iterator_t
*payloads
;
632 /* parse incoming message */
633 status
= response
->parse_body(response
);
634 if (status
!= SUCCESS
)
636 this->logger
->log(this->logger
, ERROR
, "Could not parse body");
639 /* iterate over incoming payloads */
640 status
= response
->get_payload_iterator(response
, &payloads
);
641 if (status
!= SUCCESS
)
643 response
->destroy(response
);
646 while (payloads
->has_next(payloads
))
649 payloads
->current(payloads
, (void**)&payload
);
651 this->logger
->log(this->logger
, CONTROL
|MORE
, "Processing payload %s", mapping_find(payload_type_m
, payload
->get_type(payload
)));
652 switch (payload
->get_type(payload
))
654 // case SECURITY_ASSOCIATION:
656 // sa_payload_t *sa_payload = (sa_payload_t*)payload;
657 // linked_list_iterator_t *suggested_proposals, *accepted_proposals;
658 // /* create a list for accepted proposals */
659 // if (this->ike_sa_init_data.proposals == NULL) {
660 // this->ike_sa_init_data.proposals = linked_list_create();
664 // /** @todo destroy list contents */
666 // if (this->ike_sa_init_data.proposals == NULL)
668 // payloads->destroy(payloads);
669 // return OUT_OF_RES;
671 // status = this->ike_sa_init_data.proposals->create_iterator(this->ike_sa_init_data.proposals, &accepted_proposals, FALSE);
672 // if (status != SUCCESS)
674 // payloads->destroy(payloads);
678 // /* get the list of suggested proposals */
679 // status = sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE);
680 // if (status != SUCCESS)
682 // accepted_proposals->destroy(accepted_proposals);
683 // payloads->destroy(payloads);
687 // /* now let the configuration-manager select a subset of the proposals */
688 // status = global_configuration_manager->select_proposals_for_host(global_configuration_manager,
689 // this->other.host, suggested_proposals, accepted_proposals);
690 // if (status != SUCCESS)
692 // suggested_proposals->destroy(suggested_proposals);
693 // accepted_proposals->destroy(accepted_proposals);
694 // payloads->destroy(payloads);
698 // suggested_proposals->destroy(suggested_proposals);
699 // accepted_proposals->destroy(accepted_proposals);
701 // /* ok, we have what we need for sa_payload */
706 ke_payload_t
*ke_payload
= (ke_payload_t
*)payload
;
707 diffie_hellman_t
*dh
;
708 chunk_t shared_secret
;
710 dh
= this->ike_sa_init_data
.diffie_hellman
;
715 status
= dh
->set_other_public_value(dh
, ke_payload
->get_key_exchange_data(ke_payload
));
716 if (status
!= SUCCESS
)
719 payloads
->destroy(payloads
);
723 status
= dh
->get_shared_secret(dh
, &shared_secret
);
725 this->logger
->log_chunk(this->logger
, RAW
, "Shared secret", &shared_secret
);
731 nonce_payload_t
*nonce_payload
= (nonce_payload_t
*)payload
;
734 nonce_payload
->get_nonce(nonce_payload
, &nonce
);
735 /** @todo free if there is already one */
736 this->ike_sa_init_data
.received_nonce
.ptr
= allocator_clone_bytes(nonce
.ptr
, nonce
.len
);
737 this->ike_sa_init_data
.received_nonce
.len
= nonce
.len
;
738 if (this->ike_sa_init_data
.received_nonce
.ptr
== NULL
)
740 payloads
->destroy(payloads
);
753 payloads
->destroy(payloads
);
757 /* set up the reply */
758 status
= this->build_message(this, IKE_SA_INIT
, FALSE
, &response
);
759 if (status
!= SUCCESS
)
769 * @brief implements function process_configuration of private_ike_sa_t
771 static status_t
initialize_connection(private_ike_sa_t
*this, char *name
)
773 /* work is done in transto_ike_sa_init_requested */
774 return (this->transto_ike_sa_init_requested(this,name
));
778 * @brief implements function private_ike_sa_t.get_id
780 static ike_sa_id_t
* get_id(private_ike_sa_t
*this)
782 return this->ike_sa_id
;
786 * implements private_ike_sa_t.build_sa_payload
788 static status_t
build_sa_payload(private_ike_sa_t
*this, sa_payload_t
**payload
)
790 sa_payload_t
* sa_payload
;
791 linked_list_iterator_t
*iterator
;
794 this->logger
->log(this->logger
, CONTROL
|MORE
, "building sa payload");
796 sa_payload
= sa_payload_create();
797 if (sa_payload
== NULL
)
801 status
= sa_payload
->create_proposal_substructure_iterator(sa_payload
, &iterator
, FALSE
);
802 if (status
!= SUCCESS
)
804 sa_payload
->destroy(sa_payload
);
807 status
= global_configuration_manager
->get_proposals_for_host(global_configuration_manager
, this->other
.host
, iterator
);
808 if (status
!= SUCCESS
)
810 sa_payload
->destroy(sa_payload
);
814 *payload
= sa_payload
;
819 static status_t
build_ke_payload(private_ike_sa_t
*this, ke_payload_t
**payload
)
821 ke_payload_t
*ke_payload
;
825 this->logger
->log(this->logger
, CONTROL
|MORE
, "building ke payload");
827 if (this->state
!= NO_STATE
)
829 this->logger
->log(this->logger
, ERROR
, "KE payload in state %s not supported",mapping_find(ike_sa_state_m
,this->state
));
833 switch(this->ike_sa_id
->is_initiator(this->ike_sa_id
))
837 this ->logger
->log(this->logger
, CONTROL
|MORE
, "get public dh value to send in ke payload");
838 status
= this->ike_sa_init_data
.diffie_hellman
->get_my_public_value(this->ike_sa_init_data
.diffie_hellman
,&key_data
);
839 if (status
!= SUCCESS
)
841 this->logger
->log(this->logger
, ERROR
, "Could not get my DH public value");
845 ke_payload
= ke_payload_create();
846 if (ke_payload
== NULL
)
848 this->logger
->log(this->logger
, ERROR
, "Could not create KE payload");
849 allocator_free_chunk(key_data
);
852 ke_payload
->set_dh_group_number(ke_payload
, MODP_1024_BIT
);
853 if (ke_payload
->set_key_exchange_data(ke_payload
, key_data
) != SUCCESS
)
855 this->logger
->log(this->logger
, ERROR
, "Could not set key exchange data of KE payload");
856 ke_payload
->destroy(ke_payload
);
857 allocator_free_chunk(key_data
);
860 allocator_free_chunk(key_data
);
862 *payload
= ke_payload
;
875 * implements private_ike_sa_t.build_nonce_payload
877 static status_t
build_nonce_payload(private_ike_sa_t
*this, nonce_payload_t
**payload
)
879 nonce_payload_t
*nonce_payload
;
881 this->logger
->log(this->logger
, CONTROL
|MORE
, "building nonce payload");
882 nonce_payload
= nonce_payload_create();
883 if (nonce_payload
== NULL
)
888 nonce_payload
->set_nonce(nonce_payload
, this->ike_sa_init_data
.sent_nonce
);
890 *payload
= nonce_payload
;
896 * @brief implements function destroy of private_ike_sa_t
898 static status_t
destroy (private_ike_sa_t
*this)
900 /* destroy child sa's */
901 while (this->child_sas
->get_count(this->child_sas
) > 0)
904 if (this->child_sas
->remove_first(this->child_sas
,&child_sa
) != SUCCESS
)
908 /* destroy child sa */
910 this->child_sas
->destroy(this->child_sas
);
912 /* destroy ike_sa_id */
913 this->ike_sa_id
->destroy(this->ike_sa_id
);
915 /* destroy stored requested messages */
916 while (this->requested_messages
->get_count(this->requested_messages
) > 0)
919 if (this->requested_messages
->remove_first(this->requested_messages
,(void **) &message
) != SUCCESS
)
923 message
->destroy(message
);
925 this->requested_messages
->destroy(this->requested_messages
);
927 /* destroy stored responded messages */
928 while (this->responded_messages
->get_count(this->responded_messages
) > 0)
931 if (this->responded_messages
->remove_first(this->responded_messages
,(void **) &message
) != SUCCESS
)
935 message
->destroy(message
);
937 this->responded_messages
->destroy(this->responded_messages
);
940 this->randomizer
->destroy(this->randomizer
);
941 if (this->ike_sa_init_data
.diffie_hellman
!= NULL
)
943 this->ike_sa_init_data
.diffie_hellman
->destroy(this->ike_sa_init_data
.diffie_hellman
);
945 if (this->ike_sa_init_data
.sent_nonce
.ptr
!= NULL
)
947 allocator_free_chunk(this->ike_sa_init_data
.sent_nonce
);
949 if (this->ike_sa_init_data
.received_nonce
.ptr
!= NULL
)
951 allocator_free_chunk(this->ike_sa_init_data
.received_nonce
);
954 global_logger_manager
->destroy_logger(global_logger_manager
, this->logger
);
956 allocator_free(this);
962 * Described in Header
964 ike_sa_t
* ike_sa_create(ike_sa_id_t
*ike_sa_id
)
966 private_ike_sa_t
*this = allocator_alloc_thing(private_ike_sa_t
);
973 /* Public functions */
974 this->public.process_message
= (status_t(*)(ike_sa_t
*, message_t
*)) process_message
;
975 this->public.initialize_connection
= (status_t(*)(ike_sa_t
*, char*)) initialize_connection
;
976 this->public.get_id
= (ike_sa_id_t
*(*)(ike_sa_t
*)) get_id
;
977 this->public.destroy
= (status_t(*)(ike_sa_t
*))destroy
;
979 /* private functions */
980 this->build_sa_payload
= build_sa_payload
;
981 this->build_nonce_payload
= build_nonce_payload
;
982 this->build_ke_payload
= build_ke_payload
;
983 this->build_message
= build_message
;
984 this->transto_ike_sa_init_requested
= transto_ike_sa_init_requested
;
985 this->transto_ike_sa_init_responded
= transto_ike_sa_init_responded
;
986 this->transto_ike_auth_requested
= transto_ike_auth_requested
;
990 /* initialize private fields */
991 if (ike_sa_id
->clone(ike_sa_id
,&(this->ike_sa_id
)) != SUCCESS
)
993 allocator_free(this);
996 this->child_sas
= linked_list_create();
997 if (this->child_sas
== NULL
)
999 this->ike_sa_id
->destroy(this->ike_sa_id
);
1000 allocator_free(this);
1003 this->randomizer
= randomizer_create();
1004 if (this->randomizer
== NULL
)
1006 this->child_sas
->destroy(this->child_sas
);
1007 this->ike_sa_id
->destroy(this->ike_sa_id
);
1008 allocator_free(this);
1010 this->responded_messages
= linked_list_create();
1011 if (this->responded_messages
== NULL
)
1013 this->randomizer
->destroy(this->randomizer
);
1014 this->child_sas
->destroy(this->child_sas
);
1015 this->ike_sa_id
->destroy(this->ike_sa_id
);
1016 allocator_free(this);
1018 this->requested_messages
= linked_list_create();
1019 if (this->requested_messages
== NULL
)
1021 this->randomizer
->destroy(this->randomizer
);
1022 this->child_sas
->destroy(this->child_sas
);
1023 this->ike_sa_id
->destroy(this->ike_sa_id
);
1024 this->responded_messages
->destroy(this->responded_messages
);
1025 allocator_free(this);
1028 this->logger
= global_logger_manager
->create_logger(global_logger_manager
, IKE_SA
, NULL
);
1029 if (this->logger
== NULL
)
1031 this->randomizer
->destroy(this->randomizer
);
1032 this->child_sas
->destroy(this->child_sas
);
1033 this->ike_sa_id
->destroy(this->ike_sa_id
);
1034 this->responded_messages
->destroy(this->responded_messages
);
1035 this->requested_messages
->destroy(this->requested_messages
);
1036 allocator_free(this);
1039 this->me
.host
= NULL
;
1040 this->other
.host
= NULL
;
1041 this->ike_sa_init_data
.diffie_hellman
= NULL
;
1042 this->ike_sa_init_data
.dh_group_number
= 0;
1043 /* 1 means highest priority */
1044 this->ike_sa_init_data
.dh_group_priority
= 1;
1045 this->ike_sa_init_data
.sent_nonce
.len
= 0;
1046 this->ike_sa_init_data
.sent_nonce
.ptr
= NULL
;
1047 this->ike_sa_init_data
.received_nonce
.len
= 0;
1048 this->ike_sa_init_data
.received_nonce
.ptr
= NULL
;
1049 this->ike_sa_init_data
.proposals
= NULL
;
1050 this->message_id_out
= 0;
1051 this->message_id_in
= 0;
1054 /* at creation time, IKE_SA isn't in a specific state */
1055 this->state
= NO_STATE
;
1057 return (&this->public);