diff options
author | Martin Willi <martin@revosec.ch> | 2010-10-29 11:55:19 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2011-01-05 16:45:40 +0100 |
commit | 3f759bb75b52d115d908a7fcc7b04a017fe8f690 (patch) | |
tree | 682ac8615687ae9ca7c351ffb9d45f5b6cc27bcb | |
parent | a13c1d649f686347d4512580faa51a3e21a6cf0c (diff) | |
download | strongswan-3f759bb75b52d115d908a7fcc7b04a017fe8f690.tar.bz2 strongswan-3f759bb75b52d115d908a7fcc7b04a017fe8f690.tar.xz |
Load private keys from suite and test configs
-rw-r--r-- | src/conftest/conftest.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/conftest/conftest.c b/src/conftest/conftest.c index 34051977b..6efd063b1 100644 --- a/src/conftest/conftest.c +++ b/src/conftest/conftest.c @@ -149,6 +149,66 @@ static bool load_certs(settings_t *settings, char *dir) } /** + * Load private keys from the confiuguration file + */ +static bool load_keys(settings_t *settings, char *dir) +{ + enumerator_t *enumerator; + char *type, *value, wd[PATH_MAX]; + private_key_t *key; + key_type_t key_type; + + if (getcwd(wd, sizeof(wd)) == NULL) + { + fprintf(stderr, "getting cwd failed: %s\n", strerror(errno)); + return FALSE; + } + if (chdir(dir) != 0) + { + fprintf(stderr, "opening directory '%s' failed: %s\n", + dir, strerror(errno)); + return FALSE; + } + + enumerator = settings->create_key_value_enumerator(settings, "keys"); + while (enumerator->enumerate(enumerator, &type, &value)) + { + if (strcaseeq(type, "ecdsa")) + { + key_type = KEY_ECDSA; + } + else if (strcaseeq(type, "rsa")) + { + key_type = KEY_RSA; + } + else + { + fprintf(stderr, "unkown key type: '%s'\n", type); + enumerator->destroy(enumerator); + return FALSE; + } + key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, key_type, + BUILD_FROM_FILE, value, BUILD_END); + if (!key) + { + fprintf(stderr, "loading %s key from '%s' failed\n", type, value); + enumerator->destroy(enumerator); + return FALSE; + } + conftest->creds->add_key(conftest->creds, key); + } + enumerator->destroy(enumerator); + + if (chdir(wd) != 0) + { + fprintf(stderr, "opening directory '%s' failed: %s\n", + wd, strerror(errno)); + return FALSE; + } + return TRUE; +} + +/** * Load configured hooks */ static bool load_hooks() @@ -306,6 +366,11 @@ int main(int argc, char *argv[]) { return 1; } + if (!load_keys(conftest->suite, suite_file) || + !load_keys(conftest->test, test_file)) + { + return 1; + } if (!load_hooks()) { return 1; |