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