2 * Copyright (C) 2011-2012 Tobias Brunner
3 * HSR Hochschule fuer Technik Rapperswil
5 * Copyright (C) 2011 Martin Willi
6 * Copyright (C) 2011 revosec AG
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 #include "main_mode.h"
24 #include <sa/ikev1/phase1.h>
25 #include <encoding/payloads/sa_payload.h>
26 #include <encoding/payloads/id_payload.h>
27 #include <encoding/payloads/hash_payload.h>
28 #include <sa/ikev1/tasks/xauth.h>
29 #include <sa/ikev1/tasks/mode_config.h>
30 #include <sa/ikev1/tasks/informational.h>
31 #include <sa/ikev1/tasks/isakmp_delete.h>
32 #include <processing/jobs/adopt_children_job.h>
33 #include <processing/jobs/delete_ike_sa_job.h>
35 typedef struct private_main_mode_t private_main_mode_t
;
38 * Private members of a main_mode_t task.
40 struct private_main_mode_t
{
43 * Public methods and task_t interface.
53 * Are we the initiator?
58 * Common phase 1 helper class
63 * IKE config to establish
73 * selected IKE proposal
78 * Negotiated SA lifetime
83 * Negotiated authentication method
87 /** states of main mode */
97 * Set IKE_SA to established state
99 static bool establish(private_main_mode_t
*this)
101 if (!charon
->bus
->authorize(charon
->bus
, TRUE
))
103 DBG1(DBG_IKE
, "final authorization hook forbids IKE_SA, cancelling");
107 DBG0(DBG_IKE
, "IKE_SA %s[%d] established between %H[%Y]...%H[%Y]",
108 this->ike_sa
->get_name(this->ike_sa
),
109 this->ike_sa
->get_unique_id(this->ike_sa
),
110 this->ike_sa
->get_my_host(this->ike_sa
),
111 this->ike_sa
->get_my_id(this->ike_sa
),
112 this->ike_sa
->get_other_host(this->ike_sa
),
113 this->ike_sa
->get_other_id(this->ike_sa
));
115 this->ike_sa
->set_state(this->ike_sa
, IKE_ESTABLISHED
);
116 charon
->bus
->ike_updown(charon
->bus
, this->ike_sa
, TRUE
);
122 * Check for notify errors, return TRUE if error found
124 static bool has_notify_errors(private_main_mode_t
*this, message_t
*message
)
126 enumerator_t
*enumerator
;
130 enumerator
= message
->create_payload_enumerator(message
);
131 while (enumerator
->enumerate(enumerator
, &payload
))
133 if (payload
->get_type(payload
) == PLV1_NOTIFY
)
135 notify_payload_t
*notify
;
138 notify
= (notify_payload_t
*)payload
;
139 type
= notify
->get_notify_type(notify
);
142 DBG1(DBG_IKE
, "received %N error notify",
143 notify_type_names
, type
);
146 else if (type
== INITIAL_CONTACT_IKEV1
)
148 if (!this->initiator
&& this->state
== MM_AUTH
)
150 /* If authenticated and received INITIAL_CONTACT,
151 * delete any existing IKE_SAs with that peer.
152 * The delete takes place when the SA is checked in due
153 * to other id not known until the 3rd message.*/
154 this->ike_sa
->set_condition(this->ike_sa
,
155 COND_INIT_CONTACT_SEEN
, TRUE
);
160 DBG1(DBG_IKE
, "received %N notify", notify_type_names
, type
);
164 enumerator
->destroy(enumerator
);
170 * Queue a task sending a notify in an INFORMATIONAL exchange
172 static status_t
send_notify(private_main_mode_t
*this, notify_type_t type
)
174 notify_payload_t
*notify
;
175 ike_sa_id_t
*ike_sa_id
;
176 uint64_t spi_i
, spi_r
;
179 notify
= notify_payload_create_from_protocol_and_type(PLV1_NOTIFY
,
181 ike_sa_id
= this->ike_sa
->get_id(this->ike_sa
);
182 spi_i
= ike_sa_id
->get_initiator_spi(ike_sa_id
);
183 spi_r
= ike_sa_id
->get_responder_spi(ike_sa_id
);
184 spi
= chunk_cata("cc", chunk_from_thing(spi_i
), chunk_from_thing(spi_r
));
185 notify
->set_spi_data(notify
, spi
);
187 this->ike_sa
->queue_task(this->ike_sa
,
188 (task_t
*)informational_create(this->ike_sa
, notify
));
189 /* cancel all active/passive tasks in favour of informational */
190 this->ike_sa
->flush_queue(this->ike_sa
,
191 this->initiator
? TASK_QUEUE_ACTIVE
: TASK_QUEUE_PASSIVE
);
196 * Queue a delete task if authentication failed as initiator
198 static status_t
send_delete(private_main_mode_t
*this)
200 this->ike_sa
->queue_task(this->ike_sa
,
201 (task_t
*)isakmp_delete_create(this->ike_sa
, TRUE
));
202 /* cancel all active tasks in favour of informational */
203 this->ike_sa
->flush_queue(this->ike_sa
,
204 this->initiator
? TASK_QUEUE_ACTIVE
: TASK_QUEUE_PASSIVE
);
209 * Add an INITIAL_CONTACT notify if first contact with peer
211 static void add_initial_contact(private_main_mode_t
*this, message_t
*message
,
212 identification_t
*idi
)
214 identification_t
*idr
;
216 notify_payload_t
*notify
;
217 ike_sa_id_t
*ike_sa_id
;
218 uint64_t spi_i
, spi_r
;
221 idr
= this->ph1
->get_id(this->ph1
, this->peer_cfg
, FALSE
);
222 if (idr
&& !idr
->contains_wildcards(idr
))
224 if (this->peer_cfg
->get_unique_policy(this->peer_cfg
) != UNIQUE_NEVER
)
226 host
= this->ike_sa
->get_other_host(this->ike_sa
);
227 if (!charon
->ike_sa_manager
->has_contact(charon
->ike_sa_manager
,
228 idi
, idr
, host
->get_family(host
)))
230 notify
= notify_payload_create_from_protocol_and_type(
231 PLV1_NOTIFY
, PROTO_IKE
, INITIAL_CONTACT_IKEV1
);
232 ike_sa_id
= this->ike_sa
->get_id(this->ike_sa
);
233 spi_i
= ike_sa_id
->get_initiator_spi(ike_sa_id
);
234 spi_r
= ike_sa_id
->get_responder_spi(ike_sa_id
);
235 spi
= chunk_cata("cc", chunk_from_thing(spi_i
),
236 chunk_from_thing(spi_r
));
237 notify
->set_spi_data(notify
, spi
);
238 message
->add_payload(message
, (payload_t
*)notify
);
244 METHOD(task_t
, build_i
, status_t
,
245 private_main_mode_t
*this, message_t
*message
)
251 sa_payload_t
*sa_payload
;
252 linked_list_t
*proposals
;
255 DBG0(DBG_IKE
, "initiating Main Mode IKE_SA %s[%d] to %H",
256 this->ike_sa
->get_name(this->ike_sa
),
257 this->ike_sa
->get_unique_id(this->ike_sa
),
258 this->ike_sa
->get_other_host(this->ike_sa
));
259 this->ike_sa
->set_state(this->ike_sa
, IKE_CONNECTING
);
261 this->ike_cfg
= this->ike_sa
->get_ike_cfg(this->ike_sa
);
262 this->peer_cfg
= this->ike_sa
->get_peer_cfg(this->ike_sa
);
263 this->peer_cfg
->get_ref(this->peer_cfg
);
265 this->method
= this->ph1
->get_auth_method(this->ph1
, this->peer_cfg
);
266 if (this->method
== AUTH_NONE
)
268 DBG1(DBG_CFG
, "configuration uses unsupported authentication");
271 this->lifetime
= this->peer_cfg
->get_reauth_time(this->peer_cfg
,
274 { /* fall back to rekey time of no rekey time configured */
275 this->lifetime
= this->peer_cfg
->get_rekey_time(this->peer_cfg
,
278 this->lifetime
+= this->peer_cfg
->get_over_time(this->peer_cfg
);
279 proposals
= this->ike_cfg
->get_proposals(this->ike_cfg
);
280 sa_payload
= sa_payload_create_from_proposals_v1(proposals
,
281 this->lifetime
, 0, this->method
, MODE_NONE
,
283 proposals
->destroy_offset(proposals
, offsetof(proposal_t
, destroy
));
285 message
->add_payload(message
, &sa_payload
->payload_interface
);
287 /* pregenerate message to store SA payload */
288 if (this->ike_sa
->generate_message(this->ike_sa
, message
,
291 DBG1(DBG_IKE
, "pregenerating SA payload failed");
294 packet
->destroy(packet
);
295 if (!this->ph1
->save_sa_payload(this->ph1
, message
))
307 if (!this->ph1
->create_hasher(this->ph1
))
309 return send_notify(this, NO_PROPOSAL_CHOSEN
);
311 if (!this->proposal
->get_algorithm(this->proposal
,
312 DIFFIE_HELLMAN_GROUP
, &group
, NULL
))
314 DBG1(DBG_IKE
, "DH group selection failed");
315 return send_notify(this, NO_PROPOSAL_CHOSEN
);
317 if (!this->ph1
->create_dh(this->ph1
, group
))
319 DBG1(DBG_IKE
, "negotiated DH group not supported");
320 return send_notify(this, INVALID_KEY_INFORMATION
);
322 if (!this->ph1
->add_nonce_ke(this->ph1
, message
))
324 return send_notify(this, INVALID_KEY_INFORMATION
);
331 id_payload_t
*id_payload
;
332 identification_t
*id
;
334 id
= this->ph1
->get_id(this->ph1
, this->peer_cfg
, TRUE
);
335 this->ike_sa
->set_my_id(this->ike_sa
, id
->clone(id
));
336 id_payload
= id_payload_create_from_identification(PLV1_ID
, id
);
337 message
->add_payload(message
, &id_payload
->payload_interface
);
339 if (!this->ph1
->build_auth(this->ph1
, this->method
, message
,
340 id_payload
->get_encoded(id_payload
)))
342 charon
->bus
->alert(charon
->bus
, ALERT_LOCAL_AUTH_FAILED
);
343 return send_notify(this, AUTHENTICATION_FAILED
);
346 add_initial_contact(this, message
, id
);
348 this->state
= MM_AUTH
;
356 METHOD(task_t
, process_r
, status_t
,
357 private_main_mode_t
*this, message_t
*message
)
364 sa_payload_t
*sa_payload
;
365 proposal_selection_flag_t flags
= 0;
367 this->ike_cfg
= this->ike_sa
->get_ike_cfg(this->ike_sa
);
368 DBG0(DBG_IKE
, "%H is initiating a Main Mode IKE_SA",
369 message
->get_source(message
));
370 this->ike_sa
->set_state(this->ike_sa
, IKE_CONNECTING
);
372 this->ike_sa
->update_hosts(this->ike_sa
,
373 message
->get_destination(message
),
374 message
->get_source(message
), TRUE
);
376 sa_payload
= (sa_payload_t
*)message
->get_payload(message
,
377 PLV1_SECURITY_ASSOCIATION
);
380 DBG1(DBG_IKE
, "SA payload missing");
381 return send_notify(this, INVALID_PAYLOAD_TYPE
);
383 if (!this->ph1
->save_sa_payload(this->ph1
, message
))
385 return send_notify(this, INVALID_PAYLOAD_TYPE
);
388 list
= sa_payload
->get_proposals(sa_payload
);
389 if (!this->ike_sa
->supports_extension(this->ike_sa
, EXT_STRONGSWAN
)
390 && !lib
->settings
->get_bool(lib
->settings
,
391 "%s.accept_private_algs", FALSE
, lib
->ns
))
393 flags
|= PROPOSAL_SKIP_PRIVATE
;
395 if (!lib
->settings
->get_bool(lib
->settings
,
396 "%s.prefer_configured_proposals", TRUE
, lib
->ns
))
398 flags
|= PROPOSAL_PREFER_SUPPLIED
;
400 this->proposal
= this->ike_cfg
->select_proposal(this->ike_cfg
,
402 list
->destroy_offset(list
, offsetof(proposal_t
, destroy
));
405 DBG1(DBG_IKE
, "no proposal found");
406 return send_notify(this, NO_PROPOSAL_CHOSEN
);
408 this->ike_sa
->set_proposal(this->ike_sa
, this->proposal
);
410 this->method
= sa_payload
->get_auth_method(sa_payload
);
411 this->lifetime
= sa_payload
->get_lifetime(sa_payload
,
421 if (!this->ph1
->create_hasher(this->ph1
))
423 return send_notify(this, INVALID_KEY_INFORMATION
);
425 if (!this->proposal
->get_algorithm(this->proposal
,
426 DIFFIE_HELLMAN_GROUP
, &group
, NULL
))
428 DBG1(DBG_IKE
, "DH group selection failed");
429 return send_notify(this, INVALID_KEY_INFORMATION
);
431 if (!this->ph1
->create_dh(this->ph1
, group
))
433 DBG1(DBG_IKE
, "negotiated DH group not supported");
434 return send_notify(this, INVALID_KEY_INFORMATION
);
436 if (!this->ph1
->get_nonce_ke(this->ph1
, message
))
438 return send_notify(this, INVALID_PAYLOAD_TYPE
);
445 id_payload_t
*id_payload
;
446 identification_t
*id
;
448 id_payload
= (id_payload_t
*)message
->get_payload(message
, PLV1_ID
);
451 DBG1(DBG_IKE
, "IDii payload missing");
452 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
453 return send_notify(this, INVALID_PAYLOAD_TYPE
);
455 id
= id_payload
->get_identification(id_payload
);
456 this->ike_sa
->set_other_id(this->ike_sa
, id
);
460 DESTROY_IF(this->peer_cfg
);
461 this->peer_cfg
= this->ph1
->select_config(this->ph1
,
462 this->method
, FALSE
, id
);
465 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
466 return send_notify(this, AUTHENTICATION_FAILED
);
468 this->ike_sa
->set_peer_cfg(this->ike_sa
, this->peer_cfg
);
470 if (this->ph1
->verify_auth(this->ph1
, this->method
, message
,
471 id_payload
->get_encoded(id_payload
)))
477 if (!charon
->bus
->authorize(charon
->bus
, FALSE
))
479 DBG1(DBG_IKE
, "Main Mode authorization hook forbids IKE_SA, "
481 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
482 return send_notify(this, AUTHENTICATION_FAILED
);
485 this->state
= MM_AUTH
;
486 if (has_notify_errors(this, message
))
497 METHOD(task_t
, build_r
, status_t
,
498 private_main_mode_t
*this, message_t
*message
)
504 sa_payload_t
*sa_payload
;
506 sa_payload
= sa_payload_create_from_proposal_v1(this->proposal
,
507 this->lifetime
, 0, this->method
, MODE_NONE
,
509 message
->add_payload(message
, &sa_payload
->payload_interface
);
515 if (!this->ph1
->add_nonce_ke(this->ph1
, message
))
517 return send_notify(this, INVALID_KEY_INFORMATION
);
519 if (!this->ph1
->derive_keys(this->ph1
, this->peer_cfg
, this->method
))
521 return send_notify(this, INVALID_KEY_INFORMATION
);
527 id_payload_t
*id_payload
;
528 identification_t
*id
;
529 adopt_children_job_t
*job
= NULL
;
530 xauth_t
*xauth
= NULL
;
532 id
= this->ph1
->get_id(this->ph1
, this->peer_cfg
, TRUE
);
533 this->ike_sa
->set_my_id(this->ike_sa
, id
->clone(id
));
535 id_payload
= id_payload_create_from_identification(PLV1_ID
, id
);
536 message
->add_payload(message
, &id_payload
->payload_interface
);
538 if (!this->ph1
->build_auth(this->ph1
, this->method
, message
,
539 id_payload
->get_encoded(id_payload
)))
541 charon
->bus
->alert(charon
->bus
, ALERT_LOCAL_AUTH_FAILED
);
542 return send_notify(this, AUTHENTICATION_FAILED
);
545 switch (this->method
)
547 case AUTH_XAUTH_INIT_PSK
:
548 case AUTH_XAUTH_INIT_RSA
:
549 case AUTH_HYBRID_INIT_RSA
:
550 xauth
= xauth_create(this->ike_sa
, TRUE
);
551 this->ike_sa
->queue_task(this->ike_sa
, (task_t
*)xauth
);
553 case AUTH_XAUTH_RESP_PSK
:
554 case AUTH_XAUTH_RESP_RSA
:
555 case AUTH_HYBRID_RESP_RSA
:
556 /* wait for XAUTH request */
559 if (charon
->ike_sa_manager
->check_uniqueness(
560 charon
->ike_sa_manager
, this->ike_sa
, FALSE
))
562 DBG1(DBG_IKE
, "cancelling Main Mode due to uniqueness "
564 return send_notify(this, AUTHENTICATION_FAILED
);
566 if (!establish(this))
568 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
569 return send_notify(this, AUTHENTICATION_FAILED
);
571 job
= adopt_children_job_create(
572 this->ike_sa
->get_id(this->ike_sa
));
575 if (this->ph1
->has_virtual_ip(this->ph1
, this->peer_cfg
))
577 if (this->peer_cfg
->use_pull_mode(this->peer_cfg
))
579 this->ike_sa
->queue_task(this->ike_sa
,
580 (task_t
*)mode_config_create(this->ike_sa
, TRUE
, TRUE
));
583 else if (this->ph1
->has_pool(this->ph1
, this->peer_cfg
))
585 if (!this->peer_cfg
->use_pull_mode(this->peer_cfg
))
589 job
->queue_task(job
, (task_t
*)
590 mode_config_create(this->ike_sa
, TRUE
, FALSE
));
594 xauth
->queue_mode_config_push(xauth
);
598 this->ike_sa
->queue_task(this->ike_sa
, (task_t
*)
599 mode_config_create(this->ike_sa
, TRUE
, FALSE
));
605 lib
->processor
->queue_job(lib
->processor
, (job_t
*)job
);
615 * Schedule a timeout for the IKE_SA should it not establish
617 static void schedule_timeout(ike_sa_t
*ike_sa
)
621 job
= (job_t
*)delete_ike_sa_job_create(ike_sa
->get_id(ike_sa
), FALSE
);
622 lib
->scheduler
->schedule_job(lib
->scheduler
, job
, HALF_OPEN_IKE_SA_TIMEOUT
);
625 METHOD(task_t
, process_i
, status_t
,
626 private_main_mode_t
*this, message_t
*message
)
633 sa_payload_t
*sa_payload
;
634 auth_method_t method
;
635 proposal_selection_flag_t flags
= 0;
638 sa_payload
= (sa_payload_t
*)message
->get_payload(message
,
639 PLV1_SECURITY_ASSOCIATION
);
642 DBG1(DBG_IKE
, "SA payload missing");
643 return send_notify(this, INVALID_PAYLOAD_TYPE
);
645 list
= sa_payload
->get_proposals(sa_payload
);
646 if (!this->ike_sa
->supports_extension(this->ike_sa
, EXT_STRONGSWAN
)
647 && !lib
->settings
->get_bool(lib
->settings
,
648 "%s.accept_private_algs", FALSE
, lib
->ns
))
650 flags
|= PROPOSAL_SKIP_PRIVATE
;
652 this->proposal
= this->ike_cfg
->select_proposal(this->ike_cfg
,
654 list
->destroy_offset(list
, offsetof(proposal_t
, destroy
));
657 DBG1(DBG_IKE
, "no proposal found");
658 return send_notify(this, NO_PROPOSAL_CHOSEN
);
660 this->ike_sa
->set_proposal(this->ike_sa
, this->proposal
);
662 lifetime
= sa_payload
->get_lifetime(sa_payload
, this->proposal
);
663 if (lifetime
!= this->lifetime
)
665 DBG1(DBG_IKE
, "received lifetime %us does not match configured "
666 "lifetime %us", lifetime
, this->lifetime
);
668 this->lifetime
= lifetime
;
669 method
= sa_payload
->get_auth_method(sa_payload
);
670 if (method
!= this->method
)
672 DBG1(DBG_IKE
, "received %N authentication, but configured %N, "
673 "continue with configured", auth_method_names
, method
,
674 auth_method_names
, this->method
);
680 if (!this->ph1
->get_nonce_ke(this->ph1
, message
))
682 return send_notify(this, INVALID_PAYLOAD_TYPE
);
684 if (!this->ph1
->derive_keys(this->ph1
, this->peer_cfg
, this->method
))
686 return send_notify(this, INVALID_KEY_INFORMATION
);
692 id_payload_t
*id_payload
;
693 identification_t
*id
, *cid
;
695 id_payload
= (id_payload_t
*)message
->get_payload(message
, PLV1_ID
);
698 DBG1(DBG_IKE
, "IDir payload missing");
699 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
700 return send_delete(this);
702 id
= id_payload
->get_identification(id_payload
);
703 cid
= this->ph1
->get_id(this->ph1
, this->peer_cfg
, FALSE
);
704 if (cid
&& !id
->matches(id
, cid
))
706 DBG1(DBG_IKE
, "IDir '%Y' does not match to '%Y'", id
, cid
);
708 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
709 return send_delete(this);
711 this->ike_sa
->set_other_id(this->ike_sa
, id
);
713 if (!this->ph1
->verify_auth(this->ph1
, this->method
, message
,
714 id_payload
->get_encoded(id_payload
)))
716 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
717 return send_delete(this);
719 if (!charon
->bus
->authorize(charon
->bus
, FALSE
))
721 DBG1(DBG_IKE
, "Main Mode authorization hook forbids IKE_SA, "
723 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
724 return send_delete(this);
727 switch (this->method
)
729 case AUTH_XAUTH_INIT_PSK
:
730 case AUTH_XAUTH_INIT_RSA
:
731 case AUTH_HYBRID_INIT_RSA
:
732 /* wait for XAUTH request */
733 schedule_timeout(this->ike_sa
);
735 case AUTH_XAUTH_RESP_PSK
:
736 case AUTH_XAUTH_RESP_RSA
:
737 case AUTH_HYBRID_RESP_RSA
:
738 this->ike_sa
->queue_task(this->ike_sa
,
739 (task_t
*)xauth_create(this->ike_sa
, TRUE
));
742 if (charon
->ike_sa_manager
->check_uniqueness(
743 charon
->ike_sa_manager
, this->ike_sa
, FALSE
))
745 DBG1(DBG_IKE
, "cancelling Main Mode due to uniqueness "
747 return send_delete(this);
749 if (!establish(this))
751 charon
->bus
->alert(charon
->bus
, ALERT_PEER_AUTH_FAILED
);
752 return send_delete(this);
756 /* check for and prepare mode config push/pull */
757 if (this->ph1
->has_virtual_ip(this->ph1
, this->peer_cfg
))
759 if (this->peer_cfg
->use_pull_mode(this->peer_cfg
))
761 this->ike_sa
->queue_task(this->ike_sa
,
762 (task_t
*)mode_config_create(this->ike_sa
, TRUE
, TRUE
));
766 schedule_timeout(this->ike_sa
);
769 else if (this->ph1
->has_pool(this->ph1
, this->peer_cfg
))
771 if (this->peer_cfg
->use_pull_mode(this->peer_cfg
))
773 schedule_timeout(this->ike_sa
);
777 this->ike_sa
->queue_task(this->ike_sa
,
778 (task_t
*)mode_config_create(this->ike_sa
, TRUE
, FALSE
));
788 METHOD(task_t
, get_type
, task_type_t
,
789 private_main_mode_t
*this)
791 return TASK_MAIN_MODE
;
794 METHOD(task_t
, migrate
, void,
795 private_main_mode_t
*this, ike_sa_t
*ike_sa
)
797 DESTROY_IF(this->peer_cfg
);
798 DESTROY_IF(this->proposal
);
799 this->ph1
->destroy(this->ph1
);
801 this->ike_sa
= ike_sa
;
802 this->state
= MM_INIT
;
803 this->peer_cfg
= NULL
;
804 this->proposal
= NULL
;
805 this->ph1
= phase1_create(ike_sa
, this->initiator
);
808 METHOD(task_t
, destroy
, void,
809 private_main_mode_t
*this)
811 DESTROY_IF(this->peer_cfg
);
812 DESTROY_IF(this->proposal
);
813 this->ph1
->destroy(this->ph1
);
818 * Described in header.
820 main_mode_t
*main_mode_create(ike_sa_t
*ike_sa
, bool initiator
)
822 private_main_mode_t
*this;
827 .get_type
= _get_type
,
833 .ph1
= phase1_create(ike_sa
, initiator
),
834 .initiator
= initiator
,
840 this->public.task
.build
= _build_i
;
841 this->public.task
.process
= _process_i
;
845 this->public.task
.build
= _build_r
;
846 this->public.task
.process
= _process_r
;
849 return &this->public;