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