]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Added support to parse PKCS#8 encoded ECDSA private keys.
authorTobias Brunner <tobias@strongswan.org>
Wed, 18 Jan 2012 21:33:36 +0000 (22:33 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 1 Feb 2012 17:27:45 +0000 (18:27 +0100)
src/libstrongswan/plugins/pkcs8/pkcs8_builder.c
src/libstrongswan/plugins/pkcs8/pkcs8_builder.h
src/libstrongswan/plugins/pkcs8/pkcs8_plugin.c

index f79925a0264733ba61012dbad0b5925e9386d9a2..a83dc307dab079d07326246f7cd3b643c8e71a79 100644 (file)
@@ -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, &params);
 
-                               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;
                        }
index 31965fa19433e8511aeb404c51372bff28a91684..b07f2d9276b0e32c84c8a34319e31b5871f43d31 100644 (file)
@@ -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
  */
index 433da09b6a0343a044f3c82631b9294ae9a5f6cd..f78c83054e473c20526a0ce997602257708d98ee 100644 (file)
@@ -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);