- fixed host-host tunnel traffic selection, host-host works now
[strongswan.git] / src / 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 <encoding/payloads/sa_payload.h>
27 #include <encoding/payloads/ke_payload.h>
28 #include <encoding/payloads/nonce_payload.h>
29 #include <encoding/payloads/notify_payload.h>
30 #include <encoding/payloads/id_payload.h>
31 #include <encoding/payloads/auth_payload.h>
32 #include <encoding/payloads/ts_payload.h>
33 #include <crypto/diffie_hellman.h>
34 #include <sa/states/ike_auth_requested.h>
35 #include <sa/states/initiator_init.h>
36 #include <sa/authenticator.h>
37
38
39 typedef struct private_ike_sa_init_requested_t private_ike_sa_init_requested_t;
40
41 /**
42 * Private data of a ike_sa_init_requested_t object.
43 *
44 */
45 struct private_ike_sa_init_requested_t {
46 /**
47 * Public interface of an ike_sa_init_requested_t object.
48 */
49 ike_sa_init_requested_t public;
50
51 /**
52 * Assigned IKE_SA
53 */
54 protected_ike_sa_t *ike_sa;
55
56 /**
57 * Diffie Hellman object used to compute shared secret.
58 */
59 diffie_hellman_t *diffie_hellman;
60
61 /**
62 * Sent nonce value.
63 */
64 chunk_t sent_nonce;
65
66 /**
67 * Received nonce
68 */
69 chunk_t received_nonce;
70
71 /**
72 * Selected proposal
73 */
74 proposal_t *proposal;
75
76 /**
77 * Packet data of ike_sa_init request
78 */
79 chunk_t ike_sa_init_request_data;
80
81 /**
82 * Created child sa, if any
83 */
84 child_sa_t *child_sa;
85
86 /**
87 * Assigned logger
88 *
89 * Is logger of ike_sa!
90 */
91 logger_t *logger;
92
93
94 /**
95 * Process NONCE payload of IKE_SA_INIT response.
96 *
97 * @param this calling object
98 * @param nonce_payload NONCE payload to process
99 * @return SUCCESS in any case
100 */
101 status_t (*process_nonce_payload) (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload);
102
103 /**
104 * Process SA payload of IKE_SA_INIT response.
105 *
106 * @param this calling object
107 * @param sa_payload SA payload to process
108 * @return
109 * - SUCCESS
110 * - FAILED
111 */
112 status_t (*process_sa_payload) (private_ike_sa_init_requested_t *this, sa_payload_t *sa_payload);
113
114 /**
115 * Process KE payload of IKE_SA_INIT response.
116 *
117 * @param this calling object
118 * @param sa_payload KE payload to process
119 * @return
120 * - SUCCESS
121 * - FAILED
122 */
123 status_t (*process_ke_payload) (private_ike_sa_init_requested_t *this, ke_payload_t *ke_payload);
124
125 /**
126 * Build ID payload for IKE_AUTH request.
127 *
128 * @param this calling object
129 * @param[out] id_payload buildet ID payload
130 * @param response created payload will be added to this message_t object
131 * @return
132 * - SUCCESS
133 * - FAILED
134 */
135 status_t (*build_id_payload) (private_ike_sa_init_requested_t *this,id_payload_t **id_payload, message_t *response);
136
137 /**
138 * Build IDr payload for IKE_AUTH request.
139 *
140 * Only built when the ID of the responder contains no wildcards.
141 *
142 * @param this calling object
143 * @param response created payload will be added to this message_t object
144 * @return
145 * - SUCCESS
146 * - FAILED
147 */
148 status_t (*build_idr_payload) (private_ike_sa_init_requested_t *this, message_t *response);
149
150 /**
151 * Build AUTH payload for IKE_AUTH request.
152 *
153 * @param this calling object
154 * @param my_id_payload buildet ID payload
155 * @param response created payload will be added to this message_t object
156 * @return
157 * - SUCCESS
158 * - FAILED
159 */
160 status_t (*build_auth_payload) (private_ike_sa_init_requested_t *this,id_payload_t *my_id_payload, message_t *response);
161
162 /**
163 * Build SA payload for IKE_AUTH request.
164 *
165 * @param this calling object
166 * @param response created payload will be added to this message_t object
167 * @return
168 * - SUCCESS
169 * - FAILED
170 */
171 status_t (*build_sa_payload) (private_ike_sa_init_requested_t *this, message_t *response);
172
173 /**
174 * Build TSi payload for IKE_AUTH request.
175 *
176 * @param this calling object
177 * @param response created payload will be added to this message_t object
178 * @return
179 * - SUCCESS
180 * - FAILED
181 */
182 status_t (*build_tsi_payload) (private_ike_sa_init_requested_t *this, message_t *response);
183
184 /**
185 * Build TSr payload for IKE_AUTH request.
186 *
187 * @param this calling object
188 * @param response created payload will be added to this message_t object
189 * @return
190 * - SUCCESS
191 * - FAILED
192 */
193 status_t (*build_tsr_payload) (private_ike_sa_init_requested_t *this, message_t *response);
194
195 /**
196 * Process a notify payload and react.
197 *
198 * @param this calling object
199 * @param notify_payload notify_payload to handle
200 */
201 status_t (*process_notify_payload) (private_ike_sa_init_requested_t *this, notify_payload_t *notify_payload);
202
203 /**
204 * Destroy function called internally of this class after state change to
205 * state IKE_AUTH_REQUESTED succeeded.
206 *
207 * This destroy function does not destroy objects which were passed to the new state.
208 *
209 * @param this calling object
210 */
211 void (*destroy_after_state_change) (private_ike_sa_init_requested_t *this);
212 };
213
214 /**
215 * Implementation of state_t.process_message.
216 */
217 static status_t process_message(private_ike_sa_init_requested_t *this, message_t *ike_sa_init_reply)
218 {
219 ike_auth_requested_t *next_state;
220 chunk_t ike_sa_init_reply_data;
221 sa_payload_t *sa_payload = NULL;
222 ke_payload_t *ke_payload = NULL;
223 id_payload_t *id_payload = NULL;
224 nonce_payload_t *nonce_payload = NULL;
225 u_int64_t responder_spi;
226 ike_sa_id_t *ike_sa_id;
227 iterator_t *payloads;
228 host_t *me, *other;
229 connection_t *connection;
230 policy_t *policy;
231
232 message_t *request;
233 status_t status;
234
235 /*
236 * In this state a reply message of type IKE_SA_INIT is expected:
237 *
238 * <-- HDR, SAr1, KEr, Nr, [CERTREQ]
239 * or
240 * <-- HDR, N
241 */
242
243 if (ike_sa_init_reply->get_exchange_type(ike_sa_init_reply) != IKE_SA_INIT)
244 {
245 this->logger->log(this->logger, ERROR | LEVEL1, "Message of type %s not supported in state ike_sa_init_requested",
246 mapping_find(exchange_type_m,ike_sa_init_reply->get_exchange_type(ike_sa_init_reply)));
247 return FAILED;
248 }
249
250 if (ike_sa_init_reply->get_request(ike_sa_init_reply))
251 {
252 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT requests not allowed state ike_sa_init_responded");
253 return FAILED;
254 }
255
256 /* parse incoming message */
257 status = ike_sa_init_reply->parse_body(ike_sa_init_reply, NULL, NULL);
258 if (status != SUCCESS)
259 {
260 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT reply parsing faild. Ignoring message");
261 return status;
262 }
263
264 /* because we are original initiator we have to update the responder SPI to the new one */
265 responder_spi = ike_sa_init_reply->get_responder_spi(ike_sa_init_reply);
266 if (responder_spi == 0)
267 {
268 this->logger->log(this->logger, ERROR | LEVEL1, "IKE_SA_INIT reply contained a SPI of zero");
269 return FAILED;
270 }
271 ike_sa_id = this->ike_sa->public.get_id(&(this->ike_sa->public));
272 ike_sa_id->set_responder_spi(ike_sa_id,responder_spi);
273
274 /* Iterate over all payloads.
275 *
276 * The message is already checked for the right payload types.
277 */
278 payloads = ike_sa_init_reply->get_payload_iterator(ike_sa_init_reply);
279 while (payloads->has_next(payloads))
280 {
281 payload_t *payload;
282 payloads->current(payloads, (void**)&payload);
283
284 switch (payload->get_type(payload))
285 {
286 case SECURITY_ASSOCIATION:
287 {
288 sa_payload = (sa_payload_t*)payload;
289 break;
290 }
291 case KEY_EXCHANGE:
292 {
293 ke_payload = (ke_payload_t*)payload;
294 break;
295 }
296 case NONCE:
297 {
298 nonce_payload = (nonce_payload_t*)payload;
299 break;
300 }
301 case NOTIFY:
302 {
303 notify_payload_t *notify_payload = (notify_payload_t *) payload;
304
305 status = this->process_notify_payload(this, notify_payload);
306 if (status != SUCCESS)
307 {
308 payloads->destroy(payloads);
309 return status;
310 }
311 break;
312 }
313 default:
314 {
315 this->logger->log(this->logger, ERROR|LEVEL1, "Ignoring payload %s (%d)",
316 mapping_find(payload_type_m, payload->get_type(payload)), payload->get_type(payload));
317 break;
318 }
319
320 }
321
322 }
323 payloads->destroy(payloads);
324
325 if (!(nonce_payload && sa_payload && ke_payload))
326 {
327 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply did not contain all required payloads. Deleting IKE_SA");
328 return DESTROY_ME;
329 }
330
331 status = this->process_nonce_payload (this,nonce_payload);
332 if (status != SUCCESS)
333 {
334 return status;
335 }
336
337 status = this->process_sa_payload (this,sa_payload);
338 if (status != SUCCESS)
339 {
340 return status;
341 }
342
343 status = this->process_ke_payload (this,ke_payload);
344 if (status != SUCCESS)
345 {
346 return status;
347 }
348
349 /* derive all the keys used in the IKE_SA */
350 status = this->ike_sa->build_transforms(this->ike_sa, this->proposal, this->diffie_hellman, this->sent_nonce, this->received_nonce);
351 if (status != SUCCESS)
352 {
353 this->logger->log(this->logger, AUDIT, "Transform objects could not be created from selected proposal. Deleting IKE_SA");
354 return DESTROY_ME;
355 }
356
357 /* apply the address on wich we really received the packet */
358 connection = this->ike_sa->get_connection(this->ike_sa);
359 me = ike_sa_init_reply->get_destination(ike_sa_init_reply);
360 other = ike_sa_init_reply->get_source(ike_sa_init_reply);
361 connection->update_my_host(connection, me->clone(me));
362 connection->update_other_host(connection, other->clone(other));
363 policy = this->ike_sa->get_policy(this->ike_sa);
364 policy->update_my_ts(policy, me);
365 policy->update_other_ts(policy, other);
366
367 /* build empty message */
368 this->ike_sa->build_message(this->ike_sa, IKE_AUTH, TRUE, &request);
369
370 status = this->build_id_payload(this, &id_payload, request);
371 if (status != SUCCESS)
372 {
373 request->destroy(request);
374 return status;
375 }
376 status = this->build_idr_payload(this, request);
377 if (status != SUCCESS)
378 {
379 request->destroy(request);
380 return status;
381 }
382 status = this->build_auth_payload(this, (id_payload_t*)id_payload, request);
383 if (status != SUCCESS)
384 {
385 request->destroy(request);
386 return status;
387 }
388 status = this->build_sa_payload(this, request);
389 if (status != SUCCESS)
390 {
391 request->destroy(request);
392 return status;
393 }
394 status = this->build_tsi_payload(this, request);
395 if (status != SUCCESS)
396 {
397 request->destroy(request);
398 return status;
399 }
400 status = this->build_tsr_payload(this, request);
401 if (status != SUCCESS)
402 {
403 request->destroy(request);
404 return status;
405 }
406
407 /* message can now be sent (must not be destroyed) */
408 status = this->ike_sa->send_request(this->ike_sa, request);
409 if (status != SUCCESS)
410 {
411 this->logger->log(this->logger, AUDIT, "Unable to send IKE_AUTH request. Deleting IKE_SA");
412 request->destroy(request);
413 return DESTROY_ME;
414 }
415
416 this->ike_sa->set_last_replied_message_id(this->ike_sa,ike_sa_init_reply->get_message_id(ike_sa_init_reply));
417
418 ike_sa_init_reply_data = ike_sa_init_reply->get_packet_data(ike_sa_init_reply);
419
420 /* state can now be changed */
421 next_state = ike_auth_requested_create(this->ike_sa, this->sent_nonce, this->received_nonce,
422 ike_sa_init_reply_data, this->child_sa);
423 this->ike_sa->set_new_state(this->ike_sa,(state_t *) next_state);
424
425 this->destroy_after_state_change(this);
426 return SUCCESS;
427 }
428
429
430 /**
431 * Implementation of private_ike_sa_init_requested_t.process_nonce_payload.
432 */
433 status_t process_nonce_payload (private_ike_sa_init_requested_t *this, nonce_payload_t *nonce_payload)
434 {
435 free(this->received_nonce.ptr);
436 this->received_nonce = nonce_payload->get_nonce(nonce_payload);
437 return SUCCESS;
438 }
439
440
441 /**
442 * Implementation of private_ike_sa_init_requested_t.process_sa_payload.
443 */
444 status_t process_sa_payload (private_ike_sa_init_requested_t *this, sa_payload_t *sa_payload)
445 {
446 proposal_t *proposal;
447 linked_list_t *proposal_list;
448 connection_t *connection;
449
450 connection = this->ike_sa->get_connection(this->ike_sa);
451
452 /* get the list of selected proposals, the peer has to select only one proposal */
453 proposal_list = sa_payload->get_proposals (sa_payload);
454 if (proposal_list->get_count(proposal_list) != 1)
455 {
456 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response did not contain a single proposal. Deleting IKE_SA");
457 while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
458 {
459 proposal->destroy(proposal);
460 }
461 proposal_list->destroy(proposal_list);
462 return DESTROY_ME;
463 }
464
465 /* we have to re-check if the others selection is valid */
466 this->proposal = connection->select_proposal(connection, proposal_list);
467 while (proposal_list->remove_last(proposal_list, (void**)&proposal) == SUCCESS)
468 {
469 proposal->destroy(proposal);
470 }
471 proposal_list->destroy(proposal_list);
472
473 if (this->proposal == NULL)
474 {
475 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained selected proposal we did not offer. Deleting IKE_SA");
476 return DESTROY_ME;
477 }
478
479 return SUCCESS;
480 }
481
482 /**
483 * Implementation of private_ike_sa_init_requested_t.process_ke_payload.
484 */
485 status_t process_ke_payload (private_ike_sa_init_requested_t *this, ke_payload_t *ke_payload)
486 {
487 this->diffie_hellman->set_other_public_value(this->diffie_hellman, ke_payload->get_key_exchange_data(ke_payload));
488
489 return SUCCESS;
490 }
491
492 /**
493 * Implementation of private_ike_sa_init_requested_t.build_id_payload.
494 */
495 static status_t build_id_payload (private_ike_sa_init_requested_t *this,id_payload_t **id_payload, message_t *request)
496 {
497 policy_t *policy;
498 id_payload_t *new_id_payload;
499 identification_t *identification;
500
501 policy = this->ike_sa->get_policy(this->ike_sa);
502 identification = policy->get_my_id(policy);
503 new_id_payload = id_payload_create_from_identification(TRUE, identification);
504
505 this->logger->log(this->logger, CONTROL|LEVEL2, "Add ID payload to message");
506 request->add_payload(request,(payload_t *) new_id_payload);
507
508 *id_payload = new_id_payload;
509
510 return SUCCESS;
511 }
512
513 /**
514 * Implementation of private_ike_sa_init_requested_t.build_idr_payload.
515 */
516 static status_t build_idr_payload (private_ike_sa_init_requested_t *this, message_t *request)
517 {
518 policy_t *policy;
519 id_payload_t *idr_payload;
520 identification_t *identification;
521
522 policy = this->ike_sa->get_policy(this->ike_sa);
523 identification = policy->get_other_id(policy);
524 if (!identification->contains_wildcards(identification))
525 {
526 idr_payload = id_payload_create_from_identification(FALSE, identification);
527
528 this->logger->log(this->logger, CONTROL|LEVEL2, "Add IDr payload to message");
529 request->add_payload(request,(payload_t *) idr_payload);
530 }
531 return SUCCESS;
532 }
533
534 /**
535 * Implementation of private_ike_sa_init_requested_t.build_auth_payload.
536 */
537 static status_t build_auth_payload (private_ike_sa_init_requested_t *this, id_payload_t *my_id_payload, message_t *request)
538 {
539 authenticator_t *authenticator;
540 auth_payload_t *auth_payload;
541 status_t status;
542
543 authenticator = authenticator_create(this->ike_sa);
544 status = authenticator->compute_auth_data(authenticator,&auth_payload,this->ike_sa_init_request_data,this->received_nonce,my_id_payload,TRUE);
545 authenticator->destroy(authenticator);
546
547 if (status != SUCCESS)
548 {
549 this->logger->log(this->logger, AUDIT, "Could not generate AUTH data for IKE_AUTH request. Deleting IKE_SA");
550 return DESTROY_ME;
551 }
552
553 this->logger->log(this->logger, CONTROL|LEVEL2, "Add AUTH payload to message");
554 request->add_payload(request,(payload_t *) auth_payload);
555
556 return SUCCESS;
557 }
558
559 /**
560 * Implementation of private_ike_sa_init_requested_t.build_sa_payload.
561 */
562 static status_t build_sa_payload (private_ike_sa_init_requested_t *this, message_t *request)
563 {
564 linked_list_t *proposal_list;
565 sa_payload_t *sa_payload;
566 policy_t *policy;
567 connection_t *connection;
568
569 /* get proposals form config, add to payload */
570 policy = this->ike_sa->get_policy(this->ike_sa);
571 proposal_list = policy->get_proposals(policy);
572 /* build child sa */
573 connection = this->ike_sa->get_connection(this->ike_sa);
574 this->child_sa = child_sa_create(connection->get_my_host(connection),
575 connection->get_other_host(connection));
576 if (this->child_sa->alloc(this->child_sa, proposal_list) != SUCCESS)
577 {
578 this->logger->log(this->logger, AUDIT, "Could not install CHILD_SA! Deleting IKE_SA");
579 return DESTROY_ME;
580 }
581
582 sa_payload = sa_payload_create_from_proposal_list(proposal_list);
583
584 this->logger->log(this->logger, CONTROL|LEVEL2, "Add SA payload to message");
585 request->add_payload(request,(payload_t *) sa_payload);
586
587 return SUCCESS;
588 }
589
590 /**
591 * Implementation of private_ike_sa_init_requested_t.build_tsi_payload.
592 */
593 static status_t build_tsi_payload (private_ike_sa_init_requested_t *this, message_t *request)
594 {
595 linked_list_t *ts_list;
596 ts_payload_t *ts_payload;
597 policy_t *policy;
598
599 policy = this->ike_sa->get_policy(this->ike_sa);
600 ts_list = policy->get_my_traffic_selectors(policy);
601 ts_payload = ts_payload_create_from_traffic_selectors(TRUE, ts_list);
602
603 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSi payload to message");
604 request->add_payload(request,(payload_t *) ts_payload);
605
606 return SUCCESS;
607 }
608
609 /**
610 * Implementation of private_ike_sa_init_requested_t.build_tsr_payload.
611 */
612 static status_t build_tsr_payload (private_ike_sa_init_requested_t *this, message_t *request)
613 {
614 linked_list_t *ts_list;
615 ts_payload_t *ts_payload;
616 policy_t *policy;
617
618 policy = this->ike_sa->get_policy(this->ike_sa);
619 ts_list = policy->get_other_traffic_selectors(policy);
620 ts_payload = ts_payload_create_from_traffic_selectors(FALSE, ts_list);
621
622 this->logger->log(this->logger, CONTROL|LEVEL2, "Add TSr payload to message");
623 request->add_payload(request,(payload_t *) ts_payload);
624
625 return SUCCESS;
626 }
627
628 /**
629 * Implementation of private_ike_sa_init_requested_t.process_notify_payload.
630 */
631 static status_t process_notify_payload(private_ike_sa_init_requested_t *this, notify_payload_t *notify_payload)
632 {
633 notify_message_type_t notify_message_type = notify_payload->get_notify_message_type(notify_payload);
634
635 this->logger->log(this->logger, CONTROL|LEVEL1, "Process notify type %s",
636 mapping_find(notify_message_type_m, notify_message_type));
637
638 switch (notify_message_type)
639 {
640 case NO_PROPOSAL_CHOSEN:
641 {
642 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a NO_PROPOSAL_CHOSEN notify. Deleting IKE_SA");
643 return DESTROY_ME;
644 }
645 case INVALID_MAJOR_VERSION:
646 {
647 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT response contained a INVALID_MAJOR_VERSION notify. Deleting IKE_SA");
648 return DESTROY_ME;
649 }
650 case INVALID_KE_PAYLOAD:
651 {
652 initiator_init_t *initiator_init_state;
653 chunk_t notify_data;
654 diffie_hellman_group_t dh_group, old_dh_group;
655 connection_t *connection;
656
657 connection = this->ike_sa->get_connection(this->ike_sa);
658 old_dh_group = connection->get_dh_group(connection);
659 notify_data = notify_payload->get_notification_data(notify_payload);
660 dh_group = ntohs(*((u_int16_t*)notify_data.ptr));
661
662 /* TODO:
663 * We are very restrictive here: If the other didn't accept
664 * our DH group, and we do not accept his offer, continuation
665 * is cancelled...
666 */
667
668 this->logger->log(this->logger, AUDIT, "Peer didn't accept %s, it requested %s!",
669 mapping_find(diffie_hellman_group_m, old_dh_group),
670 mapping_find(diffie_hellman_group_m, dh_group));
671 /* check if we can accept this dh group */
672 if (!connection->check_dh_group(connection, dh_group))
673 {
674 this->logger->log(this->logger, AUDIT,
675 "Peer does only accept DH group %s, which we do not accept! Aborting",
676 mapping_find(diffie_hellman_group_m, dh_group));
677 return DESTROY_ME;
678 }
679
680 /* Going to change state back to initiator_init_t */
681 this->logger->log(this->logger, CONTROL|LEVEL2, "Create next state object");
682 initiator_init_state = initiator_init_create(this->ike_sa);
683
684 /* buffer of sent and received messages has to get reseted */
685 this->ike_sa->reset_message_buffers(this->ike_sa);
686
687 /* state can now be changed */
688 this->ike_sa->set_new_state(this->ike_sa,(state_t *) initiator_init_state);
689
690 /* state has NOW changed :-) */
691 this->logger->log(this->logger, CONTROL|LEVEL2, "Destroy old sate object");
692 this->logger->log(this->logger, CONTROL|LEVEL2, "Going to retry initialization of connection");
693
694 this->public.state_interface.destroy(&(this->public.state_interface));
695 if (initiator_init_state->retry_initiate_connection (initiator_init_state, dh_group) != SUCCESS)
696 {
697 return DESTROY_ME;
698 }
699 return FAILED;
700 }
701 default:
702 {
703 /*
704 * - In case of unknown error: IKE_SA gets destroyed.
705 * - In case of unknown status: logging
706 */
707 if (notify_message_type < 16383)
708 {
709 this->logger->log(this->logger, AUDIT, "IKE_SA_INIT reply contained an unknown notify error (%d). Deleting IKE_SA",
710 notify_message_type);
711 return DESTROY_ME;
712 }
713 else
714 {
715 this->logger->log(this->logger, CONTROL, "IKE_SA_INIT reply contained an unknown notify (%d), ignored.",
716 notify_message_type);
717 return SUCCESS;
718 }
719 }
720 }
721 }
722
723 /**
724 * Implementation of state_t.get_state.
725 */
726 static ike_sa_state_t get_state(private_ike_sa_init_requested_t *this)
727 {
728 return IKE_SA_INIT_REQUESTED;
729 }
730
731 /**
732 * Implementation of private_ike_sa_init_requested_t.destroy_after_state_change.
733 */
734 static void destroy_after_state_change (private_ike_sa_init_requested_t *this)
735 {
736 this->diffie_hellman->destroy(this->diffie_hellman);
737 chunk_free(&(this->ike_sa_init_request_data));
738 if (this->proposal)
739 {
740 this->proposal->destroy(this->proposal);
741 }
742 free(this);
743 }
744
745 /**
746 * Implementation state_t.destroy.
747 */
748 static void destroy(private_ike_sa_init_requested_t *this)
749 {
750 this->diffie_hellman->destroy(this->diffie_hellman);
751 free(this->sent_nonce.ptr);
752 free(this->received_nonce.ptr);
753 chunk_free(&(this->ike_sa_init_request_data));
754 if (this->child_sa)
755 {
756 this->child_sa->destroy(this->child_sa);
757 }
758 if (this->proposal)
759 {
760 this->proposal->destroy(this->proposal);
761 }
762 free(this);
763 }
764
765 /*
766 * Described in header.
767 */
768 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)
769 {
770 private_ike_sa_init_requested_t *this = malloc_thing(private_ike_sa_init_requested_t);
771
772 /* interface functions */
773 this->public.state_interface.process_message = (status_t (*) (state_t *,message_t *)) process_message;
774 this->public.state_interface.get_state = (ike_sa_state_t (*) (state_t *)) get_state;
775 this->public.state_interface.destroy = (void (*) (state_t *)) destroy;
776
777 /* private functions */
778 this->destroy_after_state_change = destroy_after_state_change;
779 this->process_nonce_payload = process_nonce_payload;
780 this->process_sa_payload = process_sa_payload;
781 this->process_ke_payload = process_ke_payload;
782 this->build_auth_payload = build_auth_payload;
783 this->build_tsi_payload = build_tsi_payload;
784 this->build_tsr_payload = build_tsr_payload;
785 this->build_id_payload = build_id_payload;
786 this->build_idr_payload = build_idr_payload;
787 this->build_sa_payload = build_sa_payload;
788 this->process_notify_payload = process_notify_payload;
789
790 /* private data */
791 this->ike_sa = ike_sa;
792 this->received_nonce = CHUNK_INITIALIZER;
793 this->logger = logger_manager->get_logger(logger_manager, IKE_SA);
794 this->diffie_hellman = diffie_hellman;
795 this->proposal = NULL;
796 this->sent_nonce = sent_nonce;
797 this->child_sa = NULL;
798 this->ike_sa_init_request_data = ike_sa_init_request_data;
799
800 return &(this->public);
801 }