- installing of child sa works
[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
217 message_t *request;
218 status_t status;
219
220 /*
221 * In this state a reply message of type IKE_SA_INIT is expected:
222 *
223 * <-- HDR, SAr1, KEr, Nr, [CERTREQ]
224 * or
225 * <-- HDR, N
226 */
227
228 if (ike_sa_init_reply->get_exchange_type(ike_sa_init_reply) != IKE_SA_INIT)
229 {
230 this->logger->log(this->logger, ERROR | LEVEL1, "Message of type %s not supported in state ike_sa_init_requested",
231 mapping_find(exchange_type_m,ike_sa_init_reply->get_exchange_type(ike_sa_init_reply)));
232 return FAILED;
233 }
234
235 if (ike_sa_init_reply->get_request(ike_sa_init_reply))
236 {
237 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT requests not allowed state ike_sa_init_responded");
238 return FAILED;
239 }
240
241 /* parse incoming message */
242 status = ike_sa_init_reply->parse_body(ike_sa_init_reply, NULL, NULL);
243 if (status != SUCCESS)
244 {
245 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT reply parsing faild. Ignoring message");
246 return status;
247 }
248
249 /* because we are original initiator we have to update the responder SPI to the new one */
250 responder_spi = ike_sa_init_reply->get_responder_spi(ike_sa_init_reply);
251 if (responder_spi == 0)
252 {
253 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT reply contained a SPI of zero");
254 return FAILED;
255 }
256 ike_sa_id = this->ike_sa->public.get_id(&(this->ike_sa->public));
257 ike_sa_id->set_responder_spi(ike_sa_id,responder_spi);
258
259 /* Iterate over all payloads.
260 *
261 * The message is allready checked for the right payload types.
262 */
263 payloads = ike_sa_init_reply->get_payload_iterator(ike_sa_init_reply);
264 while (payloads->has_next(payloads))
265 {
266 payload_t *payload;
267 payloads->current(payloads, (void**)&payload);
268
269 switch (payload->get_type(payload))
270 {
271 case SECURITY_ASSOCIATION:
272 {
273 sa_payload = (sa_payload_t*)payload;
274 break;
275 }
276 case KEY_EXCHANGE:
277 {
278 ke_payload = (ke_payload_t*)payload;
279 break;
280 }
281 case NONCE:
282 {
283 nonce_payload = (nonce_payload_t*)payload;
284 break;
285 }
286 case NOTIFY:
287 {
288 notify_payload_t *notify_payload = (notify_payload_t *) payload;
289
290 status = this->process_notify_payload(this, notify_payload);
291 if (status != SUCCESS)
292 {
293 payloads->destroy(payloads);
294 return status;
295 }
296 }
297 default:
298 {
299 this->logger->log(this->logger, ERROR|LEVEL1, "Ignoring payload %s (%d)",
300 mapping_find(payload_type_m, payload->get_type(payload)), payload->get_type(payload));
301 break;
302 }
303
304 }
305
306 }
307 payloads->destroy(payloads);
308
309 if (!(nonce_payload && sa_payload && ke_payload))
310 {
311 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply did not contain all required payloads. Deleting IKE_SA");
312 return DELETE_ME;
313 }
314
315 status = this->process_nonce_payload (this,nonce_payload);
316 if (status != SUCCESS)
317 {
318 return status;
319 }
320
321 status = this->process_sa_payload (this,sa_payload);
322 if (status != SUCCESS)
323 {
324 return status;
325 }
326
327 status = this->process_ke_payload (this,ke_payload);
328 if (status != SUCCESS)
329 {
330 return status;
331 }
332
333 /* derive all the keys used in the IKE_SA */
334 status = this->ike_sa->build_transforms(this->ike_sa, this->proposal, this->diffie_hellman, this->sent_nonce, this->received_nonce);
335 if (status != SUCCESS)
336 {
337 this->logger->log(this->logger, AUDIT, "Transform objects could not be created from selected proposal. Deleting IKE_SA");
338 return DELETE_ME;
339 }
340
341 /* build empty message */
342 this->ike_sa->build_message(this->ike_sa, IKE_AUTH, TRUE, &request);
343
344 status = this->build_id_payload(this, &id_payload,request);
345 if (status != SUCCESS)
346 {
347 request->destroy(request);
348 return status;
349 }
350 status = this->build_auth_payload(this,(id_payload_t *) id_payload, request);
351 if (status != SUCCESS)
352 {
353 request->destroy(request);
354 return status;
355 }
356 status = this->build_sa_payload(this, request);
357 if (status != SUCCESS)
358 {
359 request->destroy(request);
360 return status;
361 }
362 status = this->build_tsi_payload(this, request);
363 if (status != SUCCESS)
364 {
365 request->destroy(request);
366 return status;
367 }
368 status = this->build_tsr_payload(this, request);
369 if (status != SUCCESS)
370 {
371 request->destroy(request);
372 return status;
373 }
374
375 /* message can now be sent (must not be destroyed) */
376 status = this->ike_sa->send_request(this->ike_sa, request);
377 if (status != SUCCESS)
378 {
379 this->logger->log(this->logger, AUDIT, "Unable to send IKE_AUTH request. Deleting IKE_SA");
380 request->destroy(request);
381 return DELETE_ME;
382 }
383
384 this->ike_sa->set_last_replied_message_id(this->ike_sa,ike_sa_init_reply->get_message_id(ike_sa_init_reply));
385
386 ike_sa_init_reply_data = ike_sa_init_reply->get_packet_data(ike_sa_init_reply);
387
388 /* state can now be changed */
389 next_state = ike_auth_requested_create(this->ike_sa, this->sent_nonce, this->received_nonce,
390 ike_sa_init_reply_data, this->child_sa);
391 this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
392
393 this->destroy_after_state_change(this);
394 return SUCCESS;
395 }
396
397
398 /**
399 * Implementation of private_ike_sa_init_requested_t.process_nonce_payload.
400 */
401 status_t process_nonce_payload (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload)
402 {
403 allocator_free(this->received_nonce.ptr);
404 this->received_nonce = nonce_payload->get_nonce(nonce_payload);
405 return SUCCESS;
406 }
407
408
409 /**
410 * Implementation of private_ike_sa_init_requested_t.process_sa_payload.
411 */
412 status_t process_sa_payload (private_ike_sa_init_requested_t *this, sa_payload_t *sa_payload)
413 {
414 proposal_t *proposal;
415 linked_list_t *proposal_list;
416 init_config_t *init_config;
417
418 init_config = this->ike_sa->get_init_config(this->ike_sa);
419
420 /* get the list of selected proposals, the peer has to select only one proposal */
421 proposal_list = sa_payload->get_proposals (sa_payload);
422 if (proposal_list->get_count(proposal_list) != 1)
423 {
424 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response did not contain a single proposal. Deleting IKE_SA");
425 while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
426 {
427 proposal->destroy(proposal);
428 }
429 proposal_list->destroy(proposal_list);
430 return DELETE_ME;
431 }
432
433 /* we have to re-check if the others selection is valid */
434 this->proposal = init_config->select_proposal(init_config, proposal_list);
435 while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
436 {
437 proposal->destroy(proposal);
438 }
439 proposal_list->destroy(proposal_list);
440
441 if (this->proposal == NULL)
442 {
443 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained selected proposal we did not offer. Deleting IKE_SA");
444 return DELETE_ME;
445 }
446
447 return SUCCESS;
448 }
449
450 /**
451 * Implementation of private_ike_sa_init_requested_t.process_ke_payload.
452 */
453 status_t process_ke_payload (private_ike_sa_init_requested_t *this, ke_payload_t *ke_payload)
454 {
455 this->diffie_hellman->set_other_public_value(this->diffie_hellman, ke_payload->get_key_exchange_data(ke_payload));
456
457 return SUCCESS;
458 }
459
460 /**
461 * Implementation of private_ike_sa_init_requested_t.build_id_payload.
462 */
463 static status_t build_id_payload (private_ike_sa_init_requested_t *this,id_payload_t **id_payload, message_t *request)
464 {
465 sa_config_t *sa_config;
466 id_payload_t *new_id_payload;
467 identification_t *identification;
468
469 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
470 /* identification_t object gets NOT cloned here */
471 identification = sa_config->get_my_id(sa_config);
472 new_id_payload = id_payload_create_from_identification(TRUE,identification);
473
474 this->logger->log(this->logger, CONTROL|LEVEL2, "Add ID payload to message");
475 request->add_payload(request,(payload_t *) new_id_payload);
476
477 *id_payload = new_id_payload;
478
479 return SUCCESS;
480 }
481
482 /**
483 * Implementation of private_ike_sa_init_requested_t.build_auth_payload.
484 */
485 static status_t build_auth_payload (private_ike_sa_init_requested_t *this, id_payload_t *my_id_payload, message_t *request)
486 {
487 authenticator_t *authenticator;
488 auth_payload_t *auth_payload;
489 status_t status;
490
491 authenticator = authenticator_create(this->ike_sa);
492 status = authenticator->compute_auth_data(authenticator,&auth_payload,this->ike_sa_init_request_data,this->received_nonce,my_id_payload,TRUE);
493 authenticator->destroy(authenticator);
494
495 if (status != SUCCESS)
496 {
497 this->logger->log(this->logger, AUDIT, "Could not generate AUTH data for IKE_AUTH request. Deleting IKE_SA");
498 return DELETE_ME;
499 }
500
501 this->logger->log(this->logger, CONTROL|LEVEL2, "Add AUTH payload to message");
502 request->add_payload(request,(payload_t *) auth_payload);
503
504 return SUCCESS;
505 }
506
507 /**
508 * Implementation of private_ike_sa_init_requested_t.build_sa_payload.
509 */
510 static status_t build_sa_payload (private_ike_sa_init_requested_t *this, message_t *request)
511 {
512 linked_list_t *proposal_list;
513 sa_payload_t *sa_payload;
514 sa_config_t *sa_config;
515
516 /* get proposals form config, add to payload */
517 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
518 proposal_list = sa_config->get_proposals(sa_config);
519 /* build child sa */
520 this->child_sa = child_sa_create(this->ike_sa->get_my_host(this->ike_sa),
521 this->ike_sa->get_other_host(this->ike_sa));
522 if (this->child_sa->alloc(this->child_sa, proposal_list) != SUCCESS)
523 {
524 this->logger->log(this->logger, AUDIT, "Could not install CHILD_SA! Deleting IKE_SA");
525 return DELETE_ME;
526 }
527
528 /* TODO:
529 * Huston, we've got a problem here. Since SPIs are stored in
530 * the proposal, and these proposals are shared across configs,
531 * there may be some threading issues... fix it!
532 */
533 sa_payload = sa_payload_create_from_proposal_list(proposal_list);
534
535 this->logger->log(this->logger, CONTROL|LEVEL2, "Add SA payload to message");
536 request->add_payload(request,(payload_t *) sa_payload);
537
538 return SUCCESS;
539 }
540
541 /**
542 * Implementation of private_ike_sa_init_requested_t.build_tsi_payload.
543 */
544 static status_t build_tsi_payload (private_ike_sa_init_requested_t *this, message_t *request)
545 {
546 traffic_selector_t **traffic_selectors;
547 size_t traffic_selectors_count;
548 ts_payload_t *ts_payload;
549 sa_config_t *sa_config;
550
551 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
552 traffic_selectors_count = sa_config->get_traffic_selectors_initiator(sa_config,&traffic_selectors);
553 ts_payload = ts_payload_create_from_traffic_selectors(TRUE,traffic_selectors, traffic_selectors_count);
554
555 /* cleanup traffic selectors */
556 while(traffic_selectors_count--)
557 {
558 traffic_selector_t *ts = *traffic_selectors + traffic_selectors_count;
559 ts->destroy(ts);
560 }
561 allocator_free(traffic_selectors);
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 traffic_selector_t **traffic_selectors;
575 size_t traffic_selectors_count;
576 ts_payload_t *ts_payload;
577 sa_config_t *sa_config;
578
579 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
580 traffic_selectors_count = sa_config->get_traffic_selectors_responder(sa_config,&traffic_selectors);
581 ts_payload = ts_payload_create_from_traffic_selectors(FALSE,traffic_selectors, traffic_selectors_count);
582
583 /* cleanup traffic selectors */
584 while(traffic_selectors_count--)
585 {
586 traffic_selector_t *ts = *traffic_selectors + traffic_selectors_count;
587 ts->destroy(ts);
588 }
589 allocator_free(traffic_selectors);
590
591 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSr payload to message");
592 request->add_payload(request,(payload_t *) ts_payload);
593
594 return SUCCESS;
595 }
596
597 /**
598 * Implementation of private_ike_sa_init_requested_t.process_notify_payload.
599 */
600 static status_t process_notify_payload(private_ike_sa_init_requested_t *this, notify_payload_t *notify_payload)
601 {
602 notify_message_type_t notify_message_type = notify_payload->get_notify_message_type(notify_payload);
603
604 this->logger->log(this->logger, CONTROL|LEVEL1, "Process notify type %s for protocol %s",
605 mapping_find(notify_message_type_m, notify_message_type),
606 mapping_find(protocol_id_m, notify_payload->get_protocol_id(notify_payload)));
607
608 if (notify_payload->get_protocol_id(notify_payload) != IKE)
609 {
610 this->logger->log(this->logger, ERROR | LEVEL1, "Notify reply not for IKE protocol.");
611 return FAILED;
612 }
613 switch (notify_message_type)
614 {
615 case NO_PROPOSAL_CHOSEN:
616 {
617 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a NO_PROPOSAL_CHOSEN notify. Deleting IKE_SA");
618 return DELETE_ME;
619 }
620 case INVALID_MAJOR_VERSION:
621 {
622 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a INVALID_MAJOR_VERSION notify. Deleting IKE_SA");
623 return DELETE_ME;
624 }
625 case INVALID_KE_PAYLOAD:
626 {
627 initiator_init_t *initiator_init_state;
628 chunk_t notify_data;
629 diffie_hellman_group_t dh_group;
630 init_config_t *init_config;
631
632 notify_data = notify_payload->get_notification_data(notify_payload);
633 dh_group = ntohs(*((u_int16_t*)notify_data.ptr));
634
635 this->logger->log(this->logger, ERROR|LEVEL1, "Peer wouldn't accept DH group, it requested %s!",
636 mapping_find(diffie_hellman_group_m, dh_group));
637 /* check if we can accept this dh group */
638 init_config = this->ike_sa->get_init_config(this->ike_sa);
639 if (!init_config->check_dh_group(init_config, dh_group))
640 {
641 this->logger->log(this->logger, AUDIT,
642 "Peer does only accept DH group %s, which we do not accept! Aborting",
643 mapping_find(diffie_hellman_group_m, dh_group));
644 return DELETE_ME;
645 }
646
647 /* Going to change state back to initiator_init_t */
648 this->logger->log(this->logger, CONTROL|LEVEL2, "Create next state object");
649 initiator_init_state = initiator_init_create(this->ike_sa);
650
651 /* buffer of sent and received messages has to get reseted */
652 this->ike_sa->reset_message_buffers(this->ike_sa);
653
654 /* state can now be changed */
655 this->ike_sa->set_new_state(this->ike_sa,(state_t *) initiator_init_state);
656
657 /* state has NOW changed :-) */
658 this->logger->log(this->logger, CONTROL|LEVEL1, "Changed state of IKE_SA from %s to %s",
659 mapping_find(ike_sa_state_m,INITIATOR_INIT), mapping_find(ike_sa_state_m,IKE_SA_INIT_REQUESTED));
660
661 this->logger->log(this->logger, CONTROL|LEVEL2, "Destroy old sate object");
662 this->logger->log(this->logger, CONTROL|LEVEL2, "Going to retry initialization of connection");
663
664 this->public.state_interface.destroy(&(this->public.state_interface));
665 if (initiator_init_state->retry_initiate_connection (initiator_init_state, dh_group) != SUCCESS)
666 {
667 return DELETE_ME;
668 }
669 return FAILED;
670 }
671 default:
672 {
673 /*
674 * - In case of unknown error: IKE_SA gets destroyed.
675 * - In case of unknown status: logging
676 */
677 if (notify_message_type < 16383)
678 {
679 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply contained an unknown notify error (%d). Deleting IKE_SA",
680 notify_message_type);
681 return DELETE_ME;
682 }
683 else
684 {
685 this->logger->log(this->logger, CONTROL, "IKE_SA_INIT reply contained an unknown notify (%d), ignored.",
686 notify_message_type);
687 return SUCCESS;
688 }
689 }
690 }
691 }
692
693 /**
694 * Implementation of state_t.get_state.
695 */
696 static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this)
697 {
698 return IKE_SA_INIT_REQUESTED;
699 }
700
701 /**
702 * Implementation of private_ike_sa_init_requested_t.destroy_after_state_change.
703 */
704 static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
705 {
706 this->diffie_hellman->destroy(this->diffie_hellman);
707 allocator_free_chunk(&(this->ike_sa_init_request_data));
708 if (this->proposal)
709 {
710 this->proposal->destroy(this->proposal);
711 }
712 allocator_free(this);
713 }
714
715 /**
716 * Implementation state_t.destroy.
717 */
718 static void destroy(private_ike_sa_init_requested_t *this)
719 {
720 this->diffie_hellman->destroy(this->diffie_hellman);
721 allocator_free(this->sent_nonce.ptr);
722 allocator_free(this->received_nonce.ptr);
723 allocator_free_chunk(&(this->ike_sa_init_request_data));
724 if (this->child_sa)
725 {
726 this->child_sa->destroy(this->child_sa);
727 }
728 if (this->proposal)
729 {
730 this->proposal->destroy(this->proposal);
731 }
732 allocator_free(this);
733 }
734
735 /*
736 * Described in header.
737 */
738 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)
739 {
740 private_ike_sa_init_requested_t *this = allocator_alloc_thing(private_ike_sa_init_requested_t);
741
742 /* interface functions */
743 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
744 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
745 this->public.state_interface.destroy = (void (*) (state_t *)) destroy;
746
747 /* private functions */
748 this->destroy_after_state_change = destroy_after_state_change;
749 this->process_nonce_payload = process_nonce_payload;
750 this->process_sa_payload = process_sa_payload;
751 this->process_ke_payload = process_ke_payload;
752 this->build_auth_payload = build_auth_payload;
753 this->build_tsi_payload = build_tsi_payload;
754 this->build_tsr_payload = build_tsr_payload;
755 this->build_id_payload = build_id_payload;
756 this->build_sa_payload = build_sa_payload;
757 this->process_notify_payload = process_notify_payload;
758
759 /* private data */
760 this->ike_sa = ike_sa;
761 this->received_nonce = CHUNK_INITIALIZER;
762 this->logger = this->ike_sa->get_logger(this->ike_sa);
763 this->diffie_hellman = diffie_hellman;
764 this->proposal = NULL;
765 this->sent_nonce = sent_nonce;
766 this->child_sa = NULL;
767 this->ike_sa_init_request_data = ike_sa_init_request_data;
768
769 return &(this->public);
770 }