d7fa1f12764fc5b385521f9e327bdfa7f7ef78c1
[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 * Process a notify payload and react.
183 *
184 * @param this calling object
185 * @param notify_payload notify_payload to handle
186 */
187 status_t (*process_notify_payload) (private_ike_sa_init_requested_t *this, notify_payload_t *notify_payload);
188
189 /**
190 * Destroy function called internally of this class after state change to
191 * state IKE_AUTH_REQUESTED succeeded.
192 *
193 * In case of state change to INITIATOR_INIT the default destroy function gets called.
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 /* build empty message */
334 this->ike_sa->build_message(this->ike_sa, IKE_AUTH, TRUE, &request);
335
336 status = this->build_id_payload(this, &id_payload,request);
337 if (status != SUCCESS)
338 {
339 request->destroy(request);
340 return status;
341 }
342 status = this->build_auth_payload(this,(id_payload_t *) id_payload, request);
343 if (status != SUCCESS)
344 {
345 request->destroy(request);
346 return status;
347 }
348 status = this->build_sa_payload(this, request);
349 if (status != SUCCESS)
350 {
351 request->destroy(request);
352 return status;
353 }
354 status = this->build_tsi_payload(this, request);
355 if (status != SUCCESS)
356 {
357 request->destroy(request);
358 return status;
359 }
360 status = this->build_tsr_payload(this, request);
361 if (status != SUCCESS)
362 {
363 request->destroy(request);
364 return status;
365 }
366
367 /* message can now be sent (must not be destroyed) */
368 status = this->ike_sa->send_request(this->ike_sa, request);
369 if (status != SUCCESS)
370 {
371 this->logger->log(this->logger, AUDIT, "Unable to send IKE_AUTH request. Deleting IKE_SA");
372 request->destroy(request);
373 return DELETE_ME;
374 }
375
376 this->ike_sa->set_last_replied_message_id(this->ike_sa,ike_sa_init_reply->get_message_id(ike_sa_init_reply));
377
378 ike_sa_init_reply_data = ike_sa_init_reply->get_packet_data(ike_sa_init_reply);
379
380 /* state can now be changed */
381 next_state = ike_auth_requested_create(this->ike_sa,this->sent_nonce,this->received_nonce,ike_sa_init_reply_data);
382 this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
383
384 this->destroy_after_state_change(this);
385 return SUCCESS;
386 }
387
388
389 /**
390 * Implementation of private_ike_sa_init_requested_t.process_nonce_payload.
391 */
392 status_t process_nonce_payload (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload)
393 {
394 allocator_free(this->received_nonce.ptr);
395 this->received_nonce = nonce_payload->get_nonce(nonce_payload);
396 return SUCCESS;
397 }
398
399
400 /**
401 * Implementation of private_ike_sa_init_requested_t.process_sa_payload.
402 */
403 status_t process_sa_payload (private_ike_sa_init_requested_t *this, sa_payload_t *sa_payload)
404 {
405 ike_proposal_t selected_proposal;
406 ike_proposal_t *ike_proposals;
407 init_config_t *init_config;
408 size_t proposal_count;
409 status_t status;
410
411 init_config = this->ike_sa->get_init_config(this->ike_sa);
412
413 /* get the list of selected proposals */
414 status = sa_payload->get_ike_proposals (sa_payload, &ike_proposals,&proposal_count);
415 if (status != SUCCESS)
416 {
417 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response did not contain any proposals. Deleting IKE_SA");
418 return DELETE_ME;
419 }
420 /* the peer has to select only one proposal */
421 if (proposal_count != 1)
422 {
423 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained more than one proposal. Deleting IKE_SA");
424 allocator_free(ike_proposals);
425 return DELETE_ME;
426 }
427
428 /* now let the configuration-manager check the selected proposals*/
429 this->logger->log(this->logger, CONTROL | LEVEL2, "Check selected proposal");
430 status = init_config->select_proposal (init_config,ike_proposals,1,&selected_proposal);
431 allocator_free(ike_proposals);
432 if (status != SUCCESS)
433 {
434 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained selected proposal we did not offer. Deleting IKE_SA");
435 return DELETE_ME;
436 }
437
438 status = this->ike_sa->create_transforms_from_proposal(this->ike_sa,&selected_proposal);
439 if (status != SUCCESS)
440 {
441 this->logger->log(this->logger, AUDIT, "Transform objects could not be created from selected proposal. Deleting IKE_SA");
442 return DELETE_ME;
443 }
444 return SUCCESS;
445 }
446
447 /**
448 * Implementation of private_ike_sa_init_requested_t.process_ke_payload.
449 */
450 status_t process_ke_payload (private_ike_sa_init_requested_t *this, ke_payload_t *ke_payload)
451 {
452 chunk_t shared_secret;
453 status_t status;
454
455 this->diffie_hellman->set_other_public_value(this->diffie_hellman, ke_payload->get_key_exchange_data(ke_payload));
456
457 /* store shared secret
458 * status of dh object does not have to get checked cause other key is set
459 */
460 this->logger->log(this->logger, CONTROL | LEVEL2, "Retrieve shared secret and store it");
461 status = this->diffie_hellman->get_shared_secret(this->diffie_hellman, &shared_secret);
462 this->logger->log_chunk(this->logger, PRIVATE, "Shared secret", &shared_secret);
463
464 this->logger->log(this->logger, CONTROL | LEVEL2, "Going to derive all secrets from shared secret");
465 this->ike_sa->compute_secrets(this->ike_sa,shared_secret,this->sent_nonce, this->received_nonce);
466
467 allocator_free_chunk(&(shared_secret));
468
469 return SUCCESS;
470 }
471
472 /**
473 * Implementation of private_ike_sa_init_requested_t.build_id_payload.
474 */
475 static status_t build_id_payload (private_ike_sa_init_requested_t *this,id_payload_t **id_payload, message_t *request)
476 {
477 sa_config_t *sa_config;
478 id_payload_t *new_id_payload;
479 identification_t *identification;
480
481 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
482 /* identification_t object gets NOT cloned here */
483 identification = sa_config->get_my_id(sa_config);
484 new_id_payload = id_payload_create_from_identification(TRUE,identification);
485
486 this->logger->log(this->logger, CONTROL|LEVEL2, "Add ID payload to message");
487 request->add_payload(request,(payload_t *) new_id_payload);
488
489 *id_payload = new_id_payload;
490
491 return SUCCESS;
492 }
493
494 /**
495 * Implementation of private_ike_sa_init_requested_t.build_auth_payload.
496 */
497 static status_t build_auth_payload (private_ike_sa_init_requested_t *this, id_payload_t *my_id_payload, message_t *request)
498 {
499 authenticator_t *authenticator;
500 auth_payload_t *auth_payload;
501 status_t status;
502
503 authenticator = authenticator_create(this->ike_sa);
504 status = authenticator->compute_auth_data(authenticator,&auth_payload,this->ike_sa_init_request_data,this->received_nonce,my_id_payload,TRUE);
505 authenticator->destroy(authenticator);
506
507 if (status != SUCCESS)
508 {
509 this->logger->log(this->logger, AUDIT, "Could not generate AUTH data for IKE_AUTH request. Deleting IKE_SA");
510 return DELETE_ME;
511 }
512
513 this->logger->log(this->logger, CONTROL|LEVEL2, "Add AUTH payload to message");
514 request->add_payload(request,(payload_t *) auth_payload);
515
516 return SUCCESS;
517 }
518
519 /**
520 * Implementation of private_ike_sa_init_requested_t.build_sa_payload.
521 */
522 static status_t build_sa_payload (private_ike_sa_init_requested_t *this, message_t *request)
523 {
524 linked_list_t *proposal_list;
525 sa_payload_t *sa_payload;
526 sa_config_t *sa_config;
527
528 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
529 proposal_list = sa_config->get_proposals(sa_config);
530 sa_payload = sa_payload_create_from_child_proposal_list(proposal_list);
531 /* TODO: fix mem allocation */
532 /* TODO child sa stuff */
533
534 this->logger->log(this->logger, CONTROL|LEVEL2, "Add SA payload to message");
535 request->add_payload(request,(payload_t *) sa_payload);
536
537 return SUCCESS;
538 }
539
540 /**
541 * Implementation of private_ike_sa_init_requested_t.build_tsi_payload.
542 */
543 static status_t build_tsi_payload (private_ike_sa_init_requested_t *this, message_t *request)
544 {
545 traffic_selector_t **traffic_selectors;
546 size_t traffic_selectors_count;
547 ts_payload_t *ts_payload;
548 sa_config_t *sa_config;
549
550 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
551 traffic_selectors_count = sa_config->get_traffic_selectors_initiator(sa_config,&traffic_selectors);
552 ts_payload = ts_payload_create_from_traffic_selectors(TRUE,traffic_selectors, traffic_selectors_count);
553
554 /* cleanup traffic selectors */
555 while(traffic_selectors_count--)
556 {
557 traffic_selector_t *ts = *traffic_selectors + traffic_selectors_count;
558 ts->destroy(ts);
559 }
560 allocator_free(traffic_selectors);
561
562 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSi payload to message");
563 request->add_payload(request,(payload_t *) ts_payload);
564
565 return SUCCESS;
566 }
567
568 /**
569 * Implementation of private_ike_sa_init_requested_t.build_tsr_payload.
570 */
571 static status_t build_tsr_payload (private_ike_sa_init_requested_t *this, message_t *request)
572 {
573 traffic_selector_t **traffic_selectors;
574 size_t traffic_selectors_count;
575 ts_payload_t *ts_payload;
576 sa_config_t *sa_config;
577
578 sa_config = this->ike_sa->get_sa_config(this->ike_sa);
579 traffic_selectors_count = sa_config->get_traffic_selectors_responder(sa_config,&traffic_selectors);
580 ts_payload = ts_payload_create_from_traffic_selectors(FALSE,traffic_selectors, traffic_selectors_count);
581
582 /* cleanup traffic selectors */
583 while(traffic_selectors_count--)
584 {
585 traffic_selector_t *ts = *traffic_selectors + traffic_selectors_count;
586 ts->destroy(ts);
587 }
588 allocator_free(traffic_selectors);
589
590 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSr payload to message");
591 request->add_payload(request,(payload_t *) ts_payload);
592
593 return SUCCESS;
594 }
595
596 /**
597 * Implementation of private_ike_sa_init_requested_t.process_notify_payload.
598 */
599 static status_t process_notify_payload(private_ike_sa_init_requested_t *this, notify_payload_t *notify_payload)
600 {
601 notify_message_type_t notify_message_type = notify_payload->get_notify_message_type(notify_payload);
602
603 this->logger->log(this->logger, CONTROL|LEVEL1, "Process notify type %s for protocol %s",
604 mapping_find(notify_message_type_m, notify_message_type),
605 mapping_find(protocol_id_m, notify_payload->get_protocol_id(notify_payload)));
606
607 if (notify_payload->get_protocol_id(notify_payload) != IKE)
608 {
609 this->logger->log(this->logger, ERROR | LEVEL1, "Notify reply not for IKE protocol.");
610 return FAILED;
611 }
612 switch (notify_message_type)
613 {
614 case NO_PROPOSAL_CHOSEN:
615 {
616 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a NO_PROPOSAL_CHOSEN notify. Deleting IKE_SA");
617 return DELETE_ME;
618 }
619 case INVALID_MAJOR_VERSION:
620 {
621 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a INVALID_MAJOR_VERSION notify. Deleting IKE_SA");
622 return DELETE_ME;
623 }
624 case INVALID_KE_PAYLOAD:
625 {
626 initiator_init_t *initiator_init_state;
627 u_int16_t new_dh_group_priority;
628
629 this->logger->log(this->logger, ERROR|LEVEL1, "Selected DH group is not the one in the proposal selected by the responder!");
630 /* Going to change state back to initiator_init_t */
631 this->logger->log(this->logger, CONTROL|LEVEL2, "Create next state object");
632 initiator_init_state = initiator_init_create(this->ike_sa);
633
634 /* buffer of sent and received messages has to get reseted */
635 this->ike_sa->reset_message_buffers(this->ike_sa);
636
637 /* state can now be changed */
638 this->ike_sa->set_new_state(this->ike_sa,(state_t *) initiator_init_state);
639
640 /* state has NOW changed :-) */
641 this->logger->log(this->logger, CONTROL|LEVEL1, "Changed state of IKE_SA from %s to %s",
642 mapping_find(ike_sa_state_m,INITIATOR_INIT), mapping_find(ike_sa_state_m,IKE_SA_INIT_REQUESTED));
643
644 this->logger->log(this->logger, CONTROL|LEVEL2, "Destroy old sate object");
645 this->logger->log(this->logger, CONTROL|LEVEL2, "Going to retry initialization of connection");
646 new_dh_group_priority = this->dh_group_priority + 1;
647
648 this->public.state_interface.destroy(&(this->public.state_interface));
649 if (initiator_init_state->retry_initiate_connection (initiator_init_state,new_dh_group_priority) != SUCCESS)
650 {
651 return DELETE_ME;
652 }
653 return FAILED;
654
655 }
656 default:
657 {
658 /*
659 * - In case of unknown error: IKE_SA gets destroyed.
660 * - In case of unknown status: logging
661 */
662 if (notify_message_type < 16383)
663 {
664 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply contained an unknown notify error (%d). Deleting IKE_SA",
665 notify_message_type);
666 return DELETE_ME;
667 }
668 else
669 {
670 this->logger->log(this->logger, CONTROL, "IKE_SA_INIT reply contained an unknown notify (%d), ignored.",
671 notify_message_type);
672 return SUCCESS;
673 }
674 }
675 }
676 }
677
678
679 /**
680 * Implementation of state_t.get_state.
681 */
682 static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this)
683 {
684 return IKE_SA_INIT_REQUESTED;
685 }
686
687 /**
688 * Implementation of private_ike_sa_init_requested_t.destroy_after_state_change.
689 */
690 static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
691 {
692 this->logger->log(this->logger, CONTROL | LEVEL3, "Going to destroy state of type ike_sa_init_requested_t after state change.");
693
694 this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy diffie hellman object");
695 this->diffie_hellman->destroy(this->diffie_hellman);
696 this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy ike_sa_init_request_data");
697 allocator_free_chunk(&(this->ike_sa_init_request_data));
698 this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy object itself");
699 allocator_free(this);
700 }
701
702 /**
703 * Implementation state_t.destroy.
704 */
705 static void destroy(private_ike_sa_init_requested_t *this)
706 {
707 this->logger->log(this->logger, CONTROL | LEVEL3, "Going to destroy state of type ike_sa_init_requested_t");
708
709 this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy diffie hellman object");
710 this->diffie_hellman->destroy(this->diffie_hellman);
711 this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy sent nonce");
712 allocator_free(this->sent_nonce.ptr);
713 this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy received nonce");
714 allocator_free(this->received_nonce.ptr);
715 this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy ike_sa_init_request_data");
716 allocator_free_chunk(&(this->ike_sa_init_request_data));
717 this->logger->log(this->logger, CONTROL | LEVEL3, "Destroy object itself");
718 allocator_free(this);
719 }
720
721 /*
722 * Described in header.
723 */
724 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)
725 {
726 private_ike_sa_init_requested_t *this = allocator_alloc_thing(private_ike_sa_init_requested_t);
727
728 /* interface functions */
729 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
730 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
731 this->public.state_interface.destroy = (void (*) (state_t *)) destroy;
732
733 /* private functions */
734 this->destroy_after_state_change = destroy_after_state_change;
735 this->process_nonce_payload = process_nonce_payload;
736 this->process_sa_payload = process_sa_payload;
737 this->process_ke_payload = process_ke_payload;
738 this->build_auth_payload = build_auth_payload;
739 this->build_tsi_payload = build_tsi_payload;
740 this->build_tsr_payload = build_tsr_payload;
741 this->build_id_payload = build_id_payload;
742 this->build_sa_payload = build_sa_payload;
743 this->process_notify_payload = process_notify_payload;
744
745 /* private data */
746 this->ike_sa = ike_sa;
747 this->received_nonce = CHUNK_INITIALIZER;
748 this->logger = this->ike_sa->get_logger(this->ike_sa);
749 this->diffie_hellman = diffie_hellman;
750 this->sent_nonce = sent_nonce;
751 this->ike_sa_init_request_data = ike_sa_init_request_data;
752 this->dh_group_priority = dh_group_priority;
753
754 return &(this->public);
755 }