SWID IMC implements recursive tag collection in /usr/share
This commit is contained in:
@@ -16,8 +16,7 @@
|
||||
#include "imc_swid_state.h"
|
||||
|
||||
#include "libpts.h"
|
||||
#include "swid/swid_tag.h"
|
||||
#include "swid/swid_tag_id.h"
|
||||
#include "swid/swid_inventory.h"
|
||||
#include "swid/swid_error.h"
|
||||
#include "tcg/swid/tcg_swid_attr_req.h"
|
||||
#include "tcg/swid/tcg_swid_attr_tag_inv.h"
|
||||
@@ -31,38 +30,6 @@
|
||||
#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>1</build>\n"
|
||||
" <review>dr1</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-1-dr1</unique_id>\n"
|
||||
" <tag_creator_regid>regid.2004-03.org.strongswan</tag_creator_regid>\n"
|
||||
"</software_id>\n"
|
||||
"<tag_creator>\n"
|
||||
" <name>strongSwan Project</name>\n"
|
||||
" <regid>regid.2004-03.org.strongswan</regid>\n"
|
||||
"</tag_creator>\n"
|
||||
"</software_identification_tag>\n";
|
||||
|
||||
/* IMC definitions */
|
||||
|
||||
@@ -187,6 +154,8 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
|
||||
tcg_swid_attr_req_t *attr_req;
|
||||
u_int8_t flags;
|
||||
u_int32_t request_id, eid_epoch;
|
||||
swid_inventory_t *swid_inventory;
|
||||
bool full_tags;
|
||||
|
||||
type = attr->get_type(attr);
|
||||
|
||||
@@ -207,29 +176,27 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
|
||||
out_msg->add_attribute(out_msg, attr);
|
||||
break;
|
||||
}
|
||||
full_tags = (flags & TCG_SWID_ATTR_REQ_FLAG_R) == 0;
|
||||
|
||||
if (flags & TCG_SWID_ATTR_REQ_FLAG_R)
|
||||
swid_inventory = swid_inventory_create(full_tags);
|
||||
if (!swid_inventory->collect(swid_inventory))
|
||||
{
|
||||
swid_tag_id_t *tag_id;
|
||||
tcg_swid_attr_tag_id_inv_t *attr_cast;
|
||||
swid_inventory->destroy(swid_inventory);
|
||||
attr = swid_error_create(TCG_SWID_ERROR, request_id,
|
||||
0, "error in SWID tag collection");
|
||||
out_msg->add_attribute(out_msg, attr);
|
||||
break;
|
||||
}
|
||||
|
||||
attr = tcg_swid_attr_tag_id_inv_create(request_id, eid_epoch, 1);
|
||||
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-1-dr1"),
|
||||
chunk_empty);
|
||||
attr_cast->add_tag_id(attr_cast, tag_id);
|
||||
if (full_tags)
|
||||
{
|
||||
attr = tcg_swid_attr_tag_inv_create(request_id, eid_epoch, 1,
|
||||
swid_inventory);
|
||||
}
|
||||
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);
|
||||
attr = tcg_swid_attr_tag_id_inv_create(request_id, eid_epoch, 1,
|
||||
swid_inventory);
|
||||
}
|
||||
out_msg->add_attribute(out_msg, attr);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "libpts.h"
|
||||
#include "swid/swid_error.h"
|
||||
#include "swid/swid_inventory.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"
|
||||
@@ -112,7 +113,8 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
TNC_IMV_Action_Recommendation rec;
|
||||
pen_type_t type;
|
||||
u_int32_t request_id, last_eid, eid_epoch;
|
||||
int tag_count = 0;
|
||||
swid_inventory_t *inventory;
|
||||
int tag_count;
|
||||
char result_str[BUF_LEN], *tag_item;
|
||||
imv_workitem_t *workitem, *found = NULL;
|
||||
enumerator_t *et, *ew;
|
||||
@@ -180,15 +182,15 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
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);
|
||||
inventory = attr_cast->get_inventory(attr_cast);
|
||||
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);
|
||||
|
||||
et = attr_cast->create_tag_id_enumerator(attr_cast);
|
||||
et = inventory->create_enumerator(inventory);
|
||||
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",
|
||||
@@ -213,15 +215,15 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
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);
|
||||
inventory = attr_cast->get_inventory(attr_cast);
|
||||
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);
|
||||
et = inventory->create_enumerator(inventory);
|
||||
while (et->enumerate(et, &tag))
|
||||
{
|
||||
tag_count++;
|
||||
tag_encoding = tag->get_encoding(tag);
|
||||
DBG3(DBG_IMV, "%.*s", tag_encoding.len, tag_encoding.ptr);
|
||||
}
|
||||
@@ -256,6 +258,7 @@ static TNC_Result receive_msg(private_imv_swid_agent_t *this,
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user