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