- added compution of all needed keys and also creation of needed
[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 proposal_substructure_t *accepted_proposal;
227
228 status = this->proposals->create_iterator(this->proposals, &accepted_proposals, FALSE);
229 if (status != SUCCESS)
230 {
231 this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on list for proposals");
232 payloads->destroy(payloads);
233 return status;
234 }
235
236 /* get the list of suggested proposals */
237 status = sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE);
238 if (status != SUCCESS)
239 {
240 this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on suggested proposals");
241 accepted_proposals->destroy(accepted_proposals);
242 payloads->destroy(payloads);
243 return status;
244 }
245
246 /* now let the configuration-manager select a subset of the proposals */
247 status = global_configuration_manager->select_proposals_for_host(global_configuration_manager,
248 this->ike_sa->get_other_host(this->ike_sa), suggested_proposals, accepted_proposals);
249 if (status != SUCCESS)
250 {
251 this->logger->log(this->logger, CONTROL | MORE, "No proposal of suggested proposals selected");
252 suggested_proposals->destroy(suggested_proposals);
253 accepted_proposals->destroy(accepted_proposals);
254 payloads->destroy(payloads);
255 return status;
256 }
257
258 /* iterators are not needed anymore */
259 suggested_proposals->destroy(suggested_proposals);
260
261
262 /* let the ike_sa create their own transforms from proposal informations */
263 accepted_proposals->reset(accepted_proposals);
264 /* TODO check for true*/
265 accepted_proposals->has_next(accepted_proposals);
266 status = accepted_proposals->current(accepted_proposals,(void **)&accepted_proposal);
267 if (status != SUCCESS)
268 {
269 this->logger->log(this->logger, ERROR | MORE, "Accepted proposals not supported?!");
270 accepted_proposals->destroy(accepted_proposals);
271 payloads->destroy(payloads);
272 return status;
273 }
274
275 status = this->ike_sa->create_transforms_from_proposal(this->ike_sa,accepted_proposal);
276 accepted_proposals->destroy(accepted_proposals);
277 if (status != SUCCESS)
278 {
279 this->logger->log(this->logger, ERROR | MORE, "Transform objects could not be created from selected proposal");
280 payloads->destroy(payloads);
281 return status;
282 }
283
284 this->logger->log(this->logger, CONTROL | MORE, "SA Payload processed");
285 /* ok, we have what we need for sa_payload (proposals are stored in this->proposals)*/
286 break;
287 }
288 case KEY_EXCHANGE:
289 {
290 ke_payload_t *ke_payload = (ke_payload_t*)payload;
291 diffie_hellman_group_t group;
292 diffie_hellman_t *dh;
293 bool allowed_group;
294
295 group = ke_payload->get_dh_group_number(ke_payload);
296
297 status = global_configuration_manager->is_dh_group_allowed_for_host(global_configuration_manager,
298 this->ike_sa->get_other_host(this->ike_sa), group, &allowed_group);
299
300 if (status != SUCCESS)
301 {
302 this->logger->log(this->logger, ERROR | MORE, "Could not get informations about DH group");
303 payloads->destroy(payloads);
304 return status;
305 }
306 if (!allowed_group)
307 {
308 /** @todo Send info reply */
309 }
310
311 /* create diffie hellman object to handle DH exchange */
312 dh = diffie_hellman_create(group);
313 if (dh == NULL)
314 {
315 this->logger->log(this->logger, ERROR, "Could not generate DH object");
316 payloads->destroy(payloads);
317 return OUT_OF_RES;
318 }
319
320 this->logger->log(this->logger, CONTROL | MORE, "Set other DH public value");
321
322 status = dh->set_other_public_value(dh, ke_payload->get_key_exchange_data(ke_payload));
323 if (status != SUCCESS)
324 {
325 this->logger->log(this->logger, ERROR, "Could not set other DH public value");
326 dh->destroy(dh);
327 payloads->destroy(payloads);
328 return OUT_OF_RES;
329 }
330
331 this->diffie_hellman = dh;
332
333 this->logger->log(this->logger, CONTROL | MORE, "KE Payload processed");
334 break;
335 }
336 case NONCE:
337 {
338 nonce_payload_t *nonce_payload = (nonce_payload_t*)payload;
339
340 if (this->received_nonce.ptr != NULL)
341 {
342 this->logger->log(this->logger, CONTROL | MOST, "Destroy stored received nonce");
343 allocator_free(this->received_nonce.ptr);
344 this->received_nonce.ptr = NULL;
345 this->received_nonce.len = 0;
346 }
347
348 this->logger->log(this->logger, CONTROL | MORE, "Get nonce value and store it");
349 status = nonce_payload->get_nonce(nonce_payload, &(this->received_nonce));
350 if (status != SUCCESS)
351 {
352 this->logger->log(this->logger, ERROR, "Fatal error: Could not get nonce");
353 payloads->destroy(payloads);
354 return OUT_OF_RES;
355 }
356
357 this->logger->log(this->logger, CONTROL | MORE, "Nonce Payload processed");
358 break;
359 }
360 default:
361 {
362 this->logger->log(this->logger, ERROR | MORE, "Payload type not supported!");
363 payloads->destroy(payloads);
364 return OUT_OF_RES;
365 }
366
367 }
368
369 }
370 /* iterator can be destroyed */
371 payloads->destroy(payloads);
372
373 this->logger->log(this->logger, CONTROL | MORE, "Request successfully handled. Going to create reply.");
374
375 this->logger->log(this->logger, CONTROL | MOST, "Going to create nonce.");
376
377 randomizer = this->ike_sa->get_randomizer(this->ike_sa);
378
379 if (randomizer->allocate_pseudo_random_bytes(randomizer, NONCE_SIZE, &(this->sent_nonce)) != SUCCESS)
380 {
381 this->logger->log(this->logger, ERROR, "Could not create nonce!");
382 return OUT_OF_RES;
383 }
384
385 /* store shared secret */
386 this->logger->log(this->logger, CONTROL | MOST, "Retrieve shared secret and store it");
387 status = this->diffie_hellman->get_shared_secret(this->diffie_hellman, &shared_secret);
388 this->logger->log_chunk(this->logger, PRIVATE, "Shared secret", &shared_secret);
389
390 status = this->ike_sa->compute_secrets(this->ike_sa,shared_secret,this->received_nonce, this->sent_nonce);
391 if (status != SUCCESS)
392 {
393 /* secrets could not be computed */
394 this->logger->log(this->logger, ERROR | MORE, "Secrets could not be computed!");
395 return status;
396 }
397
398 /* set up the reply */
399 status = this->ike_sa->build_message(this->ike_sa, IKE_SA_INIT, FALSE, &response);
400 if (status != SUCCESS)
401 {
402 this->logger->log(this->logger, ERROR, "Could not create empty message");
403 return status;
404 }
405
406 /* build SA payload */
407 status = this->build_sa_payload(this, &payload);
408 if (status != SUCCESS)
409 {
410 this->logger->log(this->logger, ERROR, "Could not build SA payload");
411 return status;
412 }
413
414 this ->logger->log(this->logger, CONTROL|MOST, "add SA payload to message");
415 status = response->add_payload(response, payload);
416 if (status != SUCCESS)
417 {
418 this->logger->log(this->logger, ERROR, "Could not add SA payload to message");
419 return status;
420 }
421
422 /* build KE payload */
423 status = this->build_ke_payload(this,&payload);
424 if (status != SUCCESS)
425 {
426 this->logger->log(this->logger, ERROR, "Could not build KE payload");
427 return status;
428 }
429
430 this ->logger->log(this->logger, CONTROL|MOST, "add KE payload to message");
431 status = response->add_payload(response, payload);
432 if (status != SUCCESS)
433 {
434 this->logger->log(this->logger, ERROR, "Could not add KE payload to message");
435 return status;
436 }
437
438 /* build Nonce payload */
439 status = this->build_nonce_payload(this, &payload);
440 if (status != SUCCESS)
441 {
442 this->logger->log(this->logger, ERROR, "Could not build NONCE payload");
443 return status;
444 }
445
446 this ->logger->log(this->logger, CONTROL|MOST, "add nonce payload to message");
447 status = response->add_payload(response, payload);
448 if (status != SUCCESS)
449 {
450 this->logger->log(this->logger, ERROR, "Could not add nonce payload to message");
451 return status;
452 }
453
454 /* generate packet */
455 this ->logger->log(this->logger, CONTROL|MOST, "generate packet from message");
456 status = response->generate(response, &packet);
457 if (status != SUCCESS)
458 {
459 this->logger->log(this->logger, ERROR, "Fatal error: could not generate packet from message");
460 return status;
461 }
462
463 this ->logger->log(this->logger, CONTROL|MOST, "Add packet to global send queue");
464 status = global_send_queue->add(global_send_queue, packet);
465 if (status != SUCCESS)
466 {
467 this->logger->log(this->logger, ERROR, "Could not add packet to send queue");
468 packet->destroy(packet);
469 return status;
470 }
471
472 /* state can now be changed */
473 this ->logger->log(this->logger, CONTROL|MOST, "Create next state object");
474
475 next_state = ike_sa_init_responded_create(this->ike_sa, shared_secret, this->received_nonce, this->sent_nonce);
476
477 if (next_state == NULL)
478 {
479 this ->logger->log(this->logger, ERROR, "Fatal error: could not create next state object of type ike_sa_init_responded_t");
480 allocator_free_chunk(&shared_secret);
481 return FAILED;
482 }
483
484 /* last message can now be set */
485 status = this->ike_sa->set_last_responded_message(this->ike_sa, response);
486
487 if (status != SUCCESS)
488 {
489 this->logger->log(this->logger, ERROR, "Could not set last responded message");
490 response->destroy(response);
491 (next_state->state_interface).destroy(&(next_state->state_interface));
492 return status;
493 }
494
495 /* state can now be changed */
496 this->ike_sa->set_new_state(this->ike_sa, (state_t *) next_state);
497 /* state has NOW changed :-) */
498 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) );
499
500 this ->logger->log(this->logger, CONTROL|MOST, "Destroy old sate object");
501 this->destroy_after_state_change(this);
502
503 return SUCCESS;
504 }
505
506 /**
507 * implements private_initiator_init_t.build_sa_payload
508 */
509 static status_t build_sa_payload(private_responder_init_t *this, payload_t **payload)
510 {
511 sa_payload_t* sa_payload;
512 iterator_t *proposal_iterator;
513 status_t status;
514
515
516 /* SA payload takes proposals from this->ike_sa_init_data.proposals and writes them to the created sa_payload */
517
518 this->logger->log(this->logger, CONTROL|MORE, "building sa payload");
519
520 status = this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE);
521 if (status != SUCCESS)
522 {
523 this->logger->log(this->logger, ERROR, "Fatal error: Could not create iterator on list for proposals");
524 return status;
525 }
526
527 sa_payload = sa_payload_create();
528 if (sa_payload == NULL)
529 {
530 this->logger->log(this->logger, ERROR, "Fatal error: Could not create SA payload object");
531 return OUT_OF_RES;
532 }
533
534 while (proposal_iterator->has_next(proposal_iterator))
535 {
536 proposal_substructure_t *current_proposal;
537 proposal_substructure_t *current_proposal_clone;
538 status = proposal_iterator->current(proposal_iterator,(void **) &current_proposal);
539 if (status != SUCCESS)
540 {
541 this->logger->log(this->logger, ERROR, "Could not get current proposal needed to copy");
542 proposal_iterator->destroy(proposal_iterator);
543 sa_payload->destroy(sa_payload);
544 return status;
545 }
546 status = current_proposal->clone(current_proposal,&current_proposal_clone);
547 if (status != SUCCESS)
548 {
549 this->logger->log(this->logger, ERROR, "Could not clone current proposal");
550 proposal_iterator->destroy(proposal_iterator);
551 sa_payload->destroy(sa_payload);
552 return status;
553 }
554
555 status = sa_payload->add_proposal_substructure(sa_payload,current_proposal_clone);
556 if (status != SUCCESS)
557 {
558 this->logger->log(this->logger, ERROR, "Could not add cloned proposal to SA payload");
559 proposal_iterator->destroy(proposal_iterator);
560 sa_payload->destroy(sa_payload);
561 return status;
562 }
563
564 }
565
566 proposal_iterator->destroy(proposal_iterator);
567
568 this->logger->log(this->logger, CONTROL|MORE, "sa payload builded");
569
570 *payload = (payload_t *) sa_payload;
571
572 return SUCCESS;
573 }
574
575 /**
576 * implements private_initiator_init_t.build_ke_payload
577 */
578 static status_t build_ke_payload(private_responder_init_t *this, payload_t **payload)
579 {
580 ke_payload_t *ke_payload;
581 chunk_t key_data;
582 status_t status;
583
584 this->logger->log(this->logger, CONTROL|MORE, "building ke payload");
585
586
587 this ->logger->log(this->logger, CONTROL|MORE, "get public dh value to send in ke payload");
588 status = this->diffie_hellman->get_my_public_value(this->diffie_hellman,&key_data);
589 if (status != SUCCESS)
590 {
591 this->logger->log(this->logger, ERROR, "Could not get my DH public value");
592 return status;
593 }
594
595 ke_payload = ke_payload_create();
596 if (ke_payload == NULL)
597 {
598 this->logger->log(this->logger, ERROR, "Could not create KE payload");
599 allocator_free_chunk(&key_data);
600 return OUT_OF_RES;
601 }
602 ke_payload->set_dh_group_number(ke_payload, MODP_1024_BIT);
603 if (ke_payload->set_key_exchange_data(ke_payload, key_data) != SUCCESS)
604 {
605 this->logger->log(this->logger, ERROR, "Could not set key exchange data of KE payload");
606 ke_payload->destroy(ke_payload);
607 allocator_free_chunk(&key_data);
608 return OUT_OF_RES;
609 }
610 allocator_free_chunk(&key_data);
611
612 *payload = (payload_t *) ke_payload;
613 return SUCCESS;
614 }
615
616 /**
617 * implements private_initiator_init_t.build_nonce_payload
618 */
619 static status_t build_nonce_payload(private_responder_init_t *this, payload_t **payload)
620 {
621 nonce_payload_t *nonce_payload;
622 status_t status;
623
624 this->logger->log(this->logger, CONTROL|MORE, "building nonce payload");
625
626 nonce_payload = nonce_payload_create();
627 if (nonce_payload == NULL)
628 {
629 this->logger->log(this->logger, ERROR, "Fatal error: could not create nonce payload object");
630 return OUT_OF_RES;
631 }
632
633 status = nonce_payload->set_nonce(nonce_payload, this->sent_nonce);
634
635 if (status != SUCCESS)
636 {
637 this->logger->log(this->logger, ERROR, "Fatal error: could not set nonce data of payload");
638 nonce_payload->destroy(nonce_payload);
639 return status;
640 }
641
642 *payload = (payload_t *) nonce_payload;
643
644 return SUCCESS;
645 }
646
647
648 /**
649 * Implements state_t.get_state
650 */
651 static ike_sa_state_t get_state(private_responder_init_t *this)
652 {
653 return RESPONDER_INIT;
654 }
655
656 /**
657 * Implements state_t.get_state
658 */
659 static status_t destroy(private_responder_init_t *this)
660 {
661 this->logger->log(this->logger, CONTROL | MORE, "Going to destroy responder init state object");
662
663 /* destroy stored proposal */
664 this->logger->log(this->logger, CONTROL | MOST, "Destroy stored proposals");
665 while (this->proposals->get_count(this->proposals) > 0)
666 {
667 proposal_substructure_t *current_proposal;
668 this->proposals->remove_first(this->proposals,(void **)&current_proposal);
669 current_proposal->destroy(current_proposal);
670 }
671 this->proposals->destroy(this->proposals);
672
673 if (this->sent_nonce.ptr != NULL)
674 {
675 this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
676 allocator_free(this->sent_nonce.ptr);
677 }
678
679 if (this->received_nonce.ptr != NULL)
680 {
681 this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
682 allocator_free(this->received_nonce.ptr);
683 }
684
685 /* destroy diffie hellman object */
686 if (this->diffie_hellman != NULL)
687 {
688 this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie_hellman_t object");
689 this->diffie_hellman->destroy(this->diffie_hellman);
690 }
691
692 allocator_free(this);
693
694 return SUCCESS;
695
696 }
697
698 /**
699 * Implements private_responder_init_t.destroy_after_state_change
700 */
701 static status_t destroy_after_state_change (private_responder_init_t *this)
702 {
703 this->logger->log(this->logger, CONTROL | MORE, "Going to destroy responder_init_t state object");
704
705 /* destroy stored proposal */
706 this->logger->log(this->logger, CONTROL | MOST, "Destroy stored proposals");
707 while (this->proposals->get_count(this->proposals) > 0)
708 {
709 proposal_substructure_t *current_proposal;
710 this->proposals->remove_first(this->proposals,(void **)&current_proposal);
711 current_proposal->destroy(current_proposal);
712 }
713 this->proposals->destroy(this->proposals);
714
715 /* destroy diffie hellman object */
716 if (this->diffie_hellman != NULL)
717 {
718 this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie_hellman_t object");
719 this->diffie_hellman->destroy(this->diffie_hellman);
720 }
721
722 allocator_free(this);
723 return SUCCESS;
724 }
725
726 /*
727 * Described in header.
728 */
729 responder_init_t *responder_init_create(protected_ike_sa_t *ike_sa)
730 {
731 private_responder_init_t *this = allocator_alloc_thing(private_responder_init_t);
732
733 if (this == NULL)
734 {
735 return NULL;
736 }
737
738 /* interface functions */
739 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
740 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
741 this->public.state_interface.destroy = (status_t (*) (state_t *)) destroy;
742
743 /* private functions */
744 this->build_sa_payload = build_sa_payload;
745 this->build_ke_payload = build_ke_payload;
746 this->build_nonce_payload = build_nonce_payload;
747 this->destroy_after_state_change = destroy_after_state_change;
748
749 /* private data */
750 this->ike_sa = ike_sa;
751 this->logger = this->ike_sa->get_logger(this->ike_sa);
752 this->sent_nonce.ptr = NULL;
753 this->sent_nonce.len = 0;
754 this->received_nonce.ptr = NULL;
755 this->received_nonce.len = 0;
756 this->proposals = linked_list_create();
757 if (this->proposals == NULL)
758 {
759 allocator_free(this);
760 return NULL;
761 }
762
763 return &(this->public);
764 }