build PA-TNC message only if there are PA-TNC attributes to send
authorAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 18 Dec 2011 16:55:20 +0000 (17:55 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sun, 18 Dec 2011 16:55:20 +0000 (17:55 +0100)
src/libpts/plugins/imv_attestation/imv_attestation.c
src/libpts/plugins/imv_attestation/imv_attestation_build.c
src/libpts/plugins/imv_attestation/imv_attestation_build.h

index 30c1832..4aa3936 100644 (file)
@@ -169,30 +169,52 @@ TNC_Result TNC_IMV_NotifyConnectionChange(TNC_IMVID imv_id,
 static TNC_Result send_message(TNC_ConnectionID connection_id)
 {
        pa_tnc_msg_t *msg;
+       pa_tnc_attr_t *attr;
        imv_state_t *state;
        imv_attestation_state_t *attestation_state;
        TNC_Result result;
+       linked_list_t *attr_list;
+       enumerator_t *enumerator;
 
        if (!imv_attestation->get_state(imv_attestation, connection_id, &state))
        {
                return TNC_RESULT_FATAL;
        }
        attestation_state = (imv_attestation_state_t*)state;
-       msg = pa_tnc_msg_create();
+       attr_list = linked_list_create();
 
-       if (imv_attestation_build(msg, attestation_state, supported_algorithms,
+       if (imv_attestation_build(attr_list, attestation_state, supported_algorithms,
                                                          supported_dh_groups, pts_db))
        {
-               msg->build(msg);
-               result = imv_attestation->send_message(imv_attestation, connection_id,
-                                                                                          FALSE, 0, TNC_IMCID_ANY,
-                                                                                          msg->get_encoding(msg));
+               if (attr_list->get_count(attr_list))
+               {
+                       msg = pa_tnc_msg_create();
+
+                       /* move PA-TNC attributes to PA-TNC message */
+                       enumerator = attr_list->create_enumerator(attr_list);
+                       while (enumerator->enumerate(enumerator, &attr))
+                       {
+                               msg->add_attribute(msg, attr);
+                       }
+                       enumerator->destroy(enumerator);
+
+                       msg->build(msg);
+                       result = imv_attestation->send_message(imv_attestation,
+                                                       connection_id, FALSE, 0, TNC_IMCID_ANY,
+                                                       msg->get_encoding(msg));
+                       msg->destroy(msg);
+               }
+               else
+               {
+                       result = TNC_RESULT_SUCCESS;
+               }
+               attr_list->destroy(attr_list);
        }
        else
        {
+               attr_list->destroy_offset(attr_list, offsetof(pa_tnc_attr_t, destroy));
                result = TNC_RESULT_FATAL;
        }
-       msg->destroy(msg);
 
        return result;
 }
@@ -310,6 +332,7 @@ static TNC_Result receive_message(TNC_IMVID imv_id,
        {
                pa_tnc_msg = pa_tnc_msg_create();
 
+               /* move PA-TNC attributes to PA-TNC message */
                enumerator = attr_list->create_enumerator(attr_list);
                while (enumerator->enumerate(enumerator, &attr))
                {
index 089ecbe..efcb1c6 100644 (file)
@@ -30,7 +30,7 @@
 
 #include <debug.h>
 
-bool imv_attestation_build(pa_tnc_msg_t *msg,
+bool imv_attestation_build(linked_list_t *attr_list,
                                                   imv_attestation_state_t *attestation_state,
                                                   pts_meas_algorithms_t supported_algorithms,
                                                   pts_dh_group_t supported_dh_groups,
@@ -90,12 +90,12 @@ bool imv_attestation_build(pa_tnc_msg_t *msg,
                        flags = pts->get_proto_caps(pts);
                        attr = tcg_pts_attr_proto_caps_create(flags, TRUE);
                        attr->set_noskip_flag(attr, TRUE);
-                       msg->add_attribute(msg, attr);
+                       attr_list->insert_last(attr_list, attr);
 
                        /* Send Measurement Algorithms attribute */
                        attr = tcg_pts_attr_meas_algo_create(supported_algorithms, FALSE);
                        attr->set_noskip_flag(attr, TRUE);
-                       msg->add_attribute(msg, attr);
+                       attr_list->insert_last(attr_list, attr);
 
                        attestation_state->set_handshake_state(attestation_state,
                                                                                IMV_ATTESTATION_STATE_NONCE_REQ);
@@ -111,7 +111,7 @@ bool imv_attestation_build(pa_tnc_msg_t *msg,
                        attr = tcg_pts_attr_dh_nonce_params_req_create(min_nonce_len,
                                                                                                         supported_dh_groups);
                        attr->set_noskip_flag(attr, TRUE);
-                       msg->add_attribute(msg, attr);
+                       attr_list->insert_last(attr_list, attr);
 
                        attestation_state->set_handshake_state(attestation_state,
                                                                                IMV_ATTESTATION_STATE_TPM_INIT);
@@ -130,18 +130,18 @@ bool imv_attestation_build(pa_tnc_msg_t *msg,
                                attr = tcg_pts_attr_dh_nonce_finish_create(selected_algorithm,
                                                                                        initiator_value, initiator_nonce);
                                attr->set_noskip_flag(attr, TRUE);
-                               msg->add_attribute(msg, attr);
+                       attr_list->insert_last(attr_list, attr);
                        }
 
                        /* Send Get TPM Version attribute */
                        attr = tcg_pts_attr_get_tpm_version_info_create();
                        attr->set_noskip_flag(attr, TRUE);
-                       msg->add_attribute(msg, attr);
+                       attr_list->insert_last(attr_list, attr);
 
                        /* Send Get AIK attribute */
                        attr = tcg_pts_attr_get_aik_create();
                        attr->set_noskip_flag(attr, TRUE);
-                       msg->add_attribute(msg, attr);
+                       attr_list->insert_last(attr_list, attr);
 
                        attestation_state->set_handshake_state(attestation_state,
                                                                                IMV_ATTESTATION_STATE_MEAS);
@@ -187,7 +187,7 @@ bool imv_attestation_build(pa_tnc_msg_t *msg,
                                attr = tcg_pts_attr_req_file_meta_create(is_dir, delimiter,
                                                                                                                 pathname);
                                attr->set_noskip_flag(attr, TRUE);
-                               msg->add_attribute(msg, attr);
+                               attr_list->insert_last(attr_list, attr);
                        }
                        enumerator->destroy(enumerator);
                        
@@ -208,7 +208,7 @@ bool imv_attestation_build(pa_tnc_msg_t *msg,
                                attr = tcg_pts_attr_req_file_meas_create(is_dir, request_id,
                                                                                                         delimiter, pathname);
                                attr->set_noskip_flag(attr, TRUE);
-                               msg->add_attribute(msg, attr);
+                               attr_list->insert_last(attr_list, attr);
                        }
                        enumerator->destroy(enumerator);
                        break;
@@ -275,12 +275,12 @@ bool imv_attestation_build(pa_tnc_msg_t *msg,
                        if (attr)
                        {
                                /* Send Request Functional Component Evidence attribute */
-                               msg->add_attribute(msg, attr);
+                               attr_list->insert_last(attr_list, 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);
+                               attr_list->insert_last(attr_list, attr);
                        }
                        break;
                }
index e397e84..7f934fd 100644 (file)
 /**
  * Process a TCG PTS attribute
  *
- * @param msg                                  PA-TNC message to be built
+ * @param attr_list                            list of PA-TNC attriubutes to be built
  * @param attestation_state            attestation state of a given connection
  * @param supported_algorithms supported PTS measurement algorithms
  * @param supported_dh_groups  supported DH groups
  * @param pts_db                               PTS configuration database
  * @return                                             TRUE if successful
  */
-bool imv_attestation_build(pa_tnc_msg_t *msg,
+bool imv_attestation_build(linked_list_t *attr_list,
                                                   imv_attestation_state_t *attestation_state,
                                                   pts_meas_algorithms_t supported_algorithms,
                                                   pts_dh_group_t supported_dh_groups,