loading PEM encoded public keys
authorMartin Willi <martin@strongswan.org>
Wed, 11 Jun 2008 14:10:02 +0000 (14:10 -0000)
committerMartin Willi <martin@strongswan.org>
Wed, 11 Jun 2008 14:10:02 +0000 (14:10 -0000)
src/libstrongswan/credentials/builder.c
src/libstrongswan/credentials/builder.h
src/libstrongswan/credentials/credential_factory.c
src/libstrongswan/plugins/pubkey/pubkey_public_key.c

index 6a03cbd..c13a8a8 100644 (file)
@@ -18,6 +18,7 @@
 ENUM(builder_part_names, BUILD_BLOB_ASN1_DER, BUILD_END,
        "BUILD_FROM_FILE",
        "BUILD_BLOB_ASN1_DER",
+       "BUILD_BLOB_ASN1_PEM",
        "BUILD_KEY_SIZE",
        "BUILD_SIGNING_KEY",
        "BUILD_SIGNING_CERT",
index 54aca33..22c106b 100644 (file)
@@ -42,6 +42,8 @@ enum builder_part_t {
        BUILD_FROM_FILE,
        /** DER encoded ASN1 blob, chunk_t */
        BUILD_BLOB_ASN1_DER,
+       /** PEM encoded ASN1 blob, null terminated char* */
+       BUILD_BLOB_ASN1_PEM,
        /** key size in bits, as used for key generation, u_int */
        BUILD_KEY_SIZE,
        /** private key to use for signing, private_key_t* */
index de4c2fb..951ddb5 100644 (file)
@@ -165,6 +165,7 @@ static void* create(private_credential_factory_t *this, credential_type_t type,
                                case BUILD_NOT_AFTER_TIME:
                                        builder->add(builder, part, va_arg(args, time_t));
                                        continue;
+                               case BUILD_BLOB_ASN1_PEM:
                                case BUILD_FROM_FILE:
                                case BUILD_SIGNING_KEY:
                                case BUILD_PUBLIC_KEY:
@@ -261,6 +262,7 @@ static void* create(private_credential_factory_t *this, credential_type_t type,
                                cert->destroy(cert);
                                continue;
                        }
+                       case BUILD_BLOB_ASN1_PEM:
                        case BUILD_FROM_FILE:
                        case BUILD_IETF_GROUP_ATTR:
                        {
index 1291b6e..5a072c4 100644 (file)
@@ -20,6 +20,7 @@
 #include "pubkey_public_key.h"
 
 #include <debug.h>
+#include <asn1/pem.h>
 #include <asn1/oid.h>
 #include <asn1/asn1.h>
 #include <asn1/asn1_parser.h>
@@ -131,19 +132,34 @@ static void add(private_builder_t *this, builder_part_t part, ...)
                DBG1("ignoring surplus build part %N", builder_part_names, part);
                return;
        }
+       va_start(args, part);
        switch (part)
        {
                case BUILD_BLOB_ASN1_DER:
                {
-                       va_start(args, part);
                        this->key = load(va_arg(args, chunk_t));
-                       va_end(args);
+                       break;
+               }
+               case BUILD_BLOB_ASN1_PEM:
+               {
+                       bool pgp;
+                       char *pem;
+                       chunk_t blob;
+                       
+                       pem = va_arg(args, char *);
+                       blob = chunk_clone(chunk_create(pem, strlen(pem)));
+                       if (pem_to_bin(&blob, &chunk_empty, &pgp))
+                       {
+                               this->key = load(chunk_clone(blob));
+                       }
+                       free(blob.ptr);
                        break;
                }
                default:
                        DBG1("ignoring unsupported build part %N", builder_part_names, part);
                        break;
        }
+       va_end(args);
 }
 
 /**