vici: Add a credential backend
This commit is contained in:
@@ -21,6 +21,7 @@ libstrongswan_vici_la_SOURCES = \
|
|||||||
vici_query.h vici_query.c \
|
vici_query.h vici_query.c \
|
||||||
vici_control.h vici_control.c \
|
vici_control.h vici_control.c \
|
||||||
vici_config.h vici_config.c \
|
vici_config.h vici_config.c \
|
||||||
|
vici_cred.h vici_cred.c \
|
||||||
vici_plugin.h vici_plugin.c
|
vici_plugin.h vici_plugin.c
|
||||||
|
|
||||||
libstrongswan_vici_la_LDFLAGS = -module -avoid-version
|
libstrongswan_vici_la_LDFLAGS = -module -avoid-version
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Martin Willi
|
||||||
|
* Copyright (C) 2014 revosec AG
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "vici_cred.h"
|
||||||
|
#include "vici_builder.h"
|
||||||
|
|
||||||
|
#include <credentials/sets/mem_cred.h>
|
||||||
|
#include <credentials/certificates/ac.h>
|
||||||
|
#include <credentials/certificates/crl.h>
|
||||||
|
#include <credentials/certificates/x509.h>
|
||||||
|
|
||||||
|
typedef struct private_vici_cred_t private_vici_cred_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private data of an vici_cred_t object.
|
||||||
|
*/
|
||||||
|
struct private_vici_cred_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public vici_cred_t interface.
|
||||||
|
*/
|
||||||
|
vici_cred_t public;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatcher
|
||||||
|
*/
|
||||||
|
vici_dispatcher_t *dispatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* credentials
|
||||||
|
*/
|
||||||
|
mem_cred_t *creds;
|
||||||
|
};
|
||||||
|
|
||||||
|
CALLBACK(clear_creds, vici_message_t*,
|
||||||
|
private_vici_cred_t *this, char *name, u_int id, vici_message_t *message)
|
||||||
|
{
|
||||||
|
vici_builder_t *builder;
|
||||||
|
|
||||||
|
this->creds->clear(this->creds);
|
||||||
|
|
||||||
|
builder = vici_builder_create();
|
||||||
|
return builder->finalize(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void manage_command(private_vici_cred_t *this,
|
||||||
|
char *name, vici_command_cb_t cb, bool reg)
|
||||||
|
{
|
||||||
|
this->dispatcher->manage_command(this->dispatcher, name,
|
||||||
|
reg ? cb : NULL, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Un-)register dispatcher functions
|
||||||
|
*/
|
||||||
|
static void manage_commands(private_vici_cred_t *this, bool reg)
|
||||||
|
{
|
||||||
|
manage_command(this, "clear-creds", clear_creds, reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(vici_cred_t, destroy, void,
|
||||||
|
private_vici_cred_t *this)
|
||||||
|
{
|
||||||
|
manage_commands(this, FALSE);
|
||||||
|
|
||||||
|
lib->credmgr->remove_set(lib->credmgr, &this->creds->set);
|
||||||
|
this->creds->destroy(this->creds);
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See header
|
||||||
|
*/
|
||||||
|
vici_cred_t *vici_cred_create(vici_dispatcher_t *dispatcher)
|
||||||
|
{
|
||||||
|
private_vici_cred_t *this;
|
||||||
|
|
||||||
|
INIT(this,
|
||||||
|
.public = {
|
||||||
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
.dispatcher = dispatcher,
|
||||||
|
.creds = mem_cred_create(),
|
||||||
|
);
|
||||||
|
|
||||||
|
lib->credmgr->add_set(lib->credmgr, &this->creds->set);
|
||||||
|
|
||||||
|
manage_commands(this, TRUE);
|
||||||
|
|
||||||
|
return &this->public;
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Martin Willi
|
||||||
|
* Copyright (C) 2014 revosec AG
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup vici_cred vici_cred
|
||||||
|
* @{ @ingroup vici
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VICI_CRED_H_
|
||||||
|
#define VICI_CRED_H_
|
||||||
|
|
||||||
|
#include "vici_dispatcher.h"
|
||||||
|
|
||||||
|
typedef struct vici_cred_t vici_cred_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In-memory credential backend, managed by VICI.
|
||||||
|
*/
|
||||||
|
struct vici_cred_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy a vici_cred_t.
|
||||||
|
*/
|
||||||
|
void (*destroy)(vici_cred_t *this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a vici_cred instance.
|
||||||
|
*
|
||||||
|
* @param dispatcher dispatcher to receive requests from
|
||||||
|
* @return credential backend
|
||||||
|
*/
|
||||||
|
vici_cred_t *vici_cred_create(vici_dispatcher_t *dispatcher);
|
||||||
|
|
||||||
|
#endif /** VICI_CRED_H_ @}*/
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "vici_dispatcher.h"
|
#include "vici_dispatcher.h"
|
||||||
#include "vici_query.h"
|
#include "vici_query.h"
|
||||||
#include "vici_control.h"
|
#include "vici_control.h"
|
||||||
|
#include "vici_cred.h"
|
||||||
#include "vici_config.h"
|
#include "vici_config.h"
|
||||||
|
|
||||||
#include <library.h>
|
#include <library.h>
|
||||||
@@ -49,6 +50,11 @@ struct private_vici_plugin_t {
|
|||||||
*/
|
*/
|
||||||
vici_control_t *control;
|
vici_control_t *control;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Credential backend
|
||||||
|
*/
|
||||||
|
vici_cred_t *cred;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration backend
|
* Configuration backend
|
||||||
*/
|
*/
|
||||||
@@ -78,6 +84,7 @@ static bool register_vici(private_vici_plugin_t *this,
|
|||||||
{
|
{
|
||||||
this->query = vici_query_create(this->dispatcher);
|
this->query = vici_query_create(this->dispatcher);
|
||||||
this->control = vici_control_create(this->dispatcher);
|
this->control = vici_control_create(this->dispatcher);
|
||||||
|
this->cred = vici_cred_create(this->dispatcher);
|
||||||
this->config = vici_config_create(this->dispatcher);
|
this->config = vici_config_create(this->dispatcher);
|
||||||
|
|
||||||
charon->backends->add_backend(charon->backends,
|
charon->backends->add_backend(charon->backends,
|
||||||
@@ -92,6 +99,7 @@ static bool register_vici(private_vici_plugin_t *this,
|
|||||||
&this->config->backend);
|
&this->config->backend);
|
||||||
|
|
||||||
this->config->destroy(this->config);
|
this->config->destroy(this->config);
|
||||||
|
this->cred->destroy(this->cred);
|
||||||
this->control->destroy(this->control);
|
this->control->destroy(this->control);
|
||||||
this->query->destroy(this->query);
|
this->query->destroy(this->query);
|
||||||
this->dispatcher->destroy(this->dispatcher);
|
this->dispatcher->destroy(this->dispatcher);
|
||||||
|
|||||||
Reference in New Issue
Block a user