- reworked configuration framework completly
[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 connection_t *connection;
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 }
299 default:
300 {
301 this->logger->log(this->logger, ERROR|LEVEL1, "Ignoring payload %s (%d)",
302 mapping_find(payload_type_m, payload->get_type(payload)), payload->get_type(payload));
303 break;
304 }
305
306 }
307
308 }
309 payloads->destroy(payloads);
310
311 if (!(nonce_payload && sa_payload && ke_payload))
312 {
313 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply did not contain all required payloads. Deleting IKE_SA");
314 return DELETE_ME;
315 }
316
317 status = this->process_nonce_payload (this,nonce_payload);
318 if (status != SUCCESS)
319 {
320 return status;
321 }
322
323 status = this->process_sa_payload (this,sa_payload);
324 if (status != SUCCESS)
325 {
326 return status;
327 }
328
329 status = this->process_ke_payload (this,ke_payload);
330 if (status != SUCCESS)
331 {
332 return status;
333 }
334
335 /* derive all the keys used in the IKE_SA */
336 status = this->ike_sa->build_transforms(this->ike_sa, this->proposal, this->diffie_hellman, this->sent_nonce, this->received_nonce);
337 if (status != SUCCESS)
338 {
339 this->logger->log(this->logger, AUDIT, "Transform objects could not be created from selected proposal. Deleting IKE_SA");
340 return DELETE_ME;
341 }
342
343 /* apply the address on wich we really received the packet */
344 connection = this->ike_sa->get_connection(this->ike_sa);
345 me = ike_sa_init_reply->get_destination(ike_sa_init_reply);
346 connection->update_my_host(connection, me->clone(me));
347
348 /* build empty message */
349 this->ike_sa->build_message(this->ike_sa, IKE_AUTH, TRUE, &request);
350
351 status = this->build_id_payload(this, &id_payload,request);
352 if (status != SUCCESS)
353 {
354 request->destroy(request);
355 return status;
356 }
357 status = this->build_auth_payload(this,(id_payload_t *) id_payload, request);
358 if (status != SUCCESS)
359 {
360 request->destroy(request);
361 return status;
362 }
363 status = this->build_sa_payload(this, request);
364 if (status != SUCCESS)
365 {
366 request->destroy(request);
367 return status;
368 }
369 status = this->build_tsi_payload(this, request);
370 if (status != SUCCESS)
371 {
372 request->destroy(request);
373 return status;
374 }
375 status = this->build_tsr_payload(this, request);
376 if (status != SUCCESS)
377 {
378 request->destroy(request);
379 return status;
380 }
381
382 /* message can now be sent (must not be destroyed) */
383 status = this->ike_sa->send_request(this->ike_sa, request);
384 if (status != SUCCESS)
385 {
386 this->logger->log(this->logger, AUDIT, "Unable to send IKE_AUTH request. Deleting IKE_SA");
387 request->destroy(request);
388 return DELETE_ME;
389 }
390
391 this->ike_sa->set_last_replied_message_id(this->ike_sa,ike_sa_init_reply->get_message_id(ike_sa_init_reply));
392
393 ike_sa_init_reply_data = ike_sa_init_reply->get_packet_data(ike_sa_init_reply);
394
395 /* state can now be changed */
396 next_state = ike_auth_requested_create(this->ike_sa, this->sent_nonce, this->received_nonce,
397 ike_sa_init_reply_data, this->child_sa);
398 this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
399
400 this->destroy_after_state_change(this);
401 return SUCCESS;
402 }
403
404
405 /**
406 * Implementation of private_ike_sa_init_requested_t.process_nonce_payload.
407 */
408 status_t process_nonce_payload (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload)
409 {
410 allocator_free(this->received_nonce.ptr);
411 this->received_nonce = nonce_payload->get_nonce(nonce_payload);
412 return SUCCESS;
413 }
414
415
416 /**
417 * Implementation of private_ike_sa_init_requested_t.process_sa_payload.
418 */
419 status_t process_sa_payload (private_ike_sa_init_requested_t *this, sa_payload_t *sa_payload)
420 {
421 proposal_t *proposal;
422 linked_list_t *proposal_list;
423 connection_t *connection;
424
425 connection = this->ike_sa->get_connection(this->ike_sa);
426
427 /* get the list of selected proposals, the peer has to select only one proposal */
428 proposal_list = sa_payload->get_proposals (sa_payload);
429 if (proposal_list->get_count(proposal_list) != 1)
430 {
431 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response did not contain a single proposal. Deleting IKE_SA");
432 while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
433 {
434 proposal->destroy(proposal);
435 }
436 proposal_list->destroy(proposal_list);
437 return DELETE_ME;
438 }
439
440 /* we have to re-check if the others selection is valid */
441 this->proposal = connection->select_proposal(connection, proposal_list);
442 while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
443 {
444 proposal->destroy(proposal);
445 }
446 proposal_list->destroy(proposal_list);
447
448 if (this->proposal == NULL)
449 {
450 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained selected proposal we did not offer. Deleting IKE_SA");
451 return DELETE_ME;
452 }
453
454 return SUCCESS;
455 }
456
457 /**
458 * Implementation of private_ike_sa_init_requested_t.process_ke_payload.
459 */
460 status_t process_ke_payload (private_ike_sa_init_requested_t *this, ke_payload_t *ke_payload)
461 {
462 this->diffie_hellman->set_other_public_value(this->diffie_hellman, ke_payload->get_key_exchange_data(ke_payload));
463
464 return SUCCESS;
465 }
466
467 /**
468 * Implementation of private_ike_sa_init_requested_t.build_id_payload.
469 */
470 static status_t build_id_payload (private_ike_sa_init_requested_t *this,id_payload_t **id_payload, message_t *request)
471 {
472 policy_t *policy;
473 id_payload_t *new_id_payload;
474 identification_t *identification;
475
476 policy = this->ike_sa->get_policy(this->ike_sa);
477 /* identification_t object gets NOT cloned here */
478 identification = policy->get_my_id(policy);
479 new_id_payload = id_payload_create_from_identification(TRUE,identification);
480
481 this->logger->log(this->logger, CONTROL|LEVEL2, "Add ID payload to message");
482 request->add_payload(request,(payload_t *) new_id_payload);
483
484 *id_payload = new_id_payload;
485
486 return SUCCESS;
487 }
488
489 /**
490 * Implementation of private_ike_sa_init_requested_t.build_auth_payload.
491 */
492 static status_t build_auth_payload (private_ike_sa_init_requested_t *this, id_payload_t *my_id_payload, message_t *request)
493 {
494 authenticator_t *authenticator;
495 auth_payload_t *auth_payload;
496 status_t status;
497
498 authenticator = authenticator_create(this->ike_sa);
499 status = authenticator->compute_auth_data(authenticator,&auth_payload,this->ike_sa_init_request_data,this->received_nonce,my_id_payload,TRUE);
500 authenticator->destroy(authenticator);
501
502 if (status != SUCCESS)
503 {
504 this->logger->log(this->logger, AUDIT, "Could not generate AUTH data for IKE_AUTH request. Deleting IKE_SA");
505 return DELETE_ME;
506 }
507
508 this->logger->log(this->logger, CONTROL|LEVEL2, "Add AUTH payload to message");
509 request->add_payload(request,(payload_t *) auth_payload);
510
511 return SUCCESS;
512 }
513
514 /**
515 * Implementation of private_ike_sa_init_requested_t.build_sa_payload.
516 */
517 static status_t build_sa_payload (private_ike_sa_init_requested_t *this, message_t *request)
518 {
519 linked_list_t *proposal_list;
520 sa_payload_t *sa_payload;
521 policy_t *policy;
522 connection_t *connection;
523
524 /* get proposals form config, add to payload */
525 policy = this->ike_sa->get_policy(this->ike_sa);
526 proposal_list = policy->get_proposals(policy);
527 /* build child sa */
528 connection = this->ike_sa->get_connection(this->ike_sa);
529 this->child_sa = child_sa_create(connection->get_my_host(connection),
530 connection->get_other_host(connection));
531 if (this->child_sa->alloc(this->child_sa, proposal_list) != SUCCESS)
532 {
533 this->logger->log(this->logger, AUDIT, "Could not install CHILD_SA! Deleting IKE_SA");
534 return DELETE_ME;
535 }
536
537 /* TODO:
538 * Huston, we've got a problem here. Since SPIs are stored in
539 * the proposal, and these proposals are shared across configs,
540 * there may be some threading issues... fix it!
541 */
542 sa_payload = sa_payload_create_from_proposal_list(proposal_list);
543
544 this->logger->log(this->logger, CONTROL|LEVEL2, "Add SA payload to message");
545 request->add_payload(request,(payload_t *) sa_payload);
546
547 return SUCCESS;
548 }
549
550 /**
551 * Implementation of private_ike_sa_init_requested_t.build_tsi_payload.
552 */
553 static status_t build_tsi_payload (private_ike_sa_init_requested_t *this, message_t *request)
554 {
555 linked_list_t *ts_list;
556 ts_payload_t *ts_payload;
557 policy_t *policy;
558
559 policy = this->ike_sa->get_policy(this->ike_sa);
560 ts_list = policy->get_my_traffic_selectors(policy);
561 ts_payload = ts_payload_create_from_traffic_selectors(TRUE, ts_list);
562
563 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSi payload to message");
564 request->add_payload(request,(payload_t *) ts_payload);
565
566 return SUCCESS;
567 }
568
569 /**
570 * Implementation of private_ike_sa_init_requested_t.build_tsr_payload.
571 */
572 static status_t build_tsr_payload (private_ike_sa_init_requested_t *this, message_t *request)
573 {
574 linked_list_t *ts_list;
575 ts_payload_t *ts_payload;
576 policy_t *policy;
577
578 policy = this->ike_sa->get_policy(this->ike_sa);
579 ts_list = policy->get_other_traffic_selectors(policy);
580 ts_payload = ts_payload_create_from_traffic_selectors(FALSE, ts_list);
581
582 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSr payload to message");
583 request->add_payload(request,(payload_t *) ts_payload);
584
585 return SUCCESS;
586 }
587
588 /**
589 * Implementation of private_ike_sa_init_requested_t.process_notify_payload.
590 */
591 static status_t process_notify_payload(private_ike_sa_init_requested_t *this, notify_payload_t *notify_payload)
592 {
593 notify_message_type_t notify_message_type = notify_payload->get_notify_message_type(notify_payload);
594
595 this->logger->log(this->logger, CONTROL|LEVEL1, "Process notify type %s for protocol %s",
596 mapping_find(notify_message_type_m, notify_message_type),
597 mapping_find(protocol_id_m, notify_payload->get_protocol_id(notify_payload)));
598
599 if (notify_payload->get_protocol_id(notify_payload) != IKE)
600 {
601 this->logger->log(this->logger, ERROR | LEVEL1, "Notify reply not for IKE protocol.");
602 return FAILED;
603 }
604 switch (notify_message_type)
605 {
606 case NO_PROPOSAL_CHOSEN:
607 {
608 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a NO_PROPOSAL_CHOSEN notify. Deleting IKE_SA");
609 return DELETE_ME;
610 }
611 case INVALID_MAJOR_VERSION:
612 {
613 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a INVALID_MAJOR_VERSION notify. Deleting IKE_SA");
614 return DELETE_ME;
615 }
616 case INVALID_KE_PAYLOAD:
617 {
618 initiator_init_t *initiator_init_state;
619 chunk_t notify_data;
620 diffie_hellman_group_t dh_group;
621 connection_t *connection;
622
623 notify_data = notify_payload->get_notification_data(notify_payload);
624 dh_group = ntohs(*((u_int16_t*)notify_data.ptr));
625
626 this->logger->log(this->logger, ERROR|LEVEL1, "Peer wouldn't accept DH group, it requested %s!",
627 mapping_find(diffie_hellman_group_m, dh_group));
628 /* check if we can accept this dh group */
629 connection = this->ike_sa->get_connection(this->ike_sa);
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|LEVEL1, "Changed state of IKE_SA from %s to %s",
650 mapping_find(ike_sa_state_m,INITIATOR_INIT), mapping_find(ike_sa_state_m,IKE_SA_INIT_REQUESTED));
651
652 this->logger->log(this->logger, CONTROL|LEVEL2, "Destroy old sate object");
653 this->logger->log(this->logger, CONTROL|LEVEL2, "Going to retry initialization of connection");
654
655 this->public.state_interface.destroy(&(this->public.state_interface));
656 if (initiator_init_state->retry_initiate_connection (initiator_init_state, dh_group) != SUCCESS)
657 {
658 return DELETE_ME;
659 }
660 return FAILED;
661 }
662 default:
663 {
664 /*
665 * - In case of unknown error: IKE_SA gets destroyed.
666 * - In case of unknown status: logging
667 */
668 if (notify_message_type < 16383)
669 {
670 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply contained an unknown notify error (%d). Deleting IKE_SA",
671 notify_message_type);
672 return DELETE_ME;
673 }
674 else
675 {
676 this->logger->log(this->logger, CONTROL, "IKE_SA_INIT reply contained an unknown notify (%d), ignored.",
677 notify_message_type);
678 return SUCCESS;
679 }
680 }
681 }
682 }
683
684 /**
685 * Implementation of state_t.get_state.
686 */
687 static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this)
688 {
689 return IKE_SA_INIT_REQUESTED;
690 }
691
692 /**
693 * Implementation of private_ike_sa_init_requested_t.destroy_after_state_change.
694 */
695 static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
696 {
697 this->diffie_hellman->destroy(this->diffie_hellman);
698 allocator_free_chunk(&(this->ike_sa_init_request_data));
699 if (this->proposal)
700 {
701 this->proposal->destroy(this->proposal);
702 }
703 allocator_free(this);
704 }
705
706 /**
707 * Implementation state_t.destroy.
708 */
709 static void destroy(private_ike_sa_init_requested_t *this)
710 {
711 this->diffie_hellman->destroy(this->diffie_hellman);
712 allocator_free(this->sent_nonce.ptr);
713 allocator_free(this->received_nonce.ptr);
714 allocator_free_chunk(&(this->ike_sa_init_request_data));
715 if (this->child_sa)
716 {
717 this->child_sa->destroy(this->child_sa);
718 }
719 if (this->proposal)
720 {
721 this->proposal->destroy(this->proposal);
722 }
723 allocator_free(this);
724 }
725
726 /*
727 * Described in header.
728 */
729 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)
730 {
731 private_ike_sa_init_requested_t *this = allocator_alloc_thing(private_ike_sa_init_requested_t);
732
733 /* interface functions */
734 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
735 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
736 this->public.state_interface.destroy = (void (*) (state_t *)) destroy;
737
738 /* private functions */
739 this->destroy_after_state_change = destroy_after_state_change;
740 this->process_nonce_payload = process_nonce_payload;
741 this->process_sa_payload = process_sa_payload;
742 this->process_ke_payload = process_ke_payload;
743 this->build_auth_payload = build_auth_payload;
744 this->build_tsi_payload = build_tsi_payload;
745 this->build_tsr_payload = build_tsr_payload;
746 this->build_id_payload = build_id_payload;
747 this->build_sa_payload = build_sa_payload;
748 this->process_notify_payload = process_notify_payload;
749
750 /* private data */
751 this->ike_sa = ike_sa;
752 this->received_nonce = CHUNK_INITIALIZER;
753 this->logger = this->ike_sa->get_logger(this->ike_sa);
754 this->diffie_hellman = diffie_hellman;
755 this->proposal = NULL;
756 this->sent_nonce = sent_nonce;
757 this->child_sa = NULL;
758 this->ike_sa_init_request_data = ike_sa_init_request_data;
759
760 return &(this->public);
761 }