8c628646e90a23fe3f474afff078c8ef0499efaa
[strongswan.git] / src / libcharon / sa / ikev2 / tasks / ike_init.c
1 /*
2 * Copyright (C) 2008-2015 Tobias Brunner
3 * Copyright (C) 2005-2008 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 #include "ike_init.h"
19
20 #include <string.h>
21
22 #include <daemon.h>
23 #include <bio/bio_reader.h>
24 #include <bio/bio_writer.h>
25 #include <sa/ikev2/keymat_v2.h>
26 #include <crypto/diffie_hellman.h>
27 #include <crypto/hashers/hash_algorithm_set.h>
28 #include <encoding/payloads/sa_payload.h>
29 #include <encoding/payloads/ke_payload.h>
30 #include <encoding/payloads/nonce_payload.h>
31
32 /** maximum retries to do with cookies/other dh groups */
33 #define MAX_RETRIES 5
34
35 typedef struct private_ike_init_t private_ike_init_t;
36
37 /**
38 * Private members of a ike_init_t task.
39 */
40 struct private_ike_init_t {
41
42 /**
43 * Public methods and task_t interface.
44 */
45 ike_init_t public;
46
47 /**
48 * Assigned IKE_SA.
49 */
50 ike_sa_t *ike_sa;
51
52 /**
53 * Are we the initiator?
54 */
55 bool initiator;
56
57 /**
58 * IKE config to establish
59 */
60 ike_cfg_t *config;
61
62 /**
63 * diffie hellman group to use
64 */
65 diffie_hellman_group_t dh_group;
66
67 /**
68 * diffie hellman key exchange
69 */
70 diffie_hellman_t *dh;
71
72 /**
73 * Applying DH public value failed?
74 */
75 bool dh_failed;
76
77 /**
78 * Keymat derivation (from IKE_SA)
79 */
80 keymat_v2_t *keymat;
81
82 /**
83 * nonce chosen by us
84 */
85 chunk_t my_nonce;
86
87 /**
88 * nonce chosen by peer
89 */
90 chunk_t other_nonce;
91
92 /**
93 * nonce generator
94 */
95 nonce_gen_t *nonceg;
96
97 /**
98 * Negotiated proposal used for IKE_SA
99 */
100 proposal_t *proposal;
101
102 /**
103 * Old IKE_SA which gets rekeyed
104 */
105 ike_sa_t *old_sa;
106
107 /**
108 * cookie received from responder
109 */
110 chunk_t cookie;
111
112 /**
113 * retries done so far after failure (cookie or bad dh group)
114 */
115 u_int retry;
116
117 /**
118 * Whether to use Signature Authentication as per RFC 7427
119 */
120 bool signature_authentication;
121 };
122
123 /**
124 * Allocate our own nonce value
125 */
126 static bool generate_nonce(private_ike_init_t *this)
127 {
128 if (!this->nonceg)
129 {
130 DBG1(DBG_IKE, "no nonce generator found to create nonce");
131 return FALSE;
132 }
133 if (!this->nonceg->allocate_nonce(this->nonceg, NONCE_SIZE,
134 &this->my_nonce))
135 {
136 DBG1(DBG_IKE, "nonce allocation failed");
137 return FALSE;
138 }
139 return TRUE;
140 }
141
142 /**
143 * Notify the peer about the hash algorithms we support or expect,
144 * as per RFC 7427
145 */
146 static void send_supported_hash_algorithms(private_ike_init_t *this,
147 message_t *message)
148 {
149 hash_algorithm_set_t *algos;
150 enumerator_t *enumerator, *rounds;
151 bio_writer_t *writer;
152 hash_algorithm_t hash;
153 peer_cfg_t *peer;
154 auth_cfg_t *auth;
155 auth_rule_t rule;
156 uintptr_t config;
157 char *plugin_name;
158
159 algos = hash_algorithm_set_create();
160 peer = this->ike_sa->get_peer_cfg(this->ike_sa);
161 if (peer)
162 {
163 rounds = peer->create_auth_cfg_enumerator(peer, FALSE);
164 while (rounds->enumerate(rounds, &auth))
165 {
166 enumerator = auth->create_enumerator(auth);
167 while (enumerator->enumerate(enumerator, &rule, &config))
168 {
169 if (rule == AUTH_RULE_SIGNATURE_SCHEME)
170 {
171 hash = hasher_from_signature_scheme(config);
172 if (hasher_algorithm_for_ikev2(hash))
173 {
174 algos->add(algos, hash);
175 }
176 }
177 }
178 enumerator->destroy(enumerator);
179 }
180 rounds->destroy(rounds);
181 }
182
183 if (!algos->count(algos))
184 {
185 enumerator = lib->crypto->create_hasher_enumerator(lib->crypto);
186 while (enumerator->enumerate(enumerator, &hash, &plugin_name))
187 {
188 if (hasher_algorithm_for_ikev2(hash))
189 {
190 algos->add(algos, hash);
191 }
192 }
193 enumerator->destroy(enumerator);
194 }
195
196 if (algos->count(algos))
197 {
198 writer = bio_writer_create(0);
199 enumerator = algos->create_enumerator(algos);
200 while (enumerator->enumerate(enumerator, &hash))
201 {
202 writer->write_uint16(writer, hash);
203 }
204 enumerator->destroy(enumerator);
205 message->add_notify(message, FALSE, SIGNATURE_HASH_ALGORITHMS,
206 writer->get_buf(writer));
207 writer->destroy(writer);
208 }
209 algos->destroy(algos);
210 }
211
212 /**
213 * Store algorithms supported by other peer
214 */
215 static void handle_supported_hash_algorithms(private_ike_init_t *this,
216 notify_payload_t *notify)
217 {
218 bio_reader_t *reader;
219 u_int16_t algo;
220 bool added = FALSE;
221
222 reader = bio_reader_create(notify->get_notification_data(notify));
223 while (reader->remaining(reader) >= 2 && reader->read_uint16(reader, &algo))
224 {
225 if (hasher_algorithm_for_ikev2(algo))
226 {
227 this->keymat->add_hash_algorithm(this->keymat, algo);
228 added = TRUE;
229 }
230 }
231 reader->destroy(reader);
232
233 if (added)
234 {
235 this->ike_sa->enable_extension(this->ike_sa, EXT_SIGNATURE_AUTH);
236 }
237 }
238
239 /**
240 * build the payloads for the message
241 */
242 static bool build_payloads(private_ike_init_t *this, message_t *message)
243 {
244 sa_payload_t *sa_payload;
245 ke_payload_t *ke_payload;
246 nonce_payload_t *nonce_payload;
247 linked_list_t *proposal_list;
248 ike_sa_id_t *id;
249 proposal_t *proposal;
250 enumerator_t *enumerator;
251
252 id = this->ike_sa->get_id(this->ike_sa);
253
254 this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
255
256 if (this->initiator)
257 {
258 proposal_list = this->config->get_proposals(this->config);
259 if (this->old_sa)
260 {
261 /* include SPI of new IKE_SA when we are rekeying */
262 enumerator = proposal_list->create_enumerator(proposal_list);
263 while (enumerator->enumerate(enumerator, (void**)&proposal))
264 {
265 proposal->set_spi(proposal, id->get_initiator_spi(id));
266 }
267 enumerator->destroy(enumerator);
268 }
269
270 sa_payload = sa_payload_create_from_proposals_v2(proposal_list);
271 proposal_list->destroy_offset(proposal_list, offsetof(proposal_t, destroy));
272 }
273 else
274 {
275 if (this->old_sa)
276 {
277 /* include SPI of new IKE_SA when we are rekeying */
278 this->proposal->set_spi(this->proposal, id->get_responder_spi(id));
279 }
280 sa_payload = sa_payload_create_from_proposal_v2(this->proposal);
281 }
282 message->add_payload(message, (payload_t*)sa_payload);
283
284 nonce_payload = nonce_payload_create(PLV2_NONCE);
285 nonce_payload->set_nonce(nonce_payload, this->my_nonce);
286 ke_payload = ke_payload_create_from_diffie_hellman(PLV2_KEY_EXCHANGE,
287 this->dh);
288 if (!ke_payload)
289 {
290 DBG1(DBG_IKE, "creating KE payload failed");
291 return FALSE;
292 }
293
294 if (this->old_sa)
295 { /* payload order differs if we are rekeying */
296 message->add_payload(message, (payload_t*)nonce_payload);
297 message->add_payload(message, (payload_t*)ke_payload);
298 }
299 else
300 {
301 message->add_payload(message, (payload_t*)ke_payload);
302 message->add_payload(message, (payload_t*)nonce_payload);
303 }
304
305 /* negotiate fragmentation if we are not rekeying */
306 if (!this->old_sa &&
307 this->config->fragmentation(this->config) != FRAGMENTATION_NO)
308 {
309 if (this->initiator ||
310 this->ike_sa->supports_extension(this->ike_sa,
311 EXT_IKE_FRAGMENTATION))
312 {
313 message->add_notify(message, FALSE, FRAGMENTATION_SUPPORTED,
314 chunk_empty);
315 }
316 }
317 /* submit supported hash algorithms for signature authentication */
318 if (!this->old_sa && this->signature_authentication)
319 {
320 if (this->initiator ||
321 this->ike_sa->supports_extension(this->ike_sa,
322 EXT_SIGNATURE_AUTH))
323 {
324 send_supported_hash_algorithms(this, message);
325 }
326 }
327 return TRUE;
328 }
329
330 /**
331 * Read payloads from message
332 */
333 static void process_payloads(private_ike_init_t *this, message_t *message)
334 {
335 enumerator_t *enumerator;
336 payload_t *payload;
337 ke_payload_t *ke_payload = NULL;
338
339 enumerator = message->create_payload_enumerator(message);
340 while (enumerator->enumerate(enumerator, &payload))
341 {
342 switch (payload->get_type(payload))
343 {
344 case PLV2_SECURITY_ASSOCIATION:
345 {
346 sa_payload_t *sa_payload = (sa_payload_t*)payload;
347 linked_list_t *proposal_list;
348 bool private;
349
350 proposal_list = sa_payload->get_proposals(sa_payload);
351 private = this->ike_sa->supports_extension(this->ike_sa,
352 EXT_STRONGSWAN);
353 this->proposal = this->config->select_proposal(this->config,
354 proposal_list, private);
355 if (!this->proposal)
356 {
357 charon->bus->alert(charon->bus, ALERT_PROPOSAL_MISMATCH_IKE,
358 proposal_list);
359 }
360 proposal_list->destroy_offset(proposal_list,
361 offsetof(proposal_t, destroy));
362 break;
363 }
364 case PLV2_KEY_EXCHANGE:
365 {
366 ke_payload = (ke_payload_t*)payload;
367
368 this->dh_group = ke_payload->get_dh_group_number(ke_payload);
369 break;
370 }
371 case PLV2_NONCE:
372 {
373 nonce_payload_t *nonce_payload = (nonce_payload_t*)payload;
374
375 this->other_nonce = nonce_payload->get_nonce(nonce_payload);
376 break;
377 }
378 case PLV2_NOTIFY:
379 {
380 notify_payload_t *notify = (notify_payload_t*)payload;
381
382 switch (notify->get_notify_type(notify))
383 {
384 case FRAGMENTATION_SUPPORTED:
385 this->ike_sa->enable_extension(this->ike_sa,
386 EXT_IKE_FRAGMENTATION);
387 break;
388 case SIGNATURE_HASH_ALGORITHMS:
389 if (this->signature_authentication)
390 {
391 handle_supported_hash_algorithms(this, notify);
392 }
393 break;
394 case REDIRECT_SUPPORTED:
395 this->ike_sa->enable_extension(this->ike_sa,
396 EXT_IKE_REDIRECTION);
397 break;
398 default:
399 /* other notifies are handled elsewhere */
400 break;
401 }
402
403 }
404 default:
405 break;
406 }
407 }
408 enumerator->destroy(enumerator);
409
410 if (ke_payload && this->proposal &&
411 this->proposal->has_dh_group(this->proposal, this->dh_group))
412 {
413 if (!this->initiator)
414 {
415 this->dh = this->keymat->keymat.create_dh(
416 &this->keymat->keymat, this->dh_group);
417 }
418 if (this->dh)
419 {
420 this->dh_failed = !this->dh->set_other_public_value(this->dh,
421 ke_payload->get_key_exchange_data(ke_payload));
422 }
423 }
424 }
425
426 METHOD(task_t, build_i, status_t,
427 private_ike_init_t *this, message_t *message)
428 {
429 this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
430 DBG0(DBG_IKE, "initiating IKE_SA %s[%d] to %H",
431 this->ike_sa->get_name(this->ike_sa),
432 this->ike_sa->get_unique_id(this->ike_sa),
433 this->ike_sa->get_other_host(this->ike_sa));
434 this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
435
436 if (this->retry >= MAX_RETRIES)
437 {
438 DBG1(DBG_IKE, "giving up after %d retries", MAX_RETRIES);
439 return FAILED;
440 }
441
442 /* if the DH group is set via use_dh_group(), we already have a DH object */
443 if (!this->dh)
444 {
445 this->dh_group = this->config->get_dh_group(this->config);
446 this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
447 this->dh_group);
448 if (!this->dh)
449 {
450 DBG1(DBG_IKE, "configured DH group %N not supported",
451 diffie_hellman_group_names, this->dh_group);
452 return FAILED;
453 }
454 }
455
456 /* generate nonce only when we are trying the first time */
457 if (this->my_nonce.ptr == NULL)
458 {
459 if (!generate_nonce(this))
460 {
461 return FAILED;
462 }
463 }
464
465 if (this->cookie.ptr)
466 {
467 message->add_notify(message, FALSE, COOKIE, this->cookie);
468 }
469
470 if (!build_payloads(this, message))
471 {
472 return FAILED;
473 }
474
475 #ifdef ME
476 {
477 chunk_t connect_id = this->ike_sa->get_connect_id(this->ike_sa);
478 if (connect_id.ptr)
479 {
480 message->add_notify(message, FALSE, ME_CONNECTID, connect_id);
481 }
482 }
483 #endif /* ME */
484
485 return NEED_MORE;
486 }
487
488 METHOD(task_t, process_r, status_t,
489 private_ike_init_t *this, message_t *message)
490 {
491 this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
492 DBG0(DBG_IKE, "%H is initiating an IKE_SA", message->get_source(message));
493 this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
494
495 if (!generate_nonce(this))
496 {
497 return FAILED;
498 }
499
500 #ifdef ME
501 {
502 notify_payload_t *notify = message->get_notify(message, ME_CONNECTID);
503 if (notify)
504 {
505 chunk_t connect_id = notify->get_notification_data(notify);
506 DBG2(DBG_IKE, "received ME_CONNECTID %#B", &connect_id);
507 charon->connect_manager->stop_checks(charon->connect_manager,
508 connect_id);
509 }
510 }
511 #endif /* ME */
512
513 process_payloads(this, message);
514
515 return NEED_MORE;
516 }
517
518 /**
519 * Derive the keymat for the IKE_SA
520 */
521 static bool derive_keys(private_ike_init_t *this,
522 chunk_t nonce_i, chunk_t nonce_r)
523 {
524 keymat_v2_t *old_keymat;
525 pseudo_random_function_t prf_alg = PRF_UNDEFINED;
526 chunk_t skd = chunk_empty;
527 ike_sa_id_t *id;
528
529 id = this->ike_sa->get_id(this->ike_sa);
530 if (this->old_sa)
531 {
532 /* rekeying: Include old SKd, use old PRF, apply SPI */
533 old_keymat = (keymat_v2_t*)this->old_sa->get_keymat(this->old_sa);
534 prf_alg = old_keymat->get_skd(old_keymat, &skd);
535 if (this->initiator)
536 {
537 id->set_responder_spi(id, this->proposal->get_spi(this->proposal));
538 }
539 else
540 {
541 id->set_initiator_spi(id, this->proposal->get_spi(this->proposal));
542 }
543 }
544 if (!this->keymat->derive_ike_keys(this->keymat, this->proposal, this->dh,
545 nonce_i, nonce_r, id, prf_alg, skd))
546 {
547 return FALSE;
548 }
549 charon->bus->ike_keys(charon->bus, this->ike_sa, this->dh, chunk_empty,
550 nonce_i, nonce_r, this->old_sa, NULL);
551 return TRUE;
552 }
553
554 METHOD(task_t, build_r, status_t,
555 private_ike_init_t *this, message_t *message)
556 {
557 /* check if we have everything we need */
558 if (this->proposal == NULL ||
559 this->other_nonce.len == 0 || this->my_nonce.len == 0)
560 {
561 DBG1(DBG_IKE, "received proposals inacceptable");
562 message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
563 return FAILED;
564 }
565 this->ike_sa->set_proposal(this->ike_sa, this->proposal);
566
567 if (this->dh == NULL ||
568 !this->proposal->has_dh_group(this->proposal, this->dh_group))
569 {
570 u_int16_t group;
571
572 if (this->proposal->get_algorithm(this->proposal, DIFFIE_HELLMAN_GROUP,
573 &group, NULL))
574 {
575 DBG1(DBG_IKE, "DH group %N inacceptable, requesting %N",
576 diffie_hellman_group_names, this->dh_group,
577 diffie_hellman_group_names, group);
578 this->dh_group = group;
579 group = htons(group);
580 message->add_notify(message, FALSE, INVALID_KE_PAYLOAD,
581 chunk_from_thing(group));
582 }
583 else
584 {
585 DBG1(DBG_IKE, "no acceptable proposal found");
586 }
587 return FAILED;
588 }
589
590 if (this->dh_failed)
591 {
592 DBG1(DBG_IKE, "applying DH public value failed");
593 message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
594 return FAILED;
595 }
596
597 if (!derive_keys(this, this->other_nonce, this->my_nonce))
598 {
599 DBG1(DBG_IKE, "key derivation failed");
600 message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
601 return FAILED;
602 }
603 if (!build_payloads(this, message))
604 {
605 message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
606 return FAILED;
607 }
608 return SUCCESS;
609 }
610
611 /**
612 * Raise alerts for received notify errors
613 */
614 static void raise_alerts(private_ike_init_t *this, notify_type_t type)
615 {
616 linked_list_t *list;
617
618 switch (type)
619 {
620 case NO_PROPOSAL_CHOSEN:
621 list = this->config->get_proposals(this->config);
622 charon->bus->alert(charon->bus, ALERT_PROPOSAL_MISMATCH_IKE, list);
623 list->destroy_offset(list, offsetof(proposal_t, destroy));
624 break;
625 default:
626 break;
627 }
628 }
629
630 METHOD(task_t, process_i, status_t,
631 private_ike_init_t *this, message_t *message)
632 {
633 enumerator_t *enumerator;
634 payload_t *payload;
635
636 /* check for erroneous notifies */
637 enumerator = message->create_payload_enumerator(message);
638 while (enumerator->enumerate(enumerator, &payload))
639 {
640 if (payload->get_type(payload) == PLV2_NOTIFY)
641 {
642 notify_payload_t *notify = (notify_payload_t*)payload;
643 notify_type_t type = notify->get_notify_type(notify);
644
645 switch (type)
646 {
647 case INVALID_KE_PAYLOAD:
648 {
649 chunk_t data;
650 diffie_hellman_group_t bad_group;
651
652 bad_group = this->dh_group;
653 data = notify->get_notification_data(notify);
654 this->dh_group = ntohs(*((u_int16_t*)data.ptr));
655 DBG1(DBG_IKE, "peer didn't accept DH group %N, "
656 "it requested %N", diffie_hellman_group_names,
657 bad_group, diffie_hellman_group_names, this->dh_group);
658
659 if (this->old_sa == NULL)
660 { /* reset the IKE_SA if we are not rekeying */
661 this->ike_sa->reset(this->ike_sa);
662 }
663
664 enumerator->destroy(enumerator);
665 this->retry++;
666 return NEED_MORE;
667 }
668 case NAT_DETECTION_SOURCE_IP:
669 case NAT_DETECTION_DESTINATION_IP:
670 /* skip, handled in ike_natd_t */
671 break;
672 case MULTIPLE_AUTH_SUPPORTED:
673 /* handled in ike_auth_t */
674 break;
675 case COOKIE:
676 {
677 chunk_free(&this->cookie);
678 this->cookie = chunk_clone(notify->get_notification_data(notify));
679 this->ike_sa->reset(this->ike_sa);
680 enumerator->destroy(enumerator);
681 DBG2(DBG_IKE, "received %N notify", notify_type_names, type);
682 this->retry++;
683 return NEED_MORE;
684 }
685 default:
686 {
687 if (type <= 16383)
688 {
689 DBG1(DBG_IKE, "received %N notify error",
690 notify_type_names, type);
691 enumerator->destroy(enumerator);
692 raise_alerts(this, type);
693 return FAILED;
694 }
695 DBG2(DBG_IKE, "received %N notify",
696 notify_type_names, type);
697 break;
698 }
699 }
700 }
701 }
702 enumerator->destroy(enumerator);
703
704 process_payloads(this, message);
705
706 /* check if we have everything */
707 if (this->proposal == NULL ||
708 this->other_nonce.len == 0 || this->my_nonce.len == 0)
709 {
710 DBG1(DBG_IKE, "peers proposal selection invalid");
711 return FAILED;
712 }
713 this->ike_sa->set_proposal(this->ike_sa, this->proposal);
714
715 if (this->dh == NULL ||
716 !this->proposal->has_dh_group(this->proposal, this->dh_group))
717 {
718 DBG1(DBG_IKE, "peer DH group selection invalid");
719 return FAILED;
720 }
721
722 if (this->dh_failed)
723 {
724 DBG1(DBG_IKE, "applying DH public value failed");
725 return FAILED;
726 }
727
728 if (!derive_keys(this, this->my_nonce, this->other_nonce))
729 {
730 DBG1(DBG_IKE, "key derivation failed");
731 return FAILED;
732 }
733 return SUCCESS;
734 }
735
736 METHOD(task_t, get_type, task_type_t,
737 private_ike_init_t *this)
738 {
739 return TASK_IKE_INIT;
740 }
741
742 METHOD(task_t, migrate, void,
743 private_ike_init_t *this, ike_sa_t *ike_sa)
744 {
745 DESTROY_IF(this->proposal);
746 chunk_free(&this->other_nonce);
747
748 this->ike_sa = ike_sa;
749 this->keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa);
750 this->proposal = NULL;
751 this->dh_failed = FALSE;
752 if (this->dh && this->dh->get_dh_group(this->dh) != this->dh_group)
753 { /* reset DH value only if group changed (INVALID_KE_PAYLOAD) */
754 this->dh->destroy(this->dh);
755 this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
756 this->dh_group);
757 }
758 }
759
760 METHOD(task_t, destroy, void,
761 private_ike_init_t *this)
762 {
763 DESTROY_IF(this->dh);
764 DESTROY_IF(this->proposal);
765 DESTROY_IF(this->nonceg);
766 chunk_free(&this->my_nonce);
767 chunk_free(&this->other_nonce);
768 chunk_free(&this->cookie);
769 free(this);
770 }
771
772 METHOD(ike_init_t, get_lower_nonce, chunk_t,
773 private_ike_init_t *this)
774 {
775 if (memcmp(this->my_nonce.ptr, this->other_nonce.ptr,
776 min(this->my_nonce.len, this->other_nonce.len)) < 0)
777 {
778 return this->my_nonce;
779 }
780 else
781 {
782 return this->other_nonce;
783 }
784 }
785
786 /*
787 * Described in header.
788 */
789 ike_init_t *ike_init_create(ike_sa_t *ike_sa, bool initiator, ike_sa_t *old_sa)
790 {
791 private_ike_init_t *this;
792
793 INIT(this,
794 .public = {
795 .task = {
796 .get_type = _get_type,
797 .migrate = _migrate,
798 .destroy = _destroy,
799 },
800 .get_lower_nonce = _get_lower_nonce,
801 },
802 .ike_sa = ike_sa,
803 .initiator = initiator,
804 .dh_group = MODP_NONE,
805 .keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa),
806 .old_sa = old_sa,
807 .signature_authentication = lib->settings->get_bool(lib->settings,
808 "%s.signature_authentication", TRUE, lib->ns),
809 );
810 this->nonceg = this->keymat->keymat.create_nonce_gen(&this->keymat->keymat);
811
812 if (initiator)
813 {
814 this->public.task.build = _build_i;
815 this->public.task.process = _process_i;
816 }
817 else
818 {
819 this->public.task.build = _build_r;
820 this->public.task.process = _process_r;
821 }
822 return &this->public;
823 }