Implemented targeted SWID request

This commit is contained in:
Andreas Steffen 2013-09-06 22:06:39 +02:00
parent 70aefb9430
commit 3adffcd9eb
5 changed files with 86 additions and 29 deletions

View File

@ -154,7 +154,7 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
tcg_swid_attr_req_t *attr_req; tcg_swid_attr_req_t *attr_req;
u_int8_t flags; u_int8_t flags;
u_int32_t request_id, eid_epoch; u_int32_t request_id, eid_epoch;
swid_inventory_t *swid_inventory; swid_inventory_t *swid_inventory, *targets;
char *swid_directory; char *swid_directory;
bool full_tags; bool full_tags;
@ -168,6 +168,7 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
attr_req = (tcg_swid_attr_req_t*)attr; attr_req = (tcg_swid_attr_req_t*)attr;
flags = attr_req->get_flags(attr_req); flags = attr_req->get_flags(attr_req);
request_id = attr_req->get_request_id(attr_req); request_id = attr_req->get_request_id(attr_req);
targets = attr_req->get_targets(attr_req);
eid_epoch = swid_state->get_eid_epoch(swid_state); eid_epoch = swid_state->get_eid_epoch(swid_state);
if (flags & (TCG_SWID_ATTR_REQ_FLAG_S | TCG_SWID_ATTR_REQ_FLAG_C)) if (flags & (TCG_SWID_ATTR_REQ_FLAG_S | TCG_SWID_ATTR_REQ_FLAG_C))
@ -183,7 +184,7 @@ static TNC_Result receive_message(imc_state_t *state, imc_msg_t *in_msg)
"libimcv.plugins.imc-swid.swid_directory", "libimcv.plugins.imc-swid.swid_directory",
SWID_DIRECTORY); SWID_DIRECTORY);
swid_inventory = swid_inventory_create(full_tags); swid_inventory = swid_inventory_create(full_tags);
if (!swid_inventory->collect(swid_inventory, swid_directory)) if (!swid_inventory->collect(swid_inventory, swid_directory, targets))
{ {
swid_inventory->destroy(swid_inventory); swid_inventory->destroy(swid_inventory);
attr = swid_error_create(TCG_SWID_ERROR, request_id, attr = swid_error_create(TCG_SWID_ERROR, request_id,

View File

@ -52,7 +52,8 @@ struct private_swid_inventory_t {
linked_list_t *list; linked_list_t *list;
}; };
static bool collect_tags(private_swid_inventory_t *this, char *pathname) static bool collect_tags(private_swid_inventory_t *this, char *pathname,
swid_inventory_t *targets)
{ {
char *rel_name, *abs_name; char *rel_name, *abs_name;
struct stat st; struct stat st;
@ -73,26 +74,50 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname)
char * start, *stop; char * start, *stop;
chunk_t tag_creator; chunk_t tag_creator;
chunk_t unique_sw_id = chunk_empty, unique_seq_id = chunk_empty; chunk_t unique_sw_id = chunk_empty, unique_seq_id = chunk_empty;
if (!strstr(rel_name, "regid.")) if (!strstr(rel_name, "regid."))
{ {
continue; continue;
} }
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
{ {
if (!collect_tags(this, abs_name)) /* In case of a targeted request */
if (targets->get_count(targets))
{
enumerator_t *target_enumerator;
swid_tag_id_t *tag_id;
bool match = FALSE;
target_enumerator = targets->create_enumerator(targets);
while (target_enumerator->enumerate(target_enumerator, &tag_id))
{
if (chunk_equals(tag_id->get_tag_creator(tag_id),
chunk_from_str(rel_name)))
{
match = TRUE;
break;
}
}
target_enumerator->destroy(target_enumerator);
if (!match)
{
continue;
}
}
if (!collect_tags(this, abs_name, targets))
{ {
goto end; goto end;
} }
continue; continue;
} }
DBG2(DBG_IMC, " %s", rel_name);
/* parse the regid filename into its components */ /* parse the regid filename into its components */
start = rel_name; start = rel_name;
stop = strchr(start, '_'); stop = strchr(start, '_');
if (!stop) if (!stop)
{ {
DBG1(DBG_IMC, " %s", rel_name);
DBG1(DBG_IMC, " '_' separator not found"); DBG1(DBG_IMC, " '_' separator not found");
goto end; goto end;
} }
@ -109,6 +134,7 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname)
stop = strstr(start, ".swidtag"); stop = strstr(start, ".swidtag");
if (!stop) if (!stop)
{ {
DBG1(DBG_IMC, " %s", rel_name);
DBG1(DBG_IMC, " swidtag postfix not found"); DBG1(DBG_IMC, " swidtag postfix not found");
goto end; goto end;
} }
@ -121,6 +147,34 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname)
unique_sw_id = chunk_create(start, stop-start); unique_sw_id = chunk_create(start, stop-start);
} }
/* In case of a targeted request */
if (targets->get_count(targets))
{
enumerator_t *target_enumerator;
swid_tag_id_t *tag_id;
bool match = FALSE;
target_enumerator = targets->create_enumerator(targets);
while (target_enumerator->enumerate(target_enumerator, &tag_id))
{
if (chunk_equals(tag_id->get_tag_creator(tag_id),
tag_creator) &&
chunk_equals(tag_id->get_unique_sw_id(tag_id, NULL),
unique_sw_id))
{
match = TRUE;
break;
}
}
target_enumerator->destroy(target_enumerator);
if (!match)
{
continue;
}
}
DBG2(DBG_IMC, " %s", rel_name);
if (this->full_tags) if (this->full_tags)
{ {
swid_tag_t *tag; swid_tag_t *tag;
@ -177,9 +231,9 @@ end:
} }
METHOD(swid_inventory_t, collect, bool, METHOD(swid_inventory_t, collect, bool,
private_swid_inventory_t *this, char *directory) private_swid_inventory_t *this, char *directory, swid_inventory_t *targets)
{ {
return collect_tags(this, directory); return collect_tags(this, directory, targets);
} }
METHOD(swid_inventory_t, add, void, METHOD(swid_inventory_t, add, void,

View File

@ -34,9 +34,11 @@ struct swid_inventory_t {
* Collect the SWID tags stored on the endpoint * Collect the SWID tags stored on the endpoint
* *
* @param directory SWID directory path * @param directory SWID directory path
* @param targets List of target tag IDs
* @return TRUE if successful * @return TRUE if successful
*/ */
bool (*collect)(swid_inventory_t *this, char *directory); bool (*collect)(swid_inventory_t *this, char *directory,
swid_inventory_t *targets);
/** /**
* Collect the SWID tags stored on the endpoint * Collect the SWID tags stored on the endpoint

View File

@ -88,9 +88,9 @@ struct private_tcg_swid_attr_req_t {
u_int32_t earliest_eid; u_int32_t earliest_eid;
/** /**
* List of Tag Identifiers * List of Target Tag Identifiers
*/ */
linked_list_t *tag_id_list; swid_inventory_t *targets;
/** /**
* Reference count * Reference count
@ -137,11 +137,11 @@ METHOD(pa_tnc_attr_t, build, void,
writer = bio_writer_create(SWID_REQ_SIZE); writer = bio_writer_create(SWID_REQ_SIZE);
writer->write_uint8 (writer, this->flags); writer->write_uint8 (writer, this->flags);
writer->write_uint24(writer, this->tag_id_list->get_count(this->tag_id_list)); writer->write_uint24(writer, this->targets->get_count(this->targets));
writer->write_uint32(writer, this->request_id); writer->write_uint32(writer, this->request_id);
writer->write_uint32(writer, this->earliest_eid); writer->write_uint32(writer, this->earliest_eid);
enumerator = this->tag_id_list->create_enumerator(this->tag_id_list); enumerator = this->targets->create_enumerator(this->targets);
while (enumerator->enumerate(enumerator, &tag_id)) while (enumerator->enumerate(enumerator, &tag_id))
{ {
tag_creator = tag_id->get_tag_creator(tag_id); tag_creator = tag_id->get_tag_creator(tag_id);
@ -202,7 +202,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
*offset += 2 + unique_sw_id.len; *offset += 2 + unique_sw_id.len;
tag_id = swid_tag_id_create(tag_creator, unique_sw_id, chunk_empty); tag_id = swid_tag_id_create(tag_creator, unique_sw_id, chunk_empty);
this->tag_id_list->insert_last(this->tag_id_list, tag_id); this->targets->add(this->targets, tag_id);
} }
reader->destroy(reader); reader->destroy(reader);
@ -221,8 +221,7 @@ METHOD(pa_tnc_attr_t, destroy, void,
{ {
if (ref_put(&this->ref)) if (ref_put(&this->ref))
{ {
this->tag_id_list->destroy_offset(this->tag_id_list, this->targets->destroy(this->targets);
offsetof(swid_tag_id_t, destroy));
free(this->value.ptr); free(this->value.ptr);
free(this); free(this);
} }
@ -246,16 +245,16 @@ METHOD(tcg_swid_attr_req_t, get_earliest_eid, u_int32_t,
return this->earliest_eid; return this->earliest_eid;
} }
METHOD(tcg_swid_attr_req_t, add_tag_id, void, METHOD(tcg_swid_attr_req_t, add_target, void,
private_tcg_swid_attr_req_t *this, swid_tag_id_t *tag_id) private_tcg_swid_attr_req_t *this, swid_tag_id_t *tag_id)
{ {
this->tag_id_list->insert_last(this->tag_id_list, tag_id); this->targets->add(this->targets, tag_id);
} }
METHOD(tcg_swid_attr_req_t, create_tag_id_enumerator, enumerator_t*, METHOD(tcg_swid_attr_req_t, get_targets, swid_inventory_t*,
private_tcg_swid_attr_req_t *this) private_tcg_swid_attr_req_t *this)
{ {
return this->tag_id_list->create_enumerator(this->tag_id_list); return this->targets;
} }
/** /**
@ -281,14 +280,14 @@ pa_tnc_attr_t *tcg_swid_attr_req_create(u_int8_t flags, u_int32_t request_id,
.get_flags = _get_flags, .get_flags = _get_flags,
.get_request_id = _get_request_id, .get_request_id = _get_request_id,
.get_earliest_eid = _get_earliest_eid, .get_earliest_eid = _get_earliest_eid,
.add_tag_id = _add_tag_id, .add_target = _add_target,
.create_tag_id_enumerator = _create_tag_id_enumerator, .get_targets = _get_targets,
}, },
.type = { PEN_TCG, TCG_SWID_REQUEST }, .type = { PEN_TCG, TCG_SWID_REQUEST },
.flags = flags & SWID_REQ_RESERVED_MASK, .flags = flags & SWID_REQ_RESERVED_MASK,
.request_id = request_id, .request_id = request_id,
.earliest_eid = eid, .earliest_eid = eid,
.tag_id_list = linked_list_create(), .targets = swid_inventory_create(FALSE),
.ref = 1, .ref = 1,
); );
@ -317,12 +316,12 @@ pa_tnc_attr_t *tcg_swid_attr_req_create_from_data(chunk_t data)
.get_flags = _get_flags, .get_flags = _get_flags,
.get_request_id = _get_request_id, .get_request_id = _get_request_id,
.get_earliest_eid = _get_earliest_eid, .get_earliest_eid = _get_earliest_eid,
.add_tag_id = _add_tag_id, .add_target = _add_target,
.create_tag_id_enumerator = _create_tag_id_enumerator, .get_targets = _get_targets,
}, },
.type = { PEN_TCG, TCG_SWID_REQUEST }, .type = { PEN_TCG, TCG_SWID_REQUEST },
.value = chunk_clone(data), .value = chunk_clone(data),
.tag_id_list = linked_list_create(), .targets = swid_inventory_create(FALSE),
.ref = 1, .ref = 1,
); );

View File

@ -33,6 +33,7 @@ enum tcg_swid_attr_req_flag_t {
#include "tcg/tcg_attr.h" #include "tcg/tcg_attr.h"
#include "swid/swid_tag_id.h" #include "swid/swid_tag_id.h"
#include "swid/swid_inventory.h"
#include "pa_tnc/pa_tnc_attr.h" #include "pa_tnc/pa_tnc_attr.h"
/** /**
@ -71,14 +72,14 @@ struct tcg_swid_attr_req_t {
* *
* @param tag_id SWID Tag ID (is not cloned by constructor!) * @param tag_id SWID Tag ID (is not cloned by constructor!)
*/ */
void (*add_tag_id)(tcg_swid_attr_req_t *this, swid_tag_id_t *tag_id); void (*add_target)(tcg_swid_attr_req_t *this, swid_tag_id_t *tag_id);
/** /**
* Create Tag ID enumerator * Create Tag ID enumerator
* *
* @return Tag ID enumerator * @return Get a list of target tag IDs
*/ */
enumerator_t* (*create_tag_id_enumerator)(tcg_swid_attr_req_t *this); swid_inventory_t* (*get_targets)(tcg_swid_attr_req_t *this);
}; };