added API for random number generators, served through credential factory
[strongswan.git] / src / charon / sa / tasks / ike_me.c
1 /*
2 * Copyright (C) 2007-2008 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include "ike_me.h"
19
20 #include <string.h>
21
22 #include <daemon.h>
23 #include <config/peer_cfg.h>
24 #include <encoding/payloads/id_payload.h>
25 #include <encoding/payloads/notify_payload.h>
26 #include <encoding/payloads/endpoint_notify.h>
27 #include <processing/jobs/mediation_job.h>
28
29 #define ME_CONNECTID_LEN 4
30 #define ME_CONNECTKEY_LEN 16
31
32 typedef struct private_ike_me_t private_ike_me_t;
33
34 /**
35 * Private members of a ike_me_t task.
36 */
37 struct private_ike_me_t {
38
39 /**
40 * Public methods and task_t interface.
41 */
42 ike_me_t public;
43
44 /**
45 * Assigned IKE_SA.
46 */
47 ike_sa_t *ike_sa;
48
49 /**
50 * Are we the initiator?
51 */
52 bool initiator;
53
54 /**
55 * Is this a mediation connection?
56 */
57 bool mediation;
58
59 /**
60 * Is this the response from another peer?
61 */
62 bool response;
63
64 /**
65 * Gathered endpoints
66 */
67 linked_list_t *local_endpoints;
68
69 /**
70 * Parsed endpoints
71 */
72 linked_list_t *remote_endpoints;
73
74 /**
75 * Did the peer request a callback?
76 */
77 bool callback;
78
79 /**
80 * Did the connect fail?
81 */
82 bool failed;
83
84 /**
85 * Was there anything wrong with the payloads?
86 */
87 bool invalid_syntax;
88
89 /**
90 * The requested peer
91 */
92 identification_t *peer_id;
93 /**
94 * Received ID used for connectivity checks
95 */
96 chunk_t connect_id;
97
98 /**
99 * Received key used for connectivity checks
100 */
101 chunk_t connect_key;
102
103 /**
104 * Peer config of the mediated connection
105 */
106 peer_cfg_t *mediated_cfg;
107
108 };
109
110 /**
111 * Adds a list of endpoints as notifies to a given message
112 */
113 static void add_endpoints_to_message(message_t *message, linked_list_t *endpoints)
114 {
115 iterator_t *iterator;
116 endpoint_notify_t *endpoint;
117
118 iterator = endpoints->create_iterator(endpoints, TRUE);
119 while (iterator->iterate(iterator, (void**)&endpoint))
120 {
121 message->add_payload(message, (payload_t*)endpoint->build_notify(endpoint));
122 }
123 iterator->destroy(iterator);
124 }
125
126 /**
127 * Gathers endpoints and adds them to the current message
128 */
129 static void gather_and_add_endpoints(private_ike_me_t *this, message_t *message)
130 {
131 iterator_t *iterator;
132 host_t *addr, *host;
133 u_int16_t port;
134
135 /* get the port that is used to communicate with the ms */
136 host = this->ike_sa->get_my_host(this->ike_sa);
137 port = host->get_port(host);
138
139 iterator = charon->kernel_interface->create_address_iterator(
140 charon->kernel_interface);
141 while (iterator->iterate(iterator, (void**)&addr))
142 {
143 host = addr->clone(addr);
144 host->set_port(host, port);
145
146 this->local_endpoints->insert_last(this->local_endpoints,
147 endpoint_notify_create_from_host(HOST, host, NULL));
148
149 host->destroy(host);
150 }
151 iterator->destroy(iterator);
152
153 host = this->ike_sa->get_server_reflexive_host(this->ike_sa);
154 if (host)
155 {
156 this->local_endpoints->insert_last(this->local_endpoints,
157 endpoint_notify_create_from_host(SERVER_REFLEXIVE, host,
158 this->ike_sa->get_my_host(this->ike_sa)));
159 }
160
161 add_endpoints_to_message(message, this->local_endpoints);
162 }
163
164 /**
165 * read notifys from message and evaluate them
166 */
167 static void process_payloads(private_ike_me_t *this, message_t *message)
168 {
169 iterator_t *iterator;
170 payload_t *payload;
171
172 iterator = message->get_payload_iterator(message);
173 while (iterator->iterate(iterator, (void**)&payload))
174 {
175 if (payload->get_type(payload) != NOTIFY)
176 {
177 continue;
178 }
179
180 notify_payload_t *notify = (notify_payload_t*)payload;
181
182 switch (notify->get_notify_type(notify))
183 {
184 case ME_CONNECT_FAILED:
185 {
186 DBG2(DBG_IKE, "received ME_CONNECT_FAILED notify");
187 this->failed = TRUE;
188 break;
189 }
190 case ME_MEDIATION:
191 {
192 DBG2(DBG_IKE, "received ME_MEDIATION notify");
193 this->mediation = TRUE;
194 break;
195 }
196 case ME_ENDPOINT:
197 {
198 endpoint_notify_t *endpoint = endpoint_notify_create_from_payload(notify);
199 if (!endpoint)
200 {
201 DBG1(DBG_IKE, "received invalid ME_ENDPOINT notify");
202 break;
203 }
204 DBG1(DBG_IKE, "received %N ME_ENDPOINT %#H", me_endpoint_type_names,
205 endpoint->get_type(endpoint), endpoint->get_host(endpoint));
206
207 this->remote_endpoints->insert_last(this->remote_endpoints, endpoint);
208 break;
209 }
210 case ME_CALLBACK:
211 {
212 DBG2(DBG_IKE, "received ME_CALLBACK notify");
213 this->callback = TRUE;
214 break;
215 }
216 case ME_CONNECTID:
217 {
218 chunk_free(&this->connect_id);
219 this->connect_id = chunk_clone(notify->get_notification_data(notify));
220 DBG2(DBG_IKE, "received ME_CONNECTID %#B", &this->connect_id);
221 break;
222 }
223 case ME_CONNECTKEY:
224 {
225 chunk_free(&this->connect_key);
226 this->connect_key = chunk_clone(notify->get_notification_data(notify));
227 DBG4(DBG_IKE, "received ME_CONNECTKEY %#B", &this->connect_key);
228 break;
229 }
230 case ME_RESPONSE:
231 {
232 DBG2(DBG_IKE, "received ME_RESPONSE notify");
233 this->response = TRUE;
234 break;
235 }
236 default:
237 break;
238 }
239 }
240 iterator->destroy(iterator);
241 }
242
243 /**
244 * Implementation of task_t.build for initiator
245 */
246 static status_t build_i(private_ike_me_t *this, message_t *message)
247 {
248 switch(message->get_exchange_type(message))
249 {
250 case IKE_SA_INIT:
251 {
252 peer_cfg_t *peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
253 if (peer_cfg->is_mediation(peer_cfg))
254 {
255 DBG2(DBG_IKE, "adding ME_MEDIATION");
256 message->add_notify(message, FALSE, ME_MEDIATION, chunk_empty);
257 }
258 else
259 {
260 return SUCCESS;
261 }
262 break;
263 }
264 case IKE_AUTH:
265 {
266 if (this->ike_sa->has_condition(this->ike_sa, COND_NAT_HERE))
267 {
268 endpoint_notify_t *endpoint = endpoint_notify_create_from_host(SERVER_REFLEXIVE, NULL, NULL);
269 message->add_payload(message, (payload_t*)endpoint->build_notify(endpoint));
270 endpoint->destroy(endpoint);
271 }
272 break;
273 }
274 case ME_CONNECT:
275 {
276 id_payload_t *id_payload;
277 rng_t *rng;
278
279 id_payload = id_payload_create_from_identification(ID_PEER, this->peer_id);
280 message->add_payload(message, (payload_t*)id_payload);
281
282 rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
283 if (!rng)
284 {
285 DBG1(DBG_IKE, "unable to generate connect ID for ME_CONNECT");
286 return FAILED;
287 }
288 if (!this->response)
289 {
290 /* only the initiator creates a connect ID. the responder returns
291 * the connect ID that it received from the initiator */
292 rng->allocate_bytes(rng, ME_CONNECTID_LEN, &this->connect_id);
293 }
294 rng->allocate_bytes(rng, ME_CONNECTKEY_LEN, &this->connect_key);
295 rng->destroy(rng);
296
297 message->add_notify(message, FALSE, ME_CONNECTID, this->connect_id);
298 message->add_notify(message, FALSE, ME_CONNECTKEY, this->connect_key);
299
300 if (this->response)
301 {
302 message->add_notify(message, FALSE, ME_RESPONSE, chunk_empty);
303 }
304 else
305 {
306 /* FIXME: should we make that configurable? */
307 message->add_notify(message, FALSE, ME_CALLBACK, chunk_empty);
308 }
309
310 gather_and_add_endpoints(this, message);
311
312 break;
313 }
314 default:
315 break;
316 }
317 return NEED_MORE;
318 }
319
320 /**
321 * Implementation of task_t.process for responder
322 */
323 static status_t process_r(private_ike_me_t *this, message_t *message)
324 {
325 switch(message->get_exchange_type(message))
326 {
327 case ME_CONNECT:
328 {
329 id_payload_t *id_payload;
330 id_payload = (id_payload_t*)message->get_payload(message, ID_PEER);
331 if (!id_payload)
332 {
333 DBG1(DBG_IKE, "received ME_CONNECT without ID_PEER payload, aborting");
334 break;
335 }
336 this->peer_id = id_payload->get_identification(id_payload);
337
338 process_payloads(this, message);
339
340 if (this->callback)
341 {
342 DBG1(DBG_IKE, "received ME_CALLBACK for '%D'", this->peer_id);
343 break;
344 }
345
346 if (!this->connect_id.ptr)
347 {
348 DBG1(DBG_IKE, "received ME_CONNECT without ME_CONNECTID notify, aborting");
349 this->invalid_syntax = TRUE;
350 break;
351 }
352
353 if (!this->connect_key.ptr)
354 {
355 DBG1(DBG_IKE, "received ME_CONNECT without ME_CONNECTKEY notify, aborting");
356 this->invalid_syntax = TRUE;
357 break;
358 }
359
360 if (!this->remote_endpoints->get_count(this->remote_endpoints))
361 {
362 DBG1(DBG_IKE, "received ME_CONNECT without any ME_ENDPOINT payloads, aborting");
363 this->invalid_syntax = TRUE;
364 break;
365 }
366
367 DBG1(DBG_IKE, "received ME_CONNECT");
368 break;
369 }
370 default:
371 break;
372 }
373 return NEED_MORE;
374 }
375
376 /**
377 * Implementation of task_t.build for responder
378 */
379 static status_t build_r(private_ike_me_t *this, message_t *message)
380 {
381 switch(message->get_exchange_type(message))
382 {
383 case ME_CONNECT:
384 {
385 if (this->invalid_syntax)
386 {
387 message->add_notify(message, TRUE, INVALID_SYNTAX, chunk_empty);
388 break;
389 }
390
391 if (this->callback)
392 {
393 charon->connect_manager->check_and_initiate(charon->connect_manager,
394 this->ike_sa->get_id(this->ike_sa),
395 this->ike_sa->get_my_id(this->ike_sa), this->peer_id);
396 return SUCCESS;
397 }
398
399 if (this->response)
400 {
401 /* FIXME: handle result of set_responder_data
402 * as initiator, upon receiving a response from another peer,
403 * update the checklist and start sending checks */
404 charon->connect_manager->set_responder_data(charon->connect_manager,
405 this->connect_id, this->connect_key, this->remote_endpoints);
406 }
407 else
408 {
409 /* FIXME: handle result of set_initiator_data
410 * as responder, create a checklist with the initiator's data */
411 charon->connect_manager->set_initiator_data(charon->connect_manager,
412 this->peer_id, this->ike_sa->get_my_id(this->ike_sa),
413 this->connect_id, this->connect_key, this->remote_endpoints,
414 FALSE);
415 if (this->ike_sa->respond(this->ike_sa, this->peer_id,
416 this->connect_id) != SUCCESS)
417 {
418 return FAILED;
419 }
420 }
421 break;
422 }
423 default:
424 break;
425 }
426 return SUCCESS;
427 }
428
429 /**
430 * Implementation of task_t.process for initiator
431 */
432 static status_t process_i(private_ike_me_t *this, message_t *message)
433 {
434 switch(message->get_exchange_type(message))
435 {
436 case IKE_SA_INIT:
437 {
438 process_payloads(this, message);
439
440 if (!this->mediation)
441 {
442 DBG1(DBG_IKE, "server did not return a ME_MEDIATION, aborting");
443 return FAILED;
444 }
445
446 return NEED_MORE;
447 }
448 case IKE_AUTH:
449 {
450 process_payloads(this, message);
451 /* FIXME: we should update the server reflexive endpoint somehow,
452 * if mobike notices a change */
453 endpoint_notify_t *reflexive;
454 if (this->remote_endpoints->get_first(this->remote_endpoints,
455 (void**)&reflexive) == SUCCESS &&
456 reflexive->get_type(reflexive) == SERVER_REFLEXIVE)
457 { /* FIXME: should we accept this endpoint even if we did not send
458 * a request? */
459 host_t *endpoint = reflexive->get_host(reflexive);
460
461 this->ike_sa->set_server_reflexive_host(this->ike_sa, endpoint->clone(endpoint));
462 }
463 /* FIXME: what if it failed? e.g. AUTH failure */
464 SIG(CHILD_UP_SUCCESS, "established mediation connection without CHILD_SA successfully");
465
466 break;
467 }
468 case ME_CONNECT:
469 {
470 process_payloads(this, message);
471
472 if (this->failed)
473 {
474 DBG1(DBG_IKE, "peer '%D' is not online", this->peer_id);
475 /* FIXME: notify the mediated connection (job?) */
476 }
477 else
478 {
479 if (this->response)
480 {
481 /* FIXME: handle result of set_responder_data.
482 * as responder, we update the checklist and start sending checks */
483 charon->connect_manager->set_responder_data(charon->connect_manager,
484 this->connect_id, this->connect_key, this->local_endpoints);
485 }
486 else
487 {
488 /* FIXME: handle result of set_initiator_data
489 * as initiator, we create a checklist and set the initiator's data */
490 charon->connect_manager->set_initiator_data(charon->connect_manager,
491 this->ike_sa->get_my_id(this->ike_sa), this->peer_id,
492 this->connect_id, this->connect_key, this->local_endpoints,
493 TRUE);
494 /* FIXME: also start a timer for the whole transaction (maybe
495 * within the connect_manager?) */
496 }
497 }
498 break;
499 }
500 default:
501 break;
502 }
503 return SUCCESS;
504 }
505
506 /**
507 * Implementation of task_t.build for initiator (mediation server)
508 */
509 static status_t build_i_ms(private_ike_me_t *this, message_t *message)
510 {
511 switch(message->get_exchange_type(message))
512 {
513 case ME_CONNECT:
514 {
515 id_payload_t *id_payload = id_payload_create_from_identification(ID_PEER, this->peer_id);
516 message->add_payload(message, (payload_t*)id_payload);
517
518 if (this->callback)
519 {
520 message->add_notify(message, FALSE, ME_CALLBACK, chunk_empty);
521 }
522 else
523 {
524 if (this->response)
525 {
526 message->add_notify(message, FALSE, ME_RESPONSE, chunk_empty);
527 }
528 message->add_notify(message, FALSE, ME_CONNECTID, this->connect_id);
529 message->add_notify(message, FALSE, ME_CONNECTKEY, this->connect_key);
530
531 add_endpoints_to_message(message, this->remote_endpoints);
532 }
533 break;
534 }
535 default:
536 break;
537 }
538
539 return NEED_MORE;
540 }
541
542 /**
543 * Implementation of task_t.process for responder (mediation server)
544 */
545 static status_t process_r_ms(private_ike_me_t *this, message_t *message)
546 {
547 switch(message->get_exchange_type(message))
548 {
549 case IKE_SA_INIT:
550 {
551 /* FIXME: we should check for SA* and TS* payloads
552 * if any are there send NO_ADDITIONAL_SAS back and delete this SA */
553 process_payloads(this, message);
554 return this->mediation ? NEED_MORE : SUCCESS;
555 }
556 case IKE_AUTH:
557 {
558 /* FIXME: we should check whether the current peer_config is configured
559 * as mediation connection */
560 process_payloads(this, message);
561 break;
562 }
563 case CREATE_CHILD_SA:
564 {
565 /* FIXME: if this is not to rekey the IKE SA we have to return a
566 * NO_ADDITIONAL_SAS and then delete the SA */
567 break;
568 }
569 case ME_CONNECT:
570 {
571 id_payload_t *id_payload;
572 id_payload = (id_payload_t*)message->get_payload(message, ID_PEER);
573 if (!id_payload)
574 {
575 DBG1(DBG_IKE, "received ME_CONNECT without ID_PEER payload, aborting");
576 this->invalid_syntax = TRUE;
577 break;
578 }
579
580 this->peer_id = id_payload->get_identification(id_payload);
581
582 process_payloads(this, message);
583
584 if (!this->connect_id.ptr)
585 {
586 DBG1(DBG_IKE, "received ME_CONNECT without ME_CONNECTID notify, aborting");
587 this->invalid_syntax = TRUE;
588 break;
589 }
590
591 if (!this->connect_key.ptr)
592 {
593 DBG1(DBG_IKE, "received ME_CONNECT without ME_CONNECTKEY notify, aborting");
594 this->invalid_syntax = TRUE;
595 break;
596 }
597
598 if (!this->remote_endpoints->get_count(this->remote_endpoints))
599 {
600 DBG1(DBG_IKE, "received ME_CONNECT without any ME_ENDPOINT payloads, aborting");
601 this->invalid_syntax = TRUE;
602 break;
603 }
604 break;
605 }
606 default:
607 break;
608 }
609
610 return NEED_MORE;
611 }
612
613 /**
614 * Implementation of task_t.build for responder (mediation server)
615 */
616 static status_t build_r_ms(private_ike_me_t *this, message_t *message)
617 {
618 switch(message->get_exchange_type(message))
619 {
620 case IKE_SA_INIT:
621 {
622 message->add_notify(message, FALSE, ME_MEDIATION, chunk_empty);
623 return NEED_MORE;
624 }
625 case IKE_AUTH:
626 {
627 endpoint_notify_t *endpoint;
628 if (this->remote_endpoints->get_first(this->remote_endpoints, (void**)&endpoint) == SUCCESS &&
629 endpoint->get_type(endpoint) == SERVER_REFLEXIVE)
630 {
631 host_t *host = this->ike_sa->get_other_host(this->ike_sa);
632
633 DBG2(DBG_IKE, "received request for a server reflexive endpoint "
634 "sending: %#H", host);
635
636 endpoint = endpoint_notify_create_from_host(SERVER_REFLEXIVE, host, NULL);
637 message->add_payload(message, (payload_t*)endpoint->build_notify(endpoint));
638 endpoint->destroy(endpoint);
639 }
640
641 /* FIXME: we actually must delete any existing IKE_SAs with the same remote id */
642 this->ike_sa->act_as_mediation_server(this->ike_sa);
643
644 SIG(CHILD_UP_SUCCESS, "established mediation connection without CHILD_SA successfully");
645
646 break;
647 }
648 case ME_CONNECT:
649 {
650 if (this->invalid_syntax)
651 {
652 message->add_notify(message, TRUE, INVALID_SYNTAX, chunk_empty);
653 break;
654 }
655
656 ike_sa_id_t *peer_sa;
657 if (this->callback)
658 {
659 peer_sa = charon->mediation_manager->check_and_register(charon->mediation_manager,
660 this->peer_id, this->ike_sa->get_other_id(this->ike_sa));
661 }
662 else
663 {
664 peer_sa = charon->mediation_manager->check(charon->mediation_manager,
665 this->peer_id);
666 }
667
668 if (!peer_sa)
669 {
670 /* the peer is not online */
671 message->add_notify(message, TRUE, ME_CONNECT_FAILED, chunk_empty);
672 break;
673 }
674
675 job_t *job = (job_t*)mediation_job_create(this->peer_id,
676 this->ike_sa->get_other_id(this->ike_sa), this->connect_id,
677 this->connect_key, this->remote_endpoints, this->response);
678 charon->processor->queue_job(charon->processor, job);
679
680 break;
681 }
682 default:
683 break;
684 }
685 return SUCCESS;
686 }
687
688 /**
689 * Implementation of task_t.process for initiator (mediation server)
690 */
691 static status_t process_i_ms(private_ike_me_t *this, message_t *message)
692 {
693 /* FIXME: theoretically we should be prepared to receive a ME_CONNECT_FAILED
694 * here if the responding peer is not able to proceed. in this case we shall
695 * notify the initiating peer with a ME_CONNECT request containing only a
696 * ME_CONNECT_FAILED */
697 return SUCCESS;
698 }
699
700 /**
701 * Implementation of ike_me.connect
702 */
703 static void me_connect(private_ike_me_t *this, identification_t *peer_id)
704 {
705 this->peer_id = peer_id->clone(peer_id);
706 }
707
708 /**
709 * Implementation of ike_me.respond
710 */
711 static void me_respond(private_ike_me_t *this, identification_t *peer_id,
712 chunk_t connect_id)
713 {
714 this->peer_id = peer_id->clone(peer_id);
715 this->connect_id = chunk_clone(connect_id);
716 this->response = TRUE;
717 }
718
719 /**
720 * Implementation of ike_me.callback
721 */
722 static void me_callback(private_ike_me_t *this, identification_t *peer_id)
723 {
724 this->peer_id = peer_id->clone(peer_id);
725 this->callback = TRUE;
726 }
727
728 /**
729 * Implementation of ike_me.relay
730 */
731 static void relay(private_ike_me_t *this, identification_t *requester, chunk_t connect_id,
732 chunk_t connect_key, linked_list_t *endpoints, bool response)
733 {
734 this->peer_id = requester->clone(requester);
735 this->connect_id = chunk_clone(connect_id);
736 this->connect_key = chunk_clone(connect_key);
737
738 this->remote_endpoints->destroy_offset(this->remote_endpoints, offsetof(endpoint_notify_t, destroy));
739 this->remote_endpoints = endpoints->clone_offset(endpoints, offsetof(endpoint_notify_t, clone));
740
741 this->response = response;
742 }
743
744 /**
745 * Implementation of task_t.get_type
746 */
747 static task_type_t get_type(private_ike_me_t *this)
748 {
749 return IKE_ME;
750 }
751
752 /**
753 * Implementation of task_t.migrate
754 */
755 static void migrate(private_ike_me_t *this, ike_sa_t *ike_sa)
756 {
757 this->ike_sa = ike_sa;
758 }
759
760 /**
761 * Implementation of task_t.destroy
762 */
763 static void destroy(private_ike_me_t *this)
764 {
765 DESTROY_IF(this->peer_id);
766
767 chunk_free(&this->connect_id);
768 chunk_free(&this->connect_key);
769
770 this->local_endpoints->destroy_offset(this->local_endpoints, offsetof(endpoint_notify_t, destroy));
771 this->remote_endpoints->destroy_offset(this->remote_endpoints, offsetof(endpoint_notify_t, destroy));
772
773 DESTROY_IF(this->mediated_cfg);
774 free(this);
775 }
776
777 /*
778 * Described in header.
779 */
780 ike_me_t *ike_me_create(ike_sa_t *ike_sa, bool initiator)
781 {
782 private_ike_me_t *this = malloc_thing(private_ike_me_t);
783
784 this->public.task.get_type = (task_type_t(*)(task_t*))get_type;
785 this->public.task.migrate = (void(*)(task_t*,ike_sa_t*))migrate;
786 this->public.task.destroy = (void(*)(task_t*))destroy;
787
788 if (ike_sa->is_ike_initiator(ike_sa))
789 {
790 if (initiator)
791 {
792 this->public.task.build = (status_t(*)(task_t*,message_t*))build_i;
793 this->public.task.process = (status_t(*)(task_t*,message_t*))process_i;
794 }
795 else
796 {
797 this->public.task.build = (status_t(*)(task_t*,message_t*))build_r;
798 this->public.task.process = (status_t(*)(task_t*,message_t*))process_r;
799 }
800 }
801 else
802 {
803 /* mediation server */
804 if (initiator)
805 {
806 this->public.task.build = (status_t(*)(task_t*,message_t*))build_i_ms;
807 this->public.task.process = (status_t(*)(task_t*,message_t*))process_i_ms;
808 }
809 else
810 {
811 this->public.task.build = (status_t(*)(task_t*,message_t*))build_r_ms;
812 this->public.task.process = (status_t(*)(task_t*,message_t*))process_r_ms;
813 }
814 }
815
816 this->public.connect = (void(*)(ike_me_t*,identification_t*))me_connect;
817 this->public.respond = (void(*)(ike_me_t*,identification_t*,chunk_t))me_respond;
818 this->public.callback = (void(*)(ike_me_t*,identification_t*))me_callback;
819 this->public.relay = (void(*)(ike_me_t*,identification_t*,chunk_t,chunk_t,linked_list_t*,bool))relay;
820
821 this->ike_sa = ike_sa;
822 this->initiator = initiator;
823
824 this->peer_id = NULL;
825 this->connect_id = chunk_empty;
826 this->connect_key = chunk_empty;
827 this->local_endpoints = linked_list_create();
828 this->remote_endpoints = linked_list_create();
829 this->mediation = FALSE;
830 this->response = FALSE;
831 this->callback = FALSE;
832 this->failed = FALSE;
833 this->invalid_syntax = FALSE;
834
835 this->mediated_cfg = NULL;
836
837 return &this->public;
838 }