Implemented BUILD_BLOB_ASN1_DER for the CERT_TRUSTED_PUBKEY subtype
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 8 Oct 2008 01:19:26 +0000 (01:19 -0000)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 8 Oct 2008 01:19:26 +0000 (01:19 -0000)
src/libstrongswan/plugins/pubkey/pubkey_cert.c
src/libstrongswan/plugins/pubkey/pubkey_public_key.c

index 6305f46..23058ec 100644 (file)
 
 #include <debug.h>
 
+/**
+ * defined in pubkey_public_key.c
+ */
+extern public_key_t *pubkey_public_key_load(chunk_t blob);
+
 typedef struct private_pubkey_cert_t private_pubkey_cert_t;
 
 /**
@@ -211,6 +216,13 @@ static pubkey_cert_t *pubkey_cert_create(public_key_t *key)
        return &this->public;
 }
 
+static pubkey_cert_t *pubkey_cert_create_from_chunk(chunk_t blob)
+{
+       public_key_t *key = pubkey_public_key_load(chunk_clone(blob));
+
+       return (key)? pubkey_cert_create(key) : NULL;
+}
+
 typedef struct private_builder_t private_builder_t;
 /**
  * Builder implementation for key loading
@@ -244,6 +256,13 @@ static void add(private_builder_t *this, builder_part_t part, ...)
        
                switch (part)
                {
+                       case BUILD_BLOB_ASN1_DER:
+                       {
+                               va_start(args, part);
+                               this->key = pubkey_cert_create_from_chunk(va_arg(args, chunk_t));
+                               va_end(args);
+                               return;
+                       }
                        case BUILD_PUBLIC_KEY:
                        {
                                va_start(args, part);
index 0bb3d71..552fa6c 100644 (file)
@@ -39,9 +39,10 @@ static const asn1Object_t pkinfoObjects[] = {
 
 
 /**
- * Load a public key from an ASN1 encoded blob
+ * Load a public key from an ASN.1 encoded blob
+ * Also used by pubkey_cert.c
  */
-static public_key_t *load(chunk_t blob)
+public_key_t *pubkey_public_key_load(chunk_t blob)
 {
        asn1_parser_t *parser;
        chunk_t object;
@@ -134,7 +135,7 @@ static void add(private_builder_t *this, builder_part_t part, ...)
                        {
                                va_start(args, part);
                                blob = va_arg(args, chunk_t);
-                               this->key = load(chunk_clone(blob));
+                               this->key = pubkey_public_key_load(chunk_clone(blob));
                                va_end(args);
                                return;
                        }
@@ -148,7 +149,7 @@ static void add(private_builder_t *this, builder_part_t part, ...)
                                blob = chunk_clone(chunk_create(pem, strlen(pem)));
                                if (pem_to_bin(&blob, &chunk_empty, &pgp))
                                {
-                                       this->key = load(chunk_clone(blob));
+                                       this->key = pubkey_public_key_load(chunk_clone(blob));
                                }
                                free(blob.ptr);
                                va_end(args);