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_DELETING
,
83 typedef struct private_ike_sa_t private_ike_sa_t
;
86 * Private data of an ike_sa_t object.
88 struct private_ike_sa_t
{
96 * Identifier for the current IKE_SA.
98 ike_sa_id_t
*ike_sa_id
;
101 * unique numerical ID for this IKE_SA.
106 * Current state of the IKE_SA
108 ike_sa_state_t state
;
111 * IKE configuration used to set up this IKE_SA
116 * Peer and authentication information to establish IKE_SA.
118 peer_cfg_t
*peer_cfg
;
121 * associated authentication/authorization info for local peer
123 auth_info_t
*my_auth
;
126 * associated authentication/authorization info for remote peer
128 auth_info_t
*other_auth
;
131 * Juggles tasks to process messages
133 task_manager_t
*task_manager
;
136 * Address of local host
141 * Address of remote host
147 * Are we mediation server
149 bool is_mediation_server
;
152 * Server reflexive host
154 host_t
*server_reflexive_host
;
163 * Identification used for us
165 identification_t
*my_id
;
168 * Identification used for other
170 identification_t
*other_id
;
173 * set of extensions the peer supports
175 ike_extension_t extensions
;
178 * set of condition flags currently enabled for this IKE_SA
180 ike_condition_t conditions
;
183 * Linked List containing the child sa's of the current IKE_SA.
185 linked_list_t
*child_sas
;
188 * String describing the selected IKE proposal
190 char *selected_proposal
;
193 * crypter for inbound traffic
195 crypter_t
*crypter_in
;
198 * crypter for outbound traffic
200 crypter_t
*crypter_out
;
203 * Signer for inbound traffic
208 * Signer for outbound traffic
210 signer_t
*signer_out
;
213 * Multi purpose prf, set key, use it, forget it
218 * Prf function for derivating keymat child SAs
223 * Key to build outging authentication data (SKp)
228 * Key to verify incoming authentication data (SKp)
233 * Virtual IP on local host, if any
235 host_t
*my_virtual_ip
;
238 * Virtual IP on remote host, if any
240 host_t
*other_virtual_ip
;
243 * List of DNS servers installed by us
245 linked_list_t
*dns_servers
;
248 * list of peers additional addresses, transmitted via MOBIKE
250 linked_list_t
*additional_addresses
;
253 * number pending UPDATE_SA_ADDRESS (MOBIKE)
255 u_int32_t pending_updates
;
258 * Timestamps for this IKE_SA
261 /** last IKE message received */
263 /** last IKE message sent */
265 /** when IKE_SA became established */
266 u_int32_t established
;
267 /** when IKE_SA gets rekeyed */
269 /** when IKE_SA gets reauthenticated */
271 /** when IKE_SA gets deleted */
276 * how many times we have retried so far (keyingtries)
281 * are we the initiator of this IKE_SA (rekeying does not affect this flag)
287 * get the time of the latest traffic processed by the kernel
289 static time_t get_use_time(private_ike_sa_t
* this, bool inbound
)
291 iterator_t
*iterator
;
292 child_sa_t
*child_sa
;
293 time_t latest
= 0, use_time
;
295 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
296 while (iterator
->iterate(iterator
, (void**)&child_sa
))
298 if (child_sa
->get_use_time(child_sa
, inbound
, &use_time
) == SUCCESS
)
300 latest
= max(latest
, use_time
);
303 iterator
->destroy(iterator
);
307 return max(this->time
.inbound
, latest
);
311 return max(this->time
.outbound
, latest
);
316 * Implementation of ike_sa_t.get_unique_id
318 static u_int32_t
get_unique_id(private_ike_sa_t
*this)
320 return this->unique_id
;
324 * Implementation of ike_sa_t.get_name.
326 static char *get_name(private_ike_sa_t
*this)
330 return this->peer_cfg
->get_name(this->peer_cfg
);
336 * Implementation of ike_sa_t.get_statistic.
338 static u_int32_t
get_statistic(private_ike_sa_t
*this, statistic_t kind
)
340 time_t now
= time(NULL
);
344 case STAT_REKEY_TIME
:
345 if (this->time
.rekey
> now
)
347 return this->time
.rekey
- now
;
350 case STAT_REAUTH_TIME
:
351 if (this->time
.reauth
> now
)
353 return this->time
.reauth
- now
;
363 * Implementation of ike_sa_t.get_my_host.
365 static host_t
*get_my_host(private_ike_sa_t
*this)
367 return this->my_host
;
371 * Implementation of ike_sa_t.set_my_host.
373 static void set_my_host(private_ike_sa_t
*this, host_t
*me
)
375 DESTROY_IF(this->my_host
);
380 * Implementation of ike_sa_t.get_other_host.
382 static host_t
*get_other_host(private_ike_sa_t
*this)
384 return this->other_host
;
388 * Implementation of ike_sa_t.set_other_host.
390 static void set_other_host(private_ike_sa_t
*this, host_t
*other
)
392 DESTROY_IF(this->other_host
);
393 this->other_host
= other
;
397 * Implementation of ike_sa_t.get_peer_cfg
399 static peer_cfg_t
* get_peer_cfg(private_ike_sa_t
*this)
401 return this->peer_cfg
;
405 * Implementation of ike_sa_t.set_peer_cfg
407 static void set_peer_cfg(private_ike_sa_t
*this, peer_cfg_t
*peer_cfg
)
409 DESTROY_IF(this->peer_cfg
);
410 peer_cfg
->get_ref(peer_cfg
);
411 this->peer_cfg
= peer_cfg
;
413 if (this->ike_cfg
== NULL
)
415 this->ike_cfg
= peer_cfg
->get_ike_cfg(peer_cfg
);
416 this->ike_cfg
->get_ref(this->ike_cfg
);
418 /* apply IDs if they are not already set */
419 if (this->my_id
->contains_wildcards(this->my_id
))
421 DESTROY_IF(this->my_id
);
422 this->my_id
= this->peer_cfg
->get_my_id(this->peer_cfg
);
423 this->my_id
= this->my_id
->clone(this->my_id
);
425 if (this->other_id
->contains_wildcards(this->other_id
))
427 DESTROY_IF(this->other_id
);
428 this->other_id
= this->peer_cfg
->get_other_id(this->peer_cfg
);
429 this->other_id
= this->other_id
->clone(this->other_id
);
434 * Implementation of ike_sa_t.get_my_auth.
436 static auth_info_t
* get_my_auth(private_ike_sa_t
*this)
438 return this->my_auth
;
442 * Implementation of ike_sa_t.get_other_auth.
444 static auth_info_t
* get_other_auth(private_ike_sa_t
*this)
446 return this->other_auth
;
450 * Implementation of ike_sa_t.send_keepalive
452 static void send_keepalive(private_ike_sa_t
*this)
454 send_keepalive_job_t
*job
;
455 time_t last_out
, now
, diff
;
457 if (!(this->conditions
& COND_NAT_HERE
))
458 { /* disable keep alives if we are not NATed anymore */
462 last_out
= get_use_time(this, FALSE
);
465 diff
= now
- last_out
;
467 if (diff
>= KEEPALIVE_INTERVAL
)
472 packet
= packet_create();
473 packet
->set_source(packet
, this->my_host
->clone(this->my_host
));
474 packet
->set_destination(packet
, this->other_host
->clone(this->other_host
));
475 data
.ptr
= malloc(1);
478 packet
->set_data(packet
, data
);
479 DBG1(DBG_IKE
, "sending keep alive");
480 charon
->sender
->send(charon
->sender
, packet
);
483 job
= send_keepalive_job_create(this->ike_sa_id
);
484 charon
->scheduler
->schedule_job(charon
->scheduler
, (job_t
*)job
,
485 (KEEPALIVE_INTERVAL
- diff
) * 1000);
489 * Implementation of ike_sa_t.get_ike_cfg
491 static ike_cfg_t
*get_ike_cfg(private_ike_sa_t
*this)
493 return this->ike_cfg
;
497 * Implementation of ike_sa_t.set_ike_cfg
499 static void set_ike_cfg(private_ike_sa_t
*this, ike_cfg_t
*ike_cfg
)
501 ike_cfg
->get_ref(ike_cfg
);
502 this->ike_cfg
= ike_cfg
;
506 * Implementation of ike_sa_t.is_ike_initiator
508 static bool is_ike_initiator(private_ike_sa_t
*this)
510 return this->ike_initiator
;
514 * Implementation of ike_sa_t.enable_extension.
516 static void enable_extension(private_ike_sa_t
*this, ike_extension_t extension
)
518 this->extensions
|= extension
;
522 * Implementation of ike_sa_t.has_extension.
524 static bool supports_extension(private_ike_sa_t
*this, ike_extension_t extension
)
526 return (this->extensions
& extension
) != FALSE
;
530 * Implementation of ike_sa_t.has_condition.
532 static bool has_condition(private_ike_sa_t
*this, ike_condition_t condition
)
534 return (this->conditions
& condition
) != FALSE
;
538 * Implementation of ike_sa_t.enable_condition.
540 static void set_condition(private_ike_sa_t
*this, ike_condition_t condition
,
543 if (has_condition(this, condition
) != enable
)
547 this->conditions
|= condition
;
551 DBG1(DBG_IKE
, "local host is behind NAT, sending keep alives");
552 this->conditions
|= COND_NAT_ANY
;
553 send_keepalive(this);
556 DBG1(DBG_IKE
, "remote host is behind NAT");
557 this->conditions
|= COND_NAT_ANY
;
560 DBG1(DBG_IKE
, "faking NAT situation to enforce UDP encapsulation");
561 this->conditions
|= COND_NAT_ANY
;
569 this->conditions
&= ~condition
;
575 set_condition(this, COND_NAT_ANY
,
576 has_condition(this, COND_NAT_HERE
) ||
577 has_condition(this, COND_NAT_THERE
) ||
578 has_condition(this, COND_NAT_FAKE
));
588 * Implementation of ike_sa_t.send_dpd
590 static status_t
send_dpd(private_ike_sa_t
*this)
595 delay
= this->peer_cfg
->get_dpd(this->peer_cfg
);
603 if (this->task_manager
->busy(this->task_manager
))
605 /* an exchange is in the air, no need to start a DPD check */
610 /* check if there was any inbound traffic */
612 last_in
= get_use_time(this, TRUE
);
614 diff
= now
- last_in
;
617 /* to long ago, initiate dead peer detection */
620 task
= (task_t
*)ike_dpd_create(TRUE
);
622 DBG1(DBG_IKE
, "sending DPD request");
624 this->task_manager
->queue_task(this->task_manager
, task
);
625 this->task_manager
->initiate(this->task_manager
);
628 /* recheck in "interval" seconds */
629 job
= send_dpd_job_create(this->ike_sa_id
);
630 charon
->scheduler
->schedule_job(charon
->scheduler
, (job_t
*)job
,
631 (delay
- diff
) * 1000);
636 * Implementation of ike_sa_t.get_state.
638 static ike_sa_state_t
get_state(private_ike_sa_t
*this)
644 * Implementation of ike_sa_t.set_state.
646 static void set_state(private_ike_sa_t
*this, ike_sa_state_t state
)
648 DBG1(DBG_IKE
, "IKE_SA '%s' state change: %N => %N",
650 ike_sa_state_names
, this->state
,
651 ike_sa_state_names
, state
);
655 case IKE_ESTABLISHED
:
657 if (this->state
== IKE_CONNECTING
)
662 /* calculate rekey, reauth and lifetime */
663 this->time
.established
= time(NULL
);
665 /* schedule rekeying if we have a time which is smaller than
666 * an already scheduled rekeying */
667 t
= this->peer_cfg
->get_rekey_time(this->peer_cfg
);
668 if (t
&& (this->time
.rekey
== 0 ||
669 (this->time
.rekey
> t
+ this->time
.established
)))
671 this->time
.rekey
= t
+ this->time
.established
;
672 job
= (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, FALSE
);
673 charon
->scheduler
->schedule_job(charon
->scheduler
,
675 DBG1(DBG_IKE
, "scheduling rekeying in %ds", t
);
677 t
= this->peer_cfg
->get_reauth_time(this->peer_cfg
);
678 if (t
&& (this->time
.reauth
== 0 ||
679 (this->time
.reauth
> t
+ this->time
.established
)))
681 this->time
.reauth
= t
+ this->time
.established
;
682 job
= (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, TRUE
);
683 charon
->scheduler
->schedule_job(charon
->scheduler
,
685 DBG1(DBG_IKE
, "scheduling reauthentication in %ds", t
);
687 t
= this->peer_cfg
->get_over_time(this->peer_cfg
);
688 if (this->time
.rekey
|| this->time
.reauth
)
690 if (this->time
.reauth
== 0)
692 this->time
.delete = this->time
.rekey
;
694 else if (this->time
.rekey
== 0)
696 this->time
.delete = this->time
.reauth
;
700 this->time
.delete = min(this->time
.rekey
, this->time
.reauth
);
702 this->time
.delete += t
;
703 t
= this->time
.delete - this->time
.established
;
704 job
= (job_t
*)delete_ike_sa_job_create(this->ike_sa_id
, TRUE
);
705 charon
->scheduler
->schedule_job(charon
->scheduler
, job
,
707 DBG1(DBG_IKE
, "maximum IKE_SA lifetime %ds", t
);
710 /* start DPD checks */
717 /* delete may fail if a packet gets lost, so set a timeout */
718 job_t
*job
= (job_t
*)delete_ike_sa_job_create(this->ike_sa_id
, TRUE
);
719 charon
->scheduler
->schedule_job(charon
->scheduler
, job
,
720 HALF_OPEN_IKE_SA_TIMEOUT
);
731 * Implementation of ike_sa_t.reset
733 static void reset(private_ike_sa_t
*this)
735 /* the responder ID is reset, as peer may choose another one */
736 if (this->ike_sa_id
->is_initiator(this->ike_sa_id
))
738 this->ike_sa_id
->set_responder_spi(this->ike_sa_id
, 0);
741 set_state(this, IKE_CREATED
);
743 this->task_manager
->reset(this->task_manager
);
747 * Implementation of ike_sa_t.set_virtual_ip
749 static void set_virtual_ip(private_ike_sa_t
*this, bool local
, host_t
*ip
)
753 DBG1(DBG_IKE
, "installing new virtual IP %H", ip
);
754 if (charon
->kernel_interface
->add_ip(charon
->kernel_interface
, ip
,
755 this->my_host
) == SUCCESS
)
757 if (this->my_virtual_ip
)
759 DBG1(DBG_IKE
, "removing old virtual IP %H", this->my_virtual_ip
);
760 charon
->kernel_interface
->del_ip(charon
->kernel_interface
,
761 this->my_virtual_ip
);
763 DESTROY_IF(this->my_virtual_ip
);
764 this->my_virtual_ip
= ip
->clone(ip
);
768 DBG1(DBG_IKE
, "installing virtual IP %H failed", ip
);
769 this->my_virtual_ip
= NULL
;
774 DESTROY_IF(this->other_virtual_ip
);
775 this->other_virtual_ip
= ip
->clone(ip
);
780 * Implementation of ike_sa_t.get_virtual_ip
782 static host_t
* get_virtual_ip(private_ike_sa_t
*this, bool local
)
786 return this->my_virtual_ip
;
790 return this->other_virtual_ip
;
795 * Implementation of ike_sa_t.add_additional_address.
797 static void add_additional_address(private_ike_sa_t
*this, host_t
*host
)
799 this->additional_addresses
->insert_last(this->additional_addresses
, host
);
803 * Implementation of ike_sa_t.create_additional_address_iterator.
805 static iterator_t
* create_additional_address_iterator(private_ike_sa_t
*this)
807 return this->additional_addresses
->create_iterator(
808 this->additional_addresses
, TRUE
);
812 * Implementation of ike_sa_t.set_pending_updates.
814 static void set_pending_updates(private_ike_sa_t
*this, u_int32_t updates
)
816 this->pending_updates
= updates
;
820 * Implementation of ike_sa_t.get_pending_updates.
822 static u_int32_t
get_pending_updates(private_ike_sa_t
*this)
824 return this->pending_updates
;
828 * Update hosts, as addresses may change (NAT)
830 static void update_hosts(private_ike_sa_t
*this, host_t
*me
, host_t
*other
)
834 if (supports_extension(this, EXT_MOBIKE
))
835 { /* if peer speaks mobike, address updates are explicit only */
845 other
= this->other_host
;
848 /* apply hosts on first received message */
849 if (this->my_host
->is_anyaddr(this->my_host
) ||
850 this->other_host
->is_anyaddr(this->other_host
))
852 set_my_host(this, me
->clone(me
));
853 set_other_host(this, other
->clone(other
));
858 /* update our address in any case */
859 if (!me
->equals(me
, this->my_host
))
861 set_my_host(this, me
->clone(me
));
865 if (!other
->equals(other
, this->other_host
))
867 /* update others adress if we are NOT NATed,
868 * and allow port changes if we are NATed */
869 if (!has_condition(this, COND_NAT_HERE
) ||
870 other
->ip_equals(other
, this->other_host
))
872 set_other_host(this, other
->clone(other
));
878 /* update all associated CHILD_SAs, if required */
881 iterator_t
*iterator
;
882 child_sa_t
*child_sa
;
884 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
885 while (iterator
->iterate(iterator
, (void**)&child_sa
))
887 child_sa
->update_hosts(child_sa
, this->my_host
, this->other_host
,
888 has_condition(this, COND_NAT_ANY
));
890 iterator
->destroy(iterator
);
895 * Implementation of ike_sa_t.generate
897 static status_t
generate_message(private_ike_sa_t
*this, message_t
*message
,
900 this->time
.outbound
= time(NULL
);
901 message
->set_ike_sa_id(message
, this->ike_sa_id
);
902 return message
->generate(message
, this->crypter_out
, this->signer_out
, packet
);
906 * send a notify back to the sender
908 static void send_notify_response(private_ike_sa_t
*this, message_t
*request
,
914 response
= message_create();
915 response
->set_exchange_type(response
, request
->get_exchange_type(request
));
916 response
->set_request(response
, FALSE
);
917 response
->set_message_id(response
, request
->get_message_id(request
));
918 response
->add_notify(response
, FALSE
, type
, chunk_empty
);
919 if (this->my_host
->is_anyaddr(this->my_host
))
921 this->my_host
->destroy(this->my_host
);
922 this->my_host
= request
->get_destination(request
);
923 this->my_host
= this->my_host
->clone(this->my_host
);
925 if (this->other_host
->is_anyaddr(this->other_host
))
927 this->other_host
->destroy(this->other_host
);
928 this->other_host
= request
->get_source(request
);
929 this->other_host
= this->other_host
->clone(this->other_host
);
931 response
->set_source(response
, this->my_host
->clone(this->my_host
));
932 response
->set_destination(response
, this->other_host
->clone(this->other_host
));
933 if (generate_message(this, response
, &packet
) == SUCCESS
)
935 charon
->sender
->send(charon
->sender
, packet
);
937 response
->destroy(response
);
942 * Implementation of ike_sa_t.act_as_mediation_server.
944 static void act_as_mediation_server(private_ike_sa_t
*this)
946 charon
->mediation_manager
->update_sa_id(charon
->mediation_manager
,
947 this->other_id
, this->ike_sa_id
);
948 this->is_mediation_server
= TRUE
;
952 * Implementation of ike_sa_t.get_server_reflexive_host.
954 static host_t
*get_server_reflexive_host(private_ike_sa_t
*this)
956 return this->server_reflexive_host
;
960 * Implementation of ike_sa_t.set_server_reflexive_host.
962 static void set_server_reflexive_host(private_ike_sa_t
*this, host_t
*host
)
964 DESTROY_IF(this->server_reflexive_host
);
965 this->server_reflexive_host
= host
;
969 * Implementation of ike_sa_t.get_connect_id.
971 static chunk_t
get_connect_id(private_ike_sa_t
*this)
973 return this->connect_id
;
977 * Implementation of ike_sa_t.respond
979 static status_t
respond(private_ike_sa_t
*this, identification_t
*peer_id
,
982 ike_me_t
*task
= ike_me_create(&this->public, TRUE
);
983 task
->respond(task
, peer_id
, connect_id
);
984 this->task_manager
->queue_task(this->task_manager
, (task_t
*)task
);
985 return this->task_manager
->initiate(this->task_manager
);
989 * Implementation of ike_sa_t.callback
991 static status_t
callback(private_ike_sa_t
*this, identification_t
*peer_id
)
993 ike_me_t
*task
= ike_me_create(&this->public, TRUE
);
994 task
->callback(task
, peer_id
);
995 this->task_manager
->queue_task(this->task_manager
, (task_t
*)task
);
996 return this->task_manager
->initiate(this->task_manager
);
1000 * Implementation of ike_sa_t.relay
1002 static status_t
relay(private_ike_sa_t
*this, identification_t
*requester
,
1003 chunk_t connect_id
, chunk_t connect_key
, linked_list_t
*endpoints
, bool response
)
1005 ike_me_t
*task
= ike_me_create(&this->public, TRUE
);
1006 task
->relay(task
, requester
, connect_id
, connect_key
, endpoints
, response
);
1007 this->task_manager
->queue_task(this->task_manager
, (task_t
*)task
);
1008 return this->task_manager
->initiate(this->task_manager
);
1012 * Implementation of ike_sa_t.initiate_mediation
1014 static status_t
initiate_mediation(private_ike_sa_t
*this, peer_cfg_t
*mediated_cfg
)
1016 ike_me_t
*task
= ike_me_create(&this->public, TRUE
);
1017 task
->connect(task
, mediated_cfg
->get_peer_id(mediated_cfg
));
1018 this->task_manager
->queue_task(this->task_manager
, (task_t
*)task
);
1019 return this->task_manager
->initiate(this->task_manager
);
1023 * Implementation of ike_sa_t.initiate_mediated
1025 static status_t
initiate_mediated(private_ike_sa_t
*this, host_t
*me
, host_t
*other
,
1028 set_my_host(this, me
->clone(me
));
1029 set_other_host(this, other
->clone(other
));
1030 chunk_free(&this->connect_id
);
1031 this->connect_id
= chunk_clone(connect_id
);
1033 return this->task_manager
->initiate(this->task_manager
);
1038 * Resolve DNS host in configuration
1040 static void resolve_hosts(private_ike_sa_t
*this)
1044 host
= host_create_from_dns(this->ike_cfg
->get_my_addr(this->ike_cfg
), 0,
1048 set_my_host(this, host
);
1050 host
= host_create_from_dns(this->ike_cfg
->get_other_addr(this->ike_cfg
),
1051 this->my_host
->get_family(this->my_host
),
1055 set_other_host(this, host
);
1060 * Initiates a CHILD_SA using the appropriate reqid
1062 static status_t
initiate_with_reqid(private_ike_sa_t
*this, child_cfg_t
*child_cfg
, u_int32_t reqid
)
1066 if (this->state
== IKE_CREATED
)
1068 resolve_hosts(this);
1070 if (this->other_host
->is_anyaddr(this->other_host
)
1072 && !this->peer_cfg
->get_mediated_by(this->peer_cfg
)
1076 child_cfg
->destroy(child_cfg
);
1077 SIG(IKE_UP_START
, "initiating IKE_SA");
1078 SIG(IKE_UP_FAILED
, "unable to initiate to %%any");
1082 this->ike_initiator
= TRUE
;
1084 task
= (task_t
*)ike_init_create(&this->public, TRUE
, NULL
);
1085 this->task_manager
->queue_task(this->task_manager
, task
);
1086 task
= (task_t
*)ike_natd_create(&this->public, TRUE
);
1087 this->task_manager
->queue_task(this->task_manager
, task
);
1088 task
= (task_t
*)ike_cert_pre_create(&this->public, TRUE
);
1089 this->task_manager
->queue_task(this->task_manager
, task
);
1090 task
= (task_t
*)ike_auth_create(&this->public, TRUE
);
1091 this->task_manager
->queue_task(this->task_manager
, task
);
1092 task
= (task_t
*)ike_cert_post_create(&this->public, TRUE
);
1093 this->task_manager
->queue_task(this->task_manager
, task
);
1094 task
= (task_t
*)ike_config_create(&this->public, TRUE
);
1095 this->task_manager
->queue_task(this->task_manager
, task
);
1096 task
= (task_t
*)ike_auth_lifetime_create(&this->public, TRUE
);
1097 this->task_manager
->queue_task(this->task_manager
, task
);
1098 if (this->peer_cfg
->use_mobike(this->peer_cfg
))
1100 task
= (task_t
*)ike_mobike_create(&this->public, TRUE
);
1101 this->task_manager
->queue_task(this->task_manager
, task
);
1104 task
= (task_t
*)ike_me_create(&this->public, TRUE
);
1105 this->task_manager
->queue_task(this->task_manager
, task
);
1110 if (this->peer_cfg
->is_mediation(this->peer_cfg
))
1112 /* mediation connection */
1113 if (this->state
== IKE_ESTABLISHED
)
1114 { /* FIXME: we should try to find a better solution to this */
1115 SIG(CHILD_UP_SUCCESS
, "mediation connection is already up and running");
1117 DESTROY_IF(child_cfg
);
1122 /* normal IKE_SA with CHILD_SA */
1123 task
= (task_t
*)child_create_create(&this->public, child_cfg
);
1124 child_cfg
->destroy(child_cfg
);
1127 child_create_t
*child_create
= (child_create_t
*)task
;
1128 child_create
->use_reqid(child_create
, reqid
);
1130 this->task_manager
->queue_task(this->task_manager
, task
);
1133 if (this->peer_cfg
->get_mediated_by(this->peer_cfg
))
1135 /* mediated connection, initiate mediation process */
1136 job_t
*job
= (job_t
*)initiate_mediation_job_create(this->ike_sa_id
);
1137 charon
->processor
->queue_job(charon
->processor
, job
);
1143 return this->task_manager
->initiate(this->task_manager
);
1147 * Implementation of ike_sa_t.initiate.
1149 static status_t
initiate(private_ike_sa_t
*this, child_cfg_t
*child_cfg
)
1151 return initiate_with_reqid(this, child_cfg
, 0);
1155 * Implementation of ike_sa_t.acquire.
1157 static status_t
acquire(private_ike_sa_t
*this, u_int32_t reqid
)
1159 child_cfg_t
*child_cfg
;
1160 iterator_t
*iterator
;
1161 child_sa_t
*current
, *child_sa
= NULL
;
1163 if (this->state
== IKE_DELETING
)
1165 SIG(CHILD_UP_START
, "acquiring CHILD_SA on kernel request");
1166 SIG(CHILD_UP_FAILED
, "acquiring CHILD_SA (reqid %d) failed: "
1167 "IKE_SA is deleting", reqid
);
1172 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1173 while (iterator
->iterate(iterator
, (void**)¤t
))
1175 if (current
->get_reqid(current
) == reqid
)
1181 iterator
->destroy(iterator
);
1184 SIG(CHILD_UP_START
, "acquiring CHILD_SA on kernel request");
1185 SIG(CHILD_UP_FAILED
, "acquiring CHILD_SA (reqid %d) failed: "
1186 "CHILD_SA not found", reqid
);
1190 child_cfg
= child_sa
->get_config(child_sa
);
1191 child_cfg
->get_ref(child_cfg
);
1193 return initiate_with_reqid(this, child_cfg
, reqid
);
1197 * Implementation of ike_sa_t.route.
1199 static status_t
route(private_ike_sa_t
*this, child_cfg_t
*child_cfg
)
1201 child_sa_t
*child_sa
;
1202 iterator_t
*iterator
;
1203 linked_list_t
*my_ts
, *other_ts
;
1207 SIG(CHILD_ROUTE_START
, "routing CHILD_SA");
1209 /* check if not already routed*/
1210 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1211 while (iterator
->iterate(iterator
, (void**)&child_sa
))
1213 if (child_sa
->get_state(child_sa
) == CHILD_ROUTED
&&
1214 streq(child_sa
->get_name(child_sa
), child_cfg
->get_name(child_cfg
)))
1216 iterator
->destroy(iterator
);
1217 SIG(CHILD_ROUTE_FAILED
, "CHILD_SA with such a config already routed");
1221 iterator
->destroy(iterator
);
1223 switch (this->state
)
1227 SIG(CHILD_ROUTE_FAILED
,
1228 "unable to route CHILD_SA, as its IKE_SA gets deleted");
1231 case IKE_CONNECTING
:
1232 case IKE_ESTABLISHED
:
1237 resolve_hosts(this);
1239 /* install kernel policies */
1240 child_sa
= child_sa_create(this->my_host
, this->other_host
, this->my_id
,
1241 this->other_id
, child_cfg
, 0, FALSE
);
1243 if (this->my_virtual_ip
)
1245 me
= this->my_virtual_ip
;
1247 other
= this->other_host
;
1248 if (this->other_virtual_ip
)
1250 other
= this->other_virtual_ip
;
1253 my_ts
= child_cfg
->get_traffic_selectors(child_cfg
, TRUE
, NULL
, me
);
1254 other_ts
= child_cfg
->get_traffic_selectors(child_cfg
, FALSE
, NULL
, other
);
1255 status
= child_sa
->add_policies(child_sa
, my_ts
, other_ts
,
1256 child_cfg
->get_mode(child_cfg
));
1257 my_ts
->destroy_offset(my_ts
, offsetof(traffic_selector_t
, destroy
));
1258 other_ts
->destroy_offset(other_ts
, offsetof(traffic_selector_t
, destroy
));
1259 if (status
== SUCCESS
)
1261 this->child_sas
->insert_last(this->child_sas
, child_sa
);
1262 SIG(CHILD_ROUTE_SUCCESS
, "CHILD_SA routed");
1266 SIG(CHILD_ROUTE_FAILED
, "routing CHILD_SA failed");
1272 * Implementation of ike_sa_t.unroute.
1274 static status_t
unroute(private_ike_sa_t
*this, u_int32_t reqid
)
1276 iterator_t
*iterator
;
1277 child_sa_t
*child_sa
;
1280 SIG(CHILD_UNROUTE_START
, "unrouting CHILD_SA");
1282 /* find CHILD_SA in ROUTED state */
1283 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1284 while (iterator
->iterate(iterator
, (void**)&child_sa
))
1286 if (child_sa
->get_state(child_sa
) == CHILD_ROUTED
&&
1287 child_sa
->get_reqid(child_sa
) == reqid
)
1289 iterator
->remove(iterator
);
1290 SIG(CHILD_UNROUTE_SUCCESS
, "CHILD_SA unrouted");
1291 child_sa
->destroy(child_sa
);
1296 iterator
->destroy(iterator
);
1300 SIG(CHILD_UNROUTE_FAILED
, "CHILD_SA to unroute not found");
1303 /* if we are not established, and we have no more routed childs, remove whole SA */
1304 if (this->state
== IKE_CREATED
&&
1305 this->child_sas
->get_count(this->child_sas
) == 0)
1312 * Implementation of ike_sa_t.process_message.
1314 static status_t
process_message(private_ike_sa_t
*this, message_t
*message
)
1319 is_request
= message
->get_request(message
);
1321 status
= message
->parse_body(message
, this->crypter_in
, this->signer_in
);
1322 if (status
!= SUCCESS
)
1330 DBG1(DBG_IKE
, "ciritcal unknown payloads found");
1333 send_notify_response(this, message
, UNSUPPORTED_CRITICAL_PAYLOAD
);
1337 DBG1(DBG_IKE
, "message parsing failed");
1340 send_notify_response(this, message
, INVALID_SYNTAX
);
1344 DBG1(DBG_IKE
, "message verification failed");
1347 send_notify_response(this, message
, INVALID_SYNTAX
);
1351 DBG1(DBG_IKE
, "integrity check failed");
1355 DBG1(DBG_IKE
, "found encrypted message, but no keys available");
1358 send_notify_response(this, message
, INVALID_SYNTAX
);
1364 DBG1(DBG_IKE
, "%N %s with message ID %d processing failed",
1365 exchange_type_names
, message
->get_exchange_type(message
),
1366 message
->get_request(message
) ?
"request" : "response",
1367 message
->get_message_id(message
));
1373 private_ike_sa_t
*new;
1374 iterator_t
*iterator
;
1376 bool has_routed
= FALSE
;
1378 me
= message
->get_destination(message
);
1379 other
= message
->get_source(message
);
1381 /* if this IKE_SA is virgin, we check for a config */
1382 if (this->ike_cfg
== NULL
)
1385 this->ike_cfg
= charon
->backends
->get_ike_cfg(charon
->backends
,
1387 if (this->ike_cfg
== NULL
)
1389 /* no config found for these hosts, destroy */
1390 DBG1(DBG_IKE
, "no IKE config found for %H...%H, sending %N",
1391 me
, other
, notify_type_names
, NO_PROPOSAL_CHOSEN
);
1392 send_notify_response(this, message
, NO_PROPOSAL_CHOSEN
);
1395 /* add a timeout if peer does not establish it completely */
1396 job
= (job_t
*)delete_ike_sa_job_create(this->ike_sa_id
, FALSE
);
1397 charon
->scheduler
->schedule_job(charon
->scheduler
, job
,
1398 HALF_OPEN_IKE_SA_TIMEOUT
);
1401 /* check if message is trustworthy, and update host information */
1402 if (this->state
== IKE_CREATED
|| this->state
== IKE_CONNECTING
||
1403 message
->get_exchange_type(message
) != IKE_SA_INIT
)
1405 update_hosts(this, me
, other
);
1406 this->time
.inbound
= time(NULL
);
1408 status
= this->task_manager
->process_message(this->task_manager
, message
);
1409 if (status
!= DESTROY_ME
)
1413 /* if IKE_SA gets closed for any reasons, reroute routed children */
1414 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1415 while (iterator
->iterate(iterator
, (void**)&child
))
1417 if (child
->get_state(child
) == CHILD_ROUTED
)
1423 iterator
->destroy(iterator
);
1428 /* move routed children to a new IKE_SA, apply connection info */
1429 new = (private_ike_sa_t
*)charon
->ike_sa_manager
->checkout_new(
1430 charon
->ike_sa_manager
, TRUE
);
1431 set_peer_cfg(new, this->peer_cfg
);
1432 new->other_host
->destroy(new->other_host
);
1433 new->other_host
= this->other_host
->clone(this->other_host
);
1434 if (!has_condition(this, COND_NAT_THERE
))
1436 new->other_host
->set_port(new->other_host
, IKEV2_UDP_PORT
);
1438 if (this->my_virtual_ip
)
1440 set_virtual_ip(new, TRUE
, this->my_virtual_ip
);
1442 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1443 while (iterator
->iterate(iterator
, (void**)&child
))
1445 if (child
->get_state(child
) == CHILD_ROUTED
)
1447 route(new, child
->get_config(child
));
1450 iterator
->destroy(iterator
);
1451 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, &new->public);
1457 * Implementation of ike_sa_t.get_prf.
1459 static prf_t
*get_prf(private_ike_sa_t
*this)
1465 * Implementation of ike_sa_t.get_prf.
1467 static prf_t
*get_child_prf(private_ike_sa_t
*this)
1469 return this->child_prf
;
1473 * Implementation of ike_sa_t.get_skp_bild
1475 static chunk_t
get_skp_build(private_ike_sa_t
*this)
1477 return this->skp_build
;
1481 * Implementation of ike_sa_t.get_skp_verify
1483 static chunk_t
get_skp_verify(private_ike_sa_t
*this)
1485 return this->skp_verify
;
1489 * Implementation of ike_sa_t.get_id.
1491 static ike_sa_id_t
* get_id(private_ike_sa_t
*this)
1493 return this->ike_sa_id
;
1497 * Implementation of ike_sa_t.get_my_id.
1499 static identification_t
* get_my_id(private_ike_sa_t
*this)
1505 * Implementation of ike_sa_t.set_my_id.
1507 static void set_my_id(private_ike_sa_t
*this, identification_t
*me
)
1509 DESTROY_IF(this->my_id
);
1514 * Implementation of ike_sa_t.get_other_id.
1516 static identification_t
* get_other_id(private_ike_sa_t
*this)
1518 return this->other_id
;
1522 * Implementation of ike_sa_t.set_other_id.
1524 static void set_other_id(private_ike_sa_t
*this, identification_t
*other
)
1526 DESTROY_IF(this->other_id
);
1527 this->other_id
= other
;
1531 * Implementation of ike_sa_t.derive_keys.
1533 static status_t
derive_keys(private_ike_sa_t
*this,
1534 proposal_t
*proposal
, chunk_t secret
,
1535 chunk_t nonce_i
, chunk_t nonce_r
,
1536 bool initiator
, prf_t
*child_prf
, prf_t
*old_prf
)
1538 prf_plus_t
*prf_plus
;
1539 chunk_t skeyseed
, key
, full_nonce
, fixed_nonce
, prf_plus_seed
;
1540 u_int16_t alg
, key_size
;
1541 crypter_t
*crypter_i
, *crypter_r
;
1542 signer_t
*signer_i
, *signer_r
;
1543 u_int8_t spi_i_buf
[sizeof(u_int64_t
)], spi_r_buf
[sizeof(u_int64_t
)];
1544 chunk_t spi_i
= chunk_from_buf(spi_i_buf
);
1545 chunk_t spi_r
= chunk_from_buf(spi_r_buf
);
1547 /* Create SAs general purpose PRF first, we may use it here */
1548 if (!proposal
->get_algorithm(proposal
, PSEUDO_RANDOM_FUNCTION
, &alg
, NULL
))
1550 DBG1(DBG_IKE
, "no %N selected",
1551 transform_type_names
, PSEUDO_RANDOM_FUNCTION
);
1554 this->prf
= lib
->crypto
->create_prf(lib
->crypto
, alg
);
1555 if (this->prf
== NULL
)
1557 DBG1(DBG_IKE
, "%N %N not supported!",
1558 transform_type_names
, PSEUDO_RANDOM_FUNCTION
,
1559 pseudo_random_function_names
, alg
);
1562 DBG4(DBG_IKE
, "shared Diffie Hellman secret %B", &secret
);
1563 /* full nonce is used as seed for PRF+ ... */
1564 full_nonce
= chunk_cat("cc", nonce_i
, nonce_r
);
1565 /* but the PRF may need a fixed key which only uses the first bytes of
1569 case PRF_AES128_XCBC
:
1570 /* while rfc4434 defines variable keys for AES-XCBC, rfc3664 does
1571 * not and therefore fixed key semantics apply to XCBC for key
1573 nonce_i
.len
= min(nonce_i
.len
, this->prf
->get_key_size(this->prf
)/2);
1574 nonce_r
.len
= min(nonce_r
.len
, this->prf
->get_key_size(this->prf
)/2);
1577 /* all other algorithms use variable key length, full nonce */
1580 fixed_nonce
= chunk_cat("cc", nonce_i
, nonce_r
);
1581 *((u_int64_t
*)spi_i
.ptr
) = this->ike_sa_id
->get_initiator_spi(this->ike_sa_id
);
1582 *((u_int64_t
*)spi_r
.ptr
) = this->ike_sa_id
->get_responder_spi(this->ike_sa_id
);
1583 prf_plus_seed
= chunk_cat("ccc", full_nonce
, spi_i
, spi_r
);
1585 /* KEYMAT = prf+ (SKEYSEED, Ni | Nr | SPIi | SPIr)
1587 * if we are rekeying, SKEYSEED is built on another way
1589 if (child_prf
== NULL
) /* not rekeying */
1591 /* SKEYSEED = prf(Ni | Nr, g^ir) */
1592 this->prf
->set_key(this->prf
, fixed_nonce
);
1593 this->prf
->allocate_bytes(this->prf
, secret
, &skeyseed
);
1594 DBG4(DBG_IKE
, "SKEYSEED %B", &skeyseed
);
1595 this->prf
->set_key(this->prf
, skeyseed
);
1596 chunk_free(&skeyseed
);
1597 chunk_free(&secret
);
1598 prf_plus
= prf_plus_create(this->prf
, prf_plus_seed
);
1602 /* SKEYSEED = prf(SK_d (old), [g^ir (new)] | Ni | Nr)
1603 * use OLD SAs PRF functions for both prf_plus and prf */
1604 secret
= chunk_cat("mc", secret
, full_nonce
);
1605 child_prf
->allocate_bytes(child_prf
, secret
, &skeyseed
);
1606 DBG4(DBG_IKE
, "SKEYSEED %B", &skeyseed
);
1607 old_prf
->set_key(old_prf
, skeyseed
);
1608 chunk_free(&skeyseed
);
1609 chunk_free(&secret
);
1610 prf_plus
= prf_plus_create(old_prf
, prf_plus_seed
);
1612 chunk_free(&full_nonce
);
1613 chunk_free(&fixed_nonce
);
1614 chunk_free(&prf_plus_seed
);
1616 /* KEYMAT = SK_d | SK_ai | SK_ar | SK_ei | SK_er | SK_pi | SK_pr */
1618 /* SK_d is used for generating CHILD_SA key mat => child_prf */
1619 proposal
->get_algorithm(proposal
, PSEUDO_RANDOM_FUNCTION
, &alg
, NULL
);
1620 this->child_prf
= lib
->crypto
->create_prf(lib
->crypto
, alg
);
1621 key_size
= this->child_prf
->get_key_size(this->child_prf
);
1622 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1623 DBG4(DBG_IKE
, "Sk_d secret %B", &key
);
1624 this->child_prf
->set_key(this->child_prf
, key
);
1627 /* SK_ai/SK_ar used for integrity protection => signer_in/signer_out */
1628 if (!proposal
->get_algorithm(proposal
, INTEGRITY_ALGORITHM
, &alg
, NULL
))
1630 DBG1(DBG_IKE
, "no %N selected",
1631 transform_type_names
, INTEGRITY_ALGORITHM
);
1634 signer_i
= lib
->crypto
->create_signer(lib
->crypto
, alg
);
1635 signer_r
= lib
->crypto
->create_signer(lib
->crypto
, alg
);
1636 if (signer_i
== NULL
|| signer_r
== NULL
)
1638 DBG1(DBG_IKE
, "%N %N not supported!",
1639 transform_type_names
, INTEGRITY_ALGORITHM
,
1640 integrity_algorithm_names
,alg
);
1641 prf_plus
->destroy(prf_plus
);
1644 key_size
= signer_i
->get_key_size(signer_i
);
1646 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1647 DBG4(DBG_IKE
, "Sk_ai secret %B", &key
);
1648 signer_i
->set_key(signer_i
, key
);
1651 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1652 DBG4(DBG_IKE
, "Sk_ar secret %B", &key
);
1653 signer_r
->set_key(signer_r
, key
);
1658 this->signer_in
= signer_r
;
1659 this->signer_out
= signer_i
;
1663 this->signer_in
= signer_i
;
1664 this->signer_out
= signer_r
;
1667 /* SK_ei/SK_er used for encryption => crypter_in/crypter_out */
1668 if (!proposal
->get_algorithm(proposal
, ENCRYPTION_ALGORITHM
, &alg
, &key_size
))
1670 DBG1(DBG_IKE
, "no %N selected",
1671 transform_type_names
, ENCRYPTION_ALGORITHM
);
1672 prf_plus
->destroy(prf_plus
);
1675 crypter_i
= lib
->crypto
->create_crypter(lib
->crypto
, alg
, key_size
/ 8);
1676 crypter_r
= lib
->crypto
->create_crypter(lib
->crypto
, alg
, key_size
/ 8);
1677 if (crypter_i
== NULL
|| crypter_r
== NULL
)
1679 DBG1(DBG_IKE
, "%N %N (key size %d) not supported!",
1680 transform_type_names
, ENCRYPTION_ALGORITHM
,
1681 encryption_algorithm_names
, alg
, key_size
);
1682 prf_plus
->destroy(prf_plus
);
1685 key_size
= crypter_i
->get_key_size(crypter_i
);
1687 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1688 DBG4(DBG_IKE
, "Sk_ei secret %B", &key
);
1689 crypter_i
->set_key(crypter_i
, key
);
1692 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1693 DBG4(DBG_IKE
, "Sk_er secret %B", &key
);
1694 crypter_r
->set_key(crypter_r
, key
);
1699 this->crypter_in
= crypter_r
;
1700 this->crypter_out
= crypter_i
;
1704 this->crypter_in
= crypter_i
;
1705 this->crypter_out
= crypter_r
;
1708 /* SK_pi/SK_pr used for authentication => stored for later */
1709 key_size
= this->prf
->get_key_size(this->prf
);
1710 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1711 DBG4(DBG_IKE
, "Sk_pi secret %B", &key
);
1714 this->skp_build
= key
;
1718 this->skp_verify
= key
;
1720 prf_plus
->allocate_bytes(prf_plus
, key_size
, &key
);
1721 DBG4(DBG_IKE
, "Sk_pr secret %B", &key
);
1724 this->skp_verify
= key
;
1728 this->skp_build
= key
;
1731 /* all done, prf_plus not needed anymore */
1732 prf_plus
->destroy(prf_plus
);
1738 * Implementation of ike_sa_t.get_proposal.
1740 static char* get_proposal(private_ike_sa_t
*this)
1742 return this->selected_proposal
;
1746 * Implementation of ike_sa_t.set_proposal.
1748 static void set_proposal(private_ike_sa_t
*this, char *proposal
)
1750 free(this->selected_proposal
);
1751 this->selected_proposal
= strdup(proposal
);
1755 * Implementation of ike_sa_t.add_child_sa.
1757 static void add_child_sa(private_ike_sa_t
*this, child_sa_t
*child_sa
)
1759 this->child_sas
->insert_last(this->child_sas
, child_sa
);
1763 * Implementation of ike_sa_t.get_child_sa.
1765 static child_sa_t
* get_child_sa(private_ike_sa_t
*this, protocol_id_t protocol
,
1766 u_int32_t spi
, bool inbound
)
1768 iterator_t
*iterator
;
1769 child_sa_t
*current
, *found
= NULL
;
1771 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1772 while (iterator
->iterate(iterator
, (void**)¤t
))
1774 if (current
->get_spi(current
, inbound
) == spi
&&
1775 current
->get_protocol(current
) == protocol
)
1780 iterator
->destroy(iterator
);
1785 * Implementation of ike_sa_t.create_child_sa_iterator.
1787 static iterator_t
* create_child_sa_iterator(private_ike_sa_t
*this)
1789 return this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1793 * Implementation of ike_sa_t.rekey_child_sa.
1795 static status_t
rekey_child_sa(private_ike_sa_t
*this, protocol_id_t protocol
, u_int32_t spi
)
1797 child_sa_t
*child_sa
;
1798 child_rekey_t
*child_rekey
;
1800 child_sa
= get_child_sa(this, protocol
, spi
, TRUE
);
1803 child_rekey
= child_rekey_create(&this->public, child_sa
);
1804 this->task_manager
->queue_task(this->task_manager
, &child_rekey
->task
);
1805 return this->task_manager
->initiate(this->task_manager
);
1811 * Implementation of ike_sa_t.delete_child_sa.
1813 static status_t
delete_child_sa(private_ike_sa_t
*this, protocol_id_t protocol
, u_int32_t spi
)
1815 child_sa_t
*child_sa
;
1816 child_delete_t
*child_delete
;
1818 child_sa
= get_child_sa(this, protocol
, spi
, TRUE
);
1821 child_delete
= child_delete_create(&this->public, child_sa
);
1822 this->task_manager
->queue_task(this->task_manager
, &child_delete
->task
);
1823 return this->task_manager
->initiate(this->task_manager
);
1829 * Implementation of ike_sa_t.destroy_child_sa.
1831 static status_t
destroy_child_sa(private_ike_sa_t
*this, protocol_id_t protocol
,
1834 iterator_t
*iterator
;
1835 child_sa_t
*child_sa
;
1836 status_t status
= NOT_FOUND
;
1838 iterator
= this->child_sas
->create_iterator(this->child_sas
, TRUE
);
1839 while (iterator
->iterate(iterator
, (void**)&child_sa
))
1841 if (child_sa
->get_protocol(child_sa
) == protocol
&&
1842 child_sa
->get_spi(child_sa
, TRUE
) == spi
)
1844 child_sa
->destroy(child_sa
);
1845 iterator
->remove(iterator
);
1850 iterator
->destroy(iterator
);
1855 * Implementation of public_ike_sa_t.delete.
1857 static status_t
delete_(private_ike_sa_t
*this)
1859 ike_delete_t
*ike_delete
;
1861 switch (this->state
)
1863 case IKE_ESTABLISHED
:
1865 ike_delete
= ike_delete_create(&this->public, TRUE
);
1866 this->task_manager
->queue_task(this->task_manager
, &ike_delete
->task
);
1867 return this->task_manager
->initiate(this->task_manager
);
1869 SIG(IKE_DOWN_SUCCESS
, "deleting unestablished IKE_SA");
1872 SIG(IKE_DOWN_SUCCESS
, "destroying IKE_SA in state %N "
1873 "without notification", ike_sa_state_names
, this->state
);
1880 * Implementation of ike_sa_t.rekey.
1882 static status_t
rekey(private_ike_sa_t
*this)
1884 ike_rekey_t
*ike_rekey
;
1886 ike_rekey
= ike_rekey_create(&this->public, TRUE
);
1888 this->task_manager
->queue_task(this->task_manager
, &ike_rekey
->task
);
1889 return this->task_manager
->initiate(this->task_manager
);
1893 * Implementation of ike_sa_t.reauth
1895 static status_t
reauth(private_ike_sa_t
*this)
1899 /* we can't reauthenticate as responder when we use EAP or virtual IPs.
1900 * If the peer does not support RFC4478, there is no way to keep the
1902 if (!this->ike_initiator
)
1904 DBG1(DBG_IKE
, "initiator did not reauthenticate as requested");
1905 if (this->other_virtual_ip
!= NULL
||
1906 has_condition(this, COND_EAP_AUTHENTICATED
)
1908 /* if we are mediation server we too cannot reauth the IKE_SA */
1909 || this->is_mediation_server
1913 time_t now
= time(NULL
);
1915 DBG1(DBG_IKE
, "IKE_SA will timeout in %#V", &now
, &this->time
.delete);
1920 DBG1(DBG_IKE
, "reauthenticating actively");
1923 task
= (task_t
*)ike_reauth_create(&this->public);
1924 this->task_manager
->queue_task(this->task_manager
, task
);
1926 return this->task_manager
->initiate(this->task_manager
);
1930 * Implementation of ike_sa_t.reestablish
1932 static status_t
reestablish(private_ike_sa_t
*this)
1937 iterator_t
*iterator
;
1938 child_sa_t
*child_sa
;
1939 child_cfg_t
*child_cfg
;
1940 bool required
= FALSE
;
1941 status_t status
= FAILED
;
1943 /* check if we have children to keep up at all*/
1944 iterator
= create_child_sa_iterator(this);
1945 while (iterator
->iterate(iterator
, (void**)&child_sa
))
1947 child_cfg
= child_sa
->get_config(child_sa
);
1948 if (this->state
== IKE_DELETING
)
1950 action
= child_cfg
->get_close_action(child_cfg
);
1954 action
= child_cfg
->get_dpd_action(child_cfg
);
1958 case ACTION_RESTART
:
1965 iterator
->destroy(iterator
);
1967 /* we initiate the new IKE_SA of the mediation connection without CHILD_SA */
1968 if (this->peer_cfg
->is_mediation(this->peer_cfg
))
1978 /* check if we are able to reestablish this IKE_SA */
1979 if (!this->ike_initiator
&&
1980 (this->other_virtual_ip
!= NULL
||
1981 has_condition(this, COND_EAP_AUTHENTICATED
)
1983 || this->is_mediation_server
1987 DBG1(DBG_IKE
, "unable to reestablish IKE_SA due asymetric setup");
1991 new = charon
->ike_sa_manager
->checkout_new(charon
->ike_sa_manager
, TRUE
);
1992 new->set_peer_cfg(new, this->peer_cfg
);
1993 host
= this->other_host
;
1994 new->set_other_host(new, host
->clone(host
));
1995 host
= this->my_host
;
1996 new->set_my_host(new, host
->clone(host
));
1997 /* if we already have a virtual IP, we reuse it */
1998 host
= this->my_virtual_ip
;
2001 new->set_virtual_ip(new, TRUE
, host
);
2005 if (this->peer_cfg
->is_mediation(this->peer_cfg
))
2007 status
= new->initiate(new, NULL
);
2012 iterator
= create_child_sa_iterator(this);
2013 while (iterator
->iterate(iterator
, (void**)&child_sa
))
2015 child_cfg
= child_sa
->get_config(child_sa
);
2016 if (this->state
== IKE_DELETING
)
2018 action
= child_cfg
->get_close_action(child_cfg
);
2022 action
= child_cfg
->get_dpd_action(child_cfg
);
2026 case ACTION_RESTART
:
2027 DBG1(DBG_IKE
, "restarting CHILD_SA %s",
2028 child_cfg
->get_name(child_cfg
));
2029 child_cfg
->get_ref(child_cfg
);
2030 status
= new->initiate(new, child_cfg
);
2033 status
= new->route(new, child_cfg
);
2038 if (status
== DESTROY_ME
)
2043 iterator
->destroy(iterator
);
2046 if (status
== DESTROY_ME
)
2048 charon
->ike_sa_manager
->checkin_and_destroy(charon
->ike_sa_manager
, new);
2053 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, new);
2059 * Implementation of ike_sa_t.retransmit.
2061 static status_t
retransmit(private_ike_sa_t
*this, u_int32_t message_id
)
2063 this->time
.outbound
= time(NULL
);
2064 if (this->task_manager
->retransmit(this->task_manager
, message_id
) != SUCCESS
)
2066 /* send a proper signal to brief interested bus listeners */
2067 switch (this->state
)
2069 case IKE_CONNECTING
:
2071 /* retry IKE_SA_INIT if we have multiple keyingtries */
2072 u_int32_t tries
= this->peer_cfg
->get_keyingtries(this->peer_cfg
);
2074 if (tries
== 0 || tries
> this->keyingtry
)
2076 SIG(IKE_UP_FAILED
, "peer not responding, trying again "
2077 "(%d/%d) in background ", this->keyingtry
+ 1, tries
);
2079 return this->task_manager
->initiate(this->task_manager
);
2081 SIG(IKE_UP_FAILED
, "establishing IKE_SA failed, peer not responding");
2085 SIG(IKE_DOWN_FAILED
, "proper IKE_SA delete failed, peer not responding");
2088 SIG(IKE_REKEY_FAILED
, "rekeying IKE_SA failed, peer not responding");
2100 * Implementation of ike_sa_t.set_auth_lifetime.
2102 static void set_auth_lifetime(private_ike_sa_t
*this, u_int32_t lifetime
)
2105 u_int32_t reduction
= this->peer_cfg
->get_over_time(this->peer_cfg
);
2107 this->time
.reauth
= time(NULL
) + lifetime
- reduction
;
2108 job
= (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, TRUE
);
2110 if (lifetime
< reduction
)
2112 DBG1(DBG_IKE
, "received AUTH_LIFETIME of %ds, starting reauthentication",
2114 charon
->processor
->queue_job(charon
->processor
, job
);
2118 DBG1(DBG_IKE
, "received AUTH_LIFETIME of %ds, scheduling reauthentication"
2119 " in %ds", lifetime
, lifetime
- reduction
);
2120 charon
->scheduler
->schedule_job(charon
->scheduler
, job
,
2121 (lifetime
- reduction
) * 1000);
2126 * Implementation of ike_sa_t.roam.
2128 static status_t
roam(private_ike_sa_t
*this, bool address
)
2131 ike_mobike_t
*mobike
;
2133 switch (this->state
)
2141 /* responder just updates the peer about changed address config */
2142 if (!this->ike_sa_id
->is_initiator(this->ike_sa_id
))
2144 if (supports_extension(this, EXT_MOBIKE
) && address
)
2146 DBG1(DBG_IKE
, "sending address list update using MOBIKE");
2147 mobike
= ike_mobike_create(&this->public, TRUE
);
2148 this->task_manager
->queue_task(this->task_manager
, (task_t
*)mobike
);
2149 return this->task_manager
->initiate(this->task_manager
);
2154 /* get best address pair to use */
2155 other
= this->other_host
;
2156 me
= charon
->kernel_interface
->get_source_addr(charon
->kernel_interface
,
2161 if (me
->ip_equals(me
, this->my_host
) &&
2162 other
->ip_equals(other
, this->other_host
))
2164 DBG2(DBG_IKE
, "keeping connection path %H - %H", this->other_host
, me
);
2171 /* update addresses with mobike, if supported ... */
2172 if (supports_extension(this, EXT_MOBIKE
))
2174 DBG1(DBG_IKE
, "requesting address change using MOBIKE");
2175 mobike
= ike_mobike_create(&this->public, TRUE
);
2176 mobike
->roam(mobike
, address
);
2177 this->task_manager
->queue_task(this->task_manager
, (task_t
*)mobike
);
2178 return this->task_manager
->initiate(this->task_manager
);
2180 DBG1(DBG_IKE
, "reauthenticating IKE_SA due address change");
2181 /* ... reauth if not */
2182 return reauth(this);
2186 * Implementation of ike_sa_t.inherit.
2188 static status_t
inherit(private_ike_sa_t
*this, private_ike_sa_t
*other
)
2190 child_sa_t
*child_sa
;
2193 /* apply hosts and ids */
2194 this->my_host
->destroy(this->my_host
);
2195 this->other_host
->destroy(this->other_host
);
2196 this->my_id
->destroy(this->my_id
);
2197 this->other_id
->destroy(this->other_id
);
2198 this->my_host
= other
->my_host
->clone(other
->my_host
);
2199 this->other_host
= other
->other_host
->clone(other
->other_host
);
2200 this->my_id
= other
->my_id
->clone(other
->my_id
);
2201 this->other_id
= other
->other_id
->clone(other
->other_id
);
2202 this->ike_initiator
= other
->ike_initiator
;
2204 /* apply virtual assigned IPs... */
2205 if (other
->my_virtual_ip
)
2207 this->my_virtual_ip
= other
->my_virtual_ip
;
2208 other
->my_virtual_ip
= NULL
;
2210 if (other
->other_virtual_ip
)
2212 this->other_virtual_ip
= other
->other_virtual_ip
;
2213 other
->other_virtual_ip
= NULL
;
2216 /* ... and DNS servers */
2217 while (other
->dns_servers
->remove_last(other
->dns_servers
,
2218 (void**)&ip
) == SUCCESS
)
2220 this->dns_servers
->insert_first(this->dns_servers
, ip
);
2223 /* inherit NAT-T conditions */
2224 this->conditions
= other
->conditions
;
2225 if (this->conditions
& COND_NAT_HERE
)
2227 send_keepalive(this);
2231 if (other
->is_mediation_server
)
2233 act_as_mediation_server(this);
2235 else if (other
->server_reflexive_host
)
2237 this->server_reflexive_host
= other
->server_reflexive_host
->clone(
2238 other
->server_reflexive_host
);
2242 /* adopt all children */
2243 while (other
->child_sas
->remove_last(other
->child_sas
,
2244 (void**)&child_sa
) == SUCCESS
)
2246 this->child_sas
->insert_first(this->child_sas
, (void*)child_sa
);
2249 /* move pending tasks to the new IKE_SA */
2250 this->task_manager
->adopt_tasks(this->task_manager
, other
->task_manager
);
2252 /* reauthentication timeout survives a rekeying */
2253 if (other
->time
.reauth
)
2255 time_t reauth
, delete, now
= time(NULL
);
2257 this->time
.reauth
= other
->time
.reauth
;
2258 reauth
= this->time
.reauth
- now
;
2259 delete = reauth
+ this->peer_cfg
->get_over_time(this->peer_cfg
);
2260 this->time
.delete = this->time
.reauth
+ delete;
2261 DBG1(DBG_IKE
, "rescheduling reauthentication in %ds after rekeying, "
2262 "lifetime reduced to %ds", reauth
, delete);
2263 charon
->scheduler
->schedule_job(charon
->scheduler
,
2264 (job_t
*)rekey_ike_sa_job_create(this->ike_sa_id
, TRUE
),
2266 charon
->scheduler
->schedule_job(charon
->scheduler
,
2267 (job_t
*)delete_ike_sa_job_create(this->ike_sa_id
, TRUE
),
2270 /* we have to initate here, there may be new tasks to handle */
2271 return this->task_manager
->initiate(this->task_manager
);
2275 * Implementation of ike_sa_t.remove_dns_server
2277 static void remove_dns_servers(private_ike_sa_t
*this)
2281 chunk_t contents
, line
, orig_line
, token
;
2282 char string
[INET6_ADDRSTRLEN
];
2284 iterator_t
*iterator
;
2286 if (this->dns_servers
->get_count(this->dns_servers
) == 0)
2288 /* don't touch anything if we have no nameservers installed */
2292 file
= fopen(RESOLV_CONF
, "r");
2293 if (file
== NULL
|| stat(RESOLV_CONF
, &stats
) != 0)
2295 DBG1(DBG_IKE
, "unable to open DNS configuration file %s: %s",
2296 RESOLV_CONF
, strerror(errno
));
2300 contents
= chunk_alloca((size_t)stats
.st_size
);
2302 if (fread(contents
.ptr
, 1, contents
.len
, file
) != contents
.len
)
2304 DBG1(DBG_IKE
, "unable to read DNS configuration file: %s", strerror(errno
));
2310 file
= fopen(RESOLV_CONF
, "w");
2313 DBG1(DBG_IKE
, "unable to open DNS configuration file %s: %s",
2314 RESOLV_CONF
, strerror(errno
));
2318 iterator
= this->dns_servers
->create_iterator(this->dns_servers
, TRUE
);
2319 while (fetchline(&contents
, &line
))
2323 if (extract_token(&token
, ' ', &line
) &&
2324 strncasecmp(token
.ptr
, "nameserver", token
.len
) == 0)
2326 if (!extract_token(&token
, ' ', &line
))
2330 iterator
->reset(iterator
);
2331 while (iterator
->iterate(iterator
, (void**)&ip
))
2333 snprintf(string
, sizeof(string
), "%H", ip
);
2334 if (strlen(string
) == token
.len
&&
2335 strncmp(token
.ptr
, string
, token
.len
) == 0)
2337 iterator
->remove(iterator
);
2347 /* write line untouched back to file */
2348 fwrite(orig_line
.ptr
, orig_line
.len
, 1, file
);
2349 fprintf(file
, "\n");
2352 iterator
->destroy(iterator
);
2357 * Implementation of ike_sa_t.add_dns_server
2359 static void add_dns_server(private_ike_sa_t
*this, host_t
*dns
)
2365 DBG1(DBG_IKE
, "installing DNS server %H", dns
);
2367 file
= fopen(RESOLV_CONF
, "a+");
2368 if (file
== NULL
|| stat(RESOLV_CONF
, &stats
) != 0)
2370 DBG1(DBG_IKE
, "unable to open DNS configuration file %s: %s",
2371 RESOLV_CONF
, strerror(errno
));
2375 contents
= chunk_alloca(stats
.st_size
);
2377 if (fread(contents
.ptr
, 1, contents
.len
, file
) != contents
.len
)
2379 DBG1(DBG_IKE
, "unable to read DNS configuration file: %s", strerror(errno
));
2385 file
= fopen(RESOLV_CONF
, "w");
2388 DBG1(DBG_IKE
, "unable to open DNS configuration file %s: %s",
2389 RESOLV_CONF
, strerror(errno
));
2393 if (fprintf(file
, "nameserver %H # added by strongSwan, assigned by %D\n",
2394 dns
, this->other_id
) < 0)
2396 DBG1(DBG_IKE
, "unable to write DNS configuration: %s", strerror(errno
));
2400 this->dns_servers
->insert_last(this->dns_servers
, dns
->clone(dns
));
2402 fwrite(contents
.ptr
, contents
.len
, 1, file
);
2408 * Implementation of ike_sa_t.destroy.
2410 static void destroy(private_ike_sa_t
*this)
2412 this->child_sas
->destroy_offset(this->child_sas
, offsetof(child_sa_t
, destroy
));
2414 DESTROY_IF(this->crypter_in
);
2415 DESTROY_IF(this->crypter_out
);
2416 DESTROY_IF(this->signer_in
);
2417 DESTROY_IF(this->signer_out
);
2418 DESTROY_IF(this->prf
);
2419 DESTROY_IF(this->child_prf
);
2420 chunk_free(&this->skp_verify
);
2421 chunk_free(&this->skp_build
);
2422 free(this->selected_proposal
);
2424 if (this->my_virtual_ip
)
2426 charon
->kernel_interface
->del_ip(charon
->kernel_interface
,
2427 this->my_virtual_ip
);
2428 this->my_virtual_ip
->destroy(this->my_virtual_ip
);
2430 if (this->other_virtual_ip
)
2432 if (this->peer_cfg
&& this->peer_cfg
->get_pool(this->peer_cfg
))
2434 charon
->attributes
->release_address(charon
->attributes
,
2435 this->peer_cfg
->get_pool(this->peer_cfg
),
2436 this->other_virtual_ip
);
2438 this->other_virtual_ip
->destroy(this->other_virtual_ip
);
2441 remove_dns_servers(this);
2442 this->dns_servers
->destroy_offset(this->dns_servers
,
2443 offsetof(host_t
, destroy
));
2444 this->additional_addresses
->destroy_offset(this->additional_addresses
,
2445 offsetof(host_t
, destroy
));
2447 if (this->is_mediation_server
)
2449 charon
->mediation_manager
->remove(charon
->mediation_manager
, this->ike_sa_id
);
2451 DESTROY_IF(this->server_reflexive_host
);
2452 chunk_free(&this->connect_id
);
2455 DESTROY_IF(this->my_host
);
2456 DESTROY_IF(this->other_host
);
2457 DESTROY_IF(this->my_id
);
2458 DESTROY_IF(this->other_id
);
2460 DESTROY_IF(this->ike_cfg
);
2461 DESTROY_IF(this->peer_cfg
);
2462 DESTROY_IF(this->my_auth
);
2463 DESTROY_IF(this->other_auth
);
2465 this->ike_sa_id
->destroy(this->ike_sa_id
);
2466 this->task_manager
->destroy(this->task_manager
);
2471 * Described in header.
2473 ike_sa_t
* ike_sa_create(ike_sa_id_t
*ike_sa_id
)
2475 private_ike_sa_t
*this = malloc_thing(private_ike_sa_t
);
2476 static u_int32_t unique_id
= 0;
2478 /* Public functions */
2479 this->public.get_state
= (ike_sa_state_t (*)(ike_sa_t
*)) get_state
;
2480 this->public.set_state
= (void (*)(ike_sa_t
*,ike_sa_state_t
)) set_state
;
2481 this->public.get_name
= (char* (*)(ike_sa_t
*))get_name
;
2482 this->public.get_statistic
= (u_int32_t(*)(ike_sa_t
*, statistic_t kind
))get_statistic
;
2483 this->public.process_message
= (status_t (*)(ike_sa_t
*, message_t
*)) process_message
;
2484 this->public.initiate
= (status_t (*)(ike_sa_t
*,child_cfg_t
*)) initiate
;
2485 this->public.route
= (status_t (*)(ike_sa_t
*,child_cfg_t
*)) route
;
2486 this->public.unroute
= (status_t (*)(ike_sa_t
*,u_int32_t
)) unroute
;
2487 this->public.acquire
= (status_t (*)(ike_sa_t
*,u_int32_t
)) acquire
;
2488 this->public.get_ike_cfg
= (ike_cfg_t
* (*)(ike_sa_t
*))get_ike_cfg
;
2489 this->public.set_ike_cfg
= (void (*)(ike_sa_t
*,ike_cfg_t
*))set_ike_cfg
;
2490 this->public.get_peer_cfg
= (peer_cfg_t
* (*)(ike_sa_t
*))get_peer_cfg
;
2491 this->public.set_peer_cfg
= (void (*)(ike_sa_t
*,peer_cfg_t
*))set_peer_cfg
;
2492 this->public.get_my_auth
= (auth_info_t
*(*)(ike_sa_t
*))get_my_auth
;
2493 this->public.get_other_auth
= (auth_info_t
*(*)(ike_sa_t
*))get_other_auth
;
2494 this->public.get_id
= (ike_sa_id_t
* (*)(ike_sa_t
*)) get_id
;
2495 this->public.get_my_host
= (host_t
* (*)(ike_sa_t
*)) get_my_host
;
2496 this->public.set_my_host
= (void (*)(ike_sa_t
*,host_t
*)) set_my_host
;
2497 this->public.get_other_host
= (host_t
* (*)(ike_sa_t
*)) get_other_host
;
2498 this->public.set_other_host
= (void (*)(ike_sa_t
*,host_t
*)) set_other_host
;
2499 this->public.update_hosts
= (void(*)(ike_sa_t
*, host_t
*me
, host_t
*other
))update_hosts
;
2500 this->public.get_my_id
= (identification_t
* (*)(ike_sa_t
*)) get_my_id
;
2501 this->public.set_my_id
= (void (*)(ike_sa_t
*,identification_t
*)) set_my_id
;
2502 this->public.get_other_id
= (identification_t
* (*)(ike_sa_t
*)) get_other_id
;
2503 this->public.set_other_id
= (void (*)(ike_sa_t
*,identification_t
*)) set_other_id
;
2504 this->public.enable_extension
= (void(*)(ike_sa_t
*, ike_extension_t extension
))enable_extension
;
2505 this->public.supports_extension
= (bool(*)(ike_sa_t
*, ike_extension_t extension
))supports_extension
;
2506 this->public.set_condition
= (void (*)(ike_sa_t
*, ike_condition_t
,bool)) set_condition
;
2507 this->public.has_condition
= (bool (*)(ike_sa_t
*,ike_condition_t
)) has_condition
;
2508 this->public.set_pending_updates
= (void(*)(ike_sa_t
*, u_int32_t updates
))set_pending_updates
;
2509 this->public.get_pending_updates
= (u_int32_t(*)(ike_sa_t
*))get_pending_updates
;
2510 this->public.is_ike_initiator
= (bool (*)(ike_sa_t
*))is_ike_initiator
;
2511 this->public.create_additional_address_iterator
= (iterator_t
*(*)(ike_sa_t
*))create_additional_address_iterator
;
2512 this->public.add_additional_address
= (void(*)(ike_sa_t
*, host_t
*host
))add_additional_address
;
2513 this->public.retransmit
= (status_t (*)(ike_sa_t
*, u_int32_t
)) retransmit
;
2514 this->public.delete = (status_t (*)(ike_sa_t
*))delete_
;
2515 this->public.destroy
= (void (*)(ike_sa_t
*))destroy
;
2516 this->public.send_dpd
= (status_t (*)(ike_sa_t
*)) send_dpd
;
2517 this->public.send_keepalive
= (void (*)(ike_sa_t
*)) send_keepalive
;
2518 this->public.get_prf
= (prf_t
* (*)(ike_sa_t
*)) get_prf
;
2519 this->public.get_child_prf
= (prf_t
* (*)(ike_sa_t
*)) get_child_prf
;
2520 this->public.get_skp_verify
= (chunk_t (*)(ike_sa_t
*)) get_skp_verify
;
2521 this->public.get_skp_build
= (chunk_t (*)(ike_sa_t
*)) get_skp_build
;
2522 this->public.derive_keys
= (status_t (*)(ike_sa_t
*,proposal_t
*,chunk_t
,chunk_t
,chunk_t
,bool,prf_t
*,prf_t
*)) derive_keys
;
2523 this->public.get_proposal
= (char* (*)(ike_sa_t
*)) get_proposal
;
2524 this->public.set_proposal
= (void (*)(ike_sa_t
*,char*)) set_proposal
;
2525 this->public.add_child_sa
= (void (*)(ike_sa_t
*,child_sa_t
*)) add_child_sa
;
2526 this->public.get_child_sa
= (child_sa_t
* (*)(ike_sa_t
*,protocol_id_t
,u_int32_t
,bool)) get_child_sa
;
2527 this->public.create_child_sa_iterator
= (iterator_t
* (*)(ike_sa_t
*)) create_child_sa_iterator
;
2528 this->public.rekey_child_sa
= (status_t (*)(ike_sa_t
*,protocol_id_t
,u_int32_t
)) rekey_child_sa
;
2529 this->public.delete_child_sa
= (status_t (*)(ike_sa_t
*,protocol_id_t
,u_int32_t
)) delete_child_sa
;
2530 this->public.destroy_child_sa
= (status_t (*)(ike_sa_t
*,protocol_id_t
,u_int32_t
))destroy_child_sa
;
2531 this->public.rekey
= (status_t (*)(ike_sa_t
*))rekey
;
2532 this->public.reauth
= (status_t (*)(ike_sa_t
*))reauth
;
2533 this->public.reestablish
= (status_t (*)(ike_sa_t
*))reestablish
;
2534 this->public.set_auth_lifetime
= (void(*)(ike_sa_t
*, u_int32_t lifetime
))set_auth_lifetime
;
2535 this->public.roam
= (status_t(*)(ike_sa_t
*,bool))roam
;
2536 this->public.inherit
= (status_t (*)(ike_sa_t
*,ike_sa_t
*))inherit
;
2537 this->public.generate_message
= (status_t (*)(ike_sa_t
*,message_t
*,packet_t
**))generate_message
;
2538 this->public.reset
= (void (*)(ike_sa_t
*))reset
;
2539 this->public.get_unique_id
= (u_int32_t (*)(ike_sa_t
*))get_unique_id
;
2540 this->public.set_virtual_ip
= (void (*)(ike_sa_t
*,bool,host_t
*))set_virtual_ip
;
2541 this->public.get_virtual_ip
= (host_t
* (*)(ike_sa_t
*,bool))get_virtual_ip
;
2542 this->public.add_dns_server
= (void (*)(ike_sa_t
*,host_t
*))add_dns_server
;
2544 this->public.act_as_mediation_server
= (void (*)(ike_sa_t
*)) act_as_mediation_server
;
2545 this->public.get_server_reflexive_host
= (host_t
* (*)(ike_sa_t
*)) get_server_reflexive_host
;
2546 this->public.set_server_reflexive_host
= (void (*)(ike_sa_t
*,host_t
*)) set_server_reflexive_host
;
2547 this->public.get_connect_id
= (chunk_t (*)(ike_sa_t
*)) get_connect_id
;
2548 this->public.initiate_mediation
= (status_t (*)(ike_sa_t
*,peer_cfg_t
*)) initiate_mediation
;
2549 this->public.initiate_mediated
= (status_t (*)(ike_sa_t
*,host_t
*,host_t
*,chunk_t
)) initiate_mediated
;
2550 this->public.relay
= (status_t (*)(ike_sa_t
*,identification_t
*,chunk_t
,chunk_t
,linked_list_t
*,bool)) relay
;
2551 this->public.callback
= (status_t (*)(ike_sa_t
*,identification_t
*)) callback
;
2552 this->public.respond
= (status_t (*)(ike_sa_t
*,identification_t
*,chunk_t
)) respond
;
2555 /* initialize private fields */
2556 this->ike_sa_id
= ike_sa_id
->clone(ike_sa_id
);
2557 this->child_sas
= linked_list_create();
2558 this->my_host
= host_create_from_string("0.0.0.0", IKEV2_UDP_PORT
);
2559 this->other_host
= host_create_from_string("0.0.0.0", IKEV2_UDP_PORT
);
2560 this->my_id
= identification_create_from_encoding(ID_ANY
, chunk_empty
);
2561 this->other_id
= identification_create_from_encoding(ID_ANY
, chunk_empty
);
2562 this->extensions
= 0;
2563 this->conditions
= 0;
2564 this->selected_proposal
= NULL
;
2565 this->crypter_in
= NULL
;
2566 this->crypter_out
= NULL
;
2567 this->signer_in
= NULL
;
2568 this->signer_out
= NULL
;
2570 this->skp_verify
= chunk_empty
;
2571 this->skp_build
= chunk_empty
;
2572 this->child_prf
= NULL
;
2573 this->state
= IKE_CREATED
;
2574 this->time
.inbound
= this->time
.outbound
= time(NULL
);
2575 this->time
.established
= 0;
2576 this->time
.rekey
= 0;
2577 this->time
.reauth
= 0;
2578 this->time
.delete = 0;
2579 this->ike_cfg
= NULL
;
2580 this->peer_cfg
= NULL
;
2581 this->my_auth
= auth_info_create();
2582 this->other_auth
= auth_info_create();
2583 this->task_manager
= task_manager_create(&this->public);
2584 this->unique_id
= ++unique_id
;
2585 this->my_virtual_ip
= NULL
;
2586 this->other_virtual_ip
= NULL
;
2587 this->dns_servers
= linked_list_create();
2588 this->additional_addresses
= linked_list_create();
2589 this->pending_updates
= 0;
2590 this->keyingtry
= 0;
2591 this->ike_initiator
= FALSE
;
2593 this->is_mediation_server
= FALSE
;
2594 this->server_reflexive_host
= NULL
;
2595 this->connect_id
= chunk_empty
;
2598 return &this->public;