X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=blobdiff_plain;f=src%2Flibpts%2Fplugins%2Fimc_swid%2Fimc_swid.c;h=d4aaeff4d375347290084e7df7d44ed540ebeace;hp=a90e5adc3aed3ea26425c3f9cdd1ae2aaa444dba;hb=50fdff70e8ffa37eca8e83076017c055f1879c22;hpb=1e82e27ac57329f2b76b5f0891f44e0942072719 diff --git a/src/libpts/plugins/imc_swid/imc_swid.c b/src/libpts/plugins/imc_swid/imc_swid.c index a90e5ad..d4aaeff 100644 --- a/src/libpts/plugins/imc_swid/imc_swid.c +++ b/src/libpts/plugins/imc_swid/imc_swid.c @@ -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 #include -static char strongswan_tag[] = - "\n" - "\n" - "true\n" - "strongSwan\n" - "\n" - " 5.1.1dr1\n" - " \n" - " 5\n" - " 1\n" - " 1\n" - " dr1\n" - " \n" - "\n" - "\n" - " strongSwan Project\n" - " regid.2004-03.org.strongswan\n" - "\n" - "\n" - " strongSwan Project\n" - " regid.2004-03.org.strongswan\n" - "\n" - "\n" - " strongSwan-5-1-1-dr1\n" - " regid.2004-03.org.strongswan\n" - "\n" - "\n" - " strongSwan Project\n" - " regid.2004-03.org.strongswan\n" - "\n" - "\n"; /* IMC definitions */ @@ -187,6 +154,9 @@ 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, *targets; + char *swid_directory; + bool full_tags; type = attr->get_type(attr); @@ -198,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; flags = attr_req->get_flags(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); if (flags & (TCG_SWID_ATTR_REQ_FLAG_S | TCG_SWID_ATTR_REQ_FLAG_C)) @@ -207,29 +178,33 @@ 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_directory = lib->settings->get_str(lib->settings, + "%s.plugins.imc-swid.swid_directory", + SWID_DIRECTORY, lib->ns); + swid_inventory = swid_inventory_create(full_tags); + if (!swid_inventory->collect(swid_inventory, swid_directory, targets)) { - 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_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); + 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; + } + DBG1(DBG_IMC, "collected %d SWID tag%s%s", + swid_inventory->get_count(swid_inventory), full_tags ? "" : " ID", + swid_inventory->get_count(swid_inventory) == 1 ? "" : "s"); + + 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); }