loading PEM encoded public keys
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
ENUM(builder_part_names, BUILD_BLOB_ASN1_DER, BUILD_END,
|
ENUM(builder_part_names, BUILD_BLOB_ASN1_DER, BUILD_END,
|
||||||
"BUILD_FROM_FILE",
|
"BUILD_FROM_FILE",
|
||||||
"BUILD_BLOB_ASN1_DER",
|
"BUILD_BLOB_ASN1_DER",
|
||||||
|
"BUILD_BLOB_ASN1_PEM",
|
||||||
"BUILD_KEY_SIZE",
|
"BUILD_KEY_SIZE",
|
||||||
"BUILD_SIGNING_KEY",
|
"BUILD_SIGNING_KEY",
|
||||||
"BUILD_SIGNING_CERT",
|
"BUILD_SIGNING_CERT",
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ enum builder_part_t {
|
|||||||
BUILD_FROM_FILE,
|
BUILD_FROM_FILE,
|
||||||
/** DER encoded ASN1 blob, chunk_t */
|
/** DER encoded ASN1 blob, chunk_t */
|
||||||
BUILD_BLOB_ASN1_DER,
|
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 */
|
/** key size in bits, as used for key generation, u_int */
|
||||||
BUILD_KEY_SIZE,
|
BUILD_KEY_SIZE,
|
||||||
/** private key to use for signing, private_key_t* */
|
/** private key to use for signing, private_key_t* */
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ static void* create(private_credential_factory_t *this, credential_type_t type,
|
|||||||
case BUILD_NOT_AFTER_TIME:
|
case BUILD_NOT_AFTER_TIME:
|
||||||
builder->add(builder, part, va_arg(args, time_t));
|
builder->add(builder, part, va_arg(args, time_t));
|
||||||
continue;
|
continue;
|
||||||
|
case BUILD_BLOB_ASN1_PEM:
|
||||||
case BUILD_FROM_FILE:
|
case BUILD_FROM_FILE:
|
||||||
case BUILD_SIGNING_KEY:
|
case BUILD_SIGNING_KEY:
|
||||||
case BUILD_PUBLIC_KEY:
|
case BUILD_PUBLIC_KEY:
|
||||||
@@ -261,6 +262,7 @@ static void* create(private_credential_factory_t *this, credential_type_t type,
|
|||||||
cert->destroy(cert);
|
cert->destroy(cert);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
case BUILD_BLOB_ASN1_PEM:
|
||||||
case BUILD_FROM_FILE:
|
case BUILD_FROM_FILE:
|
||||||
case BUILD_IETF_GROUP_ATTR:
|
case BUILD_IETF_GROUP_ATTR:
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "pubkey_public_key.h"
|
#include "pubkey_public_key.h"
|
||||||
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
#include <asn1/pem.h>
|
||||||
#include <asn1/oid.h>
|
#include <asn1/oid.h>
|
||||||
#include <asn1/asn1.h>
|
#include <asn1/asn1.h>
|
||||||
#include <asn1/asn1_parser.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);
|
DBG1("ignoring surplus build part %N", builder_part_names, part);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
va_start(args, part);
|
||||||
switch (part)
|
switch (part)
|
||||||
{
|
{
|
||||||
case BUILD_BLOB_ASN1_DER:
|
case BUILD_BLOB_ASN1_DER:
|
||||||
{
|
{
|
||||||
va_start(args, part);
|
|
||||||
this->key = load(va_arg(args, chunk_t));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
DBG1("ignoring unsupported build part %N", builder_part_names, part);
|
DBG1("ignoring unsupported build part %N", builder_part_names, part);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user