diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-01-18 22:33:36 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-02-01 18:27:45 +0100 |
commit | db3334dc32fce5e452deab997d45f5d029b72883 (patch) | |
tree | fa2c5078df6b504876d9707bec4f24f78c2c839b /src | |
parent | 27f8a61df31956a196e74070a5c35c2619bc01c8 (diff) | |
download | strongswan-db3334dc32fce5e452deab997d45f5d029b72883.tar.bz2 strongswan-db3334dc32fce5e452deab997d45f5d029b72883.tar.xz |
Added support to parse PKCS#8 encoded ECDSA private keys.
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/plugins/pkcs8/pkcs8_builder.c | 35 | ||||
-rw-r--r-- | src/libstrongswan/plugins/pkcs8/pkcs8_builder.h | 4 | ||||
-rw-r--r-- | src/libstrongswan/plugins/pkcs8/pkcs8_plugin.c | 1 |
3 files changed, 28 insertions, 12 deletions
diff --git a/src/libstrongswan/plugins/pkcs8/pkcs8_builder.c b/src/libstrongswan/plugins/pkcs8/pkcs8_builder.c index f79925a02..a83dc307d 100644 --- a/src/libstrongswan/plugins/pkcs8/pkcs8_builder.c +++ b/src/libstrongswan/plugins/pkcs8/pkcs8_builder.c @@ -42,7 +42,7 @@ static const asn1Object_t pkinfoObjects[] = { static private_key_t *parse_private_key(chunk_t blob) { asn1_parser_t *parser; - chunk_t object; + chunk_t object, params = chunk_empty; int objectID; private_key_t *key = NULL; key_type_t type = KEY_ANY; @@ -57,23 +57,38 @@ static private_key_t *parse_private_key(chunk_t blob) case PKINFO_PRIVATE_KEY_ALGORITHM: { int oid = asn1_parse_algorithmIdentifier(object, - parser->get_level(parser) + 1, NULL); + parser->get_level(parser) + 1, ¶ms); - if (oid == OID_RSA_ENCRYPTION) + switch (oid) { - type = KEY_RSA; - } - else - { /* key type not supported */ - goto end; + case OID_RSA_ENCRYPTION: + type = KEY_RSA; + break; + case OID_EC_PUBLICKEY: + type = KEY_ECDSA; + break; + default: + /* key type not supported */ + goto end; } break; } case PKINFO_PRIVATE_KEY: { DBG2(DBG_ASN, "-- > --"); - key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, type, - BUILD_BLOB_ASN1_DER, object, BUILD_END); + if (params.ptr) + { + key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, + type, BUILD_BLOB_ALGID_PARAMS, + params, BUILD_BLOB_ASN1_DER, + object, BUILD_END); + } + else + { + key = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, + type, BUILD_BLOB_ASN1_DER, object, + BUILD_END); + } DBG2(DBG_ASN, "-- < --"); break; } diff --git a/src/libstrongswan/plugins/pkcs8/pkcs8_builder.h b/src/libstrongswan/plugins/pkcs8/pkcs8_builder.h index 31965fa19..b07f2d927 100644 --- a/src/libstrongswan/plugins/pkcs8/pkcs8_builder.h +++ b/src/libstrongswan/plugins/pkcs8/pkcs8_builder.h @@ -25,9 +25,9 @@ #include <credentials/keys/private_key.h> /** - * Load an RSA private key from PKCS#8 data. + * Load an RSA or ECDSA private key from PKCS#8 data. * - * @param type type of the key, KEY_RSA + * @param type type of the key, KEY_RSA or KEY_ECDSA * @param args builder_part_t argument list * @return private key, NULL on failure */ diff --git a/src/libstrongswan/plugins/pkcs8/pkcs8_plugin.c b/src/libstrongswan/plugins/pkcs8/pkcs8_plugin.c index 433da09b6..f78c83054 100644 --- a/src/libstrongswan/plugins/pkcs8/pkcs8_plugin.c +++ b/src/libstrongswan/plugins/pkcs8/pkcs8_plugin.c @@ -44,6 +44,7 @@ METHOD(plugin_t, get_features, int, static plugin_feature_t f[] = { PLUGIN_REGISTER(PRIVKEY, pkcs8_private_key_load, FALSE), PLUGIN_PROVIDE(PRIVKEY, KEY_RSA), + PLUGIN_PROVIDE(PRIVKEY, KEY_ECDSA), }; *features = f; return countof(f); |