Updated dnskey plugin to the new builder API
This commit is contained in:
@@ -46,7 +46,7 @@ enum dnskey_algorithm_t {
|
|||||||
/**
|
/**
|
||||||
* Load a generic public key from a DNSKEY RR blob
|
* Load a generic public key from a DNSKEY RR blob
|
||||||
*/
|
*/
|
||||||
static public_key_t *parse_public_key(chunk_t blob)
|
static dnskey_public_key_t *parse_public_key(chunk_t blob)
|
||||||
{
|
{
|
||||||
dnskey_rr_t *rr = (dnskey_rr_t*)blob.ptr;
|
dnskey_rr_t *rr = (dnskey_rr_t*)blob.ptr;
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ static public_key_t *parse_public_key(chunk_t blob)
|
|||||||
/**
|
/**
|
||||||
* Load a RSA public key from DNSKEY RR data
|
* Load a RSA public key from DNSKEY RR data
|
||||||
*/
|
*/
|
||||||
static public_key_t *parse_rsa_public_key(chunk_t blob)
|
static dnskey_public_key_t *parse_rsa_public_key(chunk_t blob)
|
||||||
{
|
{
|
||||||
chunk_t n, e;
|
chunk_t n, e;
|
||||||
|
|
||||||
@@ -104,83 +104,39 @@ static public_key_t *parse_rsa_public_key(chunk_t blob)
|
|||||||
BUILD_END);
|
BUILD_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct private_builder_t private_builder_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder implementation for private/public key loading
|
* See header.
|
||||||
*/
|
*/
|
||||||
struct private_builder_t {
|
dnskey_public_key_t *dnskey_public_key_load(key_type_t type, va_list args)
|
||||||
/** implements the builder interface */
|
|
||||||
builder_t public;
|
|
||||||
/** dnskey packet data */
|
|
||||||
chunk_t blob;
|
|
||||||
/** type of key to build */
|
|
||||||
key_type_t type;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of builder_t.build for public keys
|
|
||||||
*/
|
|
||||||
static public_key_t *build_public(private_builder_t *this)
|
|
||||||
{
|
{
|
||||||
public_key_t *key = NULL;
|
chunk_t blob = chunk_empty;
|
||||||
|
|
||||||
switch (this->type)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
case KEY_ANY:
|
switch (va_arg(args, builder_part_t))
|
||||||
key = parse_public_key(this->blob);
|
|
||||||
break;
|
|
||||||
case KEY_RSA:
|
|
||||||
key = parse_rsa_public_key(this->blob);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free(this);
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of builder_t.add for public keys
|
|
||||||
*/
|
|
||||||
static void add_public(private_builder_t *this, builder_part_t part, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
|
|
||||||
switch (part)
|
|
||||||
{
|
|
||||||
case BUILD_BLOB_DNSKEY:
|
|
||||||
{
|
{
|
||||||
va_start(args, part);
|
case BUILD_BLOB_DNSKEY:
|
||||||
this->blob = va_arg(args, chunk_t);
|
blob = va_arg(args, chunk_t);
|
||||||
va_end(args);
|
continue;
|
||||||
break;
|
case BUILD_END:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
default:
|
break;
|
||||||
builder_cancel(&this->public);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
if (!blob.ptr)
|
||||||
|
|
||||||
/**
|
|
||||||
* Builder construction function for public keys
|
|
||||||
*/
|
|
||||||
builder_t *dnskey_public_key_builder(key_type_t type)
|
|
||||||
{
|
|
||||||
private_builder_t *this;
|
|
||||||
|
|
||||||
if (type != KEY_ANY && type != KEY_RSA)
|
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
switch (type)
|
||||||
this = malloc_thing(private_builder_t);
|
{
|
||||||
|
case KEY_ANY:
|
||||||
this->blob = chunk_empty;
|
return parse_public_key(blob);
|
||||||
this->type = type;
|
case KEY_RSA:
|
||||||
this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add_public;
|
return parse_rsa_public_key(blob);
|
||||||
this->public.build = (void*(*)(builder_t *this))build_public;
|
default:
|
||||||
|
return NULL;
|
||||||
return &this->public;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,31 @@
|
|||||||
#ifndef DNSKEY_BUILDER_H_
|
#ifndef DNSKEY_BUILDER_H_
|
||||||
#define DNSKEY_BUILDER_H_
|
#define DNSKEY_BUILDER_H_
|
||||||
|
|
||||||
|
#include <credentials/builder.h>
|
||||||
#include <credentials/keys/public_key.h>
|
#include <credentials/keys/public_key.h>
|
||||||
|
|
||||||
|
typedef struct dnskey_public_key_t dnskey_public_key_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the builder for a generic or an RSA public key.
|
* Public key implementation supporting RFC4034 decoding.
|
||||||
*
|
|
||||||
* @param type type of the key, either KEY_ANY or KEY_RSA
|
|
||||||
* @return builder instance
|
|
||||||
*/
|
*/
|
||||||
builder_t *dnskey_public_key_builder(key_type_t type);
|
struct dnskey_public_key_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements public_key_t interface.
|
||||||
|
*/
|
||||||
|
public_key_t interface;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a public key in RFC4034 format.
|
||||||
|
*
|
||||||
|
* Takes a BUILD_BLOB_DNSKEY to parse the public key.
|
||||||
|
*
|
||||||
|
* @param type type of the key, must be KEY_RSA or KEY_ANY
|
||||||
|
* @param args builder_part_t argument list
|
||||||
|
* @return built key, NULL on failure
|
||||||
|
*/
|
||||||
|
dnskey_public_key_t *dnskey_public_key_load(key_type_t type, va_list args);
|
||||||
|
|
||||||
#endif /** DNSKEY_BUILDER_H_ @}*/
|
#endif /** DNSKEY_BUILDER_H_ @}*/
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ struct private_dnskey_plugin_t {
|
|||||||
static void destroy(private_dnskey_plugin_t *this)
|
static void destroy(private_dnskey_plugin_t *this)
|
||||||
{
|
{
|
||||||
lib->creds->remove_builder(lib->creds,
|
lib->creds->remove_builder(lib->creds,
|
||||||
(builder_constructor_t)dnskey_public_key_builder);
|
(builder_function_t)dnskey_public_key_load);
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,9 +51,9 @@ plugin_t *plugin_create()
|
|||||||
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
|
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
|
||||||
|
|
||||||
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
|
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
|
||||||
(builder_constructor_t)dnskey_public_key_builder);
|
(builder_function_t)dnskey_public_key_load);
|
||||||
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
|
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
|
||||||
(builder_constructor_t)dnskey_public_key_builder);
|
(builder_function_t)dnskey_public_key_load);
|
||||||
|
|
||||||
return &this->public.plugin;
|
return &this->public.plugin;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user