mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-05 00:00:45 -04:00
defined ITA Dummy PA-TNC attribute for test purposes
This commit is contained in:
parent
ee200bab61
commit
22f9174609
@ -15,6 +15,7 @@ libimcv_la_SOURCES = \
|
||||
ietf/ietf_attr_product_info.h ietf/ietf_attr_product_info.c \
|
||||
ita/ita_attr.h ita/ita_attr.c \
|
||||
ita/ita_attr_command.h ita/ita_attr_command.c \
|
||||
ita/ita_attr_dummy.h ita/ita_attr_dummy.c \
|
||||
pa_tnc/pa_tnc_attr.h \
|
||||
pa_tnc/pa_tnc_msg.h pa_tnc/pa_tnc_msg.c \
|
||||
pa_tnc/pa_tnc_attr_manager.h pa_tnc/pa_tnc_attr_manager.c
|
||||
|
@ -15,9 +15,11 @@
|
||||
|
||||
#include "ita_attr.h"
|
||||
#include "ita/ita_attr_command.h"
|
||||
#include "ita/ita_attr_dummy.h"
|
||||
|
||||
ENUM(ita_attr_names, ITA_ATTR_COMMAND, ITA_ATTR_COMMAND,
|
||||
ENUM(ita_attr_names, ITA_ATTR_COMMAND, ITA_ATTR_DUMMY,
|
||||
"Command",
|
||||
"Dummy",
|
||||
);
|
||||
|
||||
/**
|
||||
@ -29,6 +31,8 @@ pa_tnc_attr_t* ita_attr_create_from_data(u_int32_t type, chunk_t value)
|
||||
{
|
||||
case ITA_ATTR_COMMAND:
|
||||
return ita_attr_command_create_from_data(value);
|
||||
case ITA_ATTR_DUMMY:
|
||||
return ita_attr_dummy_create_from_data(value);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ typedef enum ita_attr_t ita_attr_t;
|
||||
*/
|
||||
enum ita_attr_t {
|
||||
ITA_ATTR_COMMAND = 1,
|
||||
ITA_ATTR_DUMMY = 2,
|
||||
};
|
||||
|
||||
/**
|
||||
|
193
src/libimcv/ita/ita_attr_dummy.c
Normal file
193
src/libimcv/ita/ita_attr_dummy.c
Normal file
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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 "ita_attr.h"
|
||||
#include "ita_attr_dummy.h"
|
||||
|
||||
#include <pen/pen.h>
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
typedef struct private_ita_attr_dummy_t private_ita_attr_dummy_t;
|
||||
|
||||
/**
|
||||
* Private data of an ita_attr_dummy_t object.
|
||||
*/
|
||||
struct private_ita_attr_dummy_t {
|
||||
|
||||
/**
|
||||
* Public members of ita_attr_dummy_t
|
||||
*/
|
||||
ita_attr_dummy_t public;
|
||||
|
||||
/**
|
||||
* Attribute vendor ID
|
||||
*/
|
||||
pen_t vendor_id;
|
||||
|
||||
/**
|
||||
* Attribute type
|
||||
*/
|
||||
u_int32_t type;
|
||||
|
||||
/**
|
||||
* Attribute value
|
||||
*/
|
||||
chunk_t value;
|
||||
|
||||
/**
|
||||
* Noskip flag
|
||||
*/
|
||||
bool noskip_flag;
|
||||
|
||||
/**
|
||||
* Size of the attribute value
|
||||
*/
|
||||
int size;
|
||||
|
||||
/**
|
||||
* Reference count
|
||||
*/
|
||||
refcount_t ref;
|
||||
};
|
||||
|
||||
METHOD(pa_tnc_attr_t, get_vendor_id, pen_t,
|
||||
private_ita_attr_dummy_t *this)
|
||||
{
|
||||
return this->vendor_id;
|
||||
}
|
||||
|
||||
METHOD(pa_tnc_attr_t, get_type, u_int32_t,
|
||||
private_ita_attr_dummy_t *this)
|
||||
{
|
||||
return this->type;
|
||||
}
|
||||
|
||||
METHOD(pa_tnc_attr_t, get_value, chunk_t,
|
||||
private_ita_attr_dummy_t *this)
|
||||
{
|
||||
return this->value;
|
||||
}
|
||||
|
||||
METHOD(pa_tnc_attr_t, get_noskip_flag, bool,
|
||||
private_ita_attr_dummy_t *this)
|
||||
{
|
||||
return this->noskip_flag;
|
||||
}
|
||||
|
||||
METHOD(pa_tnc_attr_t, set_noskip_flag,void,
|
||||
private_ita_attr_dummy_t *this, bool noskip)
|
||||
{
|
||||
this->noskip_flag = noskip;
|
||||
}
|
||||
|
||||
METHOD(pa_tnc_attr_t, build, void,
|
||||
private_ita_attr_dummy_t *this)
|
||||
{
|
||||
this->value = chunk_alloc(this->size);
|
||||
memset(this->value.ptr, 0xdd, this->value.len);
|
||||
}
|
||||
|
||||
METHOD(pa_tnc_attr_t, process, status_t,
|
||||
private_ita_attr_dummy_t *this, u_int32_t *offset)
|
||||
{
|
||||
this->size = this->value.len;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
METHOD(pa_tnc_attr_t, get_ref, pa_tnc_attr_t*,
|
||||
private_ita_attr_dummy_t *this)
|
||||
{
|
||||
ref_get(&this->ref);
|
||||
return &this->public.pa_tnc_attribute;
|
||||
}
|
||||
|
||||
METHOD(pa_tnc_attr_t, destroy, void,
|
||||
private_ita_attr_dummy_t *this)
|
||||
{
|
||||
if (ref_put(&this->ref))
|
||||
{
|
||||
free(this->value.ptr);
|
||||
free(this);
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(ita_attr_dummy_t, get_size, int,
|
||||
private_ita_attr_dummy_t *this)
|
||||
{
|
||||
return this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
pa_tnc_attr_t *ita_attr_dummy_create(int size)
|
||||
{
|
||||
private_ita_attr_dummy_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.pa_tnc_attribute = {
|
||||
.get_vendor_id = _get_vendor_id,
|
||||
.get_type = _get_type,
|
||||
.get_value = _get_value,
|
||||
.get_noskip_flag = _get_noskip_flag,
|
||||
.set_noskip_flag = _set_noskip_flag,
|
||||
.build = _build,
|
||||
.process = _process,
|
||||
.get_ref = _get_ref,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.get_size = _get_size,
|
||||
},
|
||||
.vendor_id = PEN_ITA,
|
||||
.type = ITA_ATTR_DUMMY,
|
||||
.size = size,
|
||||
.ref = 1,
|
||||
);
|
||||
|
||||
return &this->public.pa_tnc_attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
pa_tnc_attr_t *ita_attr_dummy_create_from_data(chunk_t data)
|
||||
{
|
||||
private_ita_attr_dummy_t *this;
|
||||
|
||||
INIT(this,
|
||||
.public = {
|
||||
.pa_tnc_attribute = {
|
||||
.get_vendor_id = _get_vendor_id,
|
||||
.get_type = _get_type,
|
||||
.get_value = _get_value,
|
||||
.build = _build,
|
||||
.process = _process,
|
||||
.get_ref = _get_ref,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
.get_size = _get_size,
|
||||
},
|
||||
.vendor_id = PEN_ITA,
|
||||
.type = ITA_ATTR_DUMMY,
|
||||
.value = chunk_clone(data),
|
||||
.ref = 1,
|
||||
);
|
||||
|
||||
return &this->public.pa_tnc_attribute;
|
||||
}
|
||||
|
||||
|
61
src/libimcv/ita/ita_attr_dummy.h
Normal file
61
src/libimcv/ita/ita_attr_dummy.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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 ita_attr_dummyt ita_attr_dummy
|
||||
* @{ @ingroup ita_attr_dummy
|
||||
*/
|
||||
|
||||
#ifndef ITA_ATTR_DUMMY_H_
|
||||
#define ITA_ATTR_DUMMY_H_
|
||||
|
||||
typedef struct ita_attr_dummy_t ita_attr_dummy_t;
|
||||
|
||||
#include "pa_tnc/pa_tnc_attr.h"
|
||||
|
||||
/**
|
||||
* Class implementing the ITA Dummy PA-TNC attribute.
|
||||
*
|
||||
*/
|
||||
struct ita_attr_dummy_t {
|
||||
|
||||
/**
|
||||
* Public PA-TNC attribute interface
|
||||
*/
|
||||
pa_tnc_attr_t pa_tnc_attribute;
|
||||
|
||||
/**
|
||||
* Get the size the ITA Dummy attribute value
|
||||
*
|
||||
* @return size of dummy attribute value
|
||||
*/
|
||||
int (*get_size)(ita_attr_dummy_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an ita_attr_dummy_t object with a given size
|
||||
*
|
||||
* @param size size of dummy attribute value
|
||||
*/
|
||||
pa_tnc_attr_t* ita_attr_dummy_create(int size);
|
||||
|
||||
/**
|
||||
* Creates an ita_attr_dummy_t object from received data
|
||||
*
|
||||
* @param command ITA command string
|
||||
*/
|
||||
pa_tnc_attr_t* ita_attr_dummy_create_from_data(chunk_t value);
|
||||
|
||||
#endif /** ITA_ATTR_DUMMY_H_ @}*/
|
@ -20,6 +20,7 @@
|
||||
#include <ietf/ietf_attr_pa_tnc_error.h>
|
||||
#include <ita/ita_attr.h>
|
||||
#include <ita/ita_attr_command.h>
|
||||
#include <ita/ita_attr_dummy.h>
|
||||
|
||||
#include <tncif_names.h>
|
||||
#include <tncif_pa_subtypes.h>
|
||||
@ -75,7 +76,7 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id,
|
||||
TNC_Result result;
|
||||
char *command;
|
||||
bool retry;
|
||||
int additional_ids;
|
||||
int dummy_size, additional_ids;
|
||||
|
||||
if (!imc_test)
|
||||
{
|
||||
@ -88,9 +89,12 @@ TNC_Result TNC_IMC_NotifyConnectionChange(TNC_IMCID imc_id,
|
||||
case TNC_CONNECTION_STATE_CREATE:
|
||||
command = lib->settings->get_str(lib->settings,
|
||||
"libimcv.plugins.imc-test.command", "none");
|
||||
dummy_size = lib->settings->get_int(lib->settings,
|
||||
"libimcv.plugins.imc-test.dummy_size", 0);
|
||||
retry = lib->settings->get_bool(lib->settings,
|
||||
"libimcv.plugins.imc-test.retry", FALSE);
|
||||
state = imc_test_state_create(connection_id, command, retry);
|
||||
state = imc_test_state_create(connection_id, command, dummy_size,
|
||||
retry);
|
||||
|
||||
result = imc_test->create_state(imc_test, state);
|
||||
if (result != TNC_RESULT_SUCCESS)
|
||||
@ -166,9 +170,16 @@ static TNC_Result send_message(imc_state_t *state, TNC_UInt32 src_imc_id,
|
||||
|
||||
connection_id = state->get_connection_id(state);
|
||||
test_state = (imc_test_state_t*)state;
|
||||
|
||||
msg = pa_tnc_msg_create();
|
||||
if (test_state->get_dummy_size(test_state))
|
||||
{
|
||||
attr = ita_attr_dummy_create(test_state->get_dummy_size(test_state));
|
||||
attr->set_noskip_flag(attr, TRUE);
|
||||
msg->add_attribute(msg, attr);
|
||||
}
|
||||
attr = ita_attr_command_create(test_state->get_command(test_state));
|
||||
attr->set_noskip_flag(attr, TRUE);
|
||||
msg = pa_tnc_msg_create();
|
||||
msg->add_attribute(msg, attr);
|
||||
msg->build(msg);
|
||||
excl = dst_imv_id != TNC_IMVID_ANY;
|
||||
@ -279,14 +290,25 @@ static TNC_Result receive_message(TNC_IMCID imc_id,
|
||||
enumerator = pa_tnc_msg->create_attribute_enumerator(pa_tnc_msg);
|
||||
while (enumerator->enumerate(enumerator, &attr))
|
||||
{
|
||||
if (attr->get_vendor_id(attr) == PEN_ITA &&
|
||||
attr->get_type(attr) == ITA_ATTR_COMMAND)
|
||||
if (attr->get_vendor_id(attr) != PEN_ITA)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (attr->get_type(attr) == ITA_ATTR_COMMAND)
|
||||
{
|
||||
ita_attr_command_t *ita_attr;
|
||||
char *command;
|
||||
|
||||
|
||||
ita_attr = (ita_attr_command_t*)attr;
|
||||
command = ita_attr->get_command(ita_attr);
|
||||
DBG1(DBG_IMC, "received command '%s'",
|
||||
ita_attr->get_command(ita_attr));
|
||||
}
|
||||
else if (attr->get_type(attr) == ITA_ATTR_DUMMY)
|
||||
{
|
||||
ita_attr_dummy_t *ita_attr;
|
||||
|
||||
ita_attr = (ita_attr_dummy_t*)attr;
|
||||
DBG1(DBG_IMC, "received dummy attribute value (%d bytes)",
|
||||
ita_attr->get_size(ita_attr));
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
@ -54,6 +54,11 @@ struct private_imc_test_state_t {
|
||||
*/
|
||||
char *command;
|
||||
|
||||
/**
|
||||
* Size of the dummy attribute value to transmit to IMV
|
||||
*/
|
||||
int dummy_size;
|
||||
|
||||
/**
|
||||
* Is it the first handshake?
|
||||
*/
|
||||
@ -120,6 +125,13 @@ METHOD(imc_test_state_t, set_command, void,
|
||||
free(old_command);
|
||||
}
|
||||
|
||||
METHOD(imc_test_state_t, get_dummy_size, int,
|
||||
private_imc_test_state_t *this)
|
||||
{
|
||||
return this->dummy_size;
|
||||
}
|
||||
|
||||
|
||||
METHOD(imc_test_state_t, is_first_handshake, bool,
|
||||
private_imc_test_state_t *this)
|
||||
{
|
||||
@ -146,7 +158,7 @@ METHOD(imc_test_state_t, do_handshake_retry, bool,
|
||||
* Described in header.
|
||||
*/
|
||||
imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id,
|
||||
char *command, bool retry)
|
||||
char *command, int dummy_size, bool retry)
|
||||
{
|
||||
private_imc_test_state_t *this;
|
||||
|
||||
@ -162,12 +174,14 @@ imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id,
|
||||
},
|
||||
.get_command = _get_command,
|
||||
.set_command = _set_command,
|
||||
.get_dummy_size = _get_dummy_size,
|
||||
.is_first_handshake = _is_first_handshake,
|
||||
.do_handshake_retry = _do_handshake_retry,
|
||||
},
|
||||
.state = TNC_CONNECTION_STATE_CREATE,
|
||||
.connection_id = connection_id,
|
||||
.command = strdup(command),
|
||||
.dummy_size = dummy_size,
|
||||
.first_handshake = TRUE,
|
||||
.handshake_retry = retry,
|
||||
);
|
||||
@ -175,4 +189,3 @@ imc_state_t *imc_test_state_create(TNC_ConnectionID connection_id,
|
||||
return &this->public.interface;
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,6 +51,13 @@ struct imc_test_state_t {
|
||||
*/
|
||||
void (*set_command)(imc_test_state_t *this, char *command);
|
||||
|
||||
/**
|
||||
* get the value size of a dummy attribute to send to IMV
|
||||
*
|
||||
* @return size of the dummy attribute value to send to IMV
|
||||
*/
|
||||
int (*get_dummy_size)(imc_test_state_t *this);
|
||||
|
||||
/**
|
||||
* Test and reset the first handshake flag
|
||||
*
|
||||
@ -70,11 +77,12 @@ struct imc_test_state_t {
|
||||
/**
|
||||
* Create an imc_test_state_t instance
|
||||
*
|
||||
* @param id connection ID
|
||||
* @param command command to send to IMV
|
||||
* @param retry TRUE if a handshake retry should be done
|
||||
* @param id connection ID
|
||||
* @param command command to send to IMV
|
||||
* @param dummy_size size of the dummy attribute to send (only if > 0)
|
||||
* @param retry TRUE if a handshake retry should be done
|
||||
*/
|
||||
imc_state_t* imc_test_state_create(TNC_ConnectionID id, char* command,
|
||||
bool retry);
|
||||
int dummy_size, bool retry);
|
||||
|
||||
#endif /** IMC_TEST_STATE_H_ @}*/
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <ietf/ietf_attr_pa_tnc_error.h>
|
||||
#include <ita/ita_attr.h>
|
||||
#include <ita/ita_attr_command.h>
|
||||
#include <ita/ita_attr_dummy.h>
|
||||
|
||||
#include <tncif_names.h>
|
||||
#include <tncif_pa_subtypes.h>
|
||||
@ -143,8 +144,11 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
|
||||
enumerator = pa_tnc_msg->create_attribute_enumerator(pa_tnc_msg);
|
||||
while (enumerator->enumerate(enumerator, &attr))
|
||||
{
|
||||
if (attr->get_vendor_id(attr) == PEN_ITA &&
|
||||
attr->get_type(attr) == ITA_ATTR_COMMAND)
|
||||
if (attr->get_vendor_id(attr) != PEN_ITA)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (attr->get_type(attr) == ITA_ATTR_COMMAND)
|
||||
{
|
||||
ita_attr_command_t *ita_attr;
|
||||
char *command;
|
||||
@ -181,7 +185,15 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
|
||||
TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
|
||||
TNC_IMV_EVALUATION_RESULT_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (attr->get_type(attr) == ITA_ATTR_DUMMY)
|
||||
{
|
||||
ita_attr_dummy_t *ita_attr;
|
||||
|
||||
ita_attr = (ita_attr_dummy_t*)attr;
|
||||
DBG1(DBG_IMV, "received dummy attribute value (%d bytes)",
|
||||
ita_attr->get_size(ita_attr));
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pa_tnc_msg->destroy(pa_tnc_msg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user