Merge branch 'tkm-fixes'
[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 * Notify the peer about the hash algorithms we support or expect,
125 * as per RFC 7427
126 */
127 static void send_supported_hash_algorithms(private_ike_init_t *this,
128 message_t *message)
129 {
130 hash_algorithm_set_t *algos;
131 enumerator_t *enumerator, *rounds;
132 bio_writer_t *writer;
133 hash_algorithm_t hash;
134 peer_cfg_t *peer;
135 auth_cfg_t *auth;
136 auth_rule_t rule;
137 uintptr_t config;
138 char *plugin_name;
139
140 algos = hash_algorithm_set_create();
141 peer = this->ike_sa->get_peer_cfg(this->ike_sa);
142 if (peer)
143 {
144 rounds = peer->create_auth_cfg_enumerator(peer, FALSE);
145 while (rounds->enumerate(rounds, &auth))
146 {
147 enumerator = auth->create_enumerator(auth);
148 while (enumerator->enumerate(enumerator, &rule, &config))
149 {
150 if (rule == AUTH_RULE_SIGNATURE_SCHEME)
151 {
152 hash = hasher_from_signature_scheme(config);
153 if (hasher_algorithm_for_ikev2(hash))
154 {
155 algos->add(algos, hash);
156 }
157 }
158 }
159 enumerator->destroy(enumerator);
160 }
161 rounds->destroy(rounds);
162 }
163
164 if (!algos->count(algos))
165 {
166 enumerator = lib->crypto->create_hasher_enumerator(lib->crypto);
167 while (enumerator->enumerate(enumerator, &hash, &plugin_name))
168 {
169 if (hasher_algorithm_for_ikev2(hash))
170 {
171 algos->add(algos, hash);
172 }
173 }
174 enumerator->destroy(enumerator);
175 }
176
177 if (algos->count(algos))
178 {
179 writer = bio_writer_create(0);
180 enumerator = algos->create_enumerator(algos);
181 while (enumerator->enumerate(enumerator, &hash))
182 {
183 writer->write_uint16(writer, hash);
184 }
185 enumerator->destroy(enumerator);
186 message->add_notify(message, FALSE, SIGNATURE_HASH_ALGORITHMS,
187 writer->get_buf(writer));
188 writer->destroy(writer);
189 }
190 algos->destroy(algos);
191 }
192
193 /**
194 * Store algorithms supported by other peer
195 */
196 static void handle_supported_hash_algorithms(private_ike_init_t *this,
197 notify_payload_t *notify)
198 {
199 bio_reader_t *reader;
200 u_int16_t algo;
201 bool added = FALSE;
202
203 reader = bio_reader_create(notify->get_notification_data(notify));
204 while (reader->remaining(reader) >= 2 && reader->read_uint16(reader, &algo))
205 {
206 if (hasher_algorithm_for_ikev2(algo))
207 {
208 this->keymat->add_hash_algorithm(this->keymat, algo);
209 added = TRUE;
210 }
211 }
212 reader->destroy(reader);
213
214 if (added)
215 {
216 this->ike_sa->enable_extension(this->ike_sa, EXT_SIGNATURE_AUTH);
217 }
218 }
219
220 /**
221 * build the payloads for the message
222 */
223 static bool build_payloads(private_ike_init_t *this, message_t *message)
224 {
225 sa_payload_t *sa_payload;
226 ke_payload_t *ke_payload;
227 nonce_payload_t *nonce_payload;
228 linked_list_t *proposal_list;
229 ike_sa_id_t *id;
230 proposal_t *proposal;
231 enumerator_t *enumerator;
232
233 id = this->ike_sa->get_id(this->ike_sa);
234
235 this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
236
237 if (this->initiator)
238 {
239 proposal_list = this->config->get_proposals(this->config);
240 if (this->old_sa)
241 {
242 /* include SPI of new IKE_SA when we are rekeying */
243 enumerator = proposal_list->create_enumerator(proposal_list);
244 while (enumerator->enumerate(enumerator, (void**)&proposal))
245 {
246 proposal->set_spi(proposal, id->get_initiator_spi(id));
247 }
248 enumerator->destroy(enumerator);
249 }
250
251 sa_payload = sa_payload_create_from_proposals_v2(proposal_list);
252 proposal_list->destroy_offset(proposal_list, offsetof(proposal_t, destroy));
253 }
254 else
255 {
256 if (this->old_sa)
257 {
258 /* include SPI of new IKE_SA when we are rekeying */
259 this->proposal->set_spi(this->proposal, id->get_responder_spi(id));
260 }
261 sa_payload = sa_payload_create_from_proposal_v2(this->proposal);
262 }
263 message->add_payload(message, (payload_t*)sa_payload);
264
265 nonce_payload = nonce_payload_create(PLV2_NONCE);
266 nonce_payload->set_nonce(nonce_payload, this->my_nonce);
267 ke_payload = ke_payload_create_from_diffie_hellman(PLV2_KEY_EXCHANGE,
268 this->dh);
269 if (!ke_payload)
270 {
271 DBG1(DBG_IKE, "creating KE payload failed");
272 return FALSE;
273 }
274
275 if (this->old_sa)
276 { /* payload order differs if we are rekeying */
277 message->add_payload(message, (payload_t*)nonce_payload);
278 message->add_payload(message, (payload_t*)ke_payload);
279 }
280 else
281 {
282 message->add_payload(message, (payload_t*)ke_payload);
283 message->add_payload(message, (payload_t*)nonce_payload);
284 }
285
286 /* negotiate fragmentation if we are not rekeying */
287 if (!this->old_sa &&
288 this->config->fragmentation(this->config) != FRAGMENTATION_NO)
289 {
290 if (this->initiator ||
291 this->ike_sa->supports_extension(this->ike_sa,
292 EXT_IKE_FRAGMENTATION))
293 {
294 message->add_notify(message, FALSE, FRAGMENTATION_SUPPORTED,
295 chunk_empty);
296 }
297 }
298 /* submit supported hash algorithms for signature authentication */
299 if (!this->old_sa && this->signature_authentication)
300 {
301 if (this->initiator ||
302 this->ike_sa->supports_extension(this->ike_sa,
303 EXT_SIGNATURE_AUTH))
304 {
305 send_supported_hash_algorithms(this, message);
306 }
307 }
308 return TRUE;
309 }
310
311 /**
312 * Read payloads from message
313 */
314 static void process_payloads(private_ike_init_t *this, message_t *message)
315 {
316 enumerator_t *enumerator;
317 payload_t *payload;
318 ke_payload_t *ke_payload = NULL;
319
320 enumerator = message->create_payload_enumerator(message);
321 while (enumerator->enumerate(enumerator, &payload))
322 {
323 switch (payload->get_type(payload))
324 {
325 case PLV2_SECURITY_ASSOCIATION:
326 {
327 sa_payload_t *sa_payload = (sa_payload_t*)payload;
328 linked_list_t *proposal_list;
329 bool private;
330
331 proposal_list = sa_payload->get_proposals(sa_payload);
332 private = this->ike_sa->supports_extension(this->ike_sa,
333 EXT_STRONGSWAN);
334 this->proposal = this->config->select_proposal(this->config,
335 proposal_list, private);
336 if (!this->proposal)
337 {
338 charon->bus->alert(charon->bus, ALERT_PROPOSAL_MISMATCH_IKE,
339 proposal_list);
340 }
341 proposal_list->destroy_offset(proposal_list,
342 offsetof(proposal_t, destroy));
343 break;
344 }
345 case PLV2_KEY_EXCHANGE:
346 {
347 ke_payload = (ke_payload_t*)payload;
348
349 this->dh_group = ke_payload->get_dh_group_number(ke_payload);
350 break;
351 }
352 case PLV2_NONCE:
353 {
354 nonce_payload_t *nonce_payload = (nonce_payload_t*)payload;
355
356 this->other_nonce = nonce_payload->get_nonce(nonce_payload);
357 break;
358 }
359 case PLV2_NOTIFY:
360 {
361 notify_payload_t *notify = (notify_payload_t*)payload;
362
363 switch (notify->get_notify_type(notify))
364 {
365 case FRAGMENTATION_SUPPORTED:
366 this->ike_sa->enable_extension(this->ike_sa,
367 EXT_IKE_FRAGMENTATION);
368 break;
369 case SIGNATURE_HASH_ALGORITHMS:
370 if (this->signature_authentication)
371 {
372 handle_supported_hash_algorithms(this, notify);
373 }
374 break;
375 default:
376 /* other notifies are handled elsewhere */
377 break;
378 }
379
380 }
381 default:
382 break;
383 }
384 }
385 enumerator->destroy(enumerator);
386
387 if (ke_payload && this->proposal &&
388 this->proposal->has_dh_group(this->proposal, this->dh_group))
389 {
390 if (!this->initiator)
391 {
392 this->dh = this->keymat->keymat.create_dh(
393 &this->keymat->keymat, this->dh_group);
394 }
395 if (this->dh)
396 {
397 this->dh_failed = !this->dh->set_other_public_value(this->dh,
398 ke_payload->get_key_exchange_data(ke_payload));
399 }
400 }
401 }
402
403 METHOD(task_t, build_i, status_t,
404 private_ike_init_t *this, message_t *message)
405 {
406 this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
407 DBG0(DBG_IKE, "initiating IKE_SA %s[%d] to %H",
408 this->ike_sa->get_name(this->ike_sa),
409 this->ike_sa->get_unique_id(this->ike_sa),
410 this->ike_sa->get_other_host(this->ike_sa));
411 this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
412
413 if (this->retry >= MAX_RETRIES)
414 {
415 DBG1(DBG_IKE, "giving up after %d retries", MAX_RETRIES);
416 return FAILED;
417 }
418
419 /* if the DH group is set via use_dh_group(), we already have a DH object */
420 if (!this->dh)
421 {
422 this->dh_group = this->config->get_dh_group(this->config);
423 this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
424 this->dh_group);
425 if (!this->dh)
426 {
427 DBG1(DBG_IKE, "configured DH group %N not supported",
428 diffie_hellman_group_names, this->dh_group);
429 return FAILED;
430 }
431 }
432
433 /* generate nonce only when we are trying the first time */
434 if (this->my_nonce.ptr == NULL)
435 {
436 if (!this->nonceg->allocate_nonce(this->nonceg, NONCE_SIZE,
437 &this->my_nonce))
438 {
439 DBG1(DBG_IKE, "nonce allocation failed");
440 return FAILED;
441 }
442 }
443
444 if (this->cookie.ptr)
445 {
446 message->add_notify(message, FALSE, COOKIE, this->cookie);
447 }
448
449 if (!build_payloads(this, message))
450 {
451 return FAILED;
452 }
453
454 #ifdef ME
455 {
456 chunk_t connect_id = this->ike_sa->get_connect_id(this->ike_sa);
457 if (connect_id.ptr)
458 {
459 message->add_notify(message, FALSE, ME_CONNECTID, connect_id);
460 }
461 }
462 #endif /* ME */
463
464 return NEED_MORE;
465 }
466
467 METHOD(task_t, process_r, status_t,
468 private_ike_init_t *this, message_t *message)
469 {
470 nonce_gen_t *nonceg;
471
472 this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
473 DBG0(DBG_IKE, "%H is initiating an IKE_SA", message->get_source(message));
474 this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
475
476 if (!this->nonceg->allocate_nonce(this->nonceg, NONCE_SIZE, &this->my_nonce))
477 {
478 DBG1(DBG_IKE, "nonce allocation failed");
479 return FAILED;
480 }
481
482 #ifdef ME
483 {
484 notify_payload_t *notify = message->get_notify(message, ME_CONNECTID);
485 if (notify)
486 {
487 chunk_t connect_id = notify->get_notification_data(notify);
488 DBG2(DBG_IKE, "received ME_CONNECTID %#B", &connect_id);
489 charon->connect_manager->stop_checks(charon->connect_manager,
490 connect_id);
491 }
492 }
493 #endif /* ME */
494
495 process_payloads(this, message);
496
497 return NEED_MORE;
498 }
499
500 /**
501 * Derive the keymat for the IKE_SA
502 */
503 static bool derive_keys(private_ike_init_t *this,
504 chunk_t nonce_i, chunk_t nonce_r)
505 {
506 keymat_v2_t *old_keymat;
507 pseudo_random_function_t prf_alg = PRF_UNDEFINED;
508 chunk_t skd = chunk_empty;
509 ike_sa_id_t *id;
510
511 id = this->ike_sa->get_id(this->ike_sa);
512 if (this->old_sa)
513 {
514 /* rekeying: Include old SKd, use old PRF, apply SPI */
515 old_keymat = (keymat_v2_t*)this->old_sa->get_keymat(this->old_sa);
516 prf_alg = old_keymat->get_skd(old_keymat, &skd);
517 if (this->initiator)
518 {
519 id->set_responder_spi(id, this->proposal->get_spi(this->proposal));
520 }
521 else
522 {
523 id->set_initiator_spi(id, this->proposal->get_spi(this->proposal));
524 }
525 }
526 if (!this->keymat->derive_ike_keys(this->keymat, this->proposal, this->dh,
527 nonce_i, nonce_r, id, prf_alg, skd))
528 {
529 return FALSE;
530 }
531 charon->bus->ike_keys(charon->bus, this->ike_sa, this->dh, chunk_empty,
532 nonce_i, nonce_r, this->old_sa, NULL);
533 return TRUE;
534 }
535
536 METHOD(task_t, build_r, status_t,
537 private_ike_init_t *this, message_t *message)
538 {
539 /* check if we have everything we need */
540 if (this->proposal == NULL ||
541 this->other_nonce.len == 0 || this->my_nonce.len == 0)
542 {
543 DBG1(DBG_IKE, "received proposals inacceptable");
544 message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
545 return FAILED;
546 }
547 this->ike_sa->set_proposal(this->ike_sa, this->proposal);
548
549 if (this->dh == NULL ||
550 !this->proposal->has_dh_group(this->proposal, this->dh_group))
551 {
552 u_int16_t group;
553
554 if (this->proposal->get_algorithm(this->proposal, DIFFIE_HELLMAN_GROUP,
555 &group, NULL))
556 {
557 DBG1(DBG_IKE, "DH group %N inacceptable, requesting %N",
558 diffie_hellman_group_names, this->dh_group,
559 diffie_hellman_group_names, group);
560 this->dh_group = group;
561 group = htons(group);
562 message->add_notify(message, FALSE, INVALID_KE_PAYLOAD,
563 chunk_from_thing(group));
564 }
565 else
566 {
567 DBG1(DBG_IKE, "no acceptable proposal found");
568 }
569 return FAILED;
570 }
571
572 if (this->dh_failed)
573 {
574 DBG1(DBG_IKE, "applying DH public value failed");
575 message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
576 return FAILED;
577 }
578
579 if (!derive_keys(this, this->other_nonce, this->my_nonce))
580 {
581 DBG1(DBG_IKE, "key derivation failed");
582 message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
583 return FAILED;
584 }
585 if (!build_payloads(this, message))
586 {
587 message->add_notify(message, TRUE, NO_PROPOSAL_CHOSEN, chunk_empty);
588 return FAILED;
589 }
590 return SUCCESS;
591 }
592
593 /**
594 * Raise alerts for received notify errors
595 */
596 static void raise_alerts(private_ike_init_t *this, notify_type_t type)
597 {
598 linked_list_t *list;
599
600 switch (type)
601 {
602 case NO_PROPOSAL_CHOSEN:
603 list = this->config->get_proposals(this->config);
604 charon->bus->alert(charon->bus, ALERT_PROPOSAL_MISMATCH_IKE, list);
605 list->destroy_offset(list, offsetof(proposal_t, destroy));
606 break;
607 default:
608 break;
609 }
610 }
611
612 METHOD(task_t, process_i, status_t,
613 private_ike_init_t *this, message_t *message)
614 {
615 enumerator_t *enumerator;
616 payload_t *payload;
617
618 /* check for erroneous notifies */
619 enumerator = message->create_payload_enumerator(message);
620 while (enumerator->enumerate(enumerator, &payload))
621 {
622 if (payload->get_type(payload) == PLV2_NOTIFY)
623 {
624 notify_payload_t *notify = (notify_payload_t*)payload;
625 notify_type_t type = notify->get_notify_type(notify);
626
627 switch (type)
628 {
629 case INVALID_KE_PAYLOAD:
630 {
631 chunk_t data;
632 diffie_hellman_group_t bad_group;
633
634 bad_group = this->dh_group;
635 data = notify->get_notification_data(notify);
636 this->dh_group = ntohs(*((u_int16_t*)data.ptr));
637 DBG1(DBG_IKE, "peer didn't accept DH group %N, "
638 "it requested %N", diffie_hellman_group_names,
639 bad_group, diffie_hellman_group_names, this->dh_group);
640
641 if (this->old_sa == NULL)
642 { /* reset the IKE_SA if we are not rekeying */
643 this->ike_sa->reset(this->ike_sa);
644 }
645
646 enumerator->destroy(enumerator);
647 this->retry++;
648 return NEED_MORE;
649 }
650 case NAT_DETECTION_SOURCE_IP:
651 case NAT_DETECTION_DESTINATION_IP:
652 /* skip, handled in ike_natd_t */
653 break;
654 case MULTIPLE_AUTH_SUPPORTED:
655 /* handled in ike_auth_t */
656 break;
657 case COOKIE:
658 {
659 chunk_free(&this->cookie);
660 this->cookie = chunk_clone(notify->get_notification_data(notify));
661 this->ike_sa->reset(this->ike_sa);
662 enumerator->destroy(enumerator);
663 DBG2(DBG_IKE, "received %N notify", notify_type_names, type);
664 this->retry++;
665 return NEED_MORE;
666 }
667 default:
668 {
669 if (type <= 16383)
670 {
671 DBG1(DBG_IKE, "received %N notify error",
672 notify_type_names, type);
673 enumerator->destroy(enumerator);
674 raise_alerts(this, type);
675 return FAILED;
676 }
677 DBG2(DBG_IKE, "received %N notify",
678 notify_type_names, type);
679 break;
680 }
681 }
682 }
683 }
684 enumerator->destroy(enumerator);
685
686 process_payloads(this, message);
687
688 /* check if we have everything */
689 if (this->proposal == NULL ||
690 this->other_nonce.len == 0 || this->my_nonce.len == 0)
691 {
692 DBG1(DBG_IKE, "peers proposal selection invalid");
693 return FAILED;
694 }
695 this->ike_sa->set_proposal(this->ike_sa, this->proposal);
696
697 if (this->dh == NULL ||
698 !this->proposal->has_dh_group(this->proposal, this->dh_group))
699 {
700 DBG1(DBG_IKE, "peer DH group selection invalid");
701 return FAILED;
702 }
703
704 if (this->dh_failed)
705 {
706 DBG1(DBG_IKE, "applying DH public value failed");
707 return FAILED;
708 }
709
710 if (!derive_keys(this, this->my_nonce, this->other_nonce))
711 {
712 DBG1(DBG_IKE, "key derivation failed");
713 return FAILED;
714 }
715 return SUCCESS;
716 }
717
718 METHOD(task_t, get_type, task_type_t,
719 private_ike_init_t *this)
720 {
721 return TASK_IKE_INIT;
722 }
723
724 METHOD(task_t, migrate, void,
725 private_ike_init_t *this, ike_sa_t *ike_sa)
726 {
727 DESTROY_IF(this->proposal);
728 chunk_free(&this->other_nonce);
729
730 this->ike_sa = ike_sa;
731 this->keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa);
732 this->proposal = NULL;
733 this->dh_failed = FALSE;
734 if (this->dh && this->dh->get_dh_group(this->dh) != this->dh_group)
735 { /* reset DH value only if group changed (INVALID_KE_PAYLOAD) */
736 this->dh->destroy(this->dh);
737 this->dh = this->keymat->keymat.create_dh(&this->keymat->keymat,
738 this->dh_group);
739 }
740 }
741
742 METHOD(task_t, destroy, void,
743 private_ike_init_t *this)
744 {
745 DESTROY_IF(this->dh);
746 DESTROY_IF(this->proposal);
747 DESTROY_IF(this->nonceg);
748 chunk_free(&this->my_nonce);
749 chunk_free(&this->other_nonce);
750 chunk_free(&this->cookie);
751 free(this);
752 }
753
754 METHOD(ike_init_t, get_lower_nonce, chunk_t,
755 private_ike_init_t *this)
756 {
757 if (memcmp(this->my_nonce.ptr, this->other_nonce.ptr,
758 min(this->my_nonce.len, this->other_nonce.len)) < 0)
759 {
760 return this->my_nonce;
761 }
762 else
763 {
764 return this->other_nonce;
765 }
766 }
767
768 /*
769 * Described in header.
770 */
771 ike_init_t *ike_init_create(ike_sa_t *ike_sa, bool initiator, ike_sa_t *old_sa)
772 {
773 private_ike_init_t *this;
774
775 INIT(this,
776 .public = {
777 .task = {
778 .get_type = _get_type,
779 .migrate = _migrate,
780 .destroy = _destroy,
781 },
782 .get_lower_nonce = _get_lower_nonce,
783 },
784 .ike_sa = ike_sa,
785 .initiator = initiator,
786 .dh_group = MODP_NONE,
787 .keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa),
788 .old_sa = old_sa,
789 .signature_authentication = lib->settings->get_bool(lib->settings,
790 "%s.signature_authentication", TRUE, lib->ns),
791 );
792
793 this->nonceg = this->keymat->keymat.create_nonce_gen(&this->keymat->keymat);
794 if (!this->nonceg)
795 {
796 DBG1(DBG_IKE, "no nonce generator found to create nonce");
797 free(this);
798 return FAILED;
799 }
800
801 if (initiator)
802 {
803 this->public.task.build = _build_i;
804 this->public.task.process = _process_i;
805 }
806 else
807 {
808 this->public.task.build = _build_r;
809 this->public.task.process = _process_r;
810 }
811
812 return &this->public;
813 }