implemented IMC/IMV handler
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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_ @}*/
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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_imv_la_LIBADD = -ltnc
|
||||
|
||||
if MONOLITHIC
|
||||
noinst_LTLIBRARIES = libstrongswan-tnc-imv.la
|
||||
else
|
||||
@@ -13,7 +11,7 @@ plugin_LTLIBRARIES = libstrongswan-tnc-imv.la
|
||||
endif
|
||||
|
||||
libstrongswan_tnc_imv_la_SOURCES = \
|
||||
tnc_imv_plugin.h tnc_imv_plugin.c
|
||||
tnc_imv_plugin.h tnc_imv_plugin.c tnc_imv.h tnc_imv.c
|
||||
|
||||
libstrongswan_tnc_imv_la_LDFLAGS = -module -avoid-version
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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_imv.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <library.h>
|
||||
|
||||
typedef struct private_tnc_imv_t private_tnc_imv_t;
|
||||
|
||||
struct private_tnc_imv_t {
|
||||
|
||||
/**
|
||||
* Public members of imv_t.
|
||||
*/
|
||||
imv_t public;
|
||||
|
||||
/**
|
||||
* Name of loaded IMV
|
||||
*/
|
||||
char *name;
|
||||
|
||||
/**
|
||||
* ID of loaded IMV
|
||||
*/
|
||||
TNC_IMVID id;
|
||||
};
|
||||
|
||||
METHOD(imv_t, get_id, TNC_IMVID,
|
||||
private_tnc_imv_t *this)
|
||||
{
|
||||
return this->id;
|
||||
}
|
||||
|
||||
METHOD(imv_t, destroy, void,
|
||||
private_tnc_imv_t *this)
|
||||
{
|
||||
free(this->name);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
imv_t* tnc_imv_create(char *name, char *filename, TNC_IMVID id)
|
||||
{
|
||||
private_tnc_imv_t *this;
|
||||
void *handle;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.get_id = _get_id,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
);
|
||||
|
||||
handle = dlopen(filename, RTLD_NOW);
|
||||
if (handle == NULL)
|
||||
{
|
||||
DBG1(DBG_TNC, "IMV '%s' failed to load from '%s': %s",
|
||||
name, filename, dlerror());
|
||||
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_IMV_Initialize");
|
||||
if (!this->public.initialize)
|
||||
{
|
||||
DBG1(DBG_TNC, "could not resolve TNC_IMV_Initialize in %s: %s\n",
|
||||
filename, dlerror());
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
this->public.notify_connection_change =
|
||||
dlsym(handle, "TNC_IMV_NotifyConnectionChange");
|
||||
this->public.solicit_recommendation =
|
||||
dlsym(handle, "TNC_IMV_SolicitRecommendation");
|
||||
if (!this->public.solicit_recommendation)
|
||||
{
|
||||
DBG1(DBG_TNC, "could not resolve TNC_IMV_SolicitRecommendation in %s: %s\n",
|
||||
filename, dlerror());
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
this->public.receive_message =
|
||||
dlsym(handle, "TNC_IMV_ReceiveMessage");
|
||||
this->public.batch_ending =
|
||||
dlsym(handle, "TNC_IMV_BatchEnding");
|
||||
this->public.terminate =
|
||||
dlsym(handle, "TNC_IMV_Terminate");
|
||||
this->public.provide_bind_function =
|
||||
dlsym(handle, "TNC_IMV_ProvideBindFunction");
|
||||
if (!this->public.provide_bind_function)
|
||||
{
|
||||
DBG1(DBG_TNC, "could not resolve TNC_IMV_ProvideBindFunction in %s: %s\n",
|
||||
filename, dlerror());
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
DBG2(DBG_TNC, "IMV '%s' loaded successfully with ID %u", name, id);
|
||||
this->name = strdup(name);
|
||||
this->id = id;
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -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_imv tnc_imv
|
||||
* @{ @ingroup tnc_imv
|
||||
*/
|
||||
|
||||
#ifndef TNC_IMV_H_
|
||||
#define TNC_IMV_H_
|
||||
|
||||
#include <tnc/imv/imv.h>
|
||||
|
||||
/**
|
||||
* Create an Integrity Measurement Verifier.
|
||||
*
|
||||
* @param name name of the IMV
|
||||
* @param filename path to the dynamic IMV library
|
||||
* @param id ID of the IMV
|
||||
* @return instance of the imv_t interface
|
||||
*/
|
||||
imv_t* tnc_imv_create(char *name, char *filename, TNC_IMVID id);
|
||||
|
||||
#endif /** TNC_IMV_H_ @}*/
|
||||
@@ -14,15 +14,24 @@
|
||||
*/
|
||||
|
||||
#include "tnc_imv_plugin.h"
|
||||
|
||||
#include <libtnctncs.h>
|
||||
#include "tnc_imv.h"
|
||||
|
||||
#include <daemon.h>
|
||||
|
||||
METHOD(plugin_t, destroy, void,
|
||||
tnc_imv_plugin_t *this)
|
||||
{
|
||||
libtnc_tncs_Terminate();
|
||||
imv_t *imv;
|
||||
|
||||
while (charon->imvs->remove_last(charon->imvs, (void**)&imv) == SUCCESS)
|
||||
{
|
||||
if (imv->terminate(imv->get_id(imv)) != TNC_RESULT_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_TNC, "IMV '%s' not terminated successfully",
|
||||
imv->get_name(imv));
|
||||
}
|
||||
imv->destroy(imv);
|
||||
}
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -31,8 +40,11 @@ METHOD(plugin_t, destroy, void,
|
||||
*/
|
||||
plugin_t *tnc_imv_plugin_create()
|
||||
{
|
||||
char *tnc_config;
|
||||
TNC_IMVID next_id = 1;
|
||||
TNC_Version version;
|
||||
char *tnc_config, *name, *filename;
|
||||
tnc_imv_plugin_t *this;
|
||||
imv_t *imv;
|
||||
|
||||
INIT(this,
|
||||
.plugin = {
|
||||
@@ -42,13 +54,26 @@ plugin_t *tnc_imv_plugin_create()
|
||||
|
||||
tnc_config = lib->settings->get_str(lib->settings,
|
||||
"charon.plugins.tnc-imv.tnc_config", "/etc/tnc_config");
|
||||
if (libtnc_tncs_Initialize(tnc_config) != TNC_RESULT_SUCCESS)
|
||||
{
|
||||
free(this);
|
||||
DBG1(DBG_TNC, "TNC IMV initialization failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
name = "Dummy";
|
||||
filename = "/usr/local/lib/libdummyimv.so";
|
||||
imv = tnc_imv_create(name, filename, next_id);
|
||||
if (imv)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (imv->initialize(next_id, TNC_IFIMV_VERSION_1, TNC_IFIMV_VERSION_1,
|
||||
&version) != TNC_RESULT_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_TNC, "could not initialize IMV '%s'\n",
|
||||
imv->get_name(imv));
|
||||
imv->destroy(imv);
|
||||
}
|
||||
else
|
||||
{
|
||||
charon->imvs->insert_last(charon->imvs, imv);
|
||||
next_id++;
|
||||
}
|
||||
}
|
||||
return &this->plugin;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user