use credential builder to build attribute certificates

This commit is contained in:
Martin Willi
2009-08-26 11:23:49 +02:00
parent a5dc4a9585
commit 37f5a0da2c
2 changed files with 82 additions and 17 deletions
+75 -4
View File
@@ -30,6 +30,7 @@
#include "log.h"
#include "id.h"
#include "certs.h"
#include "ac.h"
/**
* currently building cert_t
@@ -39,7 +40,7 @@ static cert_t *cert;
/**
* builder add function
*/
static void add(builder_t *this, builder_part_t part, ...)
static void cert_add(builder_t *this, builder_part_t part, ...)
{
chunk_t blob;
va_list args;
@@ -91,7 +92,7 @@ static void add(builder_t *this, builder_part_t part, ...)
/**
* builder build function
*/
static void *build(builder_t *this)
static void *cert_build(builder_t *this)
{
free(this);
if (cert->type == CERT_NONE)
@@ -113,8 +114,8 @@ static builder_t *cert_builder(credential_type_t type, int subtype)
return NULL;
}
this = malloc_thing(builder_t);
this->add = add;
this->build = build;
this->add = cert_add;
this->build = cert_build;
cert->type = CERT_NONE;
cert->u.x509 = NULL;
@@ -123,14 +124,84 @@ static builder_t *cert_builder(credential_type_t type, int subtype)
return this;
}
/**
* currently building x509ac_t
*/
static x509acert_t *ac;
/**
* builder add function
*/
static void ac_add(builder_t *this, builder_part_t part, ...)
{
chunk_t blob;
va_list args;
switch (part)
{
case BUILD_BLOB_ASN1_DER:
{
va_start(args, part);
blob = va_arg(args, chunk_t);
va_end(args);
ac = malloc_thing(x509acert_t);
*ac = empty_ac;
if (!parse_ac(blob, ac) && !verify_x509acert(ac, FALSE))
{
free_acert(ac);
ac = NULL;
}
break;
}
default:
builder_cancel(this);
break;
}
}
/**
* builder build function
*/
static void *ac_build(builder_t *this)
{
free(this);
return ac;
}
/**
* certificate builder in x509ac_t format.
*/
static builder_t *ac_builder(credential_type_t type, int subtype)
{
builder_t *this;
if (subtype != CRED_TYPE_AC)
{
return NULL;
}
this = malloc_thing(builder_t);
this->add = ac_add;
this->build = ac_build;
ac = NULL;
return this;
}
void init_builder(void)
{
lib->creds->add_builder(lib->creds, CRED_PLUTO_CERT, CRED_TYPE_CERTIFICATE,
(builder_constructor_t)cert_builder);
lib->creds->add_builder(lib->creds, CRED_PLUTO_CERT, CRED_TYPE_AC,
(builder_constructor_t)ac_builder);
}
void free_builder(void)
{
lib->creds->remove_builder(lib->creds, (builder_constructor_t)cert_builder);
lib->creds->remove_builder(lib->creds, (builder_constructor_t)ac_builder);
}