2 * Copyright (C) 2006-2008 Tobias Brunner
3 * Copyright (C) 2006 Daniel Roethlisberger
4 * Copyright (C) 2005-2006 Martin Willi
5 * Copyright (C) 2005 Jan Hutter
6 * Hochschule fuer Technik Rapperswil
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
31 #include <utils/linked_list.h>
32 #include <utils/lexparser.h>
33 #include <crypto/diffie_hellman.h>
34 #include <crypto/prf_plus.h>
35 #include <crypto/crypters/crypter.h>
36 #include <crypto/hashers/hasher.h>
37 #include <encoding/payloads/sa_payload.h>
38 #include <encoding/payloads/nonce_payload.h>
39 #include <encoding/payloads/ke_payload.h>
40 #include <encoding/payloads/delete_payload.h>
41 #include <encoding/payloads/transform_substructure.h>
42 #include <encoding/payloads/transform_attribute.h>
43 #include <encoding/payloads/ts_payload.h>
44 #include <sa/task_manager.h>
45 #include <sa/tasks/ike_init.h>
46 #include <sa/tasks/ike_natd.h>
47 #include <sa/tasks/ike_mobike.h>
48 #include <sa/tasks/ike_auth.h>
49 #include <sa/tasks/ike_auth_lifetime.h>
50 #include <sa/tasks/ike_config.h>
51 #include <sa/tasks/ike_cert_pre.h>
52 #include <sa/tasks/ike_cert_post.h>
53 #include <sa/tasks/ike_rekey.h>
54 #include <sa/tasks/ike_reauth.h>
55 #include <sa/tasks/ike_delete.h>
56 #include <sa/tasks/ike_dpd.h>
57 #include <sa/tasks/child_create.h>
58 #include <sa/tasks/child_delete.h>
59 #include <sa/tasks/child_rekey.h>
60 #include <processing/jobs/retransmit_job.h>
61 #include <processing/jobs/delete_ike_sa_job.h>
62 #include <processing/jobs/send_dpd_job.h>
63 #include <processing/jobs/send_keepalive_job.h>
64 #include <processing/jobs/rekey_ike_sa_job.h>
67 #include <sa/tasks/ike_me.h>
68 #include <processing/jobs/initiate_mediation_job.h>
72 #define RESOLV_CONF "/etc/resolv.conf"
75 ENUM(ike_sa_state_names
, IKE_CREATED
, IKE_DESTROYING
,
84 typedef struct private_ike_sa_t private_ike_sa_t
;
87 * Private data of an ike_sa_t object.
89 struct private_ike_sa_t
{
97 * Identifier for the current IKE_SA.
99 ike_sa_id_t
*ike_sa_id
;
102 * unique numerical ID for this IKE_SA.
107 * Current state of the IKE_SA
109 ike_sa_state_t state
;
112 * IKE configuration used to set up this IKE_SA
117 * Peer and authentication information to establish IKE_SA.
119 peer_cfg_t
*peer_cfg
;
122 * associated authentication/authorization info for local peer
124 auth_info_t
*my_auth
;
127 * associated authentication/authorization info for remote peer
129 auth_info_t
*other_auth
;
132 * Juggles tasks to process messages
134 task_manager_t
*task_manager
;
137 * Address of local host
142 * Address of remote host
148 * Are we mediation server
150 bool is_mediation_server
;
153 * Server reflexive host
155 host_t
*server_reflexive_host
;
164 * Identification used for us
166 identification_t
*my_id
;
169 * Identification used for other
171 identification_t
*other_id
;
174 * EAP Identity exchange in EAP-Identity method
176 identification_t
*eap_identity
;;
179 * set of extensions the peer supports
181 ike_extension_t extensions
;
184 * set of condition flags currently enabled for this IKE_SA
186 ike_condition_t conditions
;
189 * Linked List containing the child sa's of the current IKE_SA.
191 linked_list_t
*child_sas
;
194 * String describing the selected IKE proposal
196 char *selected_proposal
;
199 * crypter for inbound traffic
201 crypter_t
*crypter_in
;
204 * crypter for outbound traffic
206 crypter_t
*crypter_out
;
209 * Signer for inbound traffic
214 * Signer for outbound traffic
216 signer_t
*signer_out
;
219 * Multi purpose prf, set key, use it, forget it
224 * Prf function for derivating keymat child SAs
229 * Key to build outging authentication data (SKp)
234 * Key to verify incoming authentication data (SKp)
239 * Virtual IP on local host, if any
241 host_t
*my_virtual_ip
;
244 * Virtual IP on remote host, if any
246 host_t
*other_virtual_ip
;
249 * List of DNS servers installed by us
251 linked_list_t
*dns_servers
;
254 * list of peers additional addresses, transmitted via MOBIKE
256 linked_list_t
*additional_addresses
;
259 * previously value of received DESTINATION_IP hash
261 chunk_t nat_detection_dest
;
264 * number pending UPDATE_SA_ADDRESS (MOBIKE)
266 u_int32_t pending_updates
;
269 * NAT keep alive interval
271 u_int32_t keepalive_interval
;
274 * Timestamps for this IKE_SA
277 /** last IKE message received */
279 /** last IKE message sent */
281 /** when IKE_SA became established */
282 u_int32_t established
;
283 /** when IKE_SA gets rekeyed */
285 /** when IKE_SA gets reauthenticated */
287 /** when IKE_SA gets deleted */
292 * how many times we have retried so far (keyingtries)
297 * are we the initiator of this IKE_SA (rekeying does not affect this flag)
303 * get the time of the latest traffic processed by the kernel
305 static time_t get_use_time(private_ike_sa_t
* this, bool inbound
)
307 iterator_t
*iterator
;
308 child_sa_t
*child_sa
;
309 time_t latest
= 0, use_time
;
311 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
312 while (iterator
->iterate(iterator
, (void**)&child_sa
))
314 if (child_sa
->get_use_time(child_sa
, inbound
, &use_time
) == SUCCESS
)
316 latest
= max(latest
, use_time
);
319 iterator
->destroy(iterator
);
323 return max(this->time
.inbound
, latest
);
327 return max(this->time
.outbound
, latest
);
332 * Implementation of ike_sa_t.get_unique_id
334 static u_int32_t
get_unique_id(private_ike_sa_t
*this)
336 return this->unique_id
;
340 * Implementation of ike_sa_t.get_name.
342 static char *get_name(private_ike_sa_t
*this)
346 return this->peer_cfg
->get_name(this->peer_cfg
);
352 * Implementation of ike_sa_t.get_statistic.
354 static u_int32_t
get_statistic(private_ike_sa_t
*this, statistic_t kind
)
356 time_t now
= time(NULL
);
360 case STAT_REKEY_TIME
:
361 if (this->time
.rekey
> now
)
363 return this->time
.rekey
- now
;
366 case STAT_REAUTH_TIME
:
367 if (this->time
.reauth
> now
)
369 return this->time
.reauth
- now
;
379 * Implementation of ike_sa_t.get_my_host.
381 static host_t
*get_my_host(private_ike_sa_t
*this)
383 return this->my_host
;
387 * Implementation of ike_sa_t.set_my_host.
389 static void set_my_host(private_ike_sa_t
*this, host_t
*me
)
391 DESTROY_IF(this->my_host
);
396 * Implementation of ike_sa_t.get_other_host.
398 static host_t
*get_other_host(private_ike_sa_t
*this)
400 return this->other_host
;
404 * Implementation of ike_sa_t.set_other_host.
406 static void set_other_host(private_ike_sa_t
*this, host_t
*other
)
408 DESTROY_IF(this->other_host
);
409 this->other_host
= other
;
413 * Implementation of ike_sa_t.get_peer_cfg
415 static peer_cfg_t
* get_peer_cfg(private_ike_sa_t
*this)
417 return this->peer_cfg
;
421 * Implementation of ike_sa_t.set_peer_cfg
423 static void set_peer_cfg(private_ike_sa_t
*this, peer_cfg_t
*peer_cfg
)
425 DESTROY_IF(this->peer_cfg
);
426 peer_cfg
->get_ref(peer_cfg
);
427 this->peer_cfg
= peer_cfg
;
429 if (this->ike_cfg
== NULL
)
431 this->ike_cfg
= peer_cfg
->get_ike_cfg(peer_cfg
);
432 this->ike_cfg
->get_ref(this->ike_cfg
);
434 /* apply IDs if they are not already set */
435 if (this->my_id
->contains_wildcards(this->my_id
))
437 DESTROY_IF(this->my_id
);
438 this->my_id
= this->peer_cfg
->get_my_id(this->peer_cfg
);
439 this->my_id
= this->my_id
->clone(this->my_id
);
441 if (this->other_id
->contains_wildcards(this->other_id
))
443 DESTROY_IF(this->other_id
);
444 this->other_id
= this->peer_cfg
->get_other_id(this->peer_cfg
);
445 this->other_id
= this->other_id
->clone(this->other_id
);
450 * Implementation of ike_sa_t.get_my_auth.
452 static auth_info_t
* get_my_auth(private_ike_sa_t
*this)
454 return this->my_auth
;
458 * Implementation of ike_sa_t.get_other_auth.
460 static auth_info_t
* get_other_auth(private_ike_sa_t
*this)
462 return this->other_auth
;
466 * Implementation of ike_sa_t.send_keepalive
468 static void send_keepalive(private_ike_sa_t
*this)
470 send_keepalive_job_t
*job
;
471 time_t last_out
, now
, diff
;
473 if (!(this->conditions
& COND_NAT_HERE
) || this->keepalive_interval
== 0)
474 { /* disable keep alives if we are not NATed anymore */
478 last_out
= get_use_time(this, FALSE
);
481 diff
= now
- last_out
;
483 if (diff
>= this->keepalive_interval
)
488 packet
= packet_create();
489 packet
->set_source(packet
, this->my_host
->clone(this->my_host
));
490 packet
->set_destination(packet
, this->other_host
->clone(this->other_host
));
491 data
.ptr
= malloc(1);
494 packet
->set_data(packet
, data
);
495 DBG1(DBG_IKE
, "sending keep alive");
496 charon
->sender
->send(charon
->sender
, packet
);
499 job
= send_keepalive_job_create(this->ike_sa_id
);
500 charon
->scheduler
->schedule_job(charon
->scheduler
, (job_t
*)job
,
501 (this->keepalive_interval
- diff
) * 1000);
505 * Implementation of ike_sa_t.get_ike_cfg
507 static ike_cfg_t
*get_ike_cfg(private_ike_sa_t
*this)
509 return this->ike_cfg
;
513 * Implementation of ike_sa_t.set_ike_cfg
515 static void set_ike_cfg(private_ike_sa_t
*this, ike_cfg_t
*ike_cfg
)
517 ike_cfg
->get_ref(ike_cfg
);
518 this->ike_cfg
= ike_cfg
;
522 * Implementation of ike_sa_t.is_ike_initiator
524 static bool is_ike_initiator(private_ike_sa_t
*this)
526 return this->ike_initiator
;
530 * Implementation of ike_sa_t.enable_extension.
532 static void enable_extension(private_ike_sa_t
*this, ike_extension_t extension
)
534 this->extensions
|= extension
;
538 * Implementation of ike_sa_t.has_extension.
540 static bool supports_extension(private_ike_sa_t
*this, ike_extension_t extension
)
542 return (this->extensions
& extension
) != FALSE
;
546 * Implementation of ike_sa_t.has_condition.
548 static bool has_condition(private_ike_sa_t
*this, ike_condition_t condition
)
550 return (this->conditions
& condition
) != FALSE
;
554 * Implementation of ike_sa_t.enable_condition.
556 static void set_condition(private_ike_sa_t
*this, ike_condition_t condition
,
559 if (has_condition(this, condition
) != enable
)
563 this->conditions
|= condition
;
567 DBG1(DBG_IKE
, "local host is behind NAT, sending keep alives");
568 this->conditions
|= COND_NAT_ANY
;
569 send_keepalive(this);
572 DBG1(DBG_IKE
, "remote host is behind NAT");
573 this->conditions
|= COND_NAT_ANY
;
576 DBG1(DBG_IKE
, "faking NAT situation to enforce UDP encapsulation");
577 this->conditions
|= COND_NAT_ANY
;
585 this->conditions
&= ~condition
;
591 set_condition(this, COND_NAT_ANY
,
592 has_condition(this, COND_NAT_HERE
) ||
593 has_condition(this, COND_NAT_THERE
) ||
594 has_condition(this, COND_NAT_FAKE
));
604 * Implementation of ike_sa_t.send_dpd
606 static status_t
send_dpd(private_ike_sa_t
*this)
611 delay
= this->peer_cfg
->get_dpd(this->peer_cfg
);
619 if (this->task_manager
->busy(this->task_manager
))
621 /* an exchange is in the air, no need to start a DPD check */
626 /* check if there was any inbound traffic */
628 last_in
= get_use_time(this, TRUE
);
630 diff
= now
- last_in
;
633 /* to long ago, initiate dead peer detection */
635 ike_mobike_t
*mobike
;
637 if (supports_extension(this, EXT_MOBIKE
) &&
638 has_condition(this, COND_NAT_HERE
))
640 /* use mobike enabled DPD to detect NAT mapping changes */
641 mobike
= ike_mobike_create(&this->public, TRUE
);
643 task
= &mobike
->task
;
647 task
= (task_t
*)ike_dpd_create(TRUE
);
650 DBG1(DBG_IKE
, "sending DPD request");
652 this->task_manager
->queue_task(this->task_manager
, task
);
653 this->task_manager
->initiate(this->task_manager
);
656 /* recheck in "interval" seconds */
657 job
= send_dpd_job_create(this->ike_sa_id
);
658 charon
->scheduler
->schedule_job(charon
->scheduler
, (job_t
*)job
,
659 (delay
- diff
) * 1000);
664 * Implementation of ike_sa_t.get_state.
666 static ike_sa_state_t
get_state(private_ike_sa_t
*this)
672 * Implementation of ike_sa_t.set_state.
674 static void set_state(private_ike_sa_t
*this, ike_sa_state_t state
)
676 DBG2(DBG_IKE
, "IKE_SA %s[%d] state change: %N => %N",
677 get_name(this), this->unique_id
,
678 ike_sa_state_names
, this->state
,
679 ike_sa_state_names
, state
);
683 case IKE_ESTABLISHED
:
685 if (this->state
== IKE_CONNECTING
)
690 /* calculate rekey, reauth and lifetime */
691 this->time
.established
= time(NULL
);
693 /* schedule rekeying if we have a time which is smaller than
694 * an already scheduled rekeying */
695 t
= this->peer_cfg
->get_rekey_time(this->peer_cfg
);
696 if (t
&& (this->time
.rekey
== 0 ||
697 (this->time
.rekey
> t
+ this->time
.established
)))
699 this->time
.rekey
= t
+ this->time
.established
;
700 job
= (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, FALSE
);
701 charon
->scheduler
->schedule_job(charon
->scheduler
,
703 DBG1(DBG_IKE
, "scheduling rekeying in %ds", t
);
705 t
= this->peer_cfg
->get_reauth_time(this->peer_cfg
);
706 if (t
&& (this->time
.reauth
== 0 ||
707 (this->time
.reauth
> t
+ this->time
.established
)))
709 this->time
.reauth
= t
+ this->time
.established
;
710 job
= (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, TRUE
);
711 charon
->scheduler
->schedule_job(charon
->scheduler
,
713 DBG1(DBG_IKE
, "scheduling reauthentication in %ds", t
);
715 t
= this->peer_cfg
->get_over_time(this->peer_cfg
);
716 if (this->time
.rekey
|| this->time
.reauth
)
718 if (this->time
.reauth
== 0)
720 this->time
.delete = this->time
.rekey
;
722 else if (this->time
.rekey
== 0)
724 this->time
.delete = this->time
.reauth
;
728 this->time
.delete = min(this->time
.rekey
, this->time
.reauth
);
730 this->time
.delete += t
;
731 t
= this->time
.delete - this->time
.established
;
732 job
= (job_t
*)delete_ike_sa_job_create(this->ike_sa_id
, TRUE
);
733 charon
->scheduler
->schedule_job(charon
->scheduler
, job
,
735 DBG1(DBG_IKE
, "maximum IKE_SA lifetime %ds", t
);
738 /* start DPD checks */
745 /* delete may fail if a packet gets lost, so set a timeout */
746 job_t
*job
= (job_t
*)delete_ike_sa_job_create(this->ike_sa_id
, TRUE
);
747 charon
->scheduler
->schedule_job(charon
->scheduler
, job
,
748 HALF_OPEN_IKE_SA_TIMEOUT
);
754 charon
->bus
->ike_state_change(charon
->bus
, &this->public, state
);
759 * Implementation of ike_sa_t.reset
761 static void reset(private_ike_sa_t
*this)
763 /* the responder ID is reset, as peer may choose another one */
764 if (this->ike_sa_id
->is_initiator(this->ike_sa_id
))
766 this->ike_sa_id
->set_responder_spi(this->ike_sa_id
, 0);
769 set_state(this, IKE_CREATED
);
771 this->task_manager
->reset(this->task_manager
);
775 * Implementation of ike_sa_t.set_virtual_ip
777 static void set_virtual_ip(private_ike_sa_t
*this, bool local
, host_t
*ip
)
781 DBG1(DBG_IKE
, "installing new virtual IP %H", ip
);
782 if (charon
->kernel_interface
->add_ip(charon
->kernel_interface
, ip
,
783 this->my_host
) == SUCCESS
)
785 if (this->my_virtual_ip
)
787 DBG1(DBG_IKE
, "removing old virtual IP %H", this->my_virtual_ip
);
788 charon
->kernel_interface
->del_ip(charon
->kernel_interface
,
789 this->my_virtual_ip
);
791 DESTROY_IF(this->my_virtual_ip
);
792 this->my_virtual_ip
= ip
->clone(ip
);
796 DBG1(DBG_IKE
, "installing virtual IP %H failed", ip
);
797 this->my_virtual_ip
= NULL
;
802 DESTROY_IF(this->other_virtual_ip
);
803 this->other_virtual_ip
= ip
->clone(ip
);
808 * Implementation of ike_sa_t.get_virtual_ip
810 static host_t
* get_virtual_ip(private_ike_sa_t
*this, bool local
)
814 return this->my_virtual_ip
;
818 return this->other_virtual_ip
;
823 * Implementation of ike_sa_t.add_additional_address.
825 static void add_additional_address(private_ike_sa_t
*this, host_t
*host
)
827 this->additional_addresses
->insert_last(this->additional_addresses
, host
);
831 * Implementation of ike_sa_t.create_additional_address_iterator.
833 static iterator_t
* create_additional_address_iterator(private_ike_sa_t
*this)
835 return this->additional_addresses
->create_iterator(
836 this->additional_addresses
, TRUE
);
840 * Implementation of ike_sa_t.has_mapping_changed
842 static bool has_mapping_changed(private_ike_sa_t
*this, chunk_t hash
)
844 if (this->nat_detection_dest
.ptr
== NULL
)
846 this->nat_detection_dest
= chunk_clone(hash
);
849 if (chunk_equals(hash
, this->nat_detection_dest
))
853 free(this->nat_detection_dest
.ptr
);
854 this->nat_detection_dest
= chunk_clone(hash
);
859 * Implementation of ike_sa_t.set_pending_updates.
861 static void set_pending_updates(private_ike_sa_t
*this, u_int32_t updates
)
863 this->pending_updates
= updates
;
867 * Implementation of ike_sa_t.get_pending_updates.
869 static u_int32_t
get_pending_updates(private_ike_sa_t
*this)
871 return this->pending_updates
;
875 * Update hosts, as addresses may change (NAT)
877 static void update_hosts(private_ike_sa_t
*this, host_t
*me
, host_t
*other
)
887 other
= this->other_host
;
890 /* apply hosts on first received message */
891 if (this->my_host
->is_anyaddr(this->my_host
) ||
892 this->other_host
->is_anyaddr(this->other_host
))
894 set_my_host(this, me
->clone(me
));
895 set_other_host(this, other
->clone(other
));
900 /* update our address in any case */
901 if (!me
->equals(me
, this->my_host
))
903 set_my_host(this, me
->clone(me
));
907 if (!other
->equals(other
, this->other_host
))
909 /* update others adress if we are NOT NATed,
910 * and allow port changes if we are NATed */
911 if (!has_condition(this, COND_NAT_HERE
) ||
912 other
->ip_equals(other
, this->other_host
))
914 set_other_host(this, other
->clone(other
));
920 /* update all associated CHILD_SAs, if required */
923 iterator_t
*iterator
;
924 child_sa_t
*child_sa
;
926 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
927 while (iterator
->iterate(iterator
, (void**)&child_sa
))
929 child_sa
->update_hosts(child_sa
, this->my_host
, this->other_host
,
930 has_condition(this, COND_NAT_ANY
));
932 iterator
->destroy(iterator
);
937 * Implementation of ike_sa_t.generate
939 static status_t
generate_message(private_ike_sa_t
*this, message_t
*message
,
942 this->time
.outbound
= time(NULL
);
943 message
->set_ike_sa_id(message
, this->ike_sa_id
);
944 return message
->generate(message
, this->crypter_out
, this->signer_out
, packet
);
948 * send a notify back to the sender
950 static void send_notify_response(private_ike_sa_t
*this, message_t
*request
,
956 response
= message_create();
957 response
->set_exchange_type(response
, request
->get_exchange_type(request
));
958 response
->set_request(response
, FALSE
);
959 response
->set_message_id(response
, request
->get_message_id(request
));
960 response
->add_notify(response
, FALSE
, type
, chunk_empty
);
961 if (this->my_host
->is_anyaddr(this->my_host
))
963 this->my_host
->destroy(this->my_host
);
964 this->my_host
= request
->get_destination(request
);
965 this->my_host
= this->my_host
->clone(this->my_host
);
967 if (this->other_host
->is_anyaddr(this->other_host
))
969 this->other_host
->destroy(this->other_host
);
970 this->other_host
= request
->get_source(request
);
971 this->other_host
= this->other_host
->clone(this->other_host
);
973 response
->set_source(response
, this->my_host
->clone(this->my_host
));
974 response
->set_destination(response
, this->other_host
->clone(this->other_host
));
975 if (generate_message(this, response
, &packet
) == SUCCESS
)
977 charon
->sender
->send(charon
->sender
, packet
);
979 response
->destroy(response
);
984 * Implementation of ike_sa_t.act_as_mediation_server.
986 static void act_as_mediation_server(private_ike_sa_t
*this)
988 charon
->mediation_manager
->update_sa_id(charon
->mediation_manager
,
989 this->other_id
, this->ike_sa_id
);
990 this->is_mediation_server
= TRUE
;
994 * Implementation of ike_sa_t.get_server_reflexive_host.
996 static host_t
*get_server_reflexive_host(private_ike_sa_t
*this)
998 return this->server_reflexive_host
;
1002 * Implementation of ike_sa_t.set_server_reflexive_host.
1004 static void set_server_reflexive_host(private_ike_sa_t
*this, host_t
*host
)
1006 DESTROY_IF(this->server_reflexive_host
);
1007 this->server_reflexive_host
= host
;
1011 * Implementation of ike_sa_t.get_connect_id.
1013 static chunk_t
get_connect_id(private_ike_sa_t
*this)
1015 return this->connect_id
;
1019 * Implementation of ike_sa_t.respond
1021 static status_t
respond(private_ike_sa_t
*this, identification_t
*peer_id
,
1024 ike_me_t
*task
= ike_me_create(&this->public, TRUE
);
1025 task
->respond(task
, peer_id
, connect_id
);
1026 this->task_manager
->queue_task(this->task_manager
, (task_t
*)task
);
1027 return this->task_manager
->initiate(this->task_manager
);
1031 * Implementation of ike_sa_t.callback
1033 static status_t
callback(private_ike_sa_t
*this, identification_t
*peer_id
)
1035 ike_me_t
*task
= ike_me_create(&this->public, TRUE
);
1036 task
->callback(task
, peer_id
);
1037 this->task_manager
->queue_task(this->task_manager
, (task_t
*)task
);
1038 return this->task_manager
->initiate(this->task_manager
);
1042 * Implementation of ike_sa_t.relay
1044 static status_t
relay(private_ike_sa_t
*this, identification_t
*requester
,
1045 chunk_t connect_id
, chunk_t connect_key
, linked_list_t
*endpoints
, bool response
)
1047 ike_me_t
*task
= ike_me_create(&this->public, TRUE
);
1048 task
->relay(task
, requester
, connect_id
, connect_key
, endpoints
, response
);
1049 this->task_manager
->queue_task(this->task_manager
, (task_t
*)task
);
1050 return this->task_manager
->initiate(this->task_manager
);
1054 * Implementation of ike_sa_t.initiate_mediation
1056 static status_t
initiate_mediation(private_ike_sa_t
*this, peer_cfg_t
*mediated_cfg
)
1058 ike_me_t
*task
= ike_me_create(&this->public, TRUE
);
1059 task
->connect(task
, mediated_cfg
->get_peer_id(mediated_cfg
));
1060 this->task_manager
->queue_task(this->task_manager
, (task_t
*)task
);
1061 return this->task_manager
->initiate(this->task_manager
);
1065 * Implementation of ike_sa_t.initiate_mediated
1067 static status_t
initiate_mediated(private_ike_sa_t
*this, host_t
*me
, host_t
*other
,
1070 set_my_host(this, me
->clone(me
));
1071 set_other_host(this, other
->clone(other
));
1072 chunk_free(&this->connect_id
);
1073 this->connect_id
= chunk_clone(connect_id
);
1075 return this->task_manager
->initiate(this->task_manager
);
1080 * Resolve DNS host in configuration
1082 static void resolve_hosts(private_ike_sa_t
*this)
1086 host
= host_create_from_dns(this->ike_cfg
->get_other_addr(this->ike_cfg
),
1090 set_other_host(this, host
);
1093 host
= host_create_from_dns(this->ike_cfg
->get_my_addr(this->ike_cfg
),
1094 this->my_host
->get_family(this->my_host
),
1097 if (host
&& host
->is_anyaddr(host
) &&
1098 !this->other_host
->is_anyaddr(this->other_host
))
1100 host
->destroy(host
);
1101 host
= charon
->kernel_interface
->get_source_addr(
1102 charon
->kernel_interface
, this->other_host
, NULL
);
1105 host
->set_port(host
, IKEV2_UDP_PORT
);
1110 set_my_host(this, host
);
1115 * Initiates a CHILD_SA using the appropriate reqid
1117 static status_t
initiate_with_reqid(private_ike_sa_t
*this, child_cfg_t
*child_cfg
, u_int32_t reqid
)
1121 if (this->state
== IKE_CREATED
)
1123 resolve_hosts(this);
1125 if (this->other_host
->is_anyaddr(this->other_host
)
1127 && !this->peer_cfg
->get_mediated_by(this->peer_cfg
)
1131 child_cfg
->destroy(child_cfg
);
1132 DBG1(DBG_IKE
, "unable to initiate to %%any");
1136 this->ike_initiator
= TRUE
;
1138 task
= (task_t
*)ike_init_create(&this->public, TRUE
, NULL
);
1139 this->task_manager
->queue_task(this->task_manager
, task
);
1140 task
= (task_t
*)ike_natd_create(&this->public, TRUE
);
1141 this->task_manager
->queue_task(this->task_manager
, task
);
1142 task
= (task_t
*)ike_cert_pre_create(&this->public, TRUE
);
1143 this->task_manager
->queue_task(this->task_manager
, task
);
1144 task
= (task_t
*)ike_auth_create(&this->public, TRUE
);
1145 this->task_manager
->queue_task(this->task_manager
, task
);
1146 task
= (task_t
*)ike_cert_post_create(&this->public, TRUE
);
1147 this->task_manager
->queue_task(this->task_manager
, task
);
1148 task
= (task_t
*)ike_config_create(&this->public, TRUE
);
1149 this->task_manager
->queue_task(this->task_manager
, task
);
1150 task
= (task_t
*)ike_auth_lifetime_create(&this->public, TRUE
);
1151 this->task_manager
->queue_task(this->task_manager
, task
);
1152 if (this->peer_cfg
->use_mobike(this->peer_cfg
))
1154 task
= (task_t
*)ike_mobike_create(&this->public, TRUE
);
1155 this->task_manager
->queue_task(this->task_manager
, task
);
1158 task
= (task_t
*)ike_me_create(&this->public, TRUE
);
1159 this->task_manager
->queue_task(this->task_manager
, task
);
1164 if (this->peer_cfg
->is_mediation(this->peer_cfg
))
1165 { /* mediation connection is already established, retrigger state change
1166 * to notify bus listeners */
1167 DBG1(DBG_IKE
, "mediation connection is already up");
1168 set_state(this, IKE_ESTABLISHED
);
1169 DESTROY_IF(child_cfg
);
1174 /* normal IKE_SA with CHILD_SA */
1175 task
= (task_t
*)child_create_create(&this->public, child_cfg
);
1176 child_cfg
->destroy(child_cfg
);
1179 child_create_t
*child_create
= (child_create_t
*)task
;
1180 child_create
->use_reqid(child_create
, reqid
);
1182 this->task_manager
->queue_task(this->task_manager
, task
);
1185 if (this->peer_cfg
->get_mediated_by(this->peer_cfg
))
1187 /* mediated connection, initiate mediation process */
1188 job_t
*job
= (job_t
*)initiate_mediation_job_create(this->ike_sa_id
);
1189 charon
->processor
->queue_job(charon
->processor
, job
);
1195 return this->task_manager
->initiate(this->task_manager
);
1199 * Implementation of ike_sa_t.initiate.
1201 static status_t
initiate(private_ike_sa_t
*this, child_cfg_t
*child_cfg
)
1203 return initiate_with_reqid(this, child_cfg
, 0);
1207 * Implementation of ike_sa_t.acquire.
1209 static status_t
acquire(private_ike_sa_t
*this, u_int32_t reqid
)
1211 child_cfg_t
*child_cfg
;
1212 iterator_t
*iterator
;
1213 child_sa_t
*current
, *child_sa
= NULL
;
1215 if (this->state
== IKE_DELETING
)
1217 DBG1(DBG_IKE
, "acquiring CHILD_SA {reqid %d} failed: "
1218 "IKE_SA is deleting", reqid
);
1223 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1224 while (iterator
->iterate(iterator
, (void**)¤t
))
1226 if (current
->get_reqid(current
) == reqid
)
1232 iterator
->destroy(iterator
);
1235 DBG1(DBG_IKE
, "acquiring CHILD_SA {reqid %d} failed: "
1236 "CHILD_SA not found", reqid
);
1240 child_cfg
= child_sa
->get_config(child_sa
);
1241 child_cfg
->get_ref(child_cfg
);
1243 return initiate_with_reqid(this, child_cfg
, reqid
);
1247 * Implementation of ike_sa_t.route.
1249 static status_t
route(private_ike_sa_t
*this, child_cfg_t
*child_cfg
)
1251 child_sa_t
*child_sa
;
1252 iterator_t
*iterator
;
1253 linked_list_t
*my_ts
, *other_ts
;
1257 /* check if not already routed*/
1258 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1259 while (iterator
->iterate(iterator
, (void**)&child_sa
))
1261 if (child_sa
->get_state(child_sa
) == CHILD_ROUTED
&&
1262 streq(child_sa
->get_name(child_sa
), child_cfg
->get_name(child_cfg
)))
1264 iterator
->destroy(iterator
);
1265 DBG1(DBG_IKE
, "routing CHILD_SA failed: already routed");
1269 iterator
->destroy(iterator
);
1271 switch (this->state
)
1275 DBG1(DBG_IKE
, "routing CHILD_SA failed: IKE_SA is %N",
1276 ike_sa_state_names
, this->state
);
1279 case IKE_CONNECTING
:
1280 case IKE_ESTABLISHED
:
1285 resolve_hosts(this);
1287 /* install kernel policies */
1288 child_sa
= child_sa_create(this->my_host
, this->other_host
, this->my_id
,
1289 this->other_id
, child_cfg
, 0, FALSE
);
1291 if (this->my_virtual_ip
)
1293 me
= this->my_virtual_ip
;
1295 other
= this->other_host
;
1296 if (this->other_virtual_ip
)
1298 other
= this->other_virtual_ip
;
1301 my_ts
= child_cfg
->get_traffic_selectors(child_cfg
, TRUE
, NULL
, me
);
1302 other_ts
= child_cfg
->get_traffic_selectors(child_cfg
, FALSE
, NULL
, other
);
1303 status
= child_sa
->add_policies(child_sa
, my_ts
, other_ts
,
1304 child_cfg
->get_mode(child_cfg
), PROTO_NONE
);
1305 my_ts
->destroy_offset(my_ts
, offsetof(traffic_selector_t
, destroy
));
1306 other_ts
->destroy_offset(other_ts
, offsetof(traffic_selector_t
, destroy
));
1307 if (status
== SUCCESS
)
1309 this->child_sas
->insert_last(this->child_sas
, child_sa
);
1310 DBG1(DBG_IKE
, "CHILD_SA routed");
1314 DBG1(DBG_IKE
, "routing CHILD_SA failed");
1320 * Implementation of ike_sa_t.unroute.
1322 static status_t
unroute(private_ike_sa_t
*this, u_int32_t reqid
)
1324 iterator_t
*iterator
;
1325 child_sa_t
*child_sa
;
1328 /* find CHILD_SA in ROUTED state */
1329 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1330 while (iterator
->iterate(iterator
, (void**)&child_sa
))
1332 if (child_sa
->get_state(child_sa
) == CHILD_ROUTED
&&
1333 child_sa
->get_reqid(child_sa
) == reqid
)
1335 iterator
->remove(iterator
);
1336 DBG1(DBG_IKE
, "CHILD_SA unrouted");
1337 child_sa
->destroy(child_sa
);
1342 iterator
->destroy(iterator
);
1346 DBG1(DBG_IKE
, "unrouting CHILD_SA failed: reqid %d not found", reqid
);
1349 /* if we are not established, and we have no more routed childs, remove whole SA */
1350 if (this->state
== IKE_CREATED
&&
1351 this->child_sas
->get_count(this->child_sas
) == 0)
1358 * Implementation of ike_sa_t.process_message.
1360 static status_t
process_message(private_ike_sa_t
*this, message_t
*message
)
1365 is_request
= message
->get_request(message
);
1367 status
= message
->parse_body(message
, this->crypter_in
, this->signer_in
);
1368 if (status
!= SUCCESS
)
1376 DBG1(DBG_IKE
, "ciritcal unknown payloads found");
1379 send_notify_response(this, message
, UNSUPPORTED_CRITICAL_PAYLOAD
);
1383 DBG1(DBG_IKE
, "message parsing failed");
1386 send_notify_response(this, message
, INVALID_SYNTAX
);
1390 DBG1(DBG_IKE
, "message verification failed");
1393 send_notify_response(this, message
, INVALID_SYNTAX
);
1397 DBG1(DBG_IKE
, "integrity check failed");
1401 DBG1(DBG_IKE
, "found encrypted message, but no keys available");
1404 send_notify_response(this, message
, INVALID_SYNTAX
);
1410 DBG1(DBG_IKE
, "%N %s with message ID %d processing failed",
1411 exchange_type_names
, message
->get_exchange_type(message
),
1412 message
->get_request(message
) ?
"request" : "response",
1413 message
->get_message_id(message
));
1419 private_ike_sa_t
*new;
1420 iterator_t
*iterator
;
1422 bool has_routed
= FALSE
;
1424 me
= message
->get_destination(message
);
1425 other
= message
->get_source(message
);
1427 /* if this IKE_SA is virgin, we check for a config */
1428 if (this->ike_cfg
== NULL
)
1431 this->ike_cfg
= charon
->backends
->get_ike_cfg(charon
->backends
,
1433 if (this->ike_cfg
== NULL
)
1435 /* no config found for these hosts, destroy */
1436 DBG1(DBG_IKE
, "no IKE config found for %H...%H, sending %N",
1437 me
, other
, notify_type_names
, NO_PROPOSAL_CHOSEN
);
1438 send_notify_response(this, message
, NO_PROPOSAL_CHOSEN
);
1441 /* add a timeout if peer does not establish it completely */
1442 job
= (job_t
*)delete_ike_sa_job_create(this->ike_sa_id
, FALSE
);
1443 charon
->scheduler
->schedule_job(charon
->scheduler
, job
,
1444 HALF_OPEN_IKE_SA_TIMEOUT
);
1446 this->time
.inbound
= time(NULL
);
1447 /* check if message is trustworthy, and update host information */
1448 if (this->state
== IKE_CREATED
|| this->state
== IKE_CONNECTING
||
1449 message
->get_exchange_type(message
) != IKE_SA_INIT
)
1451 if (!supports_extension(this, EXT_MOBIKE
))
1452 { /* with MOBIKE, we do no implicit updates */
1453 update_hosts(this, me
, other
);
1456 status
= this->task_manager
->process_message(this->task_manager
, message
);
1457 if (status
!= DESTROY_ME
)
1461 /* if IKE_SA gets closed for any reasons, reroute routed children */
1462 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1463 while (iterator
->iterate(iterator
, (void**)&child
))
1465 if (child
->get_state(child
) == CHILD_ROUTED
)
1471 iterator
->destroy(iterator
);
1476 /* move routed children to a new IKE_SA, apply connection info */
1477 new = (private_ike_sa_t
*)charon
->ike_sa_manager
->checkout_new(
1478 charon
->ike_sa_manager
, TRUE
);
1479 set_peer_cfg(new, this->peer_cfg
);
1480 new->other_host
->destroy(new->other_host
);
1481 new->other_host
= this->other_host
->clone(this->other_host
);
1482 if (!has_condition(this, COND_NAT_THERE
))
1484 new->other_host
->set_port(new->other_host
, IKEV2_UDP_PORT
);
1486 if (this->my_virtual_ip
)
1488 set_virtual_ip(new, TRUE
, this->my_virtual_ip
);
1490 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1491 while (iterator
->iterate(iterator
, (void**)&child
))
1493 if (child
->get_state(child
) == CHILD_ROUTED
)
1495 route(new, child
->get_config(child
));
1498 iterator
->destroy(iterator
);
1499 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, &new->public);
1505 * Implementation of ike_sa_t.get_prf.
1507 static prf_t
*get_prf(private_ike_sa_t
*this)
1513 * Implementation of ike_sa_t.get_prf.
1515 static prf_t
*get_child_prf(private_ike_sa_t
*this)
1517 return this->child_prf
;
1521 * Implementation of ike_sa_t.get_skp_bild
1523 static chunk_t
get_skp_build(private_ike_sa_t
*this)
1525 return this->skp_build
;
1529 * Implementation of ike_sa_t.get_skp_verify
1531 static chunk_t
get_skp_verify(private_ike_sa_t
*this)
1533 return this->skp_verify
;
1537 * Implementation of ike_sa_t.get_id.
1539 static ike_sa_id_t
* get_id(private_ike_sa_t
*this)
1541 return this->ike_sa_id
;
1545 * Implementation of ike_sa_t.get_my_id.
1547 static identification_t
* get_my_id(private_ike_sa_t
*this)
1553 * Implementation of ike_sa_t.set_my_id.
1555 static void set_my_id(private_ike_sa_t
*this, identification_t
*me
)
1557 DESTROY_IF(this->my_id
);
1562 * Implementation of ike_sa_t.get_other_id.
1564 static identification_t
* get_other_id(private_ike_sa_t
*this)
1566 return this->other_id
;
1570 * Implementation of ike_sa_t.set_other_id.
1572 static void set_other_id(private_ike_sa_t
*this, identification_t
*other
)
1574 DESTROY_IF(this->other_id
);
1575 this->other_id
= other
;
1579 * Implementation of ike_sa_t.get_eap_identity.
1581 static identification_t
* get_eap_identity(private_ike_sa_t
*this)
1583 return this->eap_identity
;
1587 * Implementation of ike_sa_t.set_eap_identity.
1589 static void set_eap_identity(private_ike_sa_t
*this, identification_t
*id
)
1591 DESTROY_IF(this->eap_identity
);
1592 this->eap_identity
= id
;
1596 * Implementation of ike_sa_t.derive_keys.
1598 static status_t
derive_keys(private_ike_sa_t
*this,
1599 proposal_t
*proposal
, chunk_t secret
,
1600 chunk_t nonce_i
, chunk_t nonce_r
,
1601 bool initiator
, prf_t
*child_prf
, prf_t
*old_prf
)
1603 prf_plus_t
*prf_plus
;
1604 chunk_t skeyseed
, key
, full_nonce
, fixed_nonce
, prf_plus_seed
;
1605 u_int16_t alg
, key_size
;
1606 crypter_t
*crypter_i
, *crypter_r
;
1607 signer_t
*signer_i
, *signer_r
;
1608 u_int8_t spi_i_buf
[sizeof(u_int64_t
)], spi_r_buf
[sizeof(u_int64_t
)];
1609 chunk_t spi_i
= chunk_from_buf(spi_i_buf
);
1610 chunk_t spi_r
= chunk_from_buf(spi_r_buf
);
1612 /* Create SAs general purpose PRF first, we may use it here */
1613 if (!proposal
->get_algorithm(proposal
, PSEUDO_RANDOM_FUNCTION
, &alg
, NULL
))
1615 DBG1(DBG_IKE
, "no %N selected",
1616 transform_type_names
, PSEUDO_RANDOM_FUNCTION
);
1619 this->prf
= lib
->crypto
->create_prf(lib
->crypto
, alg
);
1620 if (this->prf
== NULL
)
1622 DBG1(DBG_IKE
, "%N %N not supported!",
1623 transform_type_names
, PSEUDO_RANDOM_FUNCTION
,
1624 pseudo_random_function_names
, alg
);
1627 DBG4(DBG_IKE
, "shared Diffie Hellman secret %B", &secret
);
1628 /* full nonce is used as seed for PRF+ ... */
1629 full_nonce
= chunk_cat("cc", nonce_i
, nonce_r
);
1630 /* but the PRF may need a fixed key which only uses the first bytes of
1634 case PRF_AES128_XCBC
:
1635 /* while rfc4434 defines variable keys for AES-XCBC, rfc3664 does
1636 * not and therefore fixed key semantics apply to XCBC for key
1638 nonce_i
.len
= min(nonce_i
.len
, this->prf
->get_key_size(this->prf
)/2);
1639 nonce_r
.len
= min(nonce_r
.len
, this->prf
->get_key_size(this->prf
)/2);
1642 /* all other algorithms use variable key length, full nonce */
1645 fixed_nonce
= chunk_cat("cc", nonce_i
, nonce_r
);
1646 *((u_int64_t
*)spi_i
.ptr
) = this->ike_sa_id
->get_initiator_spi(this->ike_sa_id
);
1647 *((u_int64_t
*)spi_r
.ptr
) = this->ike_sa_id
->get_responder_spi(this->ike_sa_id
);
1648 prf_plus_seed
= chunk_cat("ccc", full_nonce
, spi_i
, spi_r
);
1650 /* KEYMAT = prf+ (SKEYSEED, Ni | Nr | SPIi | SPIr)
1652 * if we are rekeying, SKEYSEED is built on another way
1654 if (child_prf
== NULL
) /* not rekeying */
1656 /* SKEYSEED = prf(Ni | Nr, g^ir) */
1657 this->prf
->set_key(this->prf
, fixed_nonce
);
1658 this->prf
->allocate_bytes(this->prf
, secret
, &skeyseed
);
1659 DBG4(DBG_IKE
, "SKEYSEED %B", &skeyseed
);
1660 this->prf
->set_key(this->prf
, skeyseed
);
1661 chunk_free(&skeyseed
);
1662 chunk_free(&secret
);
1663 prf_plus
= prf_plus_create(this->prf
, prf_plus_seed
);
1667 /* SKEYSEED = prf(SK_d (old), [g^ir (new)] | Ni | Nr)
1668 * use OLD SAs PRF functions for both prf_plus and prf */
1669 secret
= chunk_cat("mc", secret
, full_nonce
);
1670 child_prf
->allocate_bytes(child_prf
, secret
, &skeyseed
);
1671 DBG4(DBG_IKE
, "SKEYSEED %B", &skeyseed
);
1672 old_prf
->set_key(old_prf
, skeyseed
);
1673 chunk_free(&skeyseed
);
1674 chunk_free(&secret
);
1675 prf_plus
= prf_plus_create(old_prf
, prf_plus_seed
);
1677 chunk_free(&full_nonce
);
1678 chunk_free(&fixed_nonce
);
1679 chunk_free(&prf_plus_seed
);
1681 /* KEYMAT = SK_d | SK_ai | SK_ar | SK_ei | SK_er | SK_pi | SK_pr */
1683 /* SK_d is used for generating CHILD_SA key mat => child_prf */
1684 proposal
->get_algorithm(proposal
, PSEUDO_RANDOM_FUNCTION
, &alg
, NULL
);
1685 this->child_prf
= lib
->crypto
->create_prf(lib
->crypto
, alg
);
1686 key_size
= this->child_prf
->get_key_size(this->child_prf
);
1687 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1688 DBG4(DBG_IKE
, "Sk_d secret %B", &key
);
1689 this->child_prf
->set_key(this->child_prf
, key
);
1692 /* SK_ai/SK_ar used for integrity protection => signer_in/signer_out */
1693 if (!proposal
->get_algorithm(proposal
, INTEGRITY_ALGORITHM
, &alg
, NULL
))
1695 DBG1(DBG_IKE
, "no %N selected",
1696 transform_type_names
, INTEGRITY_ALGORITHM
);
1699 signer_i
= lib
->crypto
->create_signer(lib
->crypto
, alg
);
1700 signer_r
= lib
->crypto
->create_signer(lib
->crypto
, alg
);
1701 if (signer_i
== NULL
|| signer_r
== NULL
)
1703 DBG1(DBG_IKE
, "%N %N not supported!",
1704 transform_type_names
, INTEGRITY_ALGORITHM
,
1705 integrity_algorithm_names
,alg
);
1706 prf_plus
->destroy(prf_plus
);
1709 key_size
= signer_i
->get_key_size(signer_i
);
1711 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1712 DBG4(DBG_IKE
, "Sk_ai secret %B", &key
);
1713 signer_i
->set_key(signer_i
, key
);
1716 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1717 DBG4(DBG_IKE
, "Sk_ar secret %B", &key
);
1718 signer_r
->set_key(signer_r
, key
);
1723 this->signer_in
= signer_r
;
1724 this->signer_out
= signer_i
;
1728 this->signer_in
= signer_i
;
1729 this->signer_out
= signer_r
;
1732 /* SK_ei/SK_er used for encryption => crypter_in/crypter_out */
1733 if (!proposal
->get_algorithm(proposal
, ENCRYPTION_ALGORITHM
, &alg
, &key_size
))
1735 DBG1(DBG_IKE
, "no %N selected",
1736 transform_type_names
, ENCRYPTION_ALGORITHM
);
1737 prf_plus
->destroy(prf_plus
);
1740 crypter_i
= lib
->crypto
->create_crypter(lib
->crypto
, alg
, key_size
/ 8);
1741 crypter_r
= lib
->crypto
->create_crypter(lib
->crypto
, alg
, key_size
/ 8);
1742 if (crypter_i
== NULL
|| crypter_r
== NULL
)
1744 DBG1(DBG_IKE
, "%N %N (key size %d) not supported!",
1745 transform_type_names
, ENCRYPTION_ALGORITHM
,
1746 encryption_algorithm_names
, alg
, key_size
);
1747 prf_plus
->destroy(prf_plus
);
1750 key_size
= crypter_i
->get_key_size(crypter_i
);
1752 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1753 DBG4(DBG_IKE
, "Sk_ei secret %B", &key
);
1754 crypter_i
->set_key(crypter_i
, key
);
1757 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1758 DBG4(DBG_IKE
, "Sk_er secret %B", &key
);
1759 crypter_r
->set_key(crypter_r
, key
);
1764 this->crypter_in
= crypter_r
;
1765 this->crypter_out
= crypter_i
;
1769 this->crypter_in
= crypter_i
;
1770 this->crypter_out
= crypter_r
;
1773 /* SK_pi/SK_pr used for authentication => stored for later */
1774 key_size
= this->prf
->get_key_size(this->prf
);
1775 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1776 DBG4(DBG_IKE
, "Sk_pi secret %B", &key
);
1779 this->skp_build
= key
;
1783 this->skp_verify
= key
;
1785 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1786 DBG4(DBG_IKE
, "Sk_pr secret %B", &key
);
1789 this->skp_verify
= key
;
1793 this->skp_build
= key
;
1796 /* all done, prf_plus not needed anymore */
1797 prf_plus
->destroy(prf_plus
);
1803 * Implementation of ike_sa_t.get_proposal.
1805 static char* get_proposal(private_ike_sa_t
*this)
1807 return this->selected_proposal
;
1811 * Implementation of ike_sa_t.set_proposal.
1813 static void set_proposal(private_ike_sa_t
*this, char *proposal
)
1815 free(this->selected_proposal
);
1816 this->selected_proposal
= strdup(proposal
);
1820 * Implementation of ike_sa_t.add_child_sa.
1822 static void add_child_sa(private_ike_sa_t
*this, child_sa_t
*child_sa
)
1824 this->child_sas
->insert_last(this->child_sas
, child_sa
);
1828 * Implementation of ike_sa_t.get_child_sa.
1830 static child_sa_t
* get_child_sa(private_ike_sa_t
*this, protocol_id_t protocol
,
1831 u_int32_t spi
, bool inbound
)
1833 iterator_t
*iterator
;
1834 child_sa_t
*current
, *found
= NULL
;
1836 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1837 while (iterator
->iterate(iterator
, (void**)¤t
))
1839 if (current
->get_spi(current
, inbound
) == spi
&&
1840 current
->get_protocol(current
) == protocol
)
1845 iterator
->destroy(iterator
);
1850 * Implementation of ike_sa_t.create_child_sa_iterator.
1852 static iterator_t
* create_child_sa_iterator(private_ike_sa_t
*this)
1854 return this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1858 * Implementation of ike_sa_t.rekey_child_sa.
1860 static status_t
rekey_child_sa(private_ike_sa_t
*this, protocol_id_t protocol
, u_int32_t spi
)
1862 child_sa_t
*child_sa
;
1863 child_rekey_t
*child_rekey
;
1865 child_sa
= get_child_sa(this, protocol
, spi
, TRUE
);
1868 child_rekey
= child_rekey_create(&this->public, child_sa
);
1869 this->task_manager
->queue_task(this->task_manager
, &child_rekey
->task
);
1870 return this->task_manager
->initiate(this->task_manager
);
1876 * Implementation of ike_sa_t.delete_child_sa.
1878 static status_t
delete_child_sa(private_ike_sa_t
*this, protocol_id_t protocol
, u_int32_t spi
)
1880 child_sa_t
*child_sa
;
1881 child_delete_t
*child_delete
;
1883 child_sa
= get_child_sa(this, protocol
, spi
, TRUE
);
1886 child_delete
= child_delete_create(&this->public, child_sa
);
1887 this->task_manager
->queue_task(this->task_manager
, &child_delete
->task
);
1888 return this->task_manager
->initiate(this->task_manager
);
1894 * Implementation of ike_sa_t.destroy_child_sa.
1896 static status_t
destroy_child_sa(private_ike_sa_t
*this, protocol_id_t protocol
,
1899 iterator_t
*iterator
;
1900 child_sa_t
*child_sa
;
1901 status_t status
= NOT_FOUND
;
1903 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1904 while (iterator
->iterate(iterator
, (void**)&child_sa
))
1906 if (child_sa
->get_protocol(child_sa
) == protocol
&&
1907 child_sa
->get_spi(child_sa
, TRUE
) == spi
)
1909 child_sa
->destroy(child_sa
);
1910 iterator
->remove(iterator
);
1915 iterator
->destroy(iterator
);
1920 * Implementation of public_ike_sa_t.delete.
1922 static status_t
delete_(private_ike_sa_t
*this)
1924 ike_delete_t
*ike_delete
;
1926 switch (this->state
)
1928 case IKE_ESTABLISHED
:
1930 ike_delete
= ike_delete_create(&this->public, TRUE
);
1931 this->task_manager
->queue_task(this->task_manager
, &ike_delete
->task
);
1932 return this->task_manager
->initiate(this->task_manager
);
1934 DBG1(DBG_IKE
, "deleting unestablished IKE_SA");
1937 DBG1(DBG_IKE
, "destroying IKE_SA in state %N "
1938 "without notification", ike_sa_state_names
, this->state
);
1945 * Implementation of ike_sa_t.rekey.
1947 static status_t
rekey(private_ike_sa_t
*this)
1949 ike_rekey_t
*ike_rekey
;
1951 ike_rekey
= ike_rekey_create(&this->public, TRUE
);
1953 this->task_manager
->queue_task(this->task_manager
, &ike_rekey
->task
);
1954 return this->task_manager
->initiate(this->task_manager
);
1958 * Implementation of ike_sa_t.reauth
1960 static status_t
reauth(private_ike_sa_t
*this)
1964 /* we can't reauthenticate as responder when we use EAP or virtual IPs.
1965 * If the peer does not support RFC4478, there is no way to keep the
1967 if (!this->ike_initiator
)
1969 DBG1(DBG_IKE
, "initiator did not reauthenticate as requested");
1970 if (this->other_virtual_ip
!= NULL
||
1971 has_condition(this, COND_EAP_AUTHENTICATED
)
1973 /* if we are mediation server we too cannot reauth the IKE_SA */
1974 || this->is_mediation_server
1978 time_t now
= time(NULL
);
1980 DBG1(DBG_IKE
, "IKE_SA will timeout in %#V", &now
, &this->time
.delete);
1985 DBG1(DBG_IKE
, "reauthenticating actively");
1988 task
= (task_t
*)ike_reauth_create(&this->public);
1989 this->task_manager
->queue_task(this->task_manager
, task
);
1991 return this->task_manager
->initiate(this->task_manager
);
1995 * Implementation of ike_sa_t.reestablish
1997 static status_t
reestablish(private_ike_sa_t
*this)
2002 iterator_t
*iterator
;
2003 child_sa_t
*child_sa
;
2004 child_cfg_t
*child_cfg
;
2005 bool required
= FALSE
;
2006 status_t status
= FAILED
;
2008 /* check if we have children to keep up at all*/
2009 iterator
= create_child_sa_iterator(this);
2010 while (iterator
->iterate(iterator
, (void**)&child_sa
))
2012 child_cfg
= child_sa
->get_config(child_sa
);
2013 if (this->state
== IKE_DELETING
)
2015 action
= child_cfg
->get_close_action(child_cfg
);
2019 action
= child_cfg
->get_dpd_action(child_cfg
);
2023 case ACTION_RESTART
:
2030 iterator
->destroy(iterator
);
2032 /* we initiate the new IKE_SA of the mediation connection without CHILD_SA */
2033 if (this->peer_cfg
->is_mediation(this->peer_cfg
))
2043 /* check if we are able to reestablish this IKE_SA */
2044 if (!this->ike_initiator
&&
2045 (this->other_virtual_ip
!= NULL
||
2046 has_condition(this, COND_EAP_AUTHENTICATED
)
2048 || this->is_mediation_server
2052 DBG1(DBG_IKE
, "unable to reestablish IKE_SA due asymetric setup");
2056 new = charon
->ike_sa_manager
->checkout_new(charon
->ike_sa_manager
, TRUE
);
2057 new->set_peer_cfg(new, this->peer_cfg
);
2058 host
= this->other_host
;
2059 new->set_other_host(new, host
->clone(host
));
2060 host
= this->my_host
;
2061 new->set_my_host(new, host
->clone(host
));
2062 /* if we already have a virtual IP, we reuse it */
2063 host
= this->my_virtual_ip
;
2066 new->set_virtual_ip(new, TRUE
, host
);
2070 if (this->peer_cfg
->is_mediation(this->peer_cfg
))
2072 status
= new->initiate(new, NULL
);
2077 iterator
= create_child_sa_iterator(this);
2078 while (iterator
->iterate(iterator
, (void**)&child_sa
))
2080 child_cfg
= child_sa
->get_config(child_sa
);
2081 if (this->state
== IKE_DELETING
)
2083 action
= child_cfg
->get_close_action(child_cfg
);
2087 action
= child_cfg
->get_dpd_action(child_cfg
);
2091 case ACTION_RESTART
:
2092 DBG1(DBG_IKE
, "restarting CHILD_SA %s",
2093 child_cfg
->get_name(child_cfg
));
2094 child_cfg
->get_ref(child_cfg
);
2095 status
= new->initiate(new, child_cfg
);
2098 status
= new->route(new, child_cfg
);
2103 if (status
== DESTROY_ME
)
2108 iterator
->destroy(iterator
);
2111 if (status
== DESTROY_ME
)
2113 charon
->ike_sa_manager
->checkin_and_destroy(charon
->ike_sa_manager
, new);
2118 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, new);
2124 * Implementation of ike_sa_t.retransmit.
2126 static status_t
retransmit(private_ike_sa_t
*this, u_int32_t message_id
)
2128 this->time
.outbound
= time(NULL
);
2129 if (this->task_manager
->retransmit(this->task_manager
, message_id
) != SUCCESS
)
2131 /* send a proper signal to brief interested bus listeners */
2132 switch (this->state
)
2134 case IKE_CONNECTING
:
2136 /* retry IKE_SA_INIT if we have multiple keyingtries */
2137 u_int32_t tries
= this->peer_cfg
->get_keyingtries(this->peer_cfg
);
2139 if (tries
== 0 || tries
> this->keyingtry
)
2141 DBG1(DBG_IKE
, "peer not responding, trying again (%d/%d)",
2142 this->keyingtry
+ 1, tries
);
2144 return this->task_manager
->initiate(this->task_manager
);
2146 DBG1(DBG_IKE
, "establishing IKE_SA failed, peer not responding");
2150 DBG1(DBG_IKE
, "proper IKE_SA delete failed, peer not responding");
2153 DBG1(DBG_IKE
, "rekeying IKE_SA failed, peer not responding");
2165 * Implementation of ike_sa_t.set_auth_lifetime.
2167 static void set_auth_lifetime(private_ike_sa_t
*this, u_int32_t lifetime
)
2169 u_int32_t reduction
= this->peer_cfg
->get_over_time(this->peer_cfg
);
2170 u_int32_t reauth_time
= time(NULL
) + lifetime
- reduction
;
2172 if (lifetime
< reduction
)
2174 DBG1(DBG_IKE
, "received AUTH_LIFETIME of %ds, starting reauthentication",
2176 charon
->processor
->queue_job(charon
->processor
,
2177 (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, TRUE
));
2179 else if (this->time
.reauth
== 0 || this->time
.reauth
> reauth_time
)
2181 this->time
.reauth
= reauth_time
;
2182 DBG1(DBG_IKE
, "received AUTH_LIFETIME of %ds, scheduling reauthentication"
2183 " in %ds", lifetime
, lifetime
- reduction
);
2184 charon
->scheduler
->schedule_job(charon
->scheduler
,
2185 (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, TRUE
),
2186 (lifetime
- reduction
) * 1000);
2190 DBG1(DBG_IKE
, "received AUTH_LIFETIME of %ds, reauthentication already "
2191 "scheduled in %ds", lifetime
, this->time
.reauth
- time(NULL
));
2196 * Implementation of ike_sa_t.roam.
2198 static status_t
roam(private_ike_sa_t
*this, bool address
)
2201 ike_mobike_t
*mobike
;
2203 switch (this->state
)
2211 /* responder just updates the peer about changed address config */
2212 if (!this->ike_sa_id
->is_initiator(this->ike_sa_id
))
2214 if (supports_extension(this, EXT_MOBIKE
) && address
)
2216 DBG1(DBG_IKE
, "sending address list update using MOBIKE");
2217 mobike
= ike_mobike_create(&this->public, TRUE
);
2218 this->task_manager
->queue_task(this->task_manager
, (task_t
*)mobike
);
2219 return this->task_manager
->initiate(this->task_manager
);
2224 /* keep existing path if possible */
2225 src
= charon
->kernel_interface
->get_source_addr(charon
->kernel_interface
,
2226 this->other_host
, this->my_host
);
2229 if (src
->ip_equals(src
, this->my_host
))
2231 DBG2(DBG_IKE
, "keeping connection path %H - %H",
2232 src
, this->other_host
);
2239 /* update addresses with mobike, if supported ... */
2240 if (supports_extension(this, EXT_MOBIKE
))
2242 DBG1(DBG_IKE
, "requesting address change using MOBIKE");
2243 mobike
= ike_mobike_create(&this->public, TRUE
);
2244 mobike
->roam(mobike
, address
);
2245 this->task_manager
->queue_task(this->task_manager
, (task_t
*)mobike
);
2246 return this->task_manager
->initiate(this->task_manager
);
2248 DBG1(DBG_IKE
, "reauthenticating IKE_SA due to address change");
2249 /* ... reauth if not */
2250 return reauth(this);
2254 * Implementation of ike_sa_t.inherit.
2256 static status_t
inherit(private_ike_sa_t
*this, private_ike_sa_t
*other
)
2258 child_sa_t
*child_sa
;
2261 /* apply hosts and ids */
2262 this->my_host
->destroy(this->my_host
);
2263 this->other_host
->destroy(this->other_host
);
2264 this->my_id
->destroy(this->my_id
);
2265 this->other_id
->destroy(this->other_id
);
2266 this->my_host
= other
->my_host
->clone(other
->my_host
);
2267 this->other_host
= other
->other_host
->clone(other
->other_host
);
2268 this->my_id
= other
->my_id
->clone(other
->my_id
);
2269 this->other_id
= other
->other_id
->clone(other
->other_id
);
2270 this->ike_initiator
= other
->ike_initiator
;
2272 /* apply virtual assigned IPs... */
2273 if (other
->my_virtual_ip
)
2275 this->my_virtual_ip
= other
->my_virtual_ip
;
2276 other
->my_virtual_ip
= NULL
;
2278 if (other
->other_virtual_ip
)
2280 this->other_virtual_ip
= other
->other_virtual_ip
;
2281 other
->other_virtual_ip
= NULL
;
2284 /* ... and DNS servers */
2285 while (other
->dns_servers
->remove_last(other
->dns_servers
,
2286 (void**)&ip
) == SUCCESS
)
2288 this->dns_servers
->insert_first(this->dns_servers
, ip
);
2291 /* inherit NAT-T conditions */
2292 this->conditions
= other
->conditions
;
2293 if (this->conditions
& COND_NAT_HERE
)
2295 send_keepalive(this);
2299 if (other
->is_mediation_server
)
2301 act_as_mediation_server(this);
2303 else if (other
->server_reflexive_host
)
2305 this->server_reflexive_host
= other
->server_reflexive_host
->clone(
2306 other
->server_reflexive_host
);
2310 /* adopt all children */
2311 while (other
->child_sas
->remove_last(other
->child_sas
,
2312 (void**)&child_sa
) == SUCCESS
)
2314 this->child_sas
->insert_first(this->child_sas
, (void*)child_sa
);
2317 /* move pending tasks to the new IKE_SA */
2318 this->task_manager
->adopt_tasks(this->task_manager
, other
->task_manager
);
2320 /* reauthentication timeout survives a rekeying */
2321 if (other
->time
.reauth
)
2323 time_t reauth
, delete, now
= time(NULL
);
2325 this->time
.reauth
= other
->time
.reauth
;
2326 reauth
= this->time
.reauth
- now
;
2327 delete = reauth
+ this->peer_cfg
->get_over_time(this->peer_cfg
);
2328 this->time
.delete = this->time
.reauth
+ delete;
2329 DBG1(DBG_IKE
, "rescheduling reauthentication in %ds after rekeying, "
2330 "lifetime reduced to %ds", reauth
, delete);
2331 charon
->scheduler
->schedule_job(charon
->scheduler
,
2332 (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, TRUE
),
2334 charon
->scheduler
->schedule_job(charon
->scheduler
,
2335 (job_t
*)delete_ike_sa_job_create(this->ike_sa_id
, TRUE
),
2338 /* we have to initate here, there may be new tasks to handle */
2339 return this->task_manager
->initiate(this->task_manager
);
2343 * Implementation of ike_sa_t.remove_dns_server
2345 static void remove_dns_servers(private_ike_sa_t
*this)
2349 chunk_t contents
, line
, orig_line
, token
;
2350 char string
[INET6_ADDRSTRLEN
];
2352 iterator_t
*iterator
;
2354 if (this->dns_servers
->get_count(this->dns_servers
) == 0)
2356 /* don't touch anything if we have no nameservers installed */
2360 file
= fopen(RESOLV_CONF
, "r");
2361 if (file
== NULL
|| stat(RESOLV_CONF
, &stats
) != 0)
2363 DBG1(DBG_IKE
, "unable to open DNS configuration file %s: %s",
2364 RESOLV_CONF
, strerror(errno
));
2368 contents
= chunk_alloca((size_t)stats
.st_size
);
2370 if (fread(contents
.ptr
, 1, contents
.len
, file
) != contents
.len
)
2372 DBG1(DBG_IKE
, "unable to read DNS configuration file: %s", strerror(errno
));
2378 file
= fopen(RESOLV_CONF
, "w");
2381 DBG1(DBG_IKE
, "unable to open DNS configuration file %s: %s",
2382 RESOLV_CONF
, strerror(errno
));
2386 iterator
= this->dns_servers
->create_iterator(this->dns_servers
, TRUE
);
2387 while (fetchline(&contents
, &line
))
2391 if (extract_token(&token
, ' ', &line
) &&
2392 strncasecmp(token
.ptr
, "nameserver", token
.len
) == 0)
2394 if (!extract_token(&token
, ' ', &line
))
2398 iterator
->reset(iterator
);
2399 while (iterator
->iterate(iterator
, (void**)&ip
))
2401 snprintf(string
, sizeof(string
), "%H", ip
);
2402 if (strlen(string
) == token
.len
&&
2403 strncmp(token
.ptr
, string
, token
.len
) == 0)
2405 iterator
->remove(iterator
);
2415 /* write line untouched back to file */
2416 fwrite(orig_line
.ptr
, orig_line
.len
, 1, file
);
2417 fprintf(file
, "\n");
2420 iterator
->destroy(iterator
);
2425 * Implementation of ike_sa_t.add_dns_server
2427 static void add_dns_server(private_ike_sa_t
*this, host_t
*dns
)
2433 DBG1(DBG_IKE
, "installing DNS server %H", dns
);
2435 file
= fopen(RESOLV_CONF
, "a+");
2436 if (file
== NULL
|| stat(RESOLV_CONF
, &stats
) != 0)
2438 DBG1(DBG_IKE
, "unable to open DNS configuration file %s: %s",
2439 RESOLV_CONF
, strerror(errno
));
2443 contents
= chunk_alloca(stats
.st_size
);
2445 if (fread(contents
.ptr
, 1, contents
.len
, file
) != contents
.len
)
2447 DBG1(DBG_IKE
, "unable to read DNS configuration file: %s", strerror(errno
));
2453 file
= fopen(RESOLV_CONF
, "w");
2456 DBG1(DBG_IKE
, "unable to open DNS configuration file %s: %s",
2457 RESOLV_CONF
, strerror(errno
));
2461 if (fprintf(file
, "nameserver %H # added by strongSwan, assigned by %D\n",
2462 dns
, this->other_id
) < 0)
2464 DBG1(DBG_IKE
, "unable to write DNS configuration: %s", strerror(errno
));
2468 this->dns_servers
->insert_last(this->dns_servers
, dns
->clone(dns
));
2470 fwrite(contents
.ptr
, contents
.len
, 1, file
);
2476 * Implementation of ike_sa_t.destroy.
2478 static void destroy(private_ike_sa_t
*this)
2480 set_state(this, IKE_DESTROYING
);
2482 this->child_sas
->destroy_offset(this->child_sas
, offsetof(child_sa_t
, destroy
));
2484 this->task_manager
->destroy(this->task_manager
);
2486 DESTROY_IF(this->crypter_in
);
2487 DESTROY_IF(this->crypter_out
);
2488 DESTROY_IF(this->signer_in
);
2489 DESTROY_IF(this->signer_out
);
2490 DESTROY_IF(this->prf
);
2491 DESTROY_IF(this->child_prf
);
2492 chunk_free(&this->skp_verify
);
2493 chunk_free(&this->skp_build
);
2494 free(this->selected_proposal
);
2496 if (this->my_virtual_ip
)
2498 charon
->kernel_interface
->del_ip(charon
->kernel_interface
,
2499 this->my_virtual_ip
);
2500 this->my_virtual_ip
->destroy(this->my_virtual_ip
);
2502 if (this->other_virtual_ip
)
2504 if (this->peer_cfg
&& this->peer_cfg
->get_pool(this->peer_cfg
))
2506 charon
->attributes
->release_address(charon
->attributes
,
2507 this->peer_cfg
->get_pool(this->peer_cfg
),
2508 this->other_virtual_ip
);
2510 this->other_virtual_ip
->destroy(this->other_virtual_ip
);
2513 remove_dns_servers(this);
2514 this->dns_servers
->destroy_offset(this->dns_servers
,
2515 offsetof(host_t
, destroy
));
2516 this->additional_addresses
->destroy_offset(this->additional_addresses
,
2517 offsetof(host_t
, destroy
));
2519 if (this->is_mediation_server
)
2521 charon
->mediation_manager
->remove(charon
->mediation_manager
, this->ike_sa_id
);
2523 DESTROY_IF(this->server_reflexive_host
);
2524 chunk_free(&this->connect_id
);
2526 free(this->nat_detection_dest
.ptr
);
2528 DESTROY_IF(this->my_host
);
2529 DESTROY_IF(this->other_host
);
2530 DESTROY_IF(this->my_id
);
2531 DESTROY_IF(this->other_id
);
2532 DESTROY_IF(this->eap_identity
);
2534 DESTROY_IF(this->ike_cfg
);
2535 DESTROY_IF(this->peer_cfg
);
2536 DESTROY_IF(this->my_auth
);
2537 DESTROY_IF(this->other_auth
);
2539 this->ike_sa_id
->destroy(this->ike_sa_id
);
2544 * Described in header.
2546 ike_sa_t
* ike_sa_create(ike_sa_id_t
*ike_sa_id
)
2548 private_ike_sa_t
*this = malloc_thing(private_ike_sa_t
);
2549 static u_int32_t unique_id
= 0;
2551 /* Public functions */
2552 this->public.get_state
= (ike_sa_state_t (*)(ike_sa_t
*)) get_state
;
2553 this->public.set_state
= (void (*)(ike_sa_t
*,ike_sa_state_t
)) set_state
;
2554 this->public.get_name
= (char* (*)(ike_sa_t
*))get_name
;
2555 this->public.get_statistic
= (u_int32_t(*)(ike_sa_t
*, statistic_t kind
))get_statistic
;
2556 this->public.process_message
= (status_t (*)(ike_sa_t
*, message_t
*)) process_message
;
2557 this->public.initiate
= (status_t (*)(ike_sa_t
*,child_cfg_t
*)) initiate
;
2558 this->public.route
= (status_t (*)(ike_sa_t
*,child_cfg_t
*)) route
;
2559 this->public.unroute
= (status_t (*)(ike_sa_t
*,u_int32_t
)) unroute
;
2560 this->public.acquire
= (status_t (*)(ike_sa_t
*,u_int32_t
)) acquire
;
2561 this->public.get_ike_cfg
= (ike_cfg_t
* (*)(ike_sa_t
*))get_ike_cfg
;
2562 this->public.set_ike_cfg
= (void (*)(ike_sa_t
*,ike_cfg_t
*))set_ike_cfg
;
2563 this->public.get_peer_cfg
= (peer_cfg_t
* (*)(ike_sa_t
*))get_peer_cfg
;
2564 this->public.set_peer_cfg
= (void (*)(ike_sa_t
*,peer_cfg_t
*))set_peer_cfg
;
2565 this->public.get_my_auth
= (auth_info_t
*(*)(ike_sa_t
*))get_my_auth
;
2566 this->public.get_other_auth
= (auth_info_t
*(*)(ike_sa_t
*))get_other_auth
;
2567 this->public.get_id
= (ike_sa_id_t
* (*)(ike_sa_t
*)) get_id
;
2568 this->public.get_my_host
= (host_t
* (*)(ike_sa_t
*)) get_my_host
;
2569 this->public.set_my_host
= (void (*)(ike_sa_t
*,host_t
*)) set_my_host
;
2570 this->public.get_other_host
= (host_t
* (*)(ike_sa_t
*)) get_other_host
;
2571 this->public.set_other_host
= (void (*)(ike_sa_t
*,host_t
*)) set_other_host
;
2572 this->public.update_hosts
= (void(*)(ike_sa_t
*, host_t
*me
, host_t
*other
))update_hosts
;
2573 this->public.get_my_id
= (identification_t
* (*)(ike_sa_t
*)) get_my_id
;
2574 this->public.set_my_id
= (void (*)(ike_sa_t
*,identification_t
*)) set_my_id
;
2575 this->public.get_other_id
= (identification_t
* (*)(ike_sa_t
*)) get_other_id
;
2576 this->public.set_other_id
= (void (*)(ike_sa_t
*,identification_t
*)) set_other_id
;
2577 this->public.get_eap_identity
= (identification_t
* (*)(ike_sa_t
*)) get_eap_identity
;
2578 this->public.set_eap_identity
= (void (*)(ike_sa_t
*,identification_t
*)) set_eap_identity
;
2579 this->public.enable_extension
= (void(*)(ike_sa_t
*, ike_extension_t extension
))enable_extension
;
2580 this->public.supports_extension
= (bool(*)(ike_sa_t
*, ike_extension_t extension
))supports_extension
;
2581 this->public.set_condition
= (void (*)(ike_sa_t
*, ike_condition_t
,bool)) set_condition
;
2582 this->public.has_condition
= (bool (*)(ike_sa_t
*,ike_condition_t
)) has_condition
;
2583 this->public.set_pending_updates
= (void(*)(ike_sa_t
*, u_int32_t updates
))set_pending_updates
;
2584 this->public.get_pending_updates
= (u_int32_t(*)(ike_sa_t
*))get_pending_updates
;
2585 this->public.is_ike_initiator
= (bool (*)(ike_sa_t
*))is_ike_initiator
;
2586 this->public.create_additional_address_iterator
= (iterator_t
*(*)(ike_sa_t
*))create_additional_address_iterator
;
2587 this->public.add_additional_address
= (void(*)(ike_sa_t
*, host_t
*host
))add_additional_address
;
2588 this->public.has_mapping_changed
= (bool(*)(ike_sa_t
*, chunk_t hash
))has_mapping_changed
;
2589 this->public.retransmit
= (status_t (*)(ike_sa_t
*, u_int32_t
)) retransmit
;
2590 this->public.delete = (status_t (*)(ike_sa_t
*))delete_
;
2591 this->public.destroy
= (void (*)(ike_sa_t
*))destroy
;
2592 this->public.send_dpd
= (status_t (*)(ike_sa_t
*)) send_dpd
;
2593 this->public.send_keepalive
= (void (*)(ike_sa_t
*)) send_keepalive
;
2594 this->public.get_prf
= (prf_t
* (*)(ike_sa_t
*)) get_prf
;
2595 this->public.get_child_prf
= (prf_t
* (*)(ike_sa_t
*)) get_child_prf
;
2596 this->public.get_skp_verify
= (chunk_t (*)(ike_sa_t
*)) get_skp_verify
;
2597 this->public.get_skp_build
= (chunk_t (*)(ike_sa_t
*)) get_skp_build
;
2598 this->public.derive_keys
= (status_t (*)(ike_sa_t
*,proposal_t
*,chunk_t
,chunk_t
,chunk_t
,bool,prf_t
*,prf_t
*)) derive_keys
;
2599 this->public.get_proposal
= (char* (*)(ike_sa_t
*)) get_proposal
;
2600 this->public.set_proposal
= (void (*)(ike_sa_t
*,char*)) set_proposal
;
2601 this->public.add_child_sa
= (void (*)(ike_sa_t
*,child_sa_t
*)) add_child_sa
;
2602 this->public.get_child_sa
= (child_sa_t
* (*)(ike_sa_t
*,protocol_id_t
,u_int32_t
,bool)) get_child_sa
;
2603 this->public.create_child_sa_iterator
= (iterator_t
* (*)(ike_sa_t
*)) create_child_sa_iterator
;
2604 this->public.rekey_child_sa
= (status_t (*)(ike_sa_t
*,protocol_id_t
,u_int32_t
)) rekey_child_sa
;
2605 this->public.delete_child_sa
= (status_t (*)(ike_sa_t
*,protocol_id_t
,u_int32_t
)) delete_child_sa
;
2606 this->public.destroy_child_sa
= (status_t (*)(ike_sa_t
*,protocol_id_t
,u_int32_t
))destroy_child_sa
;
2607 this->public.rekey
= (status_t (*)(ike_sa_t
*))rekey
;
2608 this->public.reauth
= (status_t (*)(ike_sa_t
*))reauth
;
2609 this->public.reestablish
= (status_t (*)(ike_sa_t
*))reestablish
;
2610 this->public.set_auth_lifetime
= (void(*)(ike_sa_t
*, u_int32_t lifetime
))set_auth_lifetime
;
2611 this->public.roam
= (status_t(*)(ike_sa_t
*,bool))roam
;
2612 this->public.inherit
= (status_t (*)(ike_sa_t
*,ike_sa_t
*))inherit
;
2613 this->public.generate_message
= (status_t (*)(ike_sa_t
*,message_t
*,packet_t
**))generate_message
;
2614 this->public.reset
= (void (*)(ike_sa_t
*))reset
;
2615 this->public.get_unique_id
= (u_int32_t (*)(ike_sa_t
*))get_unique_id
;
2616 this->public.set_virtual_ip
= (void (*)(ike_sa_t
*,bool,host_t
*))set_virtual_ip
;
2617 this->public.get_virtual_ip
= (host_t
* (*)(ike_sa_t
*,bool))get_virtual_ip
;
2618 this->public.add_dns_server
= (void (*)(ike_sa_t
*,host_t
*))add_dns_server
;
2620 this->public.act_as_mediation_server
= (void (*)(ike_sa_t
*)) act_as_mediation_server
;
2621 this->public.get_server_reflexive_host
= (host_t
* (*)(ike_sa_t
*)) get_server_reflexive_host
;
2622 this->public.set_server_reflexive_host
= (void (*)(ike_sa_t
*,host_t
*)) set_server_reflexive_host
;
2623 this->public.get_connect_id
= (chunk_t (*)(ike_sa_t
*)) get_connect_id
;
2624 this->public.initiate_mediation
= (status_t (*)(ike_sa_t
*,peer_cfg_t
*)) initiate_mediation
;
2625 this->public.initiate_mediated
= (status_t (*)(ike_sa_t
*,host_t
*,host_t
*,chunk_t
)) initiate_mediated
;
2626 this->public.relay
= (status_t (*)(ike_sa_t
*,identification_t
*,chunk_t
,chunk_t
,linked_list_t
*,bool)) relay
;
2627 this->public.callback
= (status_t (*)(ike_sa_t
*,identification_t
*)) callback
;
2628 this->public.respond
= (status_t (*)(ike_sa_t
*,identification_t
*,chunk_t
)) respond
;
2631 /* initialize private fields */
2632 this->ike_sa_id
= ike_sa_id
->clone(ike_sa_id
);
2633 this->child_sas
= linked_list_create();
2634 this->my_host
= host_create_from_string("0.0.0.0", IKEV2_UDP_PORT
);
2635 this->other_host
= host_create_from_string("0.0.0.0", IKEV2_UDP_PORT
);
2636 this->my_id
= identification_create_from_encoding(ID_ANY
, chunk_empty
);
2637 this->other_id
= identification_create_from_encoding(ID_ANY
, chunk_empty
);
2638 this->eap_identity
= NULL
;
2639 this->extensions
= 0;
2640 this->conditions
= 0;
2641 this->selected_proposal
= NULL
;
2642 this->crypter_in
= NULL
;
2643 this->crypter_out
= NULL
;
2644 this->signer_in
= NULL
;
2645 this->signer_out
= NULL
;
2647 this->skp_verify
= chunk_empty
;
2648 this->skp_build
= chunk_empty
;
2649 this->child_prf
= NULL
;
2650 this->state
= IKE_CREATED
;
2651 this->keepalive_interval
= lib
->settings
->get_time(lib
->settings
,
2652 "charon.keep_alive", KEEPALIVE_INTERVAL
);
2653 this->time
.inbound
= this->time
.outbound
= time(NULL
);
2654 this->time
.established
= 0;
2655 this->time
.rekey
= 0;
2656 this->time
.reauth
= 0;
2657 this->time
.delete = 0;
2658 this->ike_cfg
= NULL
;
2659 this->peer_cfg
= NULL
;
2660 this->my_auth
= auth_info_create();
2661 this->other_auth
= auth_info_create();
2662 this->task_manager
= task_manager_create(&this->public);
2663 this->unique_id
= ++unique_id
;
2664 this->my_virtual_ip
= NULL
;
2665 this->other_virtual_ip
= NULL
;
2666 this->dns_servers
= linked_list_create();
2667 this->additional_addresses
= linked_list_create();
2668 this->nat_detection_dest
= chunk_empty
;
2669 this->pending_updates
= 0;
2670 this->keyingtry
= 0;
2671 this->ike_initiator
= FALSE
;
2673 this->is_mediation_server
= FALSE
;
2674 this->server_reflexive_host
= NULL
;
2675 this->connect_id
= chunk_empty
;
2678 return &this->public;