e3769303cf11deca69c75be911509daae1e5fa1c
[strongswan.git] / Source / charon / sa / states / ike_sa_init_requested.c
1 /**
2 * @file ike_sa_init_requested.c
3 *
4 * @brief Implementation of ike_sa_init_requested_t.
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 "ike_sa_init_requested.h"
24
25 #include <daemon.h>
26 #include <encoding/payloads/sa_payload.h>
27 #include <encoding/payloads/ke_payload.h>
28 #include <encoding/payloads/nonce_payload.h>
29 #include <encoding/payloads/notify_payload.h>
30 #include <encoding/payloads/id_payload.h>
31 #include <encoding/payloads/auth_payload.h>
32 #include <encoding/payloads/ts_payload.h>
33 #include <crypto/diffie_hellman.h>
34 #include <sa/states/ike_auth_requested.h>
35 #include <sa/states/initiator_init.h>
36 #include <sa/authenticator.h>
37
38
39 typedef struct private_ike_sa_init_requested_t private_ike_sa_init_requested_t;
40
41 /**
42 * Private data of a ike_sa_init_requested_t object.
43 *
44 */
45 struct private_ike_sa_init_requested_t {
46 /**
47 * Public interface of an ike_sa_init_requested_t object.
48 */
49 ike_sa_init_requested_t public;
50
51 /**
52 * Assigned IKE_SA
53 */
54 protected_ike_sa_t *ike_sa;
55
56 /**
57 * Diffie Hellman object used to compute shared secret.
58 */
59 diffie_hellman_t *diffie_hellman;
60
61 /**
62 * Sent nonce value.
63 */
64 chunk_t sent_nonce;
65
66 /**
67 * Received nonce
68 */
69 chunk_t received_nonce;
70
71 /**
72 * Selected proposal
73 */
74 proposal_t *proposal;
75
76 /**
77 * Packet data of ike_sa_init request
78 */
79 chunk_t ike_sa_init_request_data;
80
81 /**
82 * Created child sa, if any
83 */
84 child_sa_t *child_sa;
85
86 /**
87 * Assigned logger
88 *
89 * Is logger of ike_sa!
90 */
91 logger_t *logger;
92
93
94 /**
95 * Process NONCE payload of IKE_SA_INIT response.
96 *
97 * @param this calling object
98 * @param nonce_payload NONCE payload to process
99 * @return SUCCESS in any case
100 */
101 status_t (*process_nonce_payload) (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload);
102
103 /**
104 * Process SA payload of IKE_SA_INIT response.
105 *
106 * @param this calling object
107 * @param sa_payload SA payload to process
108 * @return
109 * - SUCCESS
110 * - FAILED
111 */
112 status_t (*process_sa_payload) (private_ike_sa_init_requested_t *this, sa_payload_t *sa_payload);
113
114 /**
115 * Process KE payload of IKE_SA_INIT response.
116 *
117 * @param this calling object
118 * @param sa_payload KE payload to process
119 * @return
120 * - SUCCESS
121 * - FAILED
122 */
123 status_t (*process_ke_payload) (private_ike_sa_init_requested_t *this, ke_payload_t *ke_payload);
124
125 /**
126 * Build ID payload for IKE_AUTH request.
127 *
128 * @param this calling object
129 * @param[out] id_payload buildet ID payload
130 * @param response created payload will be added to this message_t object
131 * @return
132 * - SUCCESS
133 * - FAILED
134 */
135 status_t (*build_id_payload) (private_ike_sa_init_requested_t *this,id_payload_t **id_payload, message_t *response);
136
137 /**
138 * Build AUTH payload for IKE_AUTH request.
139 *
140 * @param this calling object
141 * @param my_id_payload buildet ID payload
142 * @param response created payload will be added to this message_t object
143 * @return
144 * - SUCCESS
145 * - FAILED
146 */
147 status_t (*build_auth_payload) (private_ike_sa_init_requested_t *this,id_payload_t *my_id_payload, message_t *response);
148
149 /**
150 * Build SA payload for IKE_AUTH request.
151 *
152 * @param this calling object
153 * @param response created payload will be added to this message_t object
154 * @return
155 * - SUCCESS
156 * - FAILED
157 */
158 status_t (*build_sa_payload) (private_ike_sa_init_requested_t *this, message_t *response);
159
160 /**
161 * Build TSi payload for IKE_AUTH request.
162 *
163 * @param this calling object
164 * @param response created payload will be added to this message_t object
165 * @return
166 * - SUCCESS
167 * - FAILED
168 */
169 status_t (*build_tsi_payload) (private_ike_sa_init_requested_t *this, message_t *response);
170
171 /**
172 * Build TSr payload for IKE_AUTH request.
173 *
174 * @param this calling object
175 * @param response created payload will be added to this message_t object
176 * @return
177 * - SUCCESS
178 * - FAILED
179 */
180 status_t (*build_tsr_payload) (private_ike_sa_init_requested_t *this, message_t *response);
181
182 /**
183 * Process a notify payload and react.
184 *
185 * @param this calling object
186 * @param notify_payload notify_payload to handle
187 */
188 status_t (*process_notify_payload) (private_ike_sa_init_requested_t *this, notify_payload_t *notify_payload);
189
190 /**
191 * Destroy function called internally of this class after state change to
192 * state IKE_AUTH_REQUESTED succeeded.
193 *
194 * This destroy function does not destroy objects which were passed to the new state.
195 *
196 * @param this calling object
197 */
198 void (*destroy_after_state_change) (private_ike_sa_init_requested_t *this);
199 };
200
201 /**
202 * Implementation of state_t.process_message.
203 */
204 static status_t process_message(private_ike_sa_init_requested_t *this, message_t *ike_sa_init_reply)
205 {
206 ike_auth_requested_t *next_state;
207 chunk_t ike_sa_init_reply_data;
208 sa_payload_t *sa_payload = NULL;
209 ke_payload_t *ke_payload = NULL;
210 id_payload_t *id_payload = NULL;
211 nonce_payload_t *nonce_payload = NULL;
212 u_int64_t responder_spi;
213 ike_sa_id_t *ike_sa_id;
214 iterator_t *payloads;
215 host_t *me;
216 connection_t *connection;
217 policy_t *policy;
218
219 message_t *request;
220 status_t status;
221
222 /*
223 * In this state a reply message of type IKE_SA_INIT is expected:
224 *
225 * <-- HDR, SAr1, KEr, Nr, [CERTREQ]
226 * or
227 * <-- HDR, N
228 */
229
230 if (ike_sa_init_reply->get_exchange_type(ike_sa_init_reply) != IKE_SA_INIT)
231 {
232 this->logger->log(this->logger, ERROR | LEVEL1, "Message of type %s not supported in state ike_sa_init_requested",
233 mapping_find(exchange_type_m,ike_sa_init_reply->get_exchange_type(ike_sa_init_reply)));
234 return FAILED;
235 }
236
237 if (ike_sa_init_reply->get_request(ike_sa_init_reply))
238 {
239 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT requests not allowed state ike_sa_init_responded");
240 return FAILED;
241 }
242
243 /* parse incoming message */
244 status = ike_sa_init_reply->parse_body(ike_sa_init_reply, NULL, NULL);
245 if (status != SUCCESS)
246 {
247 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT reply parsing faild. Ignoring message");
248 return status;
249 }
250
251 /* because we are original initiator we have to update the responder SPI to the new one */
252 responder_spi = ike_sa_init_reply->get_responder_spi(ike_sa_init_reply);
253 if (responder_spi == 0)
254 {
255 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT reply contained a SPI of zero");
256 return FAILED;
257 }
258 ike_sa_id = this->ike_sa->public.get_id(&(this->ike_sa->public));
259 ike_sa_id->set_responder_spi(ike_sa_id,responder_spi);
260
261 /* Iterate over all payloads.
262 *
263 * The message is allready checked for the right payload types.
264 */
265 payloads = ike_sa_init_reply->get_payload_iterator(ike_sa_init_reply);
266 while (payloads->has_next(payloads))
267 {
268 payload_t *payload;
269 payloads->current(payloads, (void**)&payload);
270
271 switch (payload->get_type(payload))
272 {
273 case SECURITY_ASSOCIATION:
274 {
275 sa_payload = (sa_payload_t*)payload;
276 break;
277 }
278 case KEY_EXCHANGE:
279 {
280 ke_payload = (ke_payload_t*)payload;
281 break;
282 }
283 case NONCE:
284 {
285 nonce_payload = (nonce_payload_t*)payload;
286 break;
287 }
288 case NOTIFY:
289 {
290 notify_payload_t *notify_payload = (notify_payload_t *) payload;
291
292 status = this->process_notify_payload(this, notify_payload);
293 if (status != SUCCESS)
294 {
295 payloads->destroy(payloads);
296 return status;
297 }
298 break;
299 }
300 default:
301 {
302 this->logger->log(this->logger, ERROR|LEVEL1, "Ignoring payload %s (%d)",
303 mapping_find(payload_type_m, payload->get_type(payload)), payload->get_type(payload));
304 break;
305 }
306
307 }
308
309 }
310 payloads->destroy(payloads);
311
312 if (!(nonce_payload && sa_payload && ke_payload))
313 {
314 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply did not contain all required payloads. Deleting IKE_SA");
315 return DELETE_ME;
316 }
317
318 status = this->process_nonce_payload (this,nonce_payload);
319 if (status != SUCCESS)
320 {
321 return status;
322 }
323
324 status = this->process_sa_payload (this,sa_payload);
325 if (status != SUCCESS)
326 {
327 return status;
328 }
329
330 status = this->process_ke_payload (this,ke_payload);
331 if (status != SUCCESS)
332 {
333 return status;
334 }
335
336 /* derive all the keys used in the IKE_SA */
337 status = this->ike_sa->build_transforms(this->ike_sa, this->proposal, this->diffie_hellman, this->sent_nonce, this->received_nonce);
338 if (status != SUCCESS)
339 {
340 this->logger->log(this->logger, AUDIT, "Transform objects could not be created from selected proposal. Deleting IKE_SA");
341 return DELETE_ME;
342 }
343
344 /* apply the address on wich we really received the packet */
345 connection = this->ike_sa->get_connection(this->ike_sa);
346 me = ike_sa_init_reply->get_destination(ike_sa_init_reply);
347 connection->update_my_host(connection, me->clone(me));
348 policy = this->ike_sa->get_policy(this->ike_sa);
349 policy->update_my_ts(policy, me);
350
351 /* build empty message */
352 this->ike_sa->build_message(this->ike_sa, IKE_AUTH, TRUE, &request);
353
354 status = this->build_id_payload(this, &id_payload,request);
355 if (status != SUCCESS)
356 {
357 request->destroy(request);
358 return status;
359 }
360 status = this->build_auth_payload(this,(id_payload_t *) id_payload, request);
361 if (status != SUCCESS)
362 {
363 request->destroy(request);
364 return status;
365 }
366 status = this->build_sa_payload(this, request);
367 if (status != SUCCESS)
368 {
369 request->destroy(request);
370 return status;
371 }
372 status = this->build_tsi_payload(this, request);
373 if (status != SUCCESS)
374 {
375 request->destroy(request);
376 return status;
377 }
378 status = this->build_tsr_payload(this, request);
379 if (status != SUCCESS)
380 {
381 request->destroy(request);
382 return status;
383 }
384
385 /* message can now be sent (must not be destroyed) */
386 status = this->ike_sa->send_request(this->ike_sa, request);
387 if (status != SUCCESS)
388 {
389 this->logger->log(this->logger, AUDIT, "Unable to send IKE_AUTH request. Deleting IKE_SA");
390 request->destroy(request);
391 return DELETE_ME;
392 }
393
394 this->ike_sa->set_last_replied_message_id(this->ike_sa,ike_sa_init_reply->get_message_id(ike_sa_init_reply));
395
396 ike_sa_init_reply_data = ike_sa_init_reply->get_packet_data(ike_sa_init_reply);
397
398 /* state can now be changed */
399 next_state = ike_auth_requested_create(this->ike_sa, this->sent_nonce, this->received_nonce,
400 ike_sa_init_reply_data, this->child_sa);
401 this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
402
403 this->destroy_after_state_change(this);
404 return SUCCESS;
405 }
406
407
408 /**
409 * Implementation of private_ike_sa_init_requested_t.process_nonce_payload.
410 */
411 status_t process_nonce_payload (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload)
412 {
413 free(this->received_nonce.ptr);
414 this->received_nonce = nonce_payload->get_nonce(nonce_payload);
415 return SUCCESS;
416 }
417
418
419 /**
420 * Implementation of private_ike_sa_init_requested_t.process_sa_payload.
421 */
422 status_t process_sa_payload (private_ike_sa_init_requested_t *this, sa_payload_t *sa_payload)
423 {
424 proposal_t *proposal;
425 linked_list_t *proposal_list;
426 connection_t *connection;
427
428 connection = this->ike_sa->get_connection(this->ike_sa);
429
430 /* get the list of selected proposals, the peer has to select only one proposal */
431 proposal_list = sa_payload->get_proposals (sa_payload);
432 if (proposal_list->get_count(proposal_list) != 1)
433 {
434 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response did not contain a single proposal. Deleting IKE_SA");
435 while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
436 {
437 proposal->destroy(proposal);
438 }
439 proposal_list->destroy(proposal_list);
440 return DELETE_ME;
441 }
442
443 /* we have to re-check if the others selection is valid */
444 this->proposal = connection->select_proposal(connection, proposal_list);
445 while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
446 {
447 proposal->destroy(proposal);
448 }
449 proposal_list->destroy(proposal_list);
450
451 if (this->proposal == NULL)
452 {
453 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained selected proposal we did not offer. Deleting IKE_SA");
454 return DELETE_ME;
455 }
456
457 return SUCCESS;
458 }
459
460 /**
461 * Implementation of private_ike_sa_init_requested_t.process_ke_payload.
462 */
463 status_t process_ke_payload (private_ike_sa_init_requested_t *this, ke_payload_t *ke_payload)
464 {
465 this->diffie_hellman->set_other_public_value(this->diffie_hellman, ke_payload->get_key_exchange_data(ke_payload));
466
467 return SUCCESS;
468 }
469
470 /**
471 * Implementation of private_ike_sa_init_requested_t.build_id_payload.
472 */
473 static status_t build_id_payload (private_ike_sa_init_requested_t *this,id_payload_t **id_payload, message_t *request)
474 {
475 policy_t *policy;
476 id_payload_t *new_id_payload;
477 identification_t *identification;
478
479 policy = this->ike_sa->get_policy(this->ike_sa);
480 /* identification_t object gets NOT cloned here */
481 identification = policy->get_my_id(policy);
482 new_id_payload = id_payload_create_from_identification(TRUE,identification);
483
484 this->logger->log(this->logger, CONTROL|LEVEL2, "Add ID payload to message");
485 request->add_payload(request,(payload_t *) new_id_payload);
486
487 *id_payload = new_id_payload;
488
489 return SUCCESS;
490 }
491
492 /**
493 * Implementation of private_ike_sa_init_requested_t.build_auth_payload.
494 */
495 static status_t build_auth_payload (private_ike_sa_init_requested_t *this, id_payload_t *my_id_payload, message_t *request)
496 {
497 authenticator_t *authenticator;
498 auth_payload_t *auth_payload;
499 status_t status;
500
501 authenticator = authenticator_create(this->ike_sa);
502 status = authenticator->compute_auth_data(authenticator,&auth_payload,this->ike_sa_init_request_data,this->received_nonce,my_id_payload,TRUE);
503 authenticator->destroy(authenticator);
504
505 if (status != SUCCESS)
506 {
507 this->logger->log(this->logger, AUDIT, "Could not generate AUTH data for IKE_AUTH request. Deleting IKE_SA");
508 return DELETE_ME;
509 }
510
511 this->logger->log(this->logger, CONTROL|LEVEL2, "Add AUTH payload to message");
512 request->add_payload(request,(payload_t *) auth_payload);
513
514 return SUCCESS;
515 }
516
517 /**
518 * Implementation of private_ike_sa_init_requested_t.build_sa_payload.
519 */
520 static status_t build_sa_payload (private_ike_sa_init_requested_t *this, message_t *request)
521 {
522 linked_list_t *proposal_list;
523 sa_payload_t *sa_payload;
524 policy_t *policy;
525 connection_t *connection;
526
527 /* get proposals form config, add to payload */
528 policy = this->ike_sa->get_policy(this->ike_sa);
529 proposal_list = policy->get_proposals(policy);
530 /* build child sa */
531 connection = this->ike_sa->get_connection(this->ike_sa);
532 this->child_sa = child_sa_create(connection->get_my_host(connection),
533 connection->get_other_host(connection));
534 if (this->child_sa->alloc(this->child_sa, proposal_list) != SUCCESS)
535 {
536 this->logger->log(this->logger, AUDIT, "Could not install CHILD_SA! Deleting IKE_SA");
537 return DELETE_ME;
538 }
539
540 sa_payload = sa_payload_create_from_proposal_list(proposal_list);
541
542 this->logger->log(this->logger, CONTROL|LEVEL2, "Add SA payload to message");
543 request->add_payload(request,(payload_t *) sa_payload);
544
545 return SUCCESS;
546 }
547
548 /**
549 * Implementation of private_ike_sa_init_requested_t.build_tsi_payload.
550 */
551 static status_t build_tsi_payload (private_ike_sa_init_requested_t *this, message_t *request)
552 {
553 linked_list_t *ts_list;
554 ts_payload_t *ts_payload;
555 policy_t *policy;
556
557 policy = this->ike_sa->get_policy(this->ike_sa);
558 ts_list = policy->get_my_traffic_selectors(policy);
559 ts_payload = ts_payload_create_from_traffic_selectors(TRUE, ts_list);
560
561 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSi payload to message");
562 request->add_payload(request,(payload_t *) ts_payload);
563
564 return SUCCESS;
565 }
566
567 /**
568 * Implementation of private_ike_sa_init_requested_t.build_tsr_payload.
569 */
570 static status_t build_tsr_payload (private_ike_sa_init_requested_t *this, message_t *request)
571 {
572 linked_list_t *ts_list;
573 ts_payload_t *ts_payload;
574 policy_t *policy;
575
576 policy = this->ike_sa->get_policy(this->ike_sa);
577 ts_list = policy->get_other_traffic_selectors(policy);
578 ts_payload = ts_payload_create_from_traffic_selectors(FALSE, ts_list);
579
580 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSr payload to message");
581 request->add_payload(request,(payload_t *) ts_payload);
582
583 return SUCCESS;
584 }
585
586 /**
587 * Implementation of private_ike_sa_init_requested_t.process_notify_payload.
588 */
589 static status_t process_notify_payload(private_ike_sa_init_requested_t *this, notify_payload_t *notify_payload)
590 {
591 notify_message_type_t notify_message_type = notify_payload->get_notify_message_type(notify_payload);
592
593 this->logger->log(this->logger, CONTROL|LEVEL1, "Process notify type %s",
594 mapping_find(notify_message_type_m, notify_message_type));
595
596 switch (notify_message_type)
597 {
598 case NO_PROPOSAL_CHOSEN:
599 {
600 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a NO_PROPOSAL_CHOSEN notify. Deleting IKE_SA");
601 return DELETE_ME;
602 }
603 case INVALID_MAJOR_VERSION:
604 {
605 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a INVALID_MAJOR_VERSION notify. Deleting IKE_SA");
606 return DELETE_ME;
607 }
608 case INVALID_KE_PAYLOAD:
609 {
610 initiator_init_t *initiator_init_state;
611 chunk_t notify_data;
612 diffie_hellman_group_t dh_group, old_dh_group;
613 connection_t *connection;
614
615 connection = this->ike_sa->get_connection(this->ike_sa);
616 old_dh_group = connection->get_dh_group(connection);
617 notify_data = notify_payload->get_notification_data(notify_payload);
618 dh_group = ntohs(*((u_int16_t*)notify_data.ptr));
619
620 /* TODO:
621 * We are very restrictive here: If the other didn't accept
622 * our DH group, and we do not accept his offer, continuation
623 * is cancelled...
624 */
625
626 this->logger->log(this->logger, AUDIT, "Peer didn't accept %s, it requested %s!",
627 mapping_find(diffie_hellman_group_m, old_dh_group),
628 mapping_find(diffie_hellman_group_m, dh_group));
629 /* check if we can accept this dh group */
630 if (!connection->check_dh_group(connection, dh_group))
631 {
632 this->logger->log(this->logger, AUDIT,
633 "Peer does only accept DH group %s, which we do not accept! Aborting",
634 mapping_find(diffie_hellman_group_m, dh_group));
635 return DELETE_ME;
636 }
637
638 /* Going to change state back to initiator_init_t */
639 this->logger->log(this->logger, CONTROL|LEVEL2, "Create next state object");
640 initiator_init_state = initiator_init_create(this->ike_sa);
641
642 /* buffer of sent and received messages has to get reseted */
643 this->ike_sa->reset_message_buffers(this->ike_sa);
644
645 /* state can now be changed */
646 this->ike_sa->set_new_state(this->ike_sa,(state_t *) initiator_init_state);
647
648 /* state has NOW changed :-) */
649 this->logger->log(this->logger, CONTROL|LEVEL2, "Destroy old sate object");
650 this->logger->log(this->logger, CONTROL|LEVEL2, "Going to retry initialization of connection");
651
652 this->public.state_interface.destroy(&(this->public.state_interface));
653 if (initiator_init_state->retry_initiate_connection (initiator_init_state, dh_group) != SUCCESS)
654 {
655 return DELETE_ME;
656 }
657 return FAILED;
658 }
659 default:
660 {
661 /*
662 * - In case of unknown error: IKE_SA gets destroyed.
663 * - In case of unknown status: logging
664 */
665 if (notify_message_type < 16383)
666 {
667 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply contained an unknown notify error (%d). Deleting IKE_SA",
668 notify_message_type);
669 return DELETE_ME;
670 }
671 else
672 {
673 this->logger->log(this->logger, CONTROL, "IKE_SA_INIT reply contained an unknown notify (%d), ignored.",
674 notify_message_type);
675 return SUCCESS;
676 }
677 }
678 }
679 }
680
681 /**
682 * Implementation of state_t.get_state.
683 */
684 static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this)
685 {
686 return IKE_SA_INIT_REQUESTED;
687 }
688
689 /**
690 * Implementation of private_ike_sa_init_requested_t.destroy_after_state_change.
691 */
692 static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
693 {
694 this->diffie_hellman->destroy(this->diffie_hellman);
695 chunk_free(&(this->ike_sa_init_request_data));
696 if (this->proposal)
697 {
698 this->proposal->destroy(this->proposal);
699 }
700 free(this);
701 }
702
703 /**
704 * Implementation state_t.destroy.
705 */
706 static void destroy(private_ike_sa_init_requested_t *this)
707 {
708 this->diffie_hellman->destroy(this->diffie_hellman);
709 free(this->sent_nonce.ptr);
710 free(this->received_nonce.ptr);
711 chunk_free(&(this->ike_sa_init_request_data));
712 if (this->child_sa)
713 {
714 this->child_sa->destroy(this->child_sa);
715 }
716 if (this->proposal)
717 {
718 this->proposal->destroy(this->proposal);
719 }
720 free(this);
721 }
722
723 /*
724 * Described in header.
725 */
726 ike_sa_init_requested_t *ike_sa_init_requested_create(protected_ike_sa_t *ike_sa, diffie_hellman_t *diffie_hellman, chunk_t sent_nonce,chunk_t ike_sa_init_request_data)
727 {
728 private_ike_sa_init_requested_t *this = malloc_thing(private_ike_sa_init_requested_t);
729
730 /* interface functions */
731 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
732 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
733 this->public.state_interface.destroy = (void (*) (state_t *)) destroy;
734
735 /* private functions */
736 this->destroy_after_state_change = destroy_after_state_change;
737 this->process_nonce_payload = process_nonce_payload;
738 this->process_sa_payload = process_sa_payload;
739 this->process_ke_payload = process_ke_payload;
740 this->build_auth_payload = build_auth_payload;
741 this->build_tsi_payload = build_tsi_payload;
742 this->build_tsr_payload = build_tsr_payload;
743 this->build_id_payload = build_id_payload;
744 this->build_sa_payload = build_sa_payload;
745 this->process_notify_payload = process_notify_payload;
746
747 /* private data */
748 this->ike_sa = ike_sa;
749 this->received_nonce = CHUNK_INITIALIZER;
750 this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
751 this->diffie_hellman = diffie_hellman;
752 this->proposal = NULL;
753 this->sent_nonce = sent_nonce;
754 this->child_sa = NULL;
755 this->ike_sa_init_request_data = ike_sa_init_request_data;
756
757 return &(this->public);
758 }