Factored IMC/V Attestation build/process of Component Functional Name
[strongswan.git] / src / libimcv / plugins / imv_attestation / imv_attestation_build.c
index ed5c359..d4ec8a6 100644 (file)
@@ -16,6 +16,7 @@
 #include "imv_attestation_build.h"
 #include "imv_attestation_state.h"
 
+#include <libpts.h>
 #include <tcg/tcg_pts_attr_proto_caps.h>
 #include <tcg/tcg_pts_attr_meas_algo.h>
 #include <tcg/tcg_pts_attr_dh_nonce_params_req.h>
@@ -193,8 +194,8 @@ bool imv_attestation_build(pa_tnc_msg_t *msg,
                        while (enumerator->enumerate(enumerator, &id, &type, &pathname))
                        {
                                is_dir = (type != 0);
-                               request_id = attestation_state->add_request(attestation_state,
-                                                                                                                       id, is_dir);
+                               request_id = attestation_state->add_file_meas_request(
+                                                       attestation_state, id, is_dir);
                                DBG2(DBG_IMV, "measurement request %d for %s '%s'",
                                         request_id, is_dir ? "directory" : "file", pathname);
                                attr = tcg_pts_attr_req_file_meas_create(is_dir, request_id,
@@ -207,39 +208,78 @@ bool imv_attestation_build(pa_tnc_msg_t *msg,
                }
                case IMV_ATTESTATION_STATE_COMP_EVID:
                {
-                       pts_attr_req_funct_comp_evid_flag_t flags;
-                       u_int32_t sub_comp_depth;
-                       pts_qualifier_t qualifier;
-                       pts_ita_funct_comp_name_t name;
+                       enumerator_t *enumerator;
+                       /* TODO: pts_components undeclared */
+                       /*char flags[8];
+                       int type;
+                       */
+                       char *platform_info;
+                       pts_funct_comp_evid_req_t *requests = NULL;
+                       funct_comp_evid_req_entry_t *entry;
+                       int vid, name, qualifier;
+                       
+                       bool first_req = TRUE;
 
                        attestation_state->set_handshake_state(attestation_state,
                                                                                IMV_ATTESTATION_STATE_END);
 
-                       flags = PTS_REQ_FUNC_COMP_FLAG_PCR;
-                       sub_comp_depth = 0;
-                       qualifier.kernel = FALSE;
-                       qualifier.sub_component = FALSE;
-                       qualifier.type = PTS_ITA_FUNC_COMP_TYPE_TRUSTED;
+                       /* Get Platform and OS of the PTS-IMC */
+                       platform_info = pts->get_platform_info(pts);
+                       if (!pts_db || !platform_info)
+                       {
+                               DBG1(DBG_IMV, "%s%s%s not available",
+                                       (pts_db) ? "" : "pts database",
+                                       (!pts_db && !platform_info) ? "and" : "",
+                                       (platform_info) ? "" : "platform info");
+                               break;
+                       }
+                       DBG1(DBG_IMV, "platform is '%s'", platform_info);
 
-                       /* Send Request Functional Component Evidence attribute */
-                       name = PTS_ITA_FUNC_COMP_NAME_TGRUB_STAGE2_PART1;
-                       attr = tcg_pts_attr_req_funct_comp_evid_create(flags,
-                                                                       sub_comp_depth, PEN_ITA, qualifier, name);
-                       attr->set_noskip_flag(attr, TRUE);
-                       msg->add_attribute(msg, attr);
                        
+                       enumerator = pts_db->create_comp_evid_enumerator(pts_db, platform_info);
+                       if (!enumerator)
+                       {
+                               break;
+                       }
+                       while (enumerator->enumerate(enumerator, &vid, &name, &qualifier))
+                       {
+                               entry = malloc_thing(funct_comp_evid_req_entry_t);
+                               entry->flags = PTS_REQ_FUNC_COMP_FLAG_PCR;
+                               entry->sub_comp_depth = 0;
+                               entry->name = pts_comp_func_name_create(vid, name, qualifier);
+
+                               /* TODO: pts_components undeclared */
+                               /*type = pts_components->get_qualifier(pts_components,
+                                                                                                        entry->name, &flags);
+
+                               DBG2(DBG_TNC, "%N functional component '%N' with qualifier %s '%N'",
+                                        pen_names, vid,
+                                        pts_components->get_comp_func_names(pts_components, vid),
+                                        name, flags,
+                                        pts_components->get_qualifier_type_names(pts_components, vid),
+                                        type);
+                               */
+                               if (first_req)
+                               {
+                                       /* Create a requests object */
+                                       requests = pts_funct_comp_evid_req_create();
+                                       first_req = FALSE;
+                               }
+                               requests->add(requests, entry);
+                               attestation_state->add_comp_evid_request(attestation_state, entry);
+                       }
+                       enumerator->destroy(enumerator);
+
                        /* Send Request Functional Component Evidence attribute */
-                       name = PTS_ITA_FUNC_COMP_NAME_TGRUB_STAGE2_PART2;
-                       attr = tcg_pts_attr_req_funct_comp_evid_create(flags,
-                                                                       sub_comp_depth, PEN_ITA, qualifier, name);
+                       attr = tcg_pts_attr_req_funct_comp_evid_create(requests);
                        attr->set_noskip_flag(attr, TRUE);
                        msg->add_attribute(msg, attr);
-                       
+
                        /* Send Generate Attestation Evidence attribute */
                        attr = tcg_pts_attr_gen_attest_evid_create();
                        attr->set_noskip_flag(attr, TRUE);
                        msg->add_attribute(msg, attr);
-
+                       
                        break;
                }
                default: