Implemented SWID Tag Inventory attribute
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "libpts.h"
|
||||
#include "tcg/swid/tcg_swid_attr_req.h"
|
||||
#include "tcg/swid/tcg_swid_attr_tag_inv.h"
|
||||
#include "tcg/swid/tcg_swid_attr_tag_id_inv.h"
|
||||
|
||||
#include <imcv.h>
|
||||
@@ -86,14 +87,10 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
{
|
||||
imv_msg_t *out_msg;
|
||||
imv_session_t *session;
|
||||
imv_workitem_t *workitem, *found = NULL;
|
||||
enumerator_t *enumerator;
|
||||
pa_tnc_attr_t *attr;
|
||||
pen_type_t type;
|
||||
TNC_IMV_Evaluation_Result eval;
|
||||
TNC_IMV_Action_Recommendation rec;
|
||||
TNC_Result result;
|
||||
char *result_str;
|
||||
bool fatal_error = FALSE;
|
||||
|
||||
/* parse received PA-TNC message and handle local and remote errors */
|
||||
@@ -109,6 +106,14 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
enumerator = in_msg->create_attribute_enumerator(in_msg);
|
||||
while (enumerator->enumerate(enumerator, &attr))
|
||||
{
|
||||
TNC_IMV_Evaluation_Result eval;
|
||||
TNC_IMV_Action_Recommendation rec;
|
||||
u_int32_t request_id, last_eid, eid_epoch;
|
||||
int tag_count = 0;
|
||||
char result_str[BUF_LEN], *tag_item;
|
||||
imv_workitem_t *workitem, *found = NULL;
|
||||
enumerator_t *et, *ew;
|
||||
|
||||
type = attr->get_type(attr);
|
||||
|
||||
if (type.vendor_id != PEN_TCG)
|
||||
@@ -120,19 +125,21 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
case TCG_SWID_TAG_ID_INVENTORY:
|
||||
{
|
||||
tcg_swid_attr_tag_id_inv_t *attr_cast;
|
||||
u_int32_t request_id;
|
||||
swid_tag_id_t *tag_id;
|
||||
chunk_t tag_creator, unique_sw_id;
|
||||
enumerator_t *et, *ew;
|
||||
|
||||
attr_cast = (tcg_swid_attr_tag_id_inv_t*)attr;
|
||||
request_id = attr_cast->get_request_id(attr_cast);
|
||||
last_eid = attr_cast->get_last_eid(attr_cast, &eid_epoch);
|
||||
tag_item = "tag ID";
|
||||
DBG2(DBG_IMV, "received SWID %s inventory for request %d "
|
||||
"at eid %d of epoch 0x%08x", tag_item,
|
||||
request_id, last_eid, eid_epoch);
|
||||
|
||||
DBG2(DBG_IMV, "received SWID tag ID inventory for request %d",
|
||||
request_id);
|
||||
et = attr_cast->create_tag_id_enumerator(attr_cast);
|
||||
while (et->enumerate(et, &tag_id))
|
||||
{
|
||||
tag_count++;
|
||||
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",
|
||||
@@ -146,40 +153,68 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
/* TODO handle subscribed messages */
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TCG_SWID_TAG_INVENTORY:
|
||||
{
|
||||
tcg_swid_attr_tag_inv_t *attr_cast;
|
||||
swid_tag_t *tag;
|
||||
chunk_t tag_encoding;
|
||||
|
||||
ew = session->create_workitem_enumerator(session);
|
||||
while (ew->enumerate(ew, &workitem))
|
||||
attr_cast = (tcg_swid_attr_tag_inv_t*)attr;
|
||||
request_id = attr_cast->get_request_id(attr_cast);
|
||||
last_eid = attr_cast->get_last_eid(attr_cast, &eid_epoch);
|
||||
tag_item = "tag";
|
||||
DBG2(DBG_IMV, "received SWID %s inventory for request %d "
|
||||
"at eid %d of epoch 0x%08x", tag_item,
|
||||
request_id, last_eid, eid_epoch);
|
||||
|
||||
et = attr_cast->create_tag_enumerator(attr_cast);
|
||||
while (et->enumerate(et, &tag))
|
||||
{
|
||||
if (workitem->get_id(workitem) == request_id)
|
||||
{
|
||||
found = workitem;
|
||||
break;
|
||||
}
|
||||
tag_count++;
|
||||
tag_encoding = tag->get_encoding(tag);
|
||||
DBG3(DBG_IMV, "%.*s", tag_encoding.len, tag_encoding.ptr);
|
||||
}
|
||||
et->destroy(et);
|
||||
|
||||
if (!found)
|
||||
if (request_id == 0)
|
||||
{
|
||||
DBG1(DBG_IMV, "no workitem found for SWID tag ID inventory "
|
||||
"with request ID %d", request_id);
|
||||
ew->destroy(ew);
|
||||
/* TODO handle subscribed messages */
|
||||
break;
|
||||
}
|
||||
|
||||
eval = TNC_IMV_EVALUATION_RESULT_COMPLIANT;
|
||||
result_str = "received SWID tag ID inventory";
|
||||
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);
|
||||
break;
|
||||
}
|
||||
case TCG_SWID_TAG_INVENTORY:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
ew = session->create_workitem_enumerator(session);
|
||||
while (ew->enumerate(ew, &workitem))
|
||||
{
|
||||
if (workitem->get_id(workitem) == request_id)
|
||||
{
|
||||
found = workitem;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
DBG1(DBG_IMV, "no workitem found for SWID %s inventory "
|
||||
"with request ID %d", tag_item, request_id);
|
||||
ew->destroy(ew);
|
||||
continue;
|
||||
}
|
||||
|
||||
eval = TNC_IMV_EVALUATION_RESULT_COMPLIANT;
|
||||
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);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
@@ -322,12 +357,12 @@ METHOD(imv_agent_if_t, batch_ending, TNC_Result,
|
||||
}
|
||||
request_id = workitem->get_id(workitem);
|
||||
|
||||
DBG2(DBG_IMV, "IMV %d issues SWID tag request %d",
|
||||
imv_id, request_id);
|
||||
attr = tcg_swid_attr_req_create(flags, request_id, 0);
|
||||
out_msg->add_attribute(out_msg, attr);
|
||||
workitem->set_imv_id(workitem, imv_id);
|
||||
no_workitems = FALSE;
|
||||
DBG2(DBG_IMV, "IMV %d issues SWID request %d",
|
||||
imv_id, request_id);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user