- changed interface of ike_sa
[strongswan.git] / Source / charon / sa / states / responder_init.c
1 /**
2 * @file responder_init.c
3 *
4 * @brief Start state of a IKE_SA as responder
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include "responder_init.h"
24
25 #include <globals.h>
26 #include <sa/states/state.h>
27 #include <sa/states/ike_sa_init_responded.h>
28 #include <utils/allocator.h>
29 #include <encoding/payloads/sa_payload.h>
30 #include <encoding/payloads/ke_payload.h>
31 #include <encoding/payloads/nonce_payload.h>
32 #include <transforms/diffie_hellman.h>
33
34
35 typedef struct private_responder_init_t private_responder_init_t;
36
37 /**
38 * Private data of a responder_init_t object.
39 *
40 */
41 struct private_responder_init_t {
42 /**
43 * Methods of the state_t interface.
44 */
45 responder_init_t public;
46
47 /**
48 * Assigned IKE_SA.
49 */
50 protected_ike_sa_t *ike_sa;
51
52 /**
53 * Diffie Hellman object used to compute shared secret.
54 *
55 * After processing of incoming IKE_SA_INIT-Request the shared key is
56 * passed to the next state of type ike_sa_init_responded_t.
57 */
58 diffie_hellman_t *diffie_hellman;
59
60 /**
61 * Diffie Hellman group number.
62 */
63 u_int16_t dh_group_number;
64
65 /**
66 * Priority used to get matching dh_group number.
67 */
68 u_int16_t dh_group_priority;
69
70 /**
71 * Sent nonce value.
72 *
73 * This value is passed to the next state of type ike_sa_init_responded_t.
74 */
75 chunk_t sent_nonce;
76
77 /**
78 * Received nonce value
79 *
80 * This value is passed to the next state of type ike_sa_init_responded_t.
81 */
82 chunk_t received_nonce;
83
84 /**
85 * Logger used to log data
86 *
87 * Is logger of ike_sa!
88 */
89 logger_t *logger;
90
91 /**
92 * Proposals used to initiate connection
93 */
94 linked_list_t *proposals;
95
96 /**
97 * Builds the SA payload for this state.
98 *
99 * @param this calling object
100 * @param payload The generated SA payload object of type ke_payload_t is
101 * stored at this location.
102 * @return
103 * - SUCCESS
104 * - OUT_OF_RES
105 */
106 status_t (*build_sa_payload) (private_responder_init_t *this, payload_t **payload);
107
108 /**
109 * Builds the KE payload for this state.
110 *
111 * @param this calling object
112 * @param payload The generated KE payload object of type ke_payload_t is
113 * stored at this location.
114 * @return
115 * - SUCCESS
116 * - OUT_OF_RES
117 */
118 status_t (*build_ke_payload) (private_responder_init_t *this, payload_t **payload);
119 /**
120 * Builds the NONCE payload for this state.
121 *
122 * @param this calling object
123 * @param payload The generated NONCE payload object of type ke_payload_t is
124 * stored at this location.
125 * @return
126 * - SUCCESS
127 * - OUT_OF_RES
128 */
129 status_t (*build_nonce_payload) (private_responder_init_t *this, payload_t **payload);
130
131 /**
132 * Destroy function called internally of this class after state change succeeded.
133 *
134 * This destroy function does not destroy objects which were passed to the new state.
135 *
136 * @param this calling object
137 * @return SUCCESS in any case
138 */
139 status_t (*destroy_after_state_change) (private_responder_init_t *this);
140 };
141
142 /**
143 * Implements state_t.get_state
144 */
145 static status_t process_message(private_responder_init_t *this, message_t *message)
146 {
147 iterator_t *payloads;
148 host_t *source, *destination;
149 status_t status;
150 message_t *response;
151 payload_t *payload;
152 packet_t *packet;
153 chunk_t shared_secret;
154 exchange_type_t exchange_type;
155 ike_sa_init_responded_t *next_state;
156 host_t *my_host;
157 host_t *other_host;
158 randomizer_t *randomizer;
159
160 exchange_type = message->get_exchange_type(message);
161 if (exchange_type != IKE_SA_INIT)
162 {
163 this->logger->log(this->logger, ERROR | MORE, "Message of type %s not supported in state responder_init",mapping_find(exchange_type_m,exchange_type));
164 return FAILED;
165 }
166
167 if (!message->get_request(message))
168 {
169 this->logger->log(this->logger, ERROR | MORE, "Only requests of type IKE_SA_INIT supported in state responder_init");
170 return FAILED;
171 }
172
173 /* this is the first message we process, so copy host infos */
174 message->get_source(message, &source);
175 message->get_destination(message, &destination);
176
177 /* we need to clone them, since we destroy the message later */
178 status = destination->clone(destination, &my_host);
179 if (status != SUCCESS)
180 {
181 this->logger->log(this->logger, ERROR, "Fatal error: could not clone my host informations");
182 return status;
183 }
184 status = source->clone(source, &other_host);
185 if (status != SUCCESS)
186 {
187 this->logger->log(this->logger, ERROR, "Fatal error: could not clone other host informations");
188 my_host->destroy(my_host);
189 return status;
190 }
191
192
193 this->ike_sa->set_my_host(this->ike_sa, my_host);
194 this->ike_sa->set_other_host(this->ike_sa, other_host);
195
196 /* parse incoming message */
197 status = message->parse_body(message);
198 if (status != SUCCESS)
199 {
200 this->logger->log(this->logger, ERROR | MORE, "Could not parse body of request message");
201 return status;
202 }
203
204 /* iterate over incoming payloads. We can be sure, the message contains only accepted payloads! */
205 status = message->get_payload_iterator(message, &payloads);
206 if (status != SUCCESS)
207 {
208 this->logger->log(this->logger, ERROR, "Fatal error: Could not get payload interator");
209 return status;
210 }
211
212 while (payloads->has_next(payloads))
213 {
214 payload_t *payload;
215
216 /* get current payload */
217 payloads->current(payloads, (void**)&payload);
218
219 this->logger->log(this->logger, CONTROL|MORE, "Processing payload of type %s", mapping_find(payload_type_m, payload->get_type(payload)));
220 switch (payload->get_type(payload))
221 {
222 case SECURITY_ASSOCIATION:
223 {
224 sa_payload_t *sa_payload = (sa_payload_t*)payload;
225 iterator_t *suggested_proposals, *accepted_proposals;
226 encryption_algorithm_t encryption_algorithm = ENCR_UNDEFINED;
227 pseudo_random_function_t pseudo_random_function = PRF_UNDEFINED;
228 integrity_algorithm_t integrity_algorithm = AUTH_UNDEFINED;
229 prf_t *prf;
230
231 status = this->proposals->create_iterator(this->proposals, &accepted_proposals, FALSE);
232 if (status != SUCCESS)
233 {
234 this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on list for proposals");
235 payloads->destroy(payloads);
236 return status;
237 }
238
239 /* get the list of suggested proposals */
240 status = sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE);
241 if (status != SUCCESS)
242 {
243 this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on suggested proposals");
244 accepted_proposals->destroy(accepted_proposals);
245 payloads->destroy(payloads);
246 return status;
247 }
248
249 /* now let the configuration-manager select a subset of the proposals */
250 status = global_configuration_manager->select_proposals_for_host(global_configuration_manager,
251 this->ike_sa->get_other_host(this->ike_sa), suggested_proposals, accepted_proposals);
252 if (status != SUCCESS)
253 {
254 this->logger->log(this->logger, CONTROL | MORE, "No proposal of suggested proposals selected");
255 suggested_proposals->destroy(suggested_proposals);
256 accepted_proposals->destroy(accepted_proposals);
257 payloads->destroy(payloads);
258 return status;
259 }
260
261 /* iterators are not needed anymore */
262 suggested_proposals->destroy(suggested_proposals);
263
264
265 /* now let the configuration-manager return the transforms for the given proposal*/
266 this->logger->log(this->logger, CONTROL | MOST, "Get transforms for accepted proposal");
267 status = global_configuration_manager->get_transforms_for_host_and_proposals(global_configuration_manager,
268 this->ike_sa->get_other_host(this->ike_sa), accepted_proposals, &encryption_algorithm,&pseudo_random_function,&integrity_algorithm);
269 if (status != SUCCESS)
270 {
271 this->logger->log(this->logger, ERROR | MORE, "Accepted proposals not supported?!");
272 accepted_proposals->destroy(accepted_proposals);
273 payloads->destroy(payloads);
274 return status;
275 }
276 accepted_proposals->destroy(accepted_proposals);
277
278 prf = prf_create(pseudo_random_function);
279 if (prf == NULL)
280 {
281 this->logger->log(this->logger, ERROR | MORE, "PRF type not supported");
282 payloads->destroy(payloads);
283 return FAILED;
284 }
285 this->ike_sa->set_prf(this->ike_sa,prf);
286
287 this->logger->log(this->logger, CONTROL | MORE, "SA Payload processed");
288 /* ok, we have what we need for sa_payload (proposals are stored in this->proposals)*/
289 break;
290 }
291 case KEY_EXCHANGE:
292 {
293 ke_payload_t *ke_payload = (ke_payload_t*)payload;
294 diffie_hellman_group_t group;
295 diffie_hellman_t *dh;
296 bool allowed_group;
297
298 group = ke_payload->get_dh_group_number(ke_payload);
299
300 status = global_configuration_manager->is_dh_group_allowed_for_host(global_configuration_manager,
301 this->ike_sa->get_other_host(this->ike_sa), group, &allowed_group);
302
303 if (status != SUCCESS)
304 {
305 this->logger->log(this->logger, ERROR | MORE, "Could not get informations about DH group");
306 payloads->destroy(payloads);
307 return status;
308 }
309 if (!allowed_group)
310 {
311 /** @todo Send info reply */
312 }
313
314 /* create diffie hellman object to handle DH exchange */
315 dh = diffie_hellman_create(group);
316 if (dh == NULL)
317 {
318 this->logger->log(this->logger, ERROR, "Could not generate DH object");
319 payloads->destroy(payloads);
320 return OUT_OF_RES;
321 }
322
323 this->logger->log(this->logger, CONTROL | MORE, "Set other DH public value");
324
325 status = dh->set_other_public_value(dh, ke_payload->get_key_exchange_data(ke_payload));
326 if (status != SUCCESS)
327 {
328 this->logger->log(this->logger, ERROR, "Could not set other DH public value");
329 dh->destroy(dh);
330 payloads->destroy(payloads);
331 return OUT_OF_RES;
332 }
333
334 this->diffie_hellman = dh;
335
336 this->logger->log(this->logger, CONTROL | MORE, "KE Payload processed");
337 break;
338 }
339 case NONCE:
340 {
341 nonce_payload_t *nonce_payload = (nonce_payload_t*)payload;
342
343 if (this->received_nonce.ptr != NULL)
344 {
345 this->logger->log(this->logger, CONTROL | MOST, "Destroy stored received nonce");
346 allocator_free(this->received_nonce.ptr);
347 this->received_nonce.ptr = NULL;
348 this->received_nonce.len = 0;
349 }
350
351 this->logger->log(this->logger, CONTROL | MORE, "Get nonce value and store it");
352 status = nonce_payload->get_nonce(nonce_payload, &(this->received_nonce));
353 if (status != SUCCESS)
354 {
355 this->logger->log(this->logger, ERROR, "Fatal error: Could not get nonce");
356 payloads->destroy(payloads);
357 return OUT_OF_RES;
358 }
359
360 this->logger->log(this->logger, CONTROL | MORE, "Nonce Payload processed");
361 break;
362 }
363 default:
364 {
365 this->logger->log(this->logger, ERROR | MORE, "Payload type not supported!");
366 payloads->destroy(payloads);
367 return OUT_OF_RES;
368 }
369
370 }
371
372 }
373 /* iterator can be destroyed */
374 payloads->destroy(payloads);
375
376 this->logger->log(this->logger, CONTROL | MORE, "Request successfully handled. Going to create reply.");
377
378 this->logger->log(this->logger, CONTROL | MOST, "Going to create nonce.");
379
380 randomizer = this->ike_sa->get_randomizer(this->ike_sa);
381
382 if (randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce)) != SUCCESS)
383 {
384 this->logger->log(this->logger, ERROR, "Could not create nonce!");
385 return OUT_OF_RES;
386 }
387
388 /* store shared secret */
389 this->logger->log(this->logger, CONTROL | MOST, "Retrieve shared secret and store it");
390 status = this->diffie_hellman->get_shared_secret(this->diffie_hellman, &shared_secret);
391 this->logger->log_chunk(this->logger, PRIVATE, "Shared secret", &shared_secret);
392
393 status = this->ike_sa->compute_secrets(this->ike_sa,shared_secret,this->received_nonce, this->sent_nonce);
394 if (status != SUCCESS)
395 {
396 /* secrets could not be computed */
397 this->logger->log(this->logger, ERROR | MORE, "Secrets could not be computed!");
398 return status;
399 }
400
401
402
403 /* set up the reply */
404 status = this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, FALSE, &response);
405 if (status != SUCCESS)
406 {
407 this->logger->log(this->logger, ERROR, "Could not create empty message");
408 return status;
409 }
410
411 /* build SA payload */
412 status = this->build_sa_payload(this, &payload);
413 if (status != SUCCESS)
414 {
415 this->logger->log(this->logger, ERROR, "Could not build SA payload");
416 return status;
417 }
418
419 this ->logger->log(this->logger, CONTROL|MOST, "add SA payload to message");
420 status = response->add_payload(response, payload);
421 if (status != SUCCESS)
422 {
423 this->logger->log(this->logger, ERROR, "Could not add SA payload to message");
424 return status;
425 }
426
427 /* build KE payload */
428 status = this->build_ke_payload(this,&payload);
429 if (status != SUCCESS)
430 {
431 this->logger->log(this->logger, ERROR, "Could not build KE payload");
432 return status;
433 }
434
435 this ->logger->log(this->logger, CONTROL|MOST, "add KE payload to message");
436 status = response->add_payload(response, payload);
437 if (status != SUCCESS)
438 {
439 this->logger->log(this->logger, ERROR, "Could not add KE payload to message");
440 return status;
441 }
442
443 /* build Nonce payload */
444 status = this->build_nonce_payload(this, &payload);
445 if (status != SUCCESS)
446 {
447 this->logger->log(this->logger, ERROR, "Could not build NONCE payload");
448 return status;
449 }
450
451 this ->logger->log(this->logger, CONTROL|MOST, "add nonce payload to message");
452 status = response->add_payload(response, payload);
453 if (status != SUCCESS)
454 {
455 this->logger->log(this->logger, ERROR, "Could not add nonce payload to message");
456 return status;
457 }
458
459 /* generate packet */
460 this ->logger->log(this->logger, CONTROL|MOST, "generate packet from message");
461 status = response->generate(response, &packet);
462 if (status != SUCCESS)
463 {
464 this->logger->log(this->logger, ERROR, "Fatal error: could not generate packet from message");
465 return status;
466 }
467
468 this ->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
469 status = global_send_queue->add(global_send_queue, packet);
470 if (status != SUCCESS)
471 {
472 this->logger->log(this->logger, ERROR, "Could not add packet to send queue");
473 packet->destroy(packet);
474 return status;
475 }
476
477 /* state can now be changed */
478 this ->logger->log(this->logger, CONTROL|MOST, "Create next state object");
479
480 next_state = ike_sa_init_responded_create(this->ike_sa, shared_secret, this->received_nonce, this->sent_nonce);
481
482 if (next_state == NULL)
483 {
484 this ->logger->log(this->logger, ERROR, "Fatal error: could not create next state object of type ike_sa_init_responded_t");
485 allocator_free_chunk(&shared_secret);
486 return FAILED;
487 }
488
489 /* last message can now be set */
490 status = this->ike_sa->set_last_responded_message(this->ike_sa, response);
491
492 if (status != SUCCESS)
493 {
494 this->logger->log(this->logger, ERROR, "Could not set last responded message");
495 response->destroy(response);
496 (next_state->state_interface).destroy(&(next_state->state_interface));
497 return status;
498 }
499
500 /* state can now be changed */
501 this->ike_sa->set_new_state(this->ike_sa, (state_t *) next_state);
502 /* state has NOW changed :-) */
503 this ->logger->log(this->logger, CONTROL|MORE, "Changed state of IKE_SA from %s to %s",mapping_find(ike_sa_state_m,RESPONDER_INIT),mapping_find(ike_sa_state_m,IKE_SA_INIT_RESPONDED) );
504
505 this ->logger->log(this->logger, CONTROL|MOST, "Destroy old sate object");
506 this->destroy_after_state_change(this);
507
508 return SUCCESS;
509 }
510
511 /**
512 * implements private_initiator_init_t.build_sa_payload
513 */
514 static status_t build_sa_payload(private_responder_init_t *this, payload_t **payload)
515 {
516 sa_payload_t* sa_payload;
517 iterator_t *proposal_iterator;
518 status_t status;
519
520
521 /* SA payload takes proposals from this->ike_sa_init_data.proposals and writes them to the created sa_payload */
522
523 this->logger->log(this->logger, CONTROL|MORE, "building sa payload");
524
525 status = this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE);
526 if (status != SUCCESS)
527 {
528 this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on list for proposals");
529 return status;
530 }
531
532 sa_payload = sa_payload_create();
533 if (sa_payload == NULL)
534 {
535 this->logger->log(this->logger, ERROR, "Fatal error: Could not create SA payload object");
536 return OUT_OF_RES;
537 }
538
539 while (proposal_iterator->has_next(proposal_iterator))
540 {
541 proposal_substructure_t *current_proposal;
542 proposal_substructure_t *current_proposal_clone;
543 status = proposal_iterator->current(proposal_iterator,(void **) &current_proposal);
544 if (status != SUCCESS)
545 {
546 this->logger->log(this->logger, ERROR, "Could not get current proposal needed to copy");
547 proposal_iterator->destroy(proposal_iterator);
548 sa_payload->destroy(sa_payload);
549 return status;
550 }
551 status = current_proposal->clone(current_proposal,&current_proposal_clone);
552 if (status != SUCCESS)
553 {
554 this->logger->log(this->logger, ERROR, "Could not clone current proposal");
555 proposal_iterator->destroy(proposal_iterator);
556 sa_payload->destroy(sa_payload);
557 return status;
558 }
559
560 status = sa_payload->add_proposal_substructure(sa_payload,current_proposal_clone);
561 if (status != SUCCESS)
562 {
563 this->logger->log(this->logger, ERROR, "Could not add cloned proposal to SA payload");
564 proposal_iterator->destroy(proposal_iterator);
565 sa_payload->destroy(sa_payload);
566 return status;
567 }
568
569 }
570
571 proposal_iterator->destroy(proposal_iterator);
572
573 this->logger->log(this->logger, CONTROL|MORE, "sa payload builded");
574
575 *payload = (payload_t *) sa_payload;
576
577 return SUCCESS;
578 }
579
580 /**
581 * implements private_initiator_init_t.build_ke_payload
582 */
583 static status_t build_ke_payload(private_responder_init_t *this, payload_t **payload)
584 {
585 ke_payload_t *ke_payload;
586 chunk_t key_data;
587 status_t status;
588
589 this->logger->log(this->logger, CONTROL|MORE, "building ke payload");
590
591
592 this ->logger->log(this->logger, CONTROL|MORE, "get public dh value to send in ke payload");
593 status = this->diffie_hellman->get_my_public_value(this->diffie_hellman,&key_data);
594 if (status != SUCCESS)
595 {
596 this->logger->log(this->logger, ERROR, "Could not get my DH public value");
597 return status;
598 }
599
600 ke_payload = ke_payload_create();
601 if (ke_payload == NULL)
602 {
603 this->logger->log(this->logger, ERROR, "Could not create KE payload");
604 allocator_free_chunk(&key_data);
605 return OUT_OF_RES;
606 }
607 ke_payload->set_dh_group_number(ke_payload, MODP_1024_BIT);
608 if (ke_payload->set_key_exchange_data(ke_payload, key_data) != SUCCESS)
609 {
610 this->logger->log(this->logger, ERROR, "Could not set key exchange data of KE payload");
611 ke_payload->destroy(ke_payload);
612 allocator_free_chunk(&key_data);
613 return OUT_OF_RES;
614 }
615 allocator_free_chunk(&key_data);
616
617 *payload = (payload_t *) ke_payload;
618 return SUCCESS;
619 }
620
621 /**
622 * implements private_initiator_init_t.build_nonce_payload
623 */
624 static status_t build_nonce_payload(private_responder_init_t *this, payload_t **payload)
625 {
626 nonce_payload_t *nonce_payload;
627 status_t status;
628
629 this->logger->log(this->logger, CONTROL|MORE, "building nonce payload");
630
631 nonce_payload = nonce_payload_create();
632 if (nonce_payload == NULL)
633 {
634 this->logger->log(this->logger, ERROR, "Fatal error: could not create nonce payload object");
635 return OUT_OF_RES;
636 }
637
638 status = nonce_payload->set_nonce(nonce_payload, this->sent_nonce);
639
640 if (status != SUCCESS)
641 {
642 this->logger->log(this->logger, ERROR, "Fatal error: could not set nonce data of payload");
643 nonce_payload->destroy(nonce_payload);
644 return status;
645 }
646
647 *payload = (payload_t *) nonce_payload;
648
649 return SUCCESS;
650 }
651
652
653 /**
654 * Implements state_t.get_state
655 */
656 static ike_sa_state_t get_state(private_responder_init_t *this)
657 {
658 return RESPONDER_INIT;
659 }
660
661 /**
662 * Implements state_t.get_state
663 */
664 static status_t destroy(private_responder_init_t *this)
665 {
666 this->logger->log(this->logger, CONTROL | MORE, "Going to destroy responder init state object");
667
668 /* destroy stored proposal */
669 this->logger->log(this->logger, CONTROL | MOST, "Destroy stored proposals");
670 while (this->proposals->get_count(this->proposals) > 0)
671 {
672 proposal_substructure_t *current_proposal;
673 this->proposals->remove_first(this->proposals,(void **)&current_proposal);
674 current_proposal->destroy(current_proposal);
675 }
676 this->proposals->destroy(this->proposals);
677
678 if (this->sent_nonce.ptr != NULL)
679 {
680 this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
681 allocator_free(this->sent_nonce.ptr);
682 }
683
684 if (this->received_nonce.ptr != NULL)
685 {
686 this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
687 allocator_free(this->received_nonce.ptr);
688 }
689
690 /* destroy diffie hellman object */
691 if (this->diffie_hellman != NULL)
692 {
693 this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie_hellman_t object");
694 this->diffie_hellman->destroy(this->diffie_hellman);
695 }
696
697 allocator_free(this);
698
699 return SUCCESS;
700
701 }
702
703 /**
704 * Implements private_responder_init_t.destroy_after_state_change
705 */
706 static status_t destroy_after_state_change (private_responder_init_t *this)
707 {
708 this->logger->log(this->logger, CONTROL | MORE, "Going to destroy responder_init_t state object");
709
710 /* destroy stored proposal */
711 this->logger->log(this->logger, CONTROL | MOST, "Destroy stored proposals");
712 while (this->proposals->get_count(this->proposals) > 0)
713 {
714 proposal_substructure_t *current_proposal;
715 this->proposals->remove_first(this->proposals,(void **)&current_proposal);
716 current_proposal->destroy(current_proposal);
717 }
718 this->proposals->destroy(this->proposals);
719
720 /* destroy diffie hellman object */
721 if (this->diffie_hellman != NULL)
722 {
723 this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie_hellman_t object");
724 this->diffie_hellman->destroy(this->diffie_hellman);
725 }
726
727 allocator_free(this);
728 return SUCCESS;
729 }
730
731 /*
732 * Described in header.
733 */
734 responder_init_t *responder_init_create(protected_ike_sa_t *ike_sa)
735 {
736 private_responder_init_t *this = allocator_alloc_thing(private_responder_init_t);
737
738 if (this == NULL)
739 {
740 return NULL;
741 }
742
743 /* interface functions */
744 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
745 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
746 this->public.state_interface.destroy = (status_t (*) (state_t *)) destroy;
747
748 /* private functions */
749 this->build_sa_payload = build_sa_payload;
750 this->build_ke_payload = build_ke_payload;
751 this->build_nonce_payload = build_nonce_payload;
752 this->destroy_after_state_change = destroy_after_state_change;
753
754 /* private data */
755 this->ike_sa = ike_sa;
756 this->logger = this->ike_sa->get_logger(this->ike_sa);
757 this->sent_nonce.ptr = NULL;
758 this->sent_nonce.len = 0;
759 this->received_nonce.ptr = NULL;
760 this->received_nonce.len = 0;
761 this->proposals = linked_list_create();
762 if (this->proposals == NULL)
763 {
764 allocator_free(this);
765 return NULL;
766 }
767
768 return &(this->public);
769 }