Implemented SWID Tag Inventory attribute
This commit is contained in:
@@ -16,8 +16,10 @@
|
||||
#include "imc_swid_state.h"
|
||||
|
||||
#include "libpts.h"
|
||||
#include "swid/swid_tag.h"
|
||||
#include "swid/swid_tag_id.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 <imc/imc_agent.h>
|
||||
@@ -28,6 +30,39 @@
|
||||
#include <pen/pen.h>
|
||||
#include <utils/debug.h>
|
||||
|
||||
static char strongswan_tag[] =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||
"<software_identification_tag "
|
||||
"xmlns=\"http://standards.iso.org/iso/19770/-2/2009/schema.xsd\">\n"
|
||||
"<entitlement_required_indicator>true</entitlement_required_indicator>\n"
|
||||
"<product_title>strongSwan</product_title>\n"
|
||||
"<product_version>\n"
|
||||
" <name>5.1.1dr1</name>\n"
|
||||
" <numeric>\n"
|
||||
" <major>5</major>\n"
|
||||
" <minor>1</minor>\n"
|
||||
" <build>0</build>\n"
|
||||
" <review></review>\n"
|
||||
" </numeric>\n"
|
||||
"</product_version>\n"
|
||||
"<software_creator>\n"
|
||||
" <name>strongSwan Project</name>\n"
|
||||
" <regid>regid.2004-03.org.strongswan</regid>\n"
|
||||
"</software_creator>\n"
|
||||
"<software_licensor>\n"
|
||||
" <name>strongSwan Project</name>\n"
|
||||
" <regid>regid.2004-03.org.strongswan</regid>\n"
|
||||
"</software_licensor>\n"
|
||||
"<software_id>\n"
|
||||
" <unique_id>strongSwan-5-1-0</unique_id>\n"
|
||||
" <tag_creator_regid>regid.2004-03.org.strongswan</tag_creator_regid>\n"
|
||||
"</software_id>\n"
|
||||
"<tag_creator>\n"
|
||||
" <name>strongSwan</name>\n"
|
||||
" <regid>regid.2004-03.org.strongswan</regid>\n"
|
||||
"</tag_creator>\n"
|
||||
"</software_identification_tag>\n";
|
||||
|
||||
/* IMC definitions */
|
||||
|
||||
static const char imc_name[] = "SWID";
|
||||
@@ -149,8 +184,6 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
|
||||
while (enumerator->enumerate(enumerator, &attr))
|
||||
{
|
||||
tcg_swid_attr_req_t *attr_req;
|
||||
tcg_swid_attr_tag_id_inv_t *attr_tag_id_inv;
|
||||
swid_tag_id_t *tag_id;
|
||||
u_int8_t flags;
|
||||
u_int32_t request_id, eid_epoch;
|
||||
|
||||
@@ -164,18 +197,32 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
|
||||
attr_req = (tcg_swid_attr_req_t*)attr;
|
||||
flags = attr_req->get_flags(attr_req);
|
||||
request_id = attr_req->get_request_id(attr_req);
|
||||
eid_epoch = swid_state->get_eid_epoch(swid_state);
|
||||
|
||||
if (flags & TCG_SWID_ATTR_REQ_FLAG_R)
|
||||
{
|
||||
eid_epoch = swid_state->get_eid_epoch(swid_state);
|
||||
swid_tag_id_t *tag_id;
|
||||
tcg_swid_attr_tag_id_inv_t *attr_cast;
|
||||
|
||||
attr = tcg_swid_attr_tag_id_inv_create(request_id, eid_epoch, 1);
|
||||
attr_tag_id_inv = (tcg_swid_attr_tag_id_inv_t*)attr;
|
||||
attr_cast = (tcg_swid_attr_tag_id_inv_t*)attr;
|
||||
tag_id = swid_tag_id_create(
|
||||
chunk_from_str("regid.2004-03.org.strongswan"),
|
||||
chunk_from_str("strongSwan-5-1-0"),
|
||||
chunk_empty);
|
||||
attr_tag_id_inv->add_tag_id(attr_tag_id_inv, tag_id);
|
||||
out_msg->add_attribute(out_msg, attr);
|
||||
attr_cast->add_tag_id(attr_cast, tag_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
swid_tag_t *tag;
|
||||
tcg_swid_attr_tag_inv_t *attr_cast;
|
||||
|
||||
attr = tcg_swid_attr_tag_inv_create(request_id, eid_epoch, 1);
|
||||
attr_cast = (tcg_swid_attr_tag_inv_t*)attr;
|
||||
tag = swid_tag_create(chunk_from_str(strongswan_tag), chunk_empty);
|
||||
attr_cast->add_tag(attr_cast, tag);
|
||||
}
|
||||
out_msg->add_attribute(out_msg, attr);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
|
||||
@@ -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