b4b0ce530bb3a4210645122bfc45e6f08a7585bf
[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 if (responder_spi == 0)
242 {
243 this->logger->log(this->logger, ERROR | MORE, "Responder SPI still zero");
244 return FAILED;
245 }
246 /* because I am original initiator i have to update the responder SPI to the new one */
247 responder_spi = ike_sa_init_reply->get_responder_spi(ike_sa_init_reply);
248 ike_sa_id = this->ike_sa->public.get_id(&(this->ike_sa->public));
249 ike_sa_id->set_responder_spi(ike_sa_id,responder_spi);
250
251 /* Iterate over all payloads.
252 *
253 * The message is allready checked for the right payload types.
254 */
255 payloads = ike_sa_init_reply->get_payload_iterator(ike_sa_init_reply);
256 while (payloads->has_next(payloads))
257 {
258 payload_t *payload;
259 payloads->current(payloads, (void**)&payload);
260
261 this->logger->log(this->logger, CONTROL|MORE, "Processing payload %s", mapping_find(payload_type_m, payload->get_type(payload)));
262 switch (payload->get_type(payload))
263 {
264 case NOTIFY:
265 {
266 notify_payload_t *notify_payload = (notify_payload_t *) payload;
267
268
269 this->logger->log(this->logger, CONTROL|MORE, "Process notify type %s for protocol %s",
270 mapping_find(notify_message_type_m, notify_payload->get_notify_message_type(notify_payload)),
271 mapping_find(protocol_id_m, notify_payload->get_protocol_id(notify_payload)));
272
273 if (notify_payload->get_protocol_id(notify_payload) != IKE)
274 {
275 this->logger->log(this->logger, ERROR | MORE, "Notify reply not for IKE protocol.");
276 payloads->destroy(payloads);
277 return FAILED;
278 }
279 switch (notify_payload->get_notify_message_type(notify_payload))
280 {
281 case NO_PROPOSAL_CHOSEN:
282 {
283 this->logger->log(this->logger, ERROR, "Peer didn't choose a proposal!");
284 payloads->destroy(payloads);
285 return DELETE_ME;
286 }
287 case INVALID_MAJOR_VERSION:
288 {
289 this->logger->log(this->logger, ERROR, "Peer doesn't support IKEv2!");
290 payloads->destroy(payloads);
291 return DELETE_ME;
292 }
293 case INVALID_KE_PAYLOAD:
294 {
295 initiator_init_t *initiator_init_state;
296 u_int16_t new_dh_group_priority;
297
298 this->logger->log(this->logger, ERROR, "Selected DH group is not the one in the proposal selected by the responder!");
299 payloads->destroy(payloads);
300 /* Going to change state back to initiator_init_t */
301 this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
302 initiator_init_state = initiator_init_create(this->ike_sa);
303
304 /* buffer of sent and received messages has to get reseted */
305 this->ike_sa->reset_message_buffers(this->ike_sa);
306
307 /* state can now be changed */
308 this->ike_sa->set_new_state(this->ike_sa,(state_t *) initiator_init_state);
309
310 /* state has NOW changed :-) */
311 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) );
312
313 this->logger->log(this->logger, CONTROL|MOST, "Destroy old sate object");
314 this->logger->log(this->logger, CONTROL|MOST, "Going to retry initialization of connection");
315 new_dh_group_priority = this->dh_group_priority + 1;
316
317 this->public.state_interface.destroy(&(this->public.state_interface));
318 return (initiator_init_state->retry_initiate_connection (initiator_init_state,new_dh_group_priority));
319 }
320 default:
321 {
322 /*
323 * - In case of unknown error: IKE_SA gets destroyed.
324 * - In case of unknown status: logging
325 *
326 */
327 notify_message_type_t notify_message_type = notify_payload->get_notify_message_type(notify_payload);
328 if (notify_message_type < 16383)
329 {
330 this->logger->log(this->logger, ERROR, "Notify error type %d not recognized in state IKE_SA_INIT_REQUESTED.",
331 notify_message_type);
332 payloads->destroy(payloads);
333 return DELETE_ME;
334
335 }
336 else
337 {
338 this->logger->log(this->logger, ERROR, "Notify status type %d not handled in state IKE_SA_INIT_REQUESTED.",
339 notify_message_type);
340 break;
341 }
342 }
343 }
344
345 }
346 case SECURITY_ASSOCIATION:
347 {
348 sa_payload = (sa_payload_t*)payload;
349 break;
350 }
351 case KEY_EXCHANGE:
352 {
353 ke_payload = (ke_payload_t*)payload;
354 break;
355 }
356 case NONCE:
357 {
358 nonce_payload = (nonce_payload_t*)payload;
359 break;
360 }
361 default:
362 {
363 this->logger->log(this->logger, ERROR, "Payload with ID %d not handled in state IKE_SA_INIT_REQUESTED", payload->get_type(payload));
364 break;
365 }
366
367 }
368
369 }
370 payloads->destroy(payloads);
371
372 status = this->process_nonce_payload (this,nonce_payload);
373 if (status != SUCCESS)
374 {
375 return status;
376 }
377
378 status = this->process_sa_payload (this,sa_payload);
379 if (status != SUCCESS)
380 {
381 return status;
382 }
383
384 status = this->process_ke_payload (this,ke_payload);
385 if (status != SUCCESS)
386 {
387 return status;
388 }
389
390 this->logger->log(this->logger, CONTROL|MOST, "Going to build empty message");
391 this->ike_sa->build_message(this->ike_sa, IKE_AUTH, TRUE, &request);
392
393 /* build ID payload */
394 status = this->build_id_payload(this, &id_payload,request);
395 if (status != SUCCESS)
396 {
397 request->destroy(request);
398 return status;
399 }
400
401 /* build AUTH payload */
402 status = this->build_auth_payload(this,(id_payload_t *) id_payload, request);
403 if (status != SUCCESS)
404 {
405 request->destroy(request);
406 return status;
407 }
408
409 /* build SA payload */
410 status = this->build_sa_payload(this, request);
411 if (status != SUCCESS)
412 {
413 request->destroy(request);
414 return status;
415 }
416
417 /* build TSi payload */
418 status = this->build_tsi_payload(this, request);
419 if (status != SUCCESS)
420 {
421 request->destroy(request);
422 return status;
423 }
424
425 /* build TSr payload */
426 status = this->build_tsr_payload(this, request);
427 if (status != SUCCESS)
428 {
429 request->destroy(request);
430 return status;
431 }
432
433 /* message can now be sent (must not be destroyed) */
434 status = this->ike_sa->send_request(this->ike_sa, request);
435 if (status != SUCCESS)
436 {
437 this->logger->log(this->logger, ERROR, "Could not send request message");
438 request->destroy(request);
439 return DELETE_ME;
440 }
441
442 this->ike_sa->set_last_replied_message_id(this->ike_sa,ike_sa_init_reply->get_message_id(ike_sa_init_reply));
443
444 ike_sa_init_reply_data = ike_sa_init_reply->get_packet_data(ike_sa_init_reply);
445
446 /* state can now be changed */
447 this->logger->log(this->logger, CONTROL|MOST, "Create next state object");
448 next_state = ike_auth_requested_create(this->ike_sa,this->sent_nonce,this->received_nonce,ike_sa_init_reply_data);
449
450 /* state can now be changed */
451 this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
452
453 /* state has NOW changed :-) */
454 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) );
455
456 this->logger->log(this->logger, CONTROL|MOST, "Destroy old sate object");
457 this->destroy_after_state_change(this);
458 return SUCCESS;
459 }
460
461
462 /**
463 * Implementation of private_ike_sa_init_requested_t.process_nonce_payload.
464 */
465 status_t process_nonce_payload (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload)
466 {
467 allocator_free(this->received_nonce.ptr);
468 this->received_nonce = nonce_payload->get_nonce(nonce_payload);
469 return SUCCESS;
470 }
471
472
473 /**
474 * Implementation of private_ike_sa_init_requested_t.process_sa_payload.
475 */
476 status_t process_sa_payload (private_ike_sa_init_requested_t *this, sa_payload_t *sa_payload)
477 {
478 ike_proposal_t selected_proposal;
479 ike_proposal_t *ike_proposals;
480 init_config_t *init_config;
481 size_t proposal_count;
482 status_t status;
483
484 init_config = this->ike_sa->get_init_config(this->ike_sa);
485
486 /* get the list of selected proposals */
487 status = sa_payload->get_ike_proposals (sa_payload, &ike_proposals,&proposal_count);
488 if (status != SUCCESS)
489 {
490 this->logger->log(this->logger, ERROR | MORE, "SA payload does not contain IKE proposals");
491 return DELETE_ME;
492 }
493 /* the peer has to select only one proposal */
494 if (proposal_count != 1)
495 {
496 this->logger->log(this->logger, ERROR | MORE, "More then 1 proposal (%d) selected!",proposal_count);
497 allocator_free(ike_proposals);
498 return DELETE_ME;
499 }
500
501 /* now let the configuration-manager check the selected proposals*/
502 this->logger->log(this->logger, CONTROL | MOST, "Check selected proposal");
503 status = init_config->select_proposal (init_config,ike_proposals,1,&selected_proposal);
504 allocator_free(ike_proposals);
505 if (status != SUCCESS)
506 {
507 this->logger->log(this->logger, ERROR | MORE, "Selected proposal not a suggested one! Peer is trying to trick me!");
508 return DELETE_ME;
509 }
510
511 status = this->ike_sa->create_transforms_from_proposal(this->ike_sa,&selected_proposal);
512 if (status != SUCCESS)
513 {
514 this->logger->log(this->logger, ERROR | MORE, "Transform objects could not be created from selected proposal");
515 return DELETE_ME;
516 }
517 return SUCCESS;
518 }
519
520 /**
521 * Implementation of private_ike_sa_init_requested_t.process_ke_payload.
522 */
523 status_t process_ke_payload (private_ike_sa_init_requested_t *this, ke_payload_t *ke_payload)
524 {
525 chunk_t shared_secret;
526 status_t status;
527
528 this->diffie_hellman->set_other_public_value(this->diffie_hellman, ke_payload->get_key_exchange_data(ke_payload));
529
530 /* store shared secret
531 * status of dh object does not have to get checked cause other key is set
532 */
533 this->logger->log(this->logger, CONTROL | MOST, "Retrieve shared secret and store it");
534 status = this->diffie_hellman->get_shared_secret(this->diffie_hellman, &shared_secret);
535 this->logger->log_chunk(this->logger, PRIVATE, "Shared secret", &shared_secret);
536
537 this->logger->log(this->logger, CONTROL | MOST, "Going to derive all secrets from shared secret");
538 this->ike_sa->compute_secrets(this->ike_sa,shared_secret,this->sent_nonce, this->received_nonce);
539
540 allocator_free_chunk(&(shared_secret));
541
542 return SUCCESS;
543 }
544
545 /**
546 * Implementation of private_ike_sa_init_requested_t.build_id_payload.
547 */
548 static status_t build_id_payload (private_ike_sa_init_requested_t *this,id_payload_t **id_payload, message_t *request)
549 {
550 sa_config_t *sa_config;
551 id_payload_t *new_id_payload;
552 identification_t *identification;
553
554 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
555 /* identification_t object gets NOT cloned here */
556 identification = sa_config->get_my_id(sa_config);
557 new_id_payload = id_payload_create_from_identification(TRUE,identification);
558
559 this->logger->log(this->logger, CONTROL|MOST, "Add ID payload to message");
560 request->add_payload(request,(payload_t *) new_id_payload);
561
562 *id_payload = new_id_payload;
563
564 return SUCCESS;
565 }
566
567 /**
568 * Implementation of private_ike_sa_init_requested_t.build_auth_payload.
569 */
570 static status_t build_auth_payload (private_ike_sa_init_requested_t *this, id_payload_t *my_id_payload, message_t *request)
571 {
572 authenticator_t *authenticator;
573 auth_payload_t *auth_payload;
574 status_t status;
575
576 authenticator = authenticator_create(this->ike_sa);
577 status = authenticator->compute_auth_data(authenticator,&auth_payload,this->ike_sa_init_request_data,this->received_nonce,my_id_payload,TRUE);
578 authenticator->destroy(authenticator);
579
580 if (status != SUCCESS)
581 {
582 return DELETE_ME;
583 }
584
585 this->logger->log(this->logger, CONTROL|MOST, "Add AUTH payload to message");
586 request->add_payload(request,(payload_t *) auth_payload);
587
588 return SUCCESS;
589 }
590
591 /**
592 * Implementation of private_ike_sa_init_requested_t.build_sa_payload.
593 */
594 static status_t build_sa_payload (private_ike_sa_init_requested_t *this, message_t *request)
595 {
596 child_proposal_t *proposals;
597 sa_payload_t *sa_payload;
598 sa_config_t *sa_config;
599 size_t proposal_count;
600 /*
601 * TODO: get SPIs from kernel
602 */
603 u_int8_t esp_spi[4] = {0x01,0x01,0x01,0x01};
604 u_int8_t ah_spi[4] = {0x01,0x01,0x01,0x01};
605
606 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
607 proposal_count = sa_config->get_proposals(sa_config,ah_spi,esp_spi,&proposals);
608 sa_payload = sa_payload_create_from_child_proposals(proposals, proposal_count);
609 allocator_free(proposals);
610
611 this->logger->log(this->logger, CONTROL|MOST, "Add SA payload to message");
612 request->add_payload(request,(payload_t *) sa_payload);
613
614 return SUCCESS;
615 }
616
617 /**
618 * Implementation of private_ike_sa_init_requested_t.build_tsi_payload.
619 */
620 static status_t build_tsi_payload (private_ike_sa_init_requested_t *this, message_t *request)
621 {
622 traffic_selector_t **traffic_selectors;
623 size_t traffic_selectors_count;
624 ts_payload_t *ts_payload;
625 sa_config_t *sa_config;
626
627 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
628 traffic_selectors_count = sa_config->get_traffic_selectors_initiator(sa_config,&traffic_selectors);
629 ts_payload = ts_payload_create_from_traffic_selectors(TRUE,traffic_selectors, traffic_selectors_count);
630
631 /* cleanup traffic selectors */
632 while(traffic_selectors_count--)
633 {
634 traffic_selector_t *ts = *traffic_selectors + traffic_selectors_count;
635 ts->destroy(ts);
636 }
637 allocator_free(traffic_selectors);
638
639 this->logger->log(this->logger, CONTROL|MOST, "Add TSi payload to message");
640 request->add_payload(request,(payload_t *) ts_payload);
641
642 return SUCCESS;
643 }
644
645 /**
646 * Implementation of private_ike_sa_init_requested_t.build_tsr_payload.
647 */
648 static status_t build_tsr_payload (private_ike_sa_init_requested_t *this, message_t *request)
649 {
650 traffic_selector_t **traffic_selectors;
651 size_t traffic_selectors_count;
652 ts_payload_t *ts_payload;
653 sa_config_t *sa_config;
654
655 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
656 traffic_selectors_count = sa_config->get_traffic_selectors_responder(sa_config,&traffic_selectors);
657 ts_payload = ts_payload_create_from_traffic_selectors(FALSE,traffic_selectors, traffic_selectors_count);
658
659 /* cleanup traffic selectors */
660 while(traffic_selectors_count--)
661 {
662 traffic_selector_t *ts = *traffic_selectors + traffic_selectors_count;
663 ts->destroy(ts);
664 }
665 allocator_free(traffic_selectors);
666
667 this->logger->log(this->logger, CONTROL|MOST, "Add TSr payload to message");
668 request->add_payload(request,(payload_t *) ts_payload);
669
670 return SUCCESS;
671 }
672
673
674 /**
675 * Implementation of state_t.get_state.
676 */
677 static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this)
678 {
679 return IKE_SA_INIT_REQUESTED;
680 }
681
682 /**
683 * Implementation of private_ike_sa_init_requested_t.destroy_after_state_change.
684 */
685 static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
686 {
687 this->logger->log(this->logger, CONTROL | MORE, "Going to destroy state of type ike_sa_init_requested_t after state change.");
688
689 this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie hellman object");
690 this->diffie_hellman->destroy(this->diffie_hellman);
691 this->logger->log(this->logger, CONTROL | MOST, "Destroy ike_sa_init_request_data");
692 allocator_free_chunk(&(this->ike_sa_init_request_data));
693 this->logger->log(this->logger, CONTROL | MOST, "Destroy object itself");
694 allocator_free(this);
695 }
696
697 /**
698 * Implementation state_t.destroy.
699 */
700 static void destroy(private_ike_sa_init_requested_t *this)
701 {
702 this->logger->log(this->logger, CONTROL | MORE, "Going to destroy state of type ike_sa_init_requested_t");
703
704 this->logger->log(this->logger, CONTROL | MOST, "Destroy diffie hellman object");
705 this->diffie_hellman->destroy(this->diffie_hellman);
706 this->logger->log(this->logger, CONTROL | MOST, "Destroy sent nonce");
707 allocator_free(this->sent_nonce.ptr);
708 this->logger->log(this->logger, CONTROL | MOST, "Destroy received nonce");
709 allocator_free(this->received_nonce.ptr);
710 this->logger->log(this->logger, CONTROL | MOST, "Destroy ike_sa_init_request_data");
711 allocator_free_chunk(&(this->ike_sa_init_request_data));
712 this->logger->log(this->logger, CONTROL | MOST, "Destroy object itself");
713 allocator_free(this);
714 }
715
716 /*
717 * Described in header.
718 */
719 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)
720 {
721 private_ike_sa_init_requested_t *this = allocator_alloc_thing(private_ike_sa_init_requested_t);
722
723 /* interface functions */
724 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
725 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
726 this->public.state_interface.destroy = (void (*) (state_t *)) destroy;
727
728 /* private functions */
729 this->destroy_after_state_change = destroy_after_state_change;
730 this->process_nonce_payload = process_nonce_payload;
731 this->process_sa_payload = process_sa_payload;
732 this->process_ke_payload = process_ke_payload;
733 this->build_auth_payload = build_auth_payload;
734 this->build_tsi_payload = build_tsi_payload;
735 this->build_tsr_payload = build_tsr_payload;
736 this->build_id_payload = build_id_payload;
737 this->build_sa_payload = build_sa_payload;
738
739 /* private data */
740 this->ike_sa = ike_sa;
741 this->received_nonce = CHUNK_INITIALIZER;
742 this->logger = this->ike_sa->get_logger(this->ike_sa);
743 this->diffie_hellman = diffie_hellman;
744 this->sent_nonce = sent_nonce;
745 this->ike_sa_init_request_data = ike_sa_init_request_data;
746 this->dh_group_priority = dh_group_priority;
747
748 return &(this->public);
749 }