implemented IMC/IMV handler

This commit is contained in:
Andreas Steffen
2010-11-09 20:43:50 +01:00
parent 4da597631f
commit 1888dd6bd5
21 changed files with 1262 additions and 30 deletions
+2 -4
View File
@@ -1,11 +1,9 @@
INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon `xml2-config --cflags`
-I$(top_srcdir)/src/libcharon
AM_CFLAGS = -rdynamic
libstrongswan_tnc_imc_la_LIBADD = -ltnc
if MONOLITHIC
noinst_LTLIBRARIES = libstrongswan-tnc-imc.la
else
@@ -13,7 +11,7 @@ plugin_LTLIBRARIES = libstrongswan-tnc-imc.la
endif
libstrongswan_tnc_imc_la_SOURCES = \
tnc_imc_plugin.h tnc_imc_plugin.c
tnc_imc_plugin.h tnc_imc_plugin.c tnc_imc.h tnc_imc.c
libstrongswan_tnc_imc_la_LDFLAGS = -module -avoid-version
+129
View File
@@ -0,0 +1,129 @@
/*
* Copyright (C) 2006 Mike McCauley
* Copyright (C) 2010 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
*
* 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 "tnc_imc.h"
#include <dlfcn.h>
#include <debug.h>
#include <library.h>
typedef struct private_tnc_imc_t private_tnc_imc_t;
struct private_tnc_imc_t {
/**
* Public members of imc_t.
*/
imc_t public;
/**
* Name of loaded IMC
*/
char *name;
/**
* ID of loaded IMC
*/
TNC_IMCID id;
};
METHOD(imc_t, get_id, TNC_IMCID,
private_tnc_imc_t *this)
{
return this->id;
}
METHOD(imc_t, get_name, char*,
private_tnc_imc_t *this)
{
return this->name;
}
METHOD(imc_t, destroy, void,
private_tnc_imc_t *this)
{
free(this->name);
free(this);
}
/**
* Described in header.
*/
imc_t* tnc_imc_create(char* name, char *filename, TNC_IMCID id)
{
private_tnc_imc_t *this;
void *handle;
INIT(this,
.public = {
.get_id = _get_id,
.destroy = _destroy,
},
);
handle = dlopen(filename, RTLD_NOW);
if (handle == NULL)
{
DBG1(DBG_TNC, "IMC '%s' failed to load from '%s': %s",
name, filename, dlerror());
free(this->name);
free(this);
return NULL;
}
/* we do not store or free dlopen() handles, leak_detective requires
* the modules to keep loaded until leak report */
this->public.initialize = dlsym(handle, "TNC_IMC_Initialize");
if (!this->public.initialize)
{
DBG1(DBG_TNC, "could not resolve TNC_IMC_Initialize in %s: %s\n",
filename, dlerror());
free(this);
return NULL;
}
this->public.notify_connection_change =
dlsym(handle, "TNC_IMC_NotifyConnectionChange");
this->public.begin_handshake = dlsym(handle, "TNC_IMC_BeginHandshake");
if (!this->public.begin_handshake)
{
DBG1(DBG_TNC, "could not resolve TNC_IMC_BeginHandshake in %s: %s\n",
filename, dlerror());
free(this);
return NULL;
}
this->public.receive_message =
dlsym(handle, "TNC_IMC_ReceiveMessage");
this->public.batch_ending =
dlsym(handle, "TNC_IMC_BatchEnding");
this->public.terminate =
dlsym(handle, "TNC_IMC_Terminate");
this->public.provide_bind_function =
dlsym(handle, "TNC_IMC_ProvideBindFunction");
if (!this->public.provide_bind_function)
{
DBG1(DBG_TNC, "could not resolve TNC_IMC_ProvideBindFunction in %s: %s\n",
filename, dlerror());
free(this);
return NULL;
}
DBG2(DBG_TNC, "IMC '%s' loaded successfully with ID %u", name, id);
this->name = strdup(name);
this->id = id;
return &this->public;
}
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2010 Andreas Steffen
* HSR Hochschule fuer Technik Rapperswil
*
* 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 tnc_imc tnc_imc
* @{ @ingroup tnc_imc
*/
#ifndef TNC_IMC_H_
#define TNC_IMC_H_
#include <tnc/imc/imc.h>
/**
* Create an Integrity Measurement Collector.
*
* @param name name of the IMC
* @param filename path to the dynamic IMC library
* @param id ID of the IMC
* @return instance of the imc_t interface
*/
imc_t* tnc_imc_create(char *name, char *filename, TNC_IMCID id);
#endif /** TNC_IMC_H_ @}*/
+34 -9
View File
@@ -14,15 +14,24 @@
*/
#include "tnc_imc_plugin.h"
#include <libtnctncc.h>
#include "tnc_imc.h"
#include <daemon.h>
METHOD(plugin_t, destroy, void,
tnc_imc_plugin_t *this)
{
libtnc_tncc_Terminate();
imc_t *imc;
while (charon->imcs->remove_last(charon->imcs, (void**)&imc) == SUCCESS)
{
if (imc->terminate(imc->get_id(imc)) != TNC_RESULT_SUCCESS)
{
DBG1(DBG_TNC, "IMC '%s' not terminated successfully",
imc->get_name(imc));
}
imc->destroy(imc);
}
free(this);
}
@@ -31,8 +40,12 @@ METHOD(plugin_t, destroy, void,
*/
plugin_t *tnc_imc_plugin_create()
{
char *tnc_config, *pref_lang;
TNC_IMCID next_id = 1;
TNC_Version version;
char *tnc_config, *pref_lang, *name, *filename;
tnc_imc_plugin_t *this;
imc_t *imc;
INIT(this,
.plugin = {
@@ -45,13 +58,25 @@ plugin_t *tnc_imc_plugin_create()
tnc_config = lib->settings->get_str(lib->settings,
"charon.plugins.tnc-imc.tnc_config", "/etc/tnc_config");
if (libtnc_tncc_Initialize(tnc_config) != TNC_RESULT_SUCCESS)
name = "Dummy";
filename = "/usr/local/lib/libdummyimc.so";
imc = tnc_imc_create(name, filename, next_id);
if (imc)
{
free(this);
DBG1(DBG_TNC, "TNC IMC initialization failed");
return NULL;
/* Initialize the module */
if (imc->initialize(next_id, TNC_IFIMC_VERSION_1, TNC_IFIMC_VERSION_1,
&version) != TNC_RESULT_SUCCESS)
{
DBG1(DBG_TNC, "could not initialize IMC '%s'\n",
imc->get_name(imc));
imc->destroy(imc);
}
else
{
charon->imcs->insert_last(charon->imcs, imc);
next_id++;
}
}
return &this->plugin;
}