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