Use python-based swidGenerator to generated SWID tags
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Andreas Steffen
|
||||
* Copyright (C) 2013-2014 Andreas Steffen
|
||||
* HSR Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <ietf/ietf_attr_pa_tnc_error.h>
|
||||
#include <imv/imv_agent.h>
|
||||
#include <imv/imv_msg.h>
|
||||
#include <ita/ita_attr.h>
|
||||
#include <ita/ita_attr_angel.h>
|
||||
|
||||
#include <tncif_names.h>
|
||||
#include <tncif_pa_subtypes.h>
|
||||
@@ -89,6 +91,7 @@ METHOD(imv_agent_if_t, notify_connection_change, TNC_Result,
|
||||
static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
imv_state_t *state, imv_msg_t *in_msg)
|
||||
{
|
||||
imv_swid_state_t *swid_state;
|
||||
imv_msg_t *out_msg;
|
||||
imv_session_t *session;
|
||||
enumerator_t *enumerator;
|
||||
@@ -103,6 +106,7 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
return result;
|
||||
}
|
||||
|
||||
swid_state = (imv_swid_state_t*)state;
|
||||
session = state->get_session(state);
|
||||
|
||||
/* analyze PA-TNC attributes */
|
||||
@@ -112,7 +116,7 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
TNC_IMV_Evaluation_Result eval;
|
||||
TNC_IMV_Action_Recommendation rec;
|
||||
pen_type_t type;
|
||||
u_int32_t request_id, last_eid, eid_epoch;
|
||||
uint32_t request_id, last_eid, eid_epoch;
|
||||
swid_inventory_t *inventory;
|
||||
int tag_count;
|
||||
char result_str[BUF_LEN], *tag_item;
|
||||
@@ -127,7 +131,7 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
pen_type_t error_code;
|
||||
chunk_t msg_info, description;
|
||||
bio_reader_t *reader;
|
||||
u_int32_t request_id = 0, max_attr_size;
|
||||
uint32_t request_id = 0, max_attr_size;
|
||||
bool success;
|
||||
|
||||
error_attr = (ietf_attr_pa_tnc_error_t*)attr;
|
||||
@@ -166,6 +170,20 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
reader->destroy(reader);
|
||||
}
|
||||
}
|
||||
else if (type.vendor_id == PEN_ITA)
|
||||
{
|
||||
switch (type.type)
|
||||
{
|
||||
case ITA_ATTR_START_ANGEL:
|
||||
swid_state->set_angel_count(swid_state, TRUE);
|
||||
break;
|
||||
case ITA_ATTR_STOP_ANGEL:
|
||||
swid_state->set_angel_count(swid_state, FALSE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (type.vendor_id != PEN_TCG)
|
||||
{
|
||||
continue;
|
||||
@@ -193,7 +211,7 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
{
|
||||
tag_creator = tag_id->get_tag_creator(tag_id);
|
||||
unique_sw_id = tag_id->get_unique_sw_id(tag_id, NULL);
|
||||
DBG3(DBG_IMV, " %.*s_%.*s.swidtag",
|
||||
DBG3(DBG_IMV, " %.*s_%.*s",
|
||||
tag_creator.len, tag_creator.ptr,
|
||||
unique_sw_id.len, unique_sw_id.ptr);
|
||||
}
|
||||
@@ -239,6 +257,8 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
tag_count = inventory->get_count(inventory);
|
||||
swid_state->set_count(swid_state, tag_count);
|
||||
|
||||
ew = session->create_workitem_enumerator(session);
|
||||
while (ew->enumerate(ew, &workitem))
|
||||
@@ -257,16 +277,20 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
continue;
|
||||
}
|
||||
|
||||
eval = TNC_IMV_EVALUATION_RESULT_COMPLIANT;
|
||||
tag_count = inventory->get_count(inventory);
|
||||
snprintf(result_str, BUF_LEN, "received inventory of %d SWID %s%s",
|
||||
tag_count, tag_item, (tag_count == 1) ? "" : "s");
|
||||
session->remove_workitem(session, ew);
|
||||
ew->destroy(ew);
|
||||
rec = found->set_result(found, result_str, eval);
|
||||
state->update_recommendation(state, rec, eval);
|
||||
imcv_db->finalize_workitem(imcv_db, found);
|
||||
found->destroy(found);
|
||||
if (!swid_state->get_angel_count(swid_state))
|
||||
{
|
||||
swid_state->get_count(swid_state, &tag_count);
|
||||
snprintf(result_str, BUF_LEN, "received inventory of %d SWID %s%s",
|
||||
tag_count, tag_item, (tag_count == 1) ? "" : "s");
|
||||
session->remove_workitem(session, ew);
|
||||
ew->destroy(ew);
|
||||
|
||||
eval = TNC_IMV_EVALUATION_RESULT_COMPLIANT;
|
||||
rec = found->set_result(found, result_str, eval);
|
||||
state->update_recommendation(state, rec, eval);
|
||||
imcv_db->finalize_workitem(imcv_db, found);
|
||||
found->destroy(found);
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
@@ -342,8 +366,8 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
|
||||
TNC_IMVID imv_id;
|
||||
TNC_Result result = TNC_RESULT_SUCCESS;
|
||||
bool no_workitems = TRUE;
|
||||
u_int32_t request_id;
|
||||
u_int8_t flags;
|
||||
uint32_t request_id;
|
||||
uint8_t flags;
|
||||
enumerator_t *enumerator;
|
||||
|
||||
if (!this->agent->get_state(this->agent, id, &state))
|
||||
|
||||
@@ -95,6 +95,16 @@ struct private_imv_swid_state_t {
|
||||
*/
|
||||
imv_remediation_string_t *remediation_string;
|
||||
|
||||
/**
|
||||
* Number of processed SWID Tags or SWID Tag IDs
|
||||
*/
|
||||
int count;
|
||||
|
||||
/**
|
||||
* Angel count
|
||||
*/
|
||||
int angel_count;
|
||||
|
||||
};
|
||||
|
||||
METHOD(imv_state_t, get_connection_id, TNC_ConnectionID,
|
||||
@@ -223,6 +233,33 @@ METHOD(imv_swid_state_t, get_handshake_state, imv_swid_handshake_state_t,
|
||||
return this->handshake_state;
|
||||
}
|
||||
|
||||
METHOD(imv_swid_state_t, set_count, void,
|
||||
private_imv_swid_state_t *this, int count)
|
||||
{
|
||||
this->count += count;
|
||||
}
|
||||
|
||||
METHOD(imv_swid_state_t, get_count, void,
|
||||
private_imv_swid_state_t *this, int *count)
|
||||
{
|
||||
if (count)
|
||||
{
|
||||
*count = this->count;
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(imv_swid_state_t, set_angel_count, void,
|
||||
private_imv_swid_state_t *this, bool start)
|
||||
{
|
||||
this->angel_count += start ? 1 : -1;
|
||||
}
|
||||
|
||||
METHOD(imv_swid_state_t, get_angel_count, int,
|
||||
private_imv_swid_state_t *this)
|
||||
{
|
||||
return this->angel_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
@@ -253,6 +290,10 @@ imv_state_t *imv_swid_state_create(TNC_ConnectionID connection_id)
|
||||
},
|
||||
.set_handshake_state = _set_handshake_state,
|
||||
.get_handshake_state = _get_handshake_state,
|
||||
.set_count = _set_count,
|
||||
.get_count = _get_count,
|
||||
.set_angel_count = _set_angel_count,
|
||||
.get_angel_count = _get_angel_count,
|
||||
},
|
||||
.state = TNC_CONNECTION_STATE_CREATE,
|
||||
.rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Andreas Steffen
|
||||
* Copyright (C) 2013-2014 Andreas Steffen
|
||||
* HSR Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
@@ -64,6 +64,34 @@ struct imv_swid_state_t {
|
||||
*/
|
||||
imv_swid_handshake_state_t (*get_handshake_state)(imv_swid_state_t *this);
|
||||
|
||||
/**
|
||||
* Increase/Decrease the ITA Angel count
|
||||
*
|
||||
* @param start TRUE increases and FALSE decreases count by one
|
||||
*/
|
||||
void (*set_angel_count)(imv_swid_state_t *this, bool start);
|
||||
|
||||
/**
|
||||
* Set [or with multiple attributes increment] SWID Tag [ID] counters
|
||||
*
|
||||
* @param count Number of received SWID Tags or SWID Tag IDs
|
||||
*/
|
||||
void (*set_count)(imv_swid_state_t *this, int count);
|
||||
|
||||
/**
|
||||
* Set [or with multiple attributes increment] SWID Tag [ID] counters
|
||||
*
|
||||
* @param count Number of received SWID Tags or SWID Tag IDs
|
||||
*/
|
||||
void (*get_count)(imv_swid_state_t *this, int *count);
|
||||
|
||||
/**
|
||||
* Get the ITA Angel count
|
||||
*
|
||||
* @return ITA Angel count
|
||||
*/
|
||||
int (*get_angel_count)(imv_swid_state_t *this);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user