stroke: Add support for address range definitions of in-memory pools
[strongswan.git] / src / libcharon / plugins / stroke / stroke_config.c
1 /*
2 * Copyright (C) 2012-2014 Tobias Brunner
3 * Copyright (C) 2008 Martin Willi
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 #include "stroke_config.h"
18
19 #include <hydra.h>
20 #include <daemon.h>
21 #include <threading/mutex.h>
22 #include <utils/lexparser.h>
23
24 #include <netdb.h>
25
26 typedef struct private_stroke_config_t private_stroke_config_t;
27
28 /**
29 * private data of stroke_config
30 */
31 struct private_stroke_config_t {
32
33 /**
34 * public functions
35 */
36 stroke_config_t public;
37
38 /**
39 * list of peer_cfg_t
40 */
41 linked_list_t *list;
42
43 /**
44 * mutex to lock config list
45 */
46 mutex_t *mutex;
47
48 /**
49 * ca sections
50 */
51 stroke_ca_t *ca;
52
53 /**
54 * credentials
55 */
56 stroke_cred_t *cred;
57
58 /**
59 * Virtual IP pool / DNS backend
60 */
61 stroke_attribute_t *attributes;
62 };
63
64 METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
65 private_stroke_config_t *this, identification_t *me, identification_t *other)
66 {
67 this->mutex->lock(this->mutex);
68 return enumerator_create_cleaner(this->list->create_enumerator(this->list),
69 (void*)this->mutex->unlock, this->mutex);
70 }
71
72 /**
73 * filter function for ike configs
74 */
75 static bool ike_filter(void *data, peer_cfg_t **in, ike_cfg_t **out)
76 {
77 *out = (*in)->get_ike_cfg(*in);
78 return TRUE;
79 }
80
81 METHOD(backend_t, create_ike_cfg_enumerator, enumerator_t*,
82 private_stroke_config_t *this, host_t *me, host_t *other)
83 {
84 this->mutex->lock(this->mutex);
85 return enumerator_create_filter(this->list->create_enumerator(this->list),
86 (void*)ike_filter, this->mutex,
87 (void*)this->mutex->unlock);
88 }
89
90 METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
91 private_stroke_config_t *this, char *name)
92 {
93 enumerator_t *e1, *e2;
94 peer_cfg_t *current, *found = NULL;
95 child_cfg_t *child;
96
97 this->mutex->lock(this->mutex);
98 e1 = this->list->create_enumerator(this->list);
99 while (e1->enumerate(e1, &current))
100 {
101 /* compare peer_cfgs name first */
102 if (streq(current->get_name(current), name))
103 {
104 found = current;
105 found->get_ref(found);
106 break;
107 }
108 /* compare all child_cfg names otherwise */
109 e2 = current->create_child_cfg_enumerator(current);
110 while (e2->enumerate(e2, &child))
111 {
112 if (streq(child->get_name(child), name))
113 {
114 found = current;
115 found->get_ref(found);
116 break;
117 }
118 }
119 e2->destroy(e2);
120 if (found)
121 {
122 break;
123 }
124 }
125 e1->destroy(e1);
126 this->mutex->unlock(this->mutex);
127 return found;
128 }
129
130 /**
131 * parse a proposal string, either into ike_cfg or child_cfg
132 */
133 static void add_proposals(private_stroke_config_t *this, char *string,
134 ike_cfg_t *ike_cfg, child_cfg_t *child_cfg, protocol_id_t proto)
135 {
136 if (string)
137 {
138 char *single;
139 char *strict;
140 proposal_t *proposal;
141
142 strict = string + strlen(string) - 1;
143 if (*strict == '!')
144 {
145 *strict = '\0';
146 }
147 else
148 {
149 strict = NULL;
150 }
151 while ((single = strsep(&string, ",")))
152 {
153 proposal = proposal_create_from_string(proto, single);
154 if (proposal)
155 {
156 if (ike_cfg)
157 {
158 ike_cfg->add_proposal(ike_cfg, proposal);
159 }
160 else
161 {
162 child_cfg->add_proposal(child_cfg, proposal);
163 }
164 continue;
165 }
166 DBG1(DBG_CFG, "skipped invalid proposal string: %s", single);
167 }
168 if (strict)
169 {
170 return;
171 }
172 /* add default porposal to the end if not strict */
173 }
174 if (ike_cfg)
175 {
176 ike_cfg->add_proposal(ike_cfg, proposal_create_default(proto));
177 ike_cfg->add_proposal(ike_cfg, proposal_create_default_aead(proto));
178 }
179 else
180 {
181 child_cfg->add_proposal(child_cfg, proposal_create_default(proto));
182 child_cfg->add_proposal(child_cfg, proposal_create_default_aead(proto));
183 }
184 }
185
186 /**
187 * Build an IKE config from a stroke message
188 */
189 static ike_cfg_t *build_ike_cfg(private_stroke_config_t *this, stroke_msg_t *msg)
190 {
191 enumerator_t *enumerator;
192 stroke_end_t tmp_end;
193 ike_cfg_t *ike_cfg;
194 host_t *host;
195 u_int16_t ikeport;
196 char me[256], other[256], *token;
197 bool swapped = FALSE;;
198
199 enumerator = enumerator_create_token(msg->add_conn.other.address, ",", " ");
200 while (enumerator->enumerate(enumerator, &token))
201 {
202 if (!strchr(token, '/'))
203 {
204 host = host_create_from_dns(token, 0, 0);
205 if (host)
206 {
207 if (hydra->kernel_interface->get_interface(
208 hydra->kernel_interface, host, NULL))
209 {
210 DBG2(DBG_CFG, "left is other host, swapping ends");
211 tmp_end = msg->add_conn.me;
212 msg->add_conn.me = msg->add_conn.other;
213 msg->add_conn.other = tmp_end;
214 swapped = TRUE;
215 }
216 host->destroy(host);
217 }
218 }
219 }
220 enumerator->destroy(enumerator);
221
222 if (!swapped)
223 {
224 enumerator = enumerator_create_token(msg->add_conn.me.address, ",", " ");
225 while (enumerator->enumerate(enumerator, &token))
226 {
227 if (!strchr(token, '/'))
228 {
229 host = host_create_from_dns(token, 0, 0);
230 if (host)
231 {
232 if (!hydra->kernel_interface->get_interface(
233 hydra->kernel_interface, host, NULL))
234 {
235 DBG1(DBG_CFG, "left nor right host is our side, "
236 "assuming left=local");
237 }
238 host->destroy(host);
239 }
240 }
241 }
242 enumerator->destroy(enumerator);
243 }
244
245 if (msg->add_conn.me.allow_any)
246 {
247 snprintf(me, sizeof(me), "%s,0.0.0.0/0,::/0",
248 msg->add_conn.me.address);
249 }
250 if (msg->add_conn.other.allow_any)
251 {
252 snprintf(other, sizeof(other), "%s,0.0.0.0/0,::/0",
253 msg->add_conn.other.address);
254 }
255 ikeport = msg->add_conn.me.ikeport;
256 ikeport = (ikeport == IKEV2_UDP_PORT) ?
257 charon->socket->get_port(charon->socket, FALSE) : ikeport;
258 ike_cfg = ike_cfg_create(msg->add_conn.version,
259 msg->add_conn.other.sendcert != CERT_NEVER_SEND,
260 msg->add_conn.force_encap,
261 msg->add_conn.me.allow_any ?
262 me : msg->add_conn.me.address,
263 ikeport,
264 msg->add_conn.other.allow_any ?
265 other : msg->add_conn.other.address,
266 msg->add_conn.other.ikeport,
267 msg->add_conn.fragmentation,
268 msg->add_conn.ikedscp);
269
270 add_proposals(this, msg->add_conn.algorithms.ike, ike_cfg, NULL, PROTO_IKE);
271 return ike_cfg;
272 }
273
274 /**
275 * Add CRL constraint to config
276 */
277 static void build_crl_policy(auth_cfg_t *cfg, bool local, int policy)
278 {
279 /* CRL/OCSP policy, for remote config only */
280 if (!local)
281 {
282 switch (policy)
283 {
284 case CRL_STRICT_YES:
285 /* if yes, we require a GOOD validation */
286 cfg->add(cfg, AUTH_RULE_CRL_VALIDATION, VALIDATION_GOOD);
287 break;
288 case CRL_STRICT_IFURI:
289 /* for ifuri, a SKIPPED validation is sufficient */
290 cfg->add(cfg, AUTH_RULE_CRL_VALIDATION, VALIDATION_SKIPPED);
291 break;
292 default:
293 break;
294 }
295 }
296 }
297
298 /**
299 * Parse public key / signature strength constraints
300 */
301 static void parse_pubkey_constraints(char *auth, auth_cfg_t *cfg)
302 {
303 enumerator_t *enumerator;
304 bool rsa = FALSE, ecdsa = FALSE, rsa_len = FALSE, ecdsa_len = FALSE;
305 int strength;
306 char *token;
307
308 enumerator = enumerator_create_token(auth, "-", "");
309 while (enumerator->enumerate(enumerator, &token))
310 {
311 bool found = FALSE;
312 int i;
313 struct {
314 char *name;
315 signature_scheme_t scheme;
316 key_type_t key;
317 } schemes[] = {
318 { "md5", SIGN_RSA_EMSA_PKCS1_MD5, KEY_RSA, },
319 { "sha1", SIGN_RSA_EMSA_PKCS1_SHA1, KEY_RSA, },
320 { "sha224", SIGN_RSA_EMSA_PKCS1_SHA224, KEY_RSA, },
321 { "sha256", SIGN_RSA_EMSA_PKCS1_SHA256, KEY_RSA, },
322 { "sha384", SIGN_RSA_EMSA_PKCS1_SHA384, KEY_RSA, },
323 { "sha512", SIGN_RSA_EMSA_PKCS1_SHA512, KEY_RSA, },
324 { "sha1", SIGN_ECDSA_WITH_SHA1_DER, KEY_ECDSA, },
325 { "sha256", SIGN_ECDSA_WITH_SHA256_DER, KEY_ECDSA, },
326 { "sha384", SIGN_ECDSA_WITH_SHA384_DER, KEY_ECDSA, },
327 { "sha512", SIGN_ECDSA_WITH_SHA512_DER, KEY_ECDSA, },
328 { "sha256", SIGN_ECDSA_256, KEY_ECDSA, },
329 { "sha384", SIGN_ECDSA_384, KEY_ECDSA, },
330 { "sha512", SIGN_ECDSA_521, KEY_ECDSA, },
331 };
332
333 if (rsa_len || ecdsa_len)
334 { /* expecting a key strength token */
335 strength = atoi(token);
336 if (strength)
337 {
338 if (rsa_len)
339 {
340 cfg->add(cfg, AUTH_RULE_RSA_STRENGTH, (uintptr_t)strength);
341 }
342 else if (ecdsa_len)
343 {
344 cfg->add(cfg, AUTH_RULE_ECDSA_STRENGTH, (uintptr_t)strength);
345 }
346 }
347 rsa_len = ecdsa_len = FALSE;
348 if (strength)
349 {
350 continue;
351 }
352 }
353 if (streq(token, "rsa"))
354 {
355 rsa = rsa_len = TRUE;
356 continue;
357 }
358 if (streq(token, "ecdsa"))
359 {
360 ecdsa = ecdsa_len = TRUE;
361 continue;
362 }
363 if (streq(token, "pubkey"))
364 {
365 continue;
366 }
367
368 for (i = 0; i < countof(schemes); i++)
369 {
370 if (streq(schemes[i].name, token))
371 {
372 /* for each matching string, allow the scheme, if:
373 * - it is an RSA scheme, and we enforced RSA
374 * - it is an ECDSA scheme, and we enforced ECDSA
375 * - it is not a key type specific scheme
376 */
377 if ((rsa && schemes[i].key == KEY_RSA) ||
378 (ecdsa && schemes[i].key == KEY_ECDSA) ||
379 (!rsa && !ecdsa))
380 {
381 cfg->add(cfg, AUTH_RULE_SIGNATURE_SCHEME,
382 (uintptr_t)schemes[i].scheme);
383 }
384 found = TRUE;
385 }
386 }
387 if (!found)
388 {
389 DBG1(DBG_CFG, "ignoring invalid auth token: '%s'", token);
390 }
391 }
392 enumerator->destroy(enumerator);
393 }
394
395 /**
396 * build authentication config
397 */
398 static auth_cfg_t *build_auth_cfg(private_stroke_config_t *this,
399 stroke_msg_t *msg, bool local, bool primary)
400 {
401 identification_t *identity;
402 certificate_t *certificate;
403 char *auth, *id, *pubkey, *cert, *ca, *groups;
404 stroke_end_t *end, *other_end;
405 auth_cfg_t *cfg;
406 bool loose = FALSE;
407
408 /* select strings */
409 if (local)
410 {
411 end = &msg->add_conn.me;
412 other_end = &msg->add_conn.other;
413 }
414 else
415 {
416 end = &msg->add_conn.other;
417 other_end = &msg->add_conn.me;
418 }
419 if (primary)
420 {
421 auth = end->auth;
422 id = end->id;
423 if (!id)
424 { /* leftid/rightid fallback to address */
425 id = end->address;
426 }
427 cert = end->cert;
428 ca = end->ca;
429 if (ca && streq(ca, "%same"))
430 {
431 ca = other_end->ca;
432 }
433 }
434 else
435 {
436 auth = end->auth2;
437 id = end->id2;
438 if (local && !id)
439 { /* leftid2 falls back to leftid */
440 id = end->id;
441 }
442 cert = end->cert2;
443 ca = end->ca2;
444 if (ca && streq(ca, "%same"))
445 {
446 ca = other_end->ca2;
447 }
448 }
449 if (id && *id == '%' && !streq(id, "%any") && !streq(id, "%any6"))
450 { /* has only an effect on rightid/2 */
451 loose = !local;
452 id++;
453 }
454
455 if (!auth)
456 {
457 if (primary)
458 {
459 auth = "pubkey";
460 }
461 else
462 { /* no second authentication round, fine. But load certificates
463 * for other purposes (EAP-TLS) */
464 if (cert)
465 {
466 certificate = this->cred->load_peer(this->cred, cert);
467 if (certificate)
468 {
469 certificate->destroy(certificate);
470 }
471 }
472 return NULL;
473 }
474 }
475
476 cfg = auth_cfg_create();
477
478 /* add identity and peer certificate */
479 identity = identification_create_from_string(id);
480 if (cert)
481 {
482 enumerator_t *enumerator;
483 bool has_subject = FALSE;
484 certificate_t *first = NULL;
485
486 enumerator = enumerator_create_token(cert, ",", " ");
487 while (enumerator->enumerate(enumerator, &cert))
488 {
489 certificate = this->cred->load_peer(this->cred, cert);
490 if (certificate)
491 {
492 if (local)
493 {
494 this->ca->check_for_hash_and_url(this->ca, certificate);
495 }
496 cfg->add(cfg, AUTH_RULE_SUBJECT_CERT, certificate);
497 if (!first)
498 {
499 first = certificate;
500 }
501 if (identity->get_type(identity) != ID_ANY &&
502 certificate->has_subject(certificate, identity))
503 {
504 has_subject = TRUE;
505 }
506 }
507 }
508 enumerator->destroy(enumerator);
509
510 if (first && !has_subject)
511 {
512 DBG1(DBG_CFG, " id '%Y' not confirmed by certificate, "
513 "defaulting to '%Y'", identity, first->get_subject(first));
514 identity->destroy(identity);
515 identity = first->get_subject(first);
516 identity = identity->clone(identity);
517 }
518 }
519 /* add raw RSA public key */
520 pubkey = end->rsakey;
521 if (pubkey && !streq(pubkey, "") && !streq(pubkey, "%cert"))
522 {
523 certificate = this->cred->load_pubkey(this->cred, pubkey, identity);
524 if (certificate)
525 {
526 cfg->add(cfg, AUTH_RULE_SUBJECT_CERT, certificate);
527 }
528 }
529 if (identity->get_type(identity) != ID_ANY)
530 {
531 cfg->add(cfg, AUTH_RULE_IDENTITY, identity);
532 if (loose)
533 {
534 cfg->add(cfg, AUTH_RULE_IDENTITY_LOOSE, TRUE);
535 }
536 }
537 else
538 {
539 identity->destroy(identity);
540 }
541
542 /* CA constraint */
543 if (ca)
544 {
545 identity = identification_create_from_string(ca);
546 certificate = lib->credmgr->get_cert(lib->credmgr, CERT_X509,
547 KEY_ANY, identity, TRUE);
548 identity->destroy(identity);
549 if (certificate)
550 {
551 cfg->add(cfg, AUTH_RULE_CA_CERT, certificate);
552 }
553 else
554 {
555 DBG1(DBG_CFG, "CA certificate \"%s\" not found, discarding CA "
556 "constraint", ca);
557 }
558 }
559
560 /* groups */
561 groups = primary ? end->groups : end->groups2;
562 if (groups)
563 {
564 enumerator_t *enumerator;
565 char *group;
566
567 enumerator = enumerator_create_token(groups, ",", " ");
568 while (enumerator->enumerate(enumerator, &group))
569 {
570 cfg->add(cfg, AUTH_RULE_GROUP,
571 identification_create_from_string(group));
572 }
573 enumerator->destroy(enumerator);
574 }
575
576 /* certificatePolicies */
577 if (end->cert_policy)
578 {
579 enumerator_t *enumerator;
580 char *policy;
581
582 enumerator = enumerator_create_token(end->cert_policy, ",", " ");
583 while (enumerator->enumerate(enumerator, &policy))
584 {
585 cfg->add(cfg, AUTH_RULE_CERT_POLICY, strdup(policy));
586 }
587 enumerator->destroy(enumerator);
588 }
589
590 /* authentication metod (class, actually) */
591 if (strpfx(auth, "pubkey") ||
592 strpfx(auth, "rsa") ||
593 strpfx(auth, "ecdsa"))
594 {
595 cfg->add(cfg, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PUBKEY);
596 build_crl_policy(cfg, local, msg->add_conn.crl_policy);
597
598 parse_pubkey_constraints(auth, cfg);
599 }
600 else if (streq(auth, "psk") || streq(auth, "secret"))
601 {
602 cfg->add(cfg, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_PSK);
603 }
604 else if (strpfx(auth, "xauth"))
605 {
606 char *pos;
607
608 pos = strchr(auth, '-');
609 if (pos)
610 {
611 cfg->add(cfg, AUTH_RULE_XAUTH_BACKEND, strdup(++pos));
612 }
613 cfg->add(cfg, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_XAUTH);
614 if (msg->add_conn.xauth_identity)
615 {
616 cfg->add(cfg, AUTH_RULE_XAUTH_IDENTITY,
617 identification_create_from_string(msg->add_conn.xauth_identity));
618 }
619 }
620 else if (strpfx(auth, "eap"))
621 {
622 eap_vendor_type_t *type;
623
624 cfg->add(cfg, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_EAP);
625
626 type = eap_vendor_type_from_string(auth);
627 if (type)
628 {
629 cfg->add(cfg, AUTH_RULE_EAP_TYPE, type->type);
630 if (type->vendor)
631 {
632 cfg->add(cfg, AUTH_RULE_EAP_VENDOR, type->vendor);
633 }
634 free(type);
635 }
636
637 if (msg->add_conn.eap_identity)
638 {
639 if (streq(msg->add_conn.eap_identity, "%identity"))
640 {
641 identity = identification_create_from_encoding(ID_ANY,
642 chunk_empty);
643 }
644 else
645 {
646 identity = identification_create_from_string(
647 msg->add_conn.eap_identity);
648 }
649 cfg->add(cfg, AUTH_RULE_EAP_IDENTITY, identity);
650 }
651 if (msg->add_conn.aaa_identity)
652 {
653 cfg->add(cfg, AUTH_RULE_AAA_IDENTITY,
654 identification_create_from_string(msg->add_conn.aaa_identity));
655 }
656 }
657 else
658 {
659 if (!streq(auth, "any"))
660 {
661 DBG1(DBG_CFG, "authentication method %s unknown, fallback to any",
662 auth);
663 }
664 build_crl_policy(cfg, local, msg->add_conn.crl_policy);
665 }
666 return cfg;
667 }
668
669 /**
670 * build a mem_pool_t from an address range
671 */
672 static mem_pool_t *create_pool_range(char *str)
673 {
674 mem_pool_t *pool;
675 host_t *from, *to;
676
677 if (!host_create_from_range(str, &from, &to))
678 {
679 return NULL;
680 }
681 pool = mem_pool_create_range(str, from, to);
682 from->destroy(from);
683 to->destroy(to);
684 return pool;
685 }
686
687 /**
688 * build a peer_cfg from a stroke msg
689 */
690 static peer_cfg_t *build_peer_cfg(private_stroke_config_t *this,
691 stroke_msg_t *msg, ike_cfg_t *ike_cfg)
692 {
693 identification_t *peer_id = NULL;
694 peer_cfg_t *mediated_by = NULL;
695 unique_policy_t unique;
696 u_int32_t rekey = 0, reauth = 0, over, jitter;
697 peer_cfg_t *peer_cfg;
698 auth_cfg_t *auth_cfg;
699
700 #ifdef ME
701 if (msg->add_conn.ikeme.mediation && msg->add_conn.ikeme.mediated_by)
702 {
703 DBG1(DBG_CFG, "a mediation connection cannot be a mediated connection "
704 "at the same time, aborting");
705 return NULL;
706 }
707
708 if (msg->add_conn.ikeme.mediation)
709 {
710 /* force unique connections for mediation connections */
711 msg->add_conn.unique = 1;
712 }
713
714 if (msg->add_conn.ikeme.mediated_by)
715 {
716 mediated_by = charon->backends->get_peer_cfg_by_name(charon->backends,
717 msg->add_conn.ikeme.mediated_by);
718 if (!mediated_by)
719 {
720 DBG1(DBG_CFG, "mediation connection '%s' not found, aborting",
721 msg->add_conn.ikeme.mediated_by);
722 return NULL;
723 }
724 if (!mediated_by->is_mediation(mediated_by))
725 {
726 DBG1(DBG_CFG, "connection '%s' as referred to by '%s' is "
727 "no mediation connection, aborting",
728 msg->add_conn.ikeme.mediated_by, msg->add_conn.name);
729 mediated_by->destroy(mediated_by);
730 return NULL;
731 }
732 if (msg->add_conn.ikeme.peerid)
733 {
734 peer_id = identification_create_from_string(msg->add_conn.ikeme.peerid);
735 }
736 else if (msg->add_conn.other.id)
737 {
738 peer_id = identification_create_from_string(msg->add_conn.other.id);
739 }
740 }
741 #endif /* ME */
742
743 jitter = msg->add_conn.rekey.margin * msg->add_conn.rekey.fuzz / 100;
744 over = msg->add_conn.rekey.margin;
745 if (msg->add_conn.rekey.reauth)
746 {
747 reauth = msg->add_conn.rekey.ike_lifetime - over;
748 }
749 else
750 {
751 rekey = msg->add_conn.rekey.ike_lifetime - over;
752 }
753 switch (msg->add_conn.unique)
754 {
755 case 1: /* yes */
756 case 2: /* replace */
757 unique = UNIQUE_REPLACE;
758 break;
759 case 3: /* keep */
760 unique = UNIQUE_KEEP;
761 break;
762 case 4: /* never */
763 unique = UNIQUE_NEVER;
764 break;
765 default: /* no */
766 unique = UNIQUE_NO;
767 break;
768 }
769 if (msg->add_conn.dpd.action == 0)
770 { /* dpdaction=none disables DPD */
771 msg->add_conn.dpd.delay = 0;
772 }
773
774 /* other.sourceip is managed in stroke_attributes. If it is set, we define
775 * the pool name as the connection name, which the attribute provider
776 * uses to serve pool addresses. */
777 peer_cfg = peer_cfg_create(msg->add_conn.name, ike_cfg,
778 msg->add_conn.me.sendcert, unique,
779 msg->add_conn.rekey.tries, rekey, reauth, jitter, over,
780 msg->add_conn.mobike, msg->add_conn.aggressive,
781 msg->add_conn.pushmode == 0,
782 msg->add_conn.dpd.delay, msg->add_conn.dpd.timeout,
783 msg->add_conn.ikeme.mediation, mediated_by, peer_id);
784
785 if (msg->add_conn.other.sourceip)
786 {
787 enumerator_t *enumerator;
788 char *token;
789
790 enumerator = enumerator_create_token(msg->add_conn.other.sourceip,
791 ",", " ");
792 while (enumerator->enumerate(enumerator, &token))
793 {
794 if (streq(token, "%modeconfig") || streq(token, "%modecfg") ||
795 streq(token, "%config") || streq(token, "%cfg") ||
796 streq(token, "%config4") || streq(token, "%config6"))
797 {
798 /* empty pool, uses connection name */
799 this->attributes->add_pool(this->attributes,
800 mem_pool_create(msg->add_conn.name, NULL, 0));
801 peer_cfg->add_pool(peer_cfg, msg->add_conn.name);
802 }
803 else if (*token == '%')
804 {
805 /* external named pool */
806 peer_cfg->add_pool(peer_cfg, token + 1);
807 }
808 else
809 {
810 /* in-memory pool, using range or CIDR notation */
811 mem_pool_t *pool;
812 host_t *base;
813 int bits;
814
815 pool = create_pool_range(token);
816 if (!pool)
817 {
818 base = host_create_from_subnet(token, &bits);
819 if (base)
820 {
821 pool = mem_pool_create(token, base, bits);
822 base->destroy(base);
823 }
824 }
825 if (pool)
826 {
827 this->attributes->add_pool(this->attributes, pool);
828 peer_cfg->add_pool(peer_cfg, token);
829 }
830 else
831 {
832 DBG1(DBG_CFG, "IP pool %s invalid, ignored", token);
833 }
834 }
835 }
836 enumerator->destroy(enumerator);
837 }
838
839 if (msg->add_conn.me.sourceip && msg->add_conn.other.sourceip)
840 {
841 DBG1(DBG_CFG, "'%s' has both left- and rightsourceip, but IKE can "
842 "negotiate one virtual IP only, ignoring local virtual IP",
843 msg->add_conn.name);
844 }
845 else if (msg->add_conn.me.sourceip)
846 {
847 enumerator_t *enumerator;
848 char *token;
849
850 enumerator = enumerator_create_token(msg->add_conn.me.sourceip, ",", " ");
851 while (enumerator->enumerate(enumerator, &token))
852 {
853 host_t *vip = NULL;
854
855 if (streq(token, "%modeconfig") || streq(token, "%modecfg") ||
856 streq(token, "%config") || streq(token, "%cfg"))
857 { /* try to deduce an address family */
858 if (msg->add_conn.me.subnets)
859 { /* use the same family as in local subnet, if any */
860 if (strchr(msg->add_conn.me.subnets, '.'))
861 {
862 vip = host_create_any(AF_INET);
863 }
864 else
865 {
866 vip = host_create_any(AF_INET6);
867 }
868 }
869 else if (msg->add_conn.other.subnets)
870 { /* use the same family as in remote subnet, if any */
871 if (strchr(msg->add_conn.other.subnets, '.'))
872 {
873 vip = host_create_any(AF_INET);
874 }
875 else
876 {
877 vip = host_create_any(AF_INET6);
878 }
879 }
880 else
881 {
882 char *addr, *next, *hit;
883
884 /* guess virtual IP family based on local address. If
885 * multiple addresses are specified, we look at the first
886 * only, as with leftallowany a ::/0 is always appended. */
887 addr = ike_cfg->get_my_addr(ike_cfg);
888 next = strchr(addr, ',');
889 hit = strchr(addr, ':');
890 if (hit && (!next || hit < next))
891 {
892 vip = host_create_any(AF_INET6);
893 }
894 else
895 {
896 vip = host_create_any(AF_INET);
897 }
898 }
899 }
900 else if (streq(token, "%config4"))
901 {
902 vip = host_create_any(AF_INET);
903 }
904 else if (streq(token, "%config6"))
905 {
906 vip = host_create_any(AF_INET6);
907 }
908 else
909 {
910 vip = host_create_from_string(token, 0);
911 if (!vip)
912 {
913 DBG1(DBG_CFG, "ignored invalid subnet token: %s", token);
914 }
915 }
916
917 if (vip)
918 {
919 peer_cfg->add_virtual_ip(peer_cfg, vip);
920 }
921 }
922 enumerator->destroy(enumerator);
923 }
924
925 /* build leftauth= */
926 auth_cfg = build_auth_cfg(this, msg, TRUE, TRUE);
927 if (auth_cfg)
928 {
929 peer_cfg->add_auth_cfg(peer_cfg, auth_cfg, TRUE);
930 }
931 else
932 { /* we require at least one config on our side */
933 peer_cfg->destroy(peer_cfg);
934 return NULL;
935 }
936 /* build leftauth2= */
937 auth_cfg = build_auth_cfg(this, msg, TRUE, FALSE);
938 if (auth_cfg)
939 {
940 peer_cfg->add_auth_cfg(peer_cfg, auth_cfg, TRUE);
941 }
942 /* build rightauth= */
943 auth_cfg = build_auth_cfg(this, msg, FALSE, TRUE);
944 if (auth_cfg)
945 {
946 peer_cfg->add_auth_cfg(peer_cfg, auth_cfg, FALSE);
947 }
948 /* build rightauth2= */
949 auth_cfg = build_auth_cfg(this, msg, FALSE, FALSE);
950 if (auth_cfg)
951 {
952 peer_cfg->add_auth_cfg(peer_cfg, auth_cfg, FALSE);
953 }
954 return peer_cfg;
955 }
956
957 /**
958 * Parse a protoport specifier
959 */
960 static bool parse_protoport(char *token, u_int16_t *from_port,
961 u_int16_t *to_port, u_int8_t *protocol)
962 {
963 char *sep, *port = "", *endptr;
964 struct protoent *proto;
965 struct servent *svc;
966 long int p;
967
968 sep = strrchr(token, ']');
969 if (!sep)
970 {
971 return FALSE;
972 }
973 *sep = '\0';
974
975 sep = strchr(token, '/');
976 if (sep)
977 { /* protocol/port */
978 *sep = '\0';
979 port = sep + 1;
980 }
981
982 if (streq(token, "%any"))
983 {
984 *protocol = 0;
985 }
986 else
987 {
988 proto = getprotobyname(token);
989 if (proto)
990 {
991 *protocol = proto->p_proto;
992 }
993 else
994 {
995 p = strtol(token, &endptr, 0);
996 if ((*token && *endptr) || p < 0 || p > 0xff)
997 {
998 return FALSE;
999 }
1000 *protocol = (u_int8_t)p;
1001 }
1002 }
1003 if (streq(port, "%any"))
1004 {
1005 *from_port = 0;
1006 *to_port = 0xffff;
1007 }
1008 else if (streq(port, "%opaque"))
1009 {
1010 *from_port = 0xffff;
1011 *to_port = 0;
1012 }
1013 else if (*port)
1014 {
1015 svc = getservbyname(port, NULL);
1016 if (svc)
1017 {
1018 *from_port = *to_port = ntohs(svc->s_port);
1019 }
1020 else
1021 {
1022 p = strtol(port, &endptr, 0);
1023 if (p < 0 || p > 0xffff)
1024 {
1025 return FALSE;
1026 }
1027 *from_port = p;
1028 if (*endptr == '-')
1029 {
1030 port = endptr + 1;
1031 p = strtol(port, &endptr, 0);
1032 if (p < 0 || p > 0xffff)
1033 {
1034 return FALSE;
1035 }
1036 }
1037 *to_port = p;
1038 if (*endptr)
1039 {
1040 return FALSE;
1041 }
1042 }
1043 }
1044 return TRUE;
1045 }
1046
1047 /**
1048 * build a traffic selector from a stroke_end
1049 */
1050 static void add_ts(private_stroke_config_t *this,
1051 stroke_end_t *end, child_cfg_t *child_cfg, bool local)
1052 {
1053 traffic_selector_t *ts;
1054
1055 if (end->tohost)
1056 {
1057 ts = traffic_selector_create_dynamic(end->protocol,
1058 end->from_port, end->to_port);
1059 child_cfg->add_traffic_selector(child_cfg, local, ts);
1060 }
1061 else
1062 {
1063 if (!end->subnets)
1064 {
1065 host_t *net;
1066
1067 net = host_create_from_string(end->address, 0);
1068 if (net)
1069 {
1070 ts = traffic_selector_create_from_subnet(net, 0, end->protocol,
1071 end->from_port, end->to_port);
1072 child_cfg->add_traffic_selector(child_cfg, local, ts);
1073 }
1074 }
1075 else
1076 {
1077 enumerator_t *enumerator;
1078 char *subnet, *pos;
1079 u_int16_t from_port, to_port;
1080 u_int8_t proto;
1081
1082 enumerator = enumerator_create_token(end->subnets, ",", " ");
1083 while (enumerator->enumerate(enumerator, &subnet))
1084 {
1085 from_port = end->from_port;
1086 to_port = end->to_port;
1087 proto = end->protocol;
1088
1089 pos = strchr(subnet, '[');
1090 if (pos)
1091 {
1092 *(pos++) = '\0';
1093 if (!parse_protoport(pos, &from_port, &to_port, &proto))
1094 {
1095 DBG1(DBG_CFG, "invalid proto/port: %s, skipped subnet",
1096 pos);
1097 continue;
1098 }
1099 }
1100 if (streq(subnet, "%dynamic"))
1101 {
1102 ts = traffic_selector_create_dynamic(proto,
1103 from_port, to_port);
1104 }
1105 else
1106 {
1107 ts = traffic_selector_create_from_cidr(subnet, proto,
1108 from_port, to_port);
1109 }
1110 if (ts)
1111 {
1112 child_cfg->add_traffic_selector(child_cfg, local, ts);
1113 }
1114 else
1115 {
1116 DBG1(DBG_CFG, "invalid subnet: %s, skipped", subnet);
1117 }
1118 }
1119 enumerator->destroy(enumerator);
1120 }
1121 }
1122 }
1123
1124 /**
1125 * map starter magic values to our action type
1126 */
1127 static action_t map_action(int starter_action)
1128 {
1129 switch (starter_action)
1130 {
1131 case 2: /* =hold */
1132 return ACTION_ROUTE;
1133 case 3: /* =restart */
1134 return ACTION_RESTART;
1135 default:
1136 return ACTION_NONE;
1137 }
1138 }
1139
1140 /**
1141 * build a child config from the stroke message
1142 */
1143 static child_cfg_t *build_child_cfg(private_stroke_config_t *this,
1144 stroke_msg_t *msg)
1145 {
1146 child_cfg_t *child_cfg;
1147 lifetime_cfg_t lifetime = {
1148 .time = {
1149 .life = msg->add_conn.rekey.ipsec_lifetime,
1150 .rekey = msg->add_conn.rekey.ipsec_lifetime - msg->add_conn.rekey.margin,
1151 .jitter = msg->add_conn.rekey.margin * msg->add_conn.rekey.fuzz / 100
1152 },
1153 .bytes = {
1154 .life = msg->add_conn.rekey.life_bytes,
1155 .rekey = msg->add_conn.rekey.life_bytes - msg->add_conn.rekey.margin_bytes,
1156 .jitter = msg->add_conn.rekey.margin_bytes * msg->add_conn.rekey.fuzz / 100
1157 },
1158 .packets = {
1159 .life = msg->add_conn.rekey.life_packets,
1160 .rekey = msg->add_conn.rekey.life_packets - msg->add_conn.rekey.margin_packets,
1161 .jitter = msg->add_conn.rekey.margin_packets * msg->add_conn.rekey.fuzz / 100
1162 }
1163 };
1164 mark_t mark_in = {
1165 .value = msg->add_conn.mark_in.value,
1166 .mask = msg->add_conn.mark_in.mask
1167 };
1168 mark_t mark_out = {
1169 .value = msg->add_conn.mark_out.value,
1170 .mask = msg->add_conn.mark_out.mask
1171 };
1172
1173 child_cfg = child_cfg_create(
1174 msg->add_conn.name, &lifetime, msg->add_conn.me.updown,
1175 msg->add_conn.me.hostaccess, msg->add_conn.mode, ACTION_NONE,
1176 map_action(msg->add_conn.dpd.action),
1177 map_action(msg->add_conn.close_action), msg->add_conn.ipcomp,
1178 msg->add_conn.inactivity, msg->add_conn.reqid,
1179 &mark_in, &mark_out, msg->add_conn.tfc);
1180 if (msg->add_conn.replay_window != -1)
1181 {
1182 child_cfg->set_replay_window(child_cfg, msg->add_conn.replay_window);
1183 }
1184 child_cfg->set_mipv6_options(child_cfg, msg->add_conn.proxy_mode,
1185 msg->add_conn.install_policy);
1186 add_ts(this, &msg->add_conn.me, child_cfg, TRUE);
1187 add_ts(this, &msg->add_conn.other, child_cfg, FALSE);
1188
1189 if (msg->add_conn.algorithms.ah)
1190 {
1191 add_proposals(this, msg->add_conn.algorithms.ah,
1192 NULL, child_cfg, PROTO_AH);
1193 }
1194 else
1195 {
1196 add_proposals(this, msg->add_conn.algorithms.esp,
1197 NULL, child_cfg, PROTO_ESP);
1198 }
1199 return child_cfg;
1200 }
1201
1202 METHOD(stroke_config_t, add, void,
1203 private_stroke_config_t *this, stroke_msg_t *msg)
1204 {
1205 ike_cfg_t *ike_cfg, *existing_ike;
1206 peer_cfg_t *peer_cfg, *existing;
1207 child_cfg_t *child_cfg;
1208 enumerator_t *enumerator;
1209 bool use_existing = FALSE;
1210
1211 ike_cfg = build_ike_cfg(this, msg);
1212 if (!ike_cfg)
1213 {
1214 return;
1215 }
1216 peer_cfg = build_peer_cfg(this, msg, ike_cfg);
1217 if (!peer_cfg)
1218 {
1219 ike_cfg->destroy(ike_cfg);
1220 return;
1221 }
1222
1223 enumerator = create_peer_cfg_enumerator(this, NULL, NULL);
1224 while (enumerator->enumerate(enumerator, &existing))
1225 {
1226 existing_ike = existing->get_ike_cfg(existing);
1227 if (existing->equals(existing, peer_cfg) &&
1228 existing_ike->equals(existing_ike, peer_cfg->get_ike_cfg(peer_cfg)))
1229 {
1230 use_existing = TRUE;
1231 peer_cfg->destroy(peer_cfg);
1232 peer_cfg = existing;
1233 peer_cfg->get_ref(peer_cfg);
1234 DBG1(DBG_CFG, "added child to existing configuration '%s'",
1235 peer_cfg->get_name(peer_cfg));
1236 break;
1237 }
1238 }
1239 enumerator->destroy(enumerator);
1240
1241 child_cfg = build_child_cfg(this, msg);
1242 if (!child_cfg)
1243 {
1244 peer_cfg->destroy(peer_cfg);
1245 return;
1246 }
1247 peer_cfg->add_child_cfg(peer_cfg, child_cfg);
1248
1249 if (use_existing)
1250 {
1251 peer_cfg->destroy(peer_cfg);
1252 }
1253 else
1254 {
1255 /* add config to backend */
1256 DBG1(DBG_CFG, "added configuration '%s'", msg->add_conn.name);
1257 this->mutex->lock(this->mutex);
1258 this->list->insert_last(this->list, peer_cfg);
1259 this->mutex->unlock(this->mutex);
1260 }
1261 }
1262
1263 METHOD(stroke_config_t, del, void,
1264 private_stroke_config_t *this, stroke_msg_t *msg)
1265 {
1266 enumerator_t *enumerator, *children;
1267 peer_cfg_t *peer;
1268 child_cfg_t *child;
1269 bool deleted = FALSE;
1270
1271 this->mutex->lock(this->mutex);
1272 enumerator = this->list->create_enumerator(this->list);
1273 while (enumerator->enumerate(enumerator, &peer))
1274 {
1275 bool keep = FALSE;
1276
1277 /* remove any child with such a name */
1278 children = peer->create_child_cfg_enumerator(peer);
1279 while (children->enumerate(children, &child))
1280 {
1281 if (streq(child->get_name(child), msg->del_conn.name))
1282 {
1283 peer->remove_child_cfg(peer, children);
1284 child->destroy(child);
1285 deleted = TRUE;
1286 }
1287 else
1288 {
1289 keep = TRUE;
1290 }
1291 }
1292 children->destroy(children);
1293
1294 /* if peer config has no children anymore, remove it */
1295 if (!keep)
1296 {
1297 this->list->remove_at(this->list, enumerator);
1298 peer->destroy(peer);
1299 }
1300 }
1301 enumerator->destroy(enumerator);
1302 this->mutex->unlock(this->mutex);
1303
1304 if (deleted)
1305 {
1306 DBG1(DBG_CFG, "deleted connection '%s'", msg->del_conn.name);
1307 }
1308 else
1309 {
1310 DBG1(DBG_CFG, "connection '%s' not found", msg->del_conn.name);
1311 }
1312 }
1313
1314 METHOD(stroke_config_t, set_user_credentials, void,
1315 private_stroke_config_t *this, stroke_msg_t *msg, FILE *prompt)
1316 {
1317 enumerator_t *enumerator, *children, *remote_auth;
1318 peer_cfg_t *peer, *found = NULL;
1319 auth_cfg_t *auth_cfg, *remote_cfg;
1320 auth_class_t auth_class;
1321 child_cfg_t *child;
1322 identification_t *id, *identity, *gw = NULL;
1323 shared_key_type_t type = SHARED_ANY;
1324 chunk_t password = chunk_empty;
1325
1326 this->mutex->lock(this->mutex);
1327 enumerator = this->list->create_enumerator(this->list);
1328 while (enumerator->enumerate(enumerator, (void**)&peer))
1329 { /* find the peer (or child) config with the given name */
1330 if (streq(peer->get_name(peer), msg->user_creds.name))
1331 {
1332 found = peer;
1333 }
1334 else
1335 {
1336 children = peer->create_child_cfg_enumerator(peer);
1337 while (children->enumerate(children, &child))
1338 {
1339 if (streq(child->get_name(child), msg->user_creds.name))
1340 {
1341 found = peer;
1342 break;
1343 }
1344 }
1345 children->destroy(children);
1346 }
1347
1348 if (found)
1349 {
1350 break;
1351 }
1352 }
1353 enumerator->destroy(enumerator);
1354
1355 if (!found)
1356 {
1357 DBG1(DBG_CFG, " no config named '%s'", msg->user_creds.name);
1358 fprintf(prompt, "no config named '%s'\n", msg->user_creds.name);
1359 this->mutex->unlock(this->mutex);
1360 return;
1361 }
1362
1363 id = identification_create_from_string(msg->user_creds.username);
1364 if (strlen(msg->user_creds.username) == 0 ||
1365 !id || id->get_type(id) == ID_ANY)
1366 {
1367 DBG1(DBG_CFG, " invalid username '%s'", msg->user_creds.username);
1368 fprintf(prompt, "invalid username '%s'\n", msg->user_creds.username);
1369 this->mutex->unlock(this->mutex);
1370 DESTROY_IF(id);
1371 return;
1372 }
1373
1374 /* replace/set the username in the first EAP/XAuth auth_cfg, also look for
1375 * a suitable remote ID.
1376 * note that adding the identity here is not fully thread-safe as the
1377 * peer_cfg and in turn the auth_cfg could be in use. for the default use
1378 * case (setting user credentials before upping the connection) this will
1379 * not be a problem, though. */
1380 enumerator = found->create_auth_cfg_enumerator(found, TRUE);
1381 remote_auth = found->create_auth_cfg_enumerator(found, FALSE);
1382 while (enumerator->enumerate(enumerator, (void**)&auth_cfg))
1383 {
1384 if (remote_auth->enumerate(remote_auth, (void**)&remote_cfg))
1385 { /* fall back on rightid, in case aaa_identity is not specified */
1386 identity = remote_cfg->get(remote_cfg, AUTH_RULE_IDENTITY);
1387 if (identity && identity->get_type(identity) != ID_ANY)
1388 {
1389 gw = identity;
1390 }
1391 }
1392
1393 auth_class = (uintptr_t)auth_cfg->get(auth_cfg, AUTH_RULE_AUTH_CLASS);
1394 if (auth_class == AUTH_CLASS_EAP || auth_class == AUTH_CLASS_XAUTH)
1395 {
1396 if (auth_class == AUTH_CLASS_EAP)
1397 {
1398 auth_cfg->add(auth_cfg, AUTH_RULE_EAP_IDENTITY, id->clone(id));
1399 /* if aaa_identity is specified use that as remote ID */
1400 identity = auth_cfg->get(auth_cfg, AUTH_RULE_AAA_IDENTITY);
1401 if (identity && identity->get_type(identity) != ID_ANY)
1402 {
1403 gw = identity;
1404 }
1405 DBG1(DBG_CFG, " configured EAP-Identity %Y", id);
1406 }
1407 else
1408 {
1409 auth_cfg->add(auth_cfg, AUTH_RULE_XAUTH_IDENTITY,
1410 id->clone(id));
1411 DBG1(DBG_CFG, " configured XAuth username %Y", id);
1412 }
1413 type = SHARED_EAP;
1414 break;
1415 }
1416 }
1417 enumerator->destroy(enumerator);
1418 remote_auth->destroy(remote_auth);
1419 /* clone the gw ID before unlocking the mutex */
1420 if (gw)
1421 {
1422 gw = gw->clone(gw);
1423 }
1424 this->mutex->unlock(this->mutex);
1425
1426 if (type == SHARED_ANY)
1427 {
1428 DBG1(DBG_CFG, " config '%s' unsuitable for user credentials",
1429 msg->user_creds.name);
1430 fprintf(prompt, "config '%s' unsuitable for user credentials\n",
1431 msg->user_creds.name);
1432 id->destroy(id);
1433 DESTROY_IF(gw);
1434 return;
1435 }
1436
1437 if (msg->user_creds.password)
1438 {
1439 char *pass;
1440
1441 pass = msg->user_creds.password;
1442 password = chunk_clone(chunk_create(pass, strlen(pass)));
1443 memwipe(pass, strlen(pass));
1444 }
1445 else
1446 { /* prompt the user for the password */
1447 char buf[256];
1448
1449 fprintf(prompt, "Password:\n");
1450 if (fgets(buf, sizeof(buf), prompt))
1451 {
1452 password = chunk_clone(chunk_create(buf, strlen(buf)));
1453 if (password.len > 0)
1454 { /* trim trailing \n */
1455 password.len--;
1456 }
1457 memwipe(buf, sizeof(buf));
1458 }
1459 }
1460
1461 if (password.len)
1462 {
1463 shared_key_t *shared;
1464 linked_list_t *owners;
1465
1466 shared = shared_key_create(type, password);
1467
1468 owners = linked_list_create();
1469 owners->insert_last(owners, id->clone(id));
1470 if (gw && gw->get_type(gw) != ID_ANY)
1471 {
1472 owners->insert_last(owners, gw->clone(gw));
1473 DBG1(DBG_CFG, " added %N secret for %Y %Y", shared_key_type_names,
1474 type, id, gw);
1475 }
1476 else
1477 {
1478 DBG1(DBG_CFG, " added %N secret for %Y", shared_key_type_names,
1479 type, id);
1480 }
1481 this->cred->add_shared(this->cred, shared, owners);
1482 DBG4(DBG_CFG, " secret: %#B", &password);
1483 }
1484 else
1485 { /* in case a user answers the password prompt by just pressing enter */
1486 chunk_clear(&password);
1487 }
1488 id->destroy(id);
1489 DESTROY_IF(gw);
1490 }
1491
1492 METHOD(stroke_config_t, destroy, void,
1493 private_stroke_config_t *this)
1494 {
1495 this->list->destroy_offset(this->list, offsetof(peer_cfg_t, destroy));
1496 this->mutex->destroy(this->mutex);
1497 free(this);
1498 }
1499
1500 /*
1501 * see header file
1502 */
1503 stroke_config_t *stroke_config_create(stroke_ca_t *ca, stroke_cred_t *cred,
1504 stroke_attribute_t *attributes)
1505 {
1506 private_stroke_config_t *this;
1507
1508 INIT(this,
1509 .public = {
1510 .backend = {
1511 .create_peer_cfg_enumerator = _create_peer_cfg_enumerator,
1512 .create_ike_cfg_enumerator = _create_ike_cfg_enumerator,
1513 .get_peer_cfg_by_name = _get_peer_cfg_by_name,
1514 },
1515 .add = _add,
1516 .del = _del,
1517 .set_user_credentials = _set_user_credentials,
1518 .destroy = _destroy,
1519 },
1520 .list = linked_list_create(),
1521 .mutex = mutex_create(MUTEX_TYPE_RECURSIVE),
1522 .ca = ca,
1523 .cred = cred,
1524 .attributes = attributes,
1525 );
1526
1527 return &this->public;
1528 }