diff options
author | Yves-Alexis Perez <corsac@debian.org> | 2014-07-11 07:23:31 +0200 |
---|---|---|
committer | Yves-Alexis Perez <corsac@debian.org> | 2014-07-11 07:23:31 +0200 |
commit | 81c63b0eed39432878f78727f60a1e7499645199 (patch) | |
tree | 82387d8fecd1c20788fd8bd784a9b0bde091fb6b /src/libstrongswan/plugins/sshkey/sshkey_builder.c | |
parent | c5ebfc7b9c16551fe825dc1d79c3f7e2f096f6c9 (diff) | |
download | vyos-strongswan-81c63b0eed39432878f78727f60a1e7499645199.tar.gz vyos-strongswan-81c63b0eed39432878f78727f60a1e7499645199.zip |
Imported Upstream version 5.2.0
Diffstat (limited to 'src/libstrongswan/plugins/sshkey/sshkey_builder.c')
-rw-r--r-- | src/libstrongswan/plugins/sshkey/sshkey_builder.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/libstrongswan/plugins/sshkey/sshkey_builder.c b/src/libstrongswan/plugins/sshkey/sshkey_builder.c index 652663108..4a9f5b849 100644 --- a/src/libstrongswan/plugins/sshkey/sshkey_builder.c +++ b/src/libstrongswan/plugins/sshkey/sshkey_builder.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Tobias Brunner + * Copyright (C) 2013-2014 Tobias Brunner * Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it @@ -140,8 +140,8 @@ static sshkey_public_key_t *load_from_stream(FILE *file) char line[1024], *token; while (!public && fgets(line, sizeof(line), file)) - { /* the format is: ssh-[rsa|ecdsa-...] <key(base64)> <identifier> */ - if (!strpfx(line, "ssh-")) + { /* the format is: ssh-rsa|ecdsa-... <key(base64)> <identifier> */ + if (!strpfx(line, "ssh-rsa") && !strpfx(line, ECDSA_PREFIX)) { continue; } @@ -235,3 +235,46 @@ sshkey_public_key_t *sshkey_public_key_load(key_type_t type, va_list args) } return NULL; } + +/** + * See header. + */ +certificate_t *sshkey_certificate_load(certificate_type_t type, va_list args) +{ + certificate_t *cert; + public_key_t *key; + identification_t *subject = NULL; + char *file = NULL; + + while (TRUE) + { + switch (va_arg(args, builder_part_t)) + { + case BUILD_FROM_FILE: + file = va_arg(args, char*); + continue; + case BUILD_SUBJECT: + subject = va_arg(args, identification_t*); + continue; + case BUILD_END: + break; + default: + return NULL; + } + break; + } + if (!file || !subject) + { + return NULL; + } + key = (public_key_t*)load_from_file(file); + if (!key) + { + return NULL; + } + cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, + CERT_TRUSTED_PUBKEY, BUILD_PUBLIC_KEY, key, + BUILD_SUBJECT, subject, BUILD_END); + key->destroy(key); + return cert; +} |