defined ITA Dummy PA-TNC attribute for test purposes

This commit is contained in:
Andreas Steffen
2012-07-11 17:09:04 +02:00
parent ee200bab61
commit 22f9174609
9 changed files with 333 additions and 18 deletions
+30 -8
View File
@@ -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);
+15 -2
View File
@@ -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;
}
+12 -4
View File
@@ -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_ @}*/
+15 -3
View File
@@ -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);