2 * Copyright (C) 2008-2011 Tobias Brunner
3 * Copyright (C) 2008 Martin Willi
4 * Hochschule fuer Technik Rapperswil
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>.
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
17 #include <sys/types.h>
30 #include "stroke_cred.h"
32 #include <credentials/certificates/x509.h>
33 #include <credentials/certificates/crl.h>
34 #include <credentials/certificates/ac.h>
35 #include <credentials/sets/mem_cred.h>
36 #include <credentials/sets/callback_cred.h>
37 #include <utils/linked_list.h>
38 #include <utils/lexparser.h>
39 #include <threading/rwlock.h>
42 /* configuration directories and files */
43 #define CONFIG_DIR IPSEC_CONFDIR
44 #define IPSEC_D_DIR CONFIG_DIR "/ipsec.d"
45 #define PRIVATE_KEY_DIR IPSEC_D_DIR "/private"
46 #define CERTIFICATE_DIR IPSEC_D_DIR "/certs"
47 #define CA_CERTIFICATE_DIR IPSEC_D_DIR "/cacerts"
48 #define AA_CERTIFICATE_DIR IPSEC_D_DIR "/aacerts"
49 #define ATTR_CERTIFICATE_DIR IPSEC_D_DIR "/acerts"
50 #define OCSP_CERTIFICATE_DIR IPSEC_D_DIR "/ocspcerts"
51 #define CRL_DIR IPSEC_D_DIR "/crls"
52 #define SECRETS_FILE CONFIG_DIR "/ipsec.secrets"
54 #define MAX_SECRETS_RECURSION 10
56 typedef struct private_stroke_cred_t private_stroke_cred_t
;
59 * private data of stroke_cred
61 struct private_stroke_cred_t
{
74 * ignore missing CA basic constraint (i.e. treat all certificates in
75 * ipsec.conf ca sections and ipsec.d/cacert as CA certificates)
85 METHOD(stroke_cred_t
, load_ca
, certificate_t
*,
86 private_stroke_cred_t
*this, char *filename
)
93 snprintf(path
, sizeof(path
), "%s", filename
);
97 snprintf(path
, sizeof(path
), "%s/%s", CA_CERTIFICATE_DIR
, filename
);
100 if (this->force_ca_cert
)
101 { /* we treat this certificate as a CA certificate even if it has no
102 * CA basic constraint */
103 cert
= lib
->creds
->create(lib
->creds
,
104 CRED_CERTIFICATE
, CERT_X509
,
105 BUILD_FROM_FILE
, path
, BUILD_X509_FLAG
, X509_CA
,
110 cert
= lib
->creds
->create(lib
->creds
,
111 CRED_CERTIFICATE
, CERT_X509
,
112 BUILD_FROM_FILE
, path
,
117 x509_t
*x509
= (x509_t
*)cert
;
119 if (!(x509
->get_flags(x509
) & X509_CA
))
121 DBG1(DBG_CFG
, " ca certificate \"%Y\" misses ca basic constraint, "
122 "discarded", cert
->get_subject(cert
));
126 return this->creds
->add_cert_ref(this->creds
, TRUE
, cert
);
131 METHOD(stroke_cred_t
, load_peer
, certificate_t
*,
132 private_stroke_cred_t
*this, char *filename
)
137 if (*filename
== '/')
139 snprintf(path
, sizeof(path
), "%s", filename
);
143 snprintf(path
, sizeof(path
), "%s/%s", CERTIFICATE_DIR
, filename
);
146 cert
= lib
->creds
->create(lib
->creds
,
147 CRED_CERTIFICATE
, CERT_ANY
,
148 BUILD_FROM_FILE
, path
,
152 cert
= this->creds
->add_cert_ref(this->creds
, TRUE
, cert
);
153 DBG1(DBG_CFG
, " loaded certificate \"%Y\" from '%s'",
154 cert
->get_subject(cert
), filename
);
157 DBG1(DBG_CFG
, " loading certificate from '%s' failed", filename
);
162 * load trusted certificates from a directory
164 static void load_certdir(private_stroke_cred_t
*this, char *path
,
165 certificate_type_t type
, x509_flag_t flag
)
170 enumerator_t
*enumerator
= enumerator_create_directory(path
);
174 DBG1(DBG_CFG
, " reading directory failed");
178 while (enumerator
->enumerate(enumerator
, NULL
, &file
, &st
))
182 if (!S_ISREG(st
.st_mode
))
184 /* skip special file */
192 if (this->force_ca_cert
)
193 { /* treat this certificate as CA cert even it has no
194 * CA basic constraint */
195 cert
= lib
->creds
->create(lib
->creds
,
196 CRED_CERTIFICATE
, CERT_X509
,
197 BUILD_FROM_FILE
, file
, BUILD_X509_FLAG
,
202 cert
= lib
->creds
->create(lib
->creds
,
203 CRED_CERTIFICATE
, CERT_X509
,
204 BUILD_FROM_FILE
, file
, BUILD_END
);
208 x509_t
*x509
= (x509_t
*)cert
;
210 if (!(x509
->get_flags(x509
) & X509_CA
))
212 DBG1(DBG_CFG
, " ca certificate \"%Y\" lacks "
213 "ca basic constraint, discarded",
214 cert
->get_subject(cert
));
220 DBG1(DBG_CFG
, " loaded ca certificate \"%Y\" "
221 "from '%s'", cert
->get_subject(cert
), file
);
226 DBG1(DBG_CFG
, " loading ca certificate from '%s' "
231 { /* for all other flags, we add them to the certificate. */
232 cert
= lib
->creds
->create(lib
->creds
,
233 CRED_CERTIFICATE
, CERT_X509
,
234 BUILD_FROM_FILE
, file
,
235 BUILD_X509_FLAG
, flag
, BUILD_END
);
238 DBG1(DBG_CFG
, " loaded certificate \"%Y\" from '%s'",
239 cert
->get_subject(cert
), file
);
243 DBG1(DBG_CFG
, " loading certificate from '%s' "
249 this->creds
->add_cert(this->creds
, TRUE
, cert
);
253 cert
= lib
->creds
->create(lib
->creds
,
254 CRED_CERTIFICATE
, CERT_X509_CRL
,
255 BUILD_FROM_FILE
, file
,
259 this->creds
->add_crl(this->creds
, (crl_t
*)cert
);
260 DBG1(DBG_CFG
, " loaded crl from '%s'", file
);
264 DBG1(DBG_CFG
, " loading crl from '%s' failed", file
);
268 cert
= lib
->creds
->create(lib
->creds
,
269 CRED_CERTIFICATE
, CERT_X509_AC
,
270 BUILD_FROM_FILE
, file
,
274 this->creds
->add_cert(this->creds
, FALSE
, cert
);
275 DBG1(DBG_CFG
, " loaded attribute certificate from '%s'",
280 DBG1(DBG_CFG
, " loading attribute certificate from '%s' "
288 enumerator
->destroy(enumerator
);
291 METHOD(stroke_cred_t
, cache_cert
, void,
292 private_stroke_cred_t
*this, certificate_t
*cert
)
294 if (cert
->get_type(cert
) == CERT_X509_CRL
&& this->cachecrl
)
296 /* CRLs get written to /etc/ipsec.d/crls/<authkeyId>.crl */
297 crl_t
*crl
= (crl_t
*)cert
;
300 if (this->creds
->add_crl(this->creds
, crl
))
305 chunk
= crl
->get_authKeyIdentifier(crl
);
306 hex
= chunk_to_hex(chunk
, NULL
, FALSE
);
307 snprintf(buf
, sizeof(buf
), "%s/%s.crl", CRL_DIR
, hex
.ptr
);
310 if (cert
->get_encoding(cert
, CERT_ASN1_DER
, &chunk
))
312 chunk_write(chunk
, buf
, "crl", 022, TRUE
);
319 METHOD(stroke_cred_t
, cachecrl
, void,
320 private_stroke_cred_t
*this, bool enabled
)
322 DBG1(DBG_CFG
, "crl caching to %s %s",
323 CRL_DIR
, enabled ?
"enabled" : "disabled");
324 this->cachecrl
= enabled
;
329 * Convert a string of characters into a binary secret
330 * A string between single or double quotes is treated as ASCII characters
331 * A string prepended by 0x is treated as HEX and prepended by 0s as Base64
333 static err_t
extract_secret(chunk_t
*secret
, chunk_t
*line
)
336 char delimiter
= ' ';
339 if (!eat_whitespace(line
))
341 return "missing secret";
344 if (*line
->ptr
== '\'' || *line
->ptr
== '"')
347 delimiter
= *line
->ptr
;
348 line
->ptr
++; line
->len
--;
351 if (!extract_token(&raw_secret
, delimiter
, line
))
353 if (delimiter
== ' ')
359 return "missing second delimiter";
365 /* treat as an ASCII string */
366 *secret
= chunk_clone(raw_secret
);
369 /* treat 0x as hex, 0s as base64 */
370 if (raw_secret
.len
> 2)
372 if (strncasecmp("0x", raw_secret
.ptr
, 2) == 0)
374 *secret
= chunk_from_hex(chunk_skip(raw_secret
, 2), NULL
);
377 if (strncasecmp("0s", raw_secret
.ptr
, 2) == 0)
379 *secret
= chunk_from_base64(chunk_skip(raw_secret
, 2), NULL
);
383 *secret
= chunk_clone(raw_secret
);
388 * Data for passphrase callback
391 /** socket we use for prompting */
393 /** private key file */
395 /** number of tries */
397 } passphrase_cb_data_t
;
400 * Callback function to receive Passphrases
402 static shared_key_t
* passphrase_cb(passphrase_cb_data_t
*data
,
403 shared_key_type_t type
,
404 identification_t
*me
, identification_t
*other
,
405 id_match_t
*match_me
, id_match_t
*match_other
)
410 if (type
!= SHARED_ANY
&& type
!= SHARED_PRIVATE_KEY_PASS
)
419 fprintf(data
->prompt
, "PIN invalid, giving up.\n");
422 fprintf(data
->prompt
, "PIN invalid!\n");
425 fprintf(data
->prompt
, "Private key '%s' is encrypted.\n", data
->path
);
426 fprintf(data
->prompt
, "Passphrase:\n");
427 if (fgets(buf
, sizeof(buf
), data
->prompt
))
429 secret
= chunk_create(buf
, strlen(buf
));
431 { /* trim appended \n */
435 *match_me
= ID_MATCH_PERFECT
;
439 *match_other
= ID_MATCH_NONE
;
441 return shared_key_create(SHARED_PRIVATE_KEY_PASS
, chunk_clone(secret
));
448 * Data for PIN callback
451 /** socket we use for prompting */
457 /** number of tries */
462 * Callback function to receive PINs
464 static shared_key_t
* pin_cb(pin_cb_data_t
*data
, shared_key_type_t type
,
465 identification_t
*me
, identification_t
*other
,
466 id_match_t
*match_me
, id_match_t
*match_other
)
471 if (type
!= SHARED_ANY
&& type
!= SHARED_PIN
)
476 if (!me
|| !chunk_equals(me
->get_encoding(me
), data
->keyid
))
483 fprintf(data
->prompt
, "PIN invalid, aborting.\n");
487 fprintf(data
->prompt
, "Login to '%s' required\n", data
->card
);
488 fprintf(data
->prompt
, "PIN:\n");
489 if (fgets(buf
, sizeof(buf
), data
->prompt
))
491 secret
= chunk_create(buf
, strlen(buf
));
493 { /* trim appended \n */
497 *match_me
= ID_MATCH_PERFECT
;
501 *match_other
= ID_MATCH_NONE
;
503 return shared_key_create(SHARED_PIN
, chunk_clone(secret
));
510 * Load a smartcard with a PIN
512 static bool load_pin(private_stroke_cred_t
*this, chunk_t line
, int line_nr
,
515 chunk_t sc
= chunk_empty
, secret
= chunk_empty
;
516 char smartcard
[64], keyid
[64], module
[64], *pos
;
517 private_key_t
*key
= NULL
;
520 shared_key_t
*shared
;
521 identification_t
*id
;
522 mem_cred_t
*mem
= NULL
;
523 callback_cred_t
*cb
= NULL
;
524 pin_cb_data_t pin_data
;
526 SC_FORMAT_SLOT_MODULE_KEYID
,
527 SC_FORMAT_SLOT_KEYID
,
531 err_t ugh
= extract_value(&sc
, &line
);
535 DBG1(DBG_CFG
, "line %d: %s", line_nr
, ugh
);
540 DBG1(DBG_CFG
, "line %d: expected %%smartcard specifier", line_nr
);
543 snprintf(smartcard
, sizeof(smartcard
), "%.*s", (int)sc
.len
, sc
.ptr
);
544 smartcard
[sizeof(smartcard
) - 1] = '\0';
546 /* parse slot and key id. Three formats are supported:
547 * - %smartcard<slot>@<module>:<keyid>
548 * - %smartcard<slot>:<keyid>
549 * - %smartcard:<keyid>
551 if (sscanf(smartcard
, "%%smartcard%u@%s", &slot
, module
) == 2)
553 pos
= strchr(module
, ':');
556 DBG1(DBG_CFG
, "line %d: the given %%smartcard specifier is "
561 strncpy(keyid
, pos
+ 1, sizeof(keyid
));
562 format
= SC_FORMAT_SLOT_MODULE_KEYID
;
564 else if (sscanf(smartcard
, "%%smartcard%u:%s", &slot
, keyid
) == 2)
566 format
= SC_FORMAT_SLOT_KEYID
;
568 else if (sscanf(smartcard
, "%%smartcard:%s", keyid
) == 1)
570 format
= SC_FORMAT_KEYID
;
574 DBG1(DBG_CFG
, "line %d: the given %%smartcard specifier is not"
575 " supported or invalid", line_nr
);
579 if (!eat_whitespace(&line
))
581 DBG1(DBG_CFG
, "line %d: expected PIN", line_nr
);
584 ugh
= extract_secret(&secret
, &line
);
587 DBG1(DBG_CFG
, "line %d: malformed PIN: %s", line_nr
, ugh
);
591 chunk
= chunk_from_hex(chunk_create(keyid
, strlen(keyid
)), NULL
);
592 if (secret
.len
== 7 && strneq(secret
.ptr
, "%prompt", 7))
596 { /* no IO channel to prompt, skip */
600 /* use callback credential set to prompt for the pin */
601 pin_data
.prompt
= prompt
;
602 pin_data
.card
= smartcard
;
603 pin_data
.keyid
= chunk
;
605 cb
= callback_cred_create_shared((void*)pin_cb
, &pin_data
);
606 lib
->credmgr
->add_local_set(lib
->credmgr
, &cb
->set
);
610 /* provide our pin in a temporary credential set */
611 shared
= shared_key_create(SHARED_PIN
, secret
);
612 id
= identification_create_from_encoding(ID_KEY_ID
, chunk
);
613 mem
= mem_cred_create();
614 mem
->add_shared(mem
, shared
, id
, NULL
);
615 lib
->credmgr
->add_local_set(lib
->credmgr
, &mem
->set
);
618 /* unlock: smartcard needs the pin and potentially calls public set */
621 case SC_FORMAT_SLOT_MODULE_KEYID
:
622 key
= lib
->creds
->create(lib
->creds
,
623 CRED_PRIVATE_KEY
, KEY_ANY
,
624 BUILD_PKCS11_SLOT
, slot
,
625 BUILD_PKCS11_MODULE
, module
,
626 BUILD_PKCS11_KEYID
, chunk
, BUILD_END
);
628 case SC_FORMAT_SLOT_KEYID
:
629 key
= lib
->creds
->create(lib
->creds
,
630 CRED_PRIVATE_KEY
, KEY_ANY
,
631 BUILD_PKCS11_SLOT
, slot
,
632 BUILD_PKCS11_KEYID
, chunk
, BUILD_END
);
634 case SC_FORMAT_KEYID
:
635 key
= lib
->creds
->create(lib
->creds
,
636 CRED_PRIVATE_KEY
, KEY_ANY
,
637 BUILD_PKCS11_KEYID
, chunk
, BUILD_END
);
642 lib
->credmgr
->remove_local_set(lib
->credmgr
, &mem
->set
);
647 lib
->credmgr
->remove_local_set(lib
->credmgr
, &cb
->set
);
653 DBG1(DBG_CFG
, " loaded private key from %.*s", sc
.len
, sc
.ptr
);
654 this->creds
->add_key(this->creds
, key
);
662 static bool load_private(private_stroke_cred_t
*this, chunk_t line
, int line_nr
,
663 FILE *prompt
, key_type_t key_type
)
667 chunk_t secret
= chunk_empty
;
670 err_t ugh
= extract_value(&filename
, &line
);
674 DBG1(DBG_CFG
, "line %d: %s", line_nr
, ugh
);
677 if (filename
.len
== 0)
679 DBG1(DBG_CFG
, "line %d: empty filename", line_nr
);
682 if (*filename
.ptr
== '/')
684 /* absolute path name */
685 snprintf(path
, sizeof(path
), "%.*s", (int)filename
.len
, filename
.ptr
);
689 /* relative path name */
690 snprintf(path
, sizeof(path
), "%s/%.*s", PRIVATE_KEY_DIR
,
691 (int)filename
.len
, filename
.ptr
);
694 /* check for optional passphrase */
695 if (eat_whitespace(&line
))
697 ugh
= extract_secret(&secret
, &line
);
700 DBG1(DBG_CFG
, "line %d: malformed passphrase: %s", line_nr
, ugh
);
704 if (secret
.len
== 7 && strneq(secret
.ptr
, "%prompt", 7))
706 callback_cred_t
*cb
= NULL
;
707 passphrase_cb_data_t pp_data
= {
718 /* use callback credential set to prompt for the passphrase */
719 pp_data
.prompt
= prompt
;
722 cb
= callback_cred_create_shared((void*)passphrase_cb
, &pp_data
);
723 lib
->credmgr
->add_local_set(lib
->credmgr
, &cb
->set
);
725 key
= lib
->creds
->create(lib
->creds
, CRED_PRIVATE_KEY
, key_type
,
726 BUILD_FROM_FILE
, path
, BUILD_END
);
728 lib
->credmgr
->remove_local_set(lib
->credmgr
, &cb
->set
);
733 mem_cred_t
*mem
= NULL
;
734 shared_key_t
*shared
;
736 /* provide our pin in a temporary credential set */
737 shared
= shared_key_create(SHARED_PRIVATE_KEY_PASS
, secret
);
738 mem
= mem_cred_create();
739 mem
->add_shared(mem
, shared
, NULL
);
740 lib
->credmgr
->add_local_set(lib
->credmgr
, &mem
->set
);
742 key
= lib
->creds
->create(lib
->creds
, CRED_PRIVATE_KEY
, key_type
,
743 BUILD_FROM_FILE
, path
, BUILD_END
);
745 lib
->credmgr
->remove_local_set(lib
->credmgr
, &mem
->set
);
750 DBG1(DBG_CFG
, " loaded %N private key from '%s'",
751 key_type_names
, key
->get_type(key
), path
);
752 this->creds
->add_key(this->creds
, key
);
756 DBG1(DBG_CFG
, " loading private key from '%s' failed", path
);
764 static bool load_shared(private_stroke_cred_t
*this, chunk_t line
, int line_nr
,
765 shared_key_type_t type
, chunk_t ids
)
767 shared_key_t
*shared_key
;
768 linked_list_t
*owners
;
769 chunk_t secret
= chunk_empty
;
772 err_t ugh
= extract_secret(&secret
, &line
);
775 DBG1(DBG_CFG
, "line %d: malformed secret: %s", line_nr
, ugh
);
778 shared_key
= shared_key_create(type
, secret
);
779 DBG1(DBG_CFG
, " loaded %N secret for %s", shared_key_type_names
, type
,
780 ids
.len
> 0 ?
(char*)ids
.ptr
: "%any");
781 DBG4(DBG_CFG
, " secret: %#B", &secret
);
783 owners
= linked_list_create();
787 identification_t
*peer_id
;
789 ugh
= extract_value(&id
, &ids
);
792 DBG1(DBG_CFG
, "line %d: %s", line_nr
, ugh
);
793 shared_key
->destroy(shared_key
);
794 owners
->destroy_offset(owners
, offsetof(identification_t
, destroy
));
802 /* NULL terminate the ID string */
803 *(id
.ptr
+ id
.len
) = '\0';
804 peer_id
= identification_create_from_string(id
.ptr
);
805 if (peer_id
->get_type(peer_id
) == ID_ANY
)
807 peer_id
->destroy(peer_id
);
811 owners
->insert_last(owners
, peer_id
);
816 owners
->insert_last(owners
,
817 identification_create_from_encoding(ID_ANY
, chunk_empty
));
819 this->creds
->add_shared_list(this->creds
, shared_key
, owners
);
824 * reload ipsec.secrets
826 static void load_secrets(private_stroke_cred_t
*this, char *file
, int level
,
834 DBG1(DBG_CFG
, "loading secrets from '%s'", file
);
835 fd
= open(file
, O_RDONLY
);
838 DBG1(DBG_CFG
, "opening secrets file '%s' failed: %s", file
,
842 if (fstat(fd
, &sb
) == -1)
844 DBG1(DBG_LIB
, "getting file size of '%s' failed: %s", file
,
849 addr
= mmap(NULL
, sb
.st_size
, PROT_READ
| PROT_WRITE
, MAP_PRIVATE
, fd
, 0);
850 if (addr
== MAP_FAILED
)
852 DBG1(DBG_LIB
, "mapping '%s' failed: %s", file
, strerror(errno
));
856 src
= chunk_create(addr
, sb
.st_size
);
859 { /* flush secrets on non-recursive invocation */
860 this->creds
->clear_secrets(this->creds
);
863 while (fetchline(&src
, &line
))
866 shared_key_type_t type
;
870 if (!eat_whitespace(&line
))
874 if (line
.len
> strlen("include ") &&
875 strneq(line
.ptr
, "include ", strlen("include ")))
877 char **expanded
, *dir
, pattern
[PATH_MAX
];
880 if (level
> MAX_SECRETS_RECURSION
)
882 DBG1(DBG_CFG
, "maximum level of %d includes reached, ignored",
883 MAX_SECRETS_RECURSION
);
886 /* terminate filename by space */
887 line
= chunk_skip(line
, strlen("include "));
888 pos
= memchr(line
.ptr
, ' ', line
.len
);
891 line
.len
= pos
- line
.ptr
;
893 if (line
.len
&& line
.ptr
[0] == '/')
895 if (line
.len
+ 1 > sizeof(pattern
))
897 DBG1(DBG_CFG
, "include pattern too long, ignored");
900 snprintf(pattern
, sizeof(pattern
), "%.*s",
901 (int)line
.len
, line
.ptr
);
904 { /* use directory of current file if relative */
908 if (line
.len
+ 1 + strlen(dir
) + 1 > sizeof(pattern
))
910 DBG1(DBG_CFG
, "include pattern too long, ignored");
914 snprintf(pattern
, sizeof(pattern
), "%s/%.*s",
915 dir
, (int)line
.len
, line
.ptr
);
921 if (glob(pattern
, GLOB_ERR
, NULL
, &buf
) != 0)
923 DBG1(DBG_CFG
, "expanding file expression '%s' failed",
928 for (expanded
= buf
.gl_pathv
; *expanded
!= NULL
; expanded
++)
930 load_secrets(this, *expanded
, level
+ 1, prompt
);
935 #else /* HAVE_GLOB_H */
936 /* if glob(3) is not available, try to load pattern directly */
937 load_secrets(this, pattern
, level
+ 1, prompt
);
938 #endif /* HAVE_GLOB_H */
942 if (line
.len
> 2 && strneq(": ", line
.ptr
, 2))
944 /* no ids, skip the ':' */
949 else if (extract_token_str(&ids
, " : ", &line
))
951 /* NULL terminate the extracted id string */
952 *(ids
.ptr
+ ids
.len
) = '\0';
956 DBG1(DBG_CFG
, "line %d: missing ' : ' separator", line_nr
);
960 if (!eat_whitespace(&line
) || !extract_token(&token
, ' ', &line
))
962 DBG1(DBG_CFG
, "line %d: missing token", line_nr
);
965 if (match("RSA", &token
) || match("ECDSA", &token
))
967 if (!load_private(this, line
, line_nr
, prompt
,
968 match("RSA", &token
) ? KEY_RSA
: KEY_ECDSA
))
973 else if (match("PIN", &token
))
975 if (!load_pin(this, line
, line_nr
, prompt
))
980 else if ((match("PSK", &token
) && (type
= SHARED_IKE
)) ||
981 (match("EAP", &token
) && (type
= SHARED_EAP
)) ||
982 (match("NTLM", &token
) && (type
= SHARED_NT_HASH
)) ||
983 (match("XAUTH", &token
) && (type
= SHARED_EAP
)))
985 if (!load_shared(this, line
, line_nr
, type
, ids
))
992 DBG1(DBG_CFG
, "line %d: token must be either "
993 "RSA, ECDSA, PSK, EAP, XAUTH or PIN", line_nr
);
997 munmap(addr
, sb
.st_size
);
1002 * load all certificates from ipsec.d
1004 static void load_certs(private_stroke_cred_t
*this)
1006 DBG1(DBG_CFG
, "loading ca certificates from '%s'",
1007 CA_CERTIFICATE_DIR
);
1008 load_certdir(this, CA_CERTIFICATE_DIR
, CERT_X509
, X509_CA
);
1010 DBG1(DBG_CFG
, "loading aa certificates from '%s'",
1011 AA_CERTIFICATE_DIR
);
1012 load_certdir(this, AA_CERTIFICATE_DIR
, CERT_X509
, X509_AA
);
1014 DBG1(DBG_CFG
, "loading ocsp signer certificates from '%s'",
1015 OCSP_CERTIFICATE_DIR
);
1016 load_certdir(this, OCSP_CERTIFICATE_DIR
, CERT_X509
, X509_OCSP_SIGNER
);
1018 DBG1(DBG_CFG
, "loading attribute certificates from '%s'",
1019 ATTR_CERTIFICATE_DIR
);
1020 load_certdir(this, ATTR_CERTIFICATE_DIR
, CERT_X509_AC
, 0);
1022 DBG1(DBG_CFG
, "loading crls from '%s'",
1024 load_certdir(this, CRL_DIR
, CERT_X509_CRL
, 0);
1027 METHOD(stroke_cred_t
, reread
, void,
1028 private_stroke_cred_t
*this, stroke_msg_t
*msg
, FILE *prompt
)
1030 if (msg
->reread
.flags
& REREAD_SECRETS
)
1032 DBG1(DBG_CFG
, "rereading secrets");
1033 load_secrets(this, SECRETS_FILE
, 0, prompt
);
1035 if (msg
->reread
.flags
& REREAD_CACERTS
)
1037 DBG1(DBG_CFG
, "rereading ca certificates from '%s'",
1038 CA_CERTIFICATE_DIR
);
1039 load_certdir(this, CA_CERTIFICATE_DIR
, CERT_X509
, X509_CA
);
1041 if (msg
->reread
.flags
& REREAD_OCSPCERTS
)
1043 DBG1(DBG_CFG
, "rereading ocsp signer certificates from '%s'",
1044 OCSP_CERTIFICATE_DIR
);
1045 load_certdir(this, OCSP_CERTIFICATE_DIR
, CERT_X509
,
1048 if (msg
->reread
.flags
& REREAD_AACERTS
)
1050 DBG1(DBG_CFG
, "rereading aa certificates from '%s'",
1051 AA_CERTIFICATE_DIR
);
1052 load_certdir(this, AA_CERTIFICATE_DIR
, CERT_X509
, X509_AA
);
1054 if (msg
->reread
.flags
& REREAD_ACERTS
)
1056 DBG1(DBG_CFG
, "rereading attribute certificates from '%s'",
1057 ATTR_CERTIFICATE_DIR
);
1058 load_certdir(this, ATTR_CERTIFICATE_DIR
, CERT_X509_AC
, 0);
1060 if (msg
->reread
.flags
& REREAD_CRLS
)
1062 DBG1(DBG_CFG
, "rereading crls from '%s'",
1064 load_certdir(this, CRL_DIR
, CERT_X509_CRL
, 0);
1068 METHOD(stroke_cred_t
, destroy
, void,
1069 private_stroke_cred_t
*this)
1071 lib
->credmgr
->remove_set(lib
->credmgr
, &this->creds
->set
);
1072 this->creds
->destroy(this->creds
);
1079 stroke_cred_t
*stroke_cred_create()
1081 private_stroke_cred_t
*this;
1086 .create_private_enumerator
= (void*)return_null
,
1087 .create_cert_enumerator
= (void*)return_null
,
1088 .create_shared_enumerator
= (void*)return_null
,
1089 .create_cdp_enumerator
= (void*)return_null
,
1090 .cache_cert
= (void*)_cache_cert
,
1093 .load_ca
= _load_ca
,
1094 .load_peer
= _load_peer
,
1095 .cachecrl
= _cachecrl
,
1096 .destroy
= _destroy
,
1098 .creds
= mem_cred_create(),
1101 lib
->credmgr
->add_set(lib
->credmgr
, &this->creds
->set
);
1103 this->force_ca_cert
= lib
->settings
->get_bool(lib
->settings
,
1104 "charon.plugins.stroke.ignore_missing_ca_basic_constraint", FALSE
);
1107 load_secrets(this, SECRETS_FILE
, 0, NULL
);
1109 return &this->public;