File not Found, Invalid path, Invalid Delimiter PTS errors case checks implemented
[strongswan.git] / src / libimcv / plugins / imc_attestation / imc_attestation.c
index 9b60bc0..58fb178 100644 (file)
@@ -21,7 +21,9 @@
 #include <ietf/ietf_attr_pa_tnc_error.h>
 #include <ietf/ietf_attr_product_info.h>
 
 #include <ietf/ietf_attr_pa_tnc_error.h>
 #include <ietf/ietf_attr_product_info.h>
 
-#include <tcg/pts/pts_error.h>
+#include <libpts.h>
+
+#include <pts/pts_error.h>
 
 #include <tcg/tcg_pts_attr_proto_caps.h>
 #include <tcg/tcg_pts_attr_meas_algo.h>
 
 #include <tcg/tcg_pts_attr_proto_caps.h>
 #include <tcg/tcg_pts_attr_meas_algo.h>
@@ -69,12 +71,19 @@ TNC_Result TNC_IMC_Initialize(TNC_IMCID imc_id,
                DBG1(DBG_IMC, "IMC \"%s\" has already been initialized", imc_name);
                return TNC_RESULT_ALREADY_INITIALIZED;
        }
                DBG1(DBG_IMC, "IMC \"%s\" has already been initialized", imc_name);
                return TNC_RESULT_ALREADY_INITIALIZED;
        }
+       if (!pts_meas_probe_algorithms(&supported_algorithms))
+       {
+               return TNC_RESULT_FATAL;
+       }
        imc_attestation = imc_agent_create(imc_name, IMC_VENDOR_ID, IMC_SUBTYPE,
        imc_attestation = imc_agent_create(imc_name, IMC_VENDOR_ID, IMC_SUBTYPE,
-                                                               imc_id, actual_version);
-       if (!imc_attestation || !pts_meas_probe_algorithms(&supported_algorithms))
+                                                                          imc_id, actual_version);
+       if (!imc_attestation)
        {
                return TNC_RESULT_FATAL;
        }
        {
                return TNC_RESULT_FATAL;
        }
+
+       libpts_init();
+
        if (min_version > TNC_IFIMC_VERSION_1 || max_version < TNC_IFIMC_VERSION_1)
        {
                DBG1(DBG_IMC, "no common IF-IMC version");
        if (min_version > TNC_IFIMC_VERSION_1 || max_version < TNC_IFIMC_VERSION_1)
        {
                DBG1(DBG_IMC, "no common IF-IMC version");
@@ -345,12 +354,39 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                        char *pathname;
                                        u_int16_t request_id;
                                        bool is_directory;
                                        char *pathname;
                                        u_int16_t request_id;
                                        bool is_directory;
+                                       u_int32_t delimiter;
                                        pts_file_meas_t *measurements;
                                        pts_file_meas_t *measurements;
-
+                                       pts_error_code_t pts_error;
+                                       chunk_t attr_info;
+                                       
+                                       attr_info = attr->get_value(attr);
                                        attr_cast = (tcg_pts_attr_req_file_meas_t*)attr;
                                        is_directory = attr_cast->get_directory_flag(attr_cast);
                                        request_id = attr_cast->get_request_id(attr_cast);
                                        attr_cast = (tcg_pts_attr_req_file_meas_t*)attr;
                                        is_directory = attr_cast->get_directory_flag(attr_cast);
                                        request_id = attr_cast->get_request_id(attr_cast);
+                                       delimiter = attr_cast->get_delimiter(attr_cast);
                                        pathname = attr_cast->get_pathname(attr_cast);
                                        pathname = attr_cast->get_pathname(attr_cast);
+                                       
+                                       if (pts->is_path_valid(pts, pathname, &pts_error) && pts_error)
+                                       {
+                                               attr_info = attr->get_value(attr);
+                                               attr = ietf_attr_pa_tnc_error_create(PEN_TCG,
+                                                                                               pts_error, attr_info);
+                                               attr_list->insert_last(attr_list, attr);
+                                               break;
+                                       }
+                                       else if (!pts->is_path_valid(pts, pathname, &pts_error))
+                                       {
+                                               break;
+                                       }
+                                       
+                                       if (delimiter != SOLIDUS_UTF && delimiter != REVERSE_SOLIDUS_UTF)
+                                       {
+                                               attr_info = attr->get_value(attr);
+                                               attr = ietf_attr_pa_tnc_error_create(PEN_TCG,
+                                                                                               TCG_PTS_INVALID_DELIMITER, attr_info);
+                                               attr_list->insert_last(attr_list, attr);
+                                               break;
+                                       }
 
                                        /* Do PTS File Measurements and send them to PTS-IMV */
                                        DBG2(DBG_IMC, "measurement request %d for %s '%s'",
 
                                        /* Do PTS File Measurements and send them to PTS-IMV */
                                        DBG2(DBG_IMC, "measurement request %d for %s '%s'",
@@ -418,10 +454,9 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                pa_tnc_msg->build(pa_tnc_msg);
                result = imc_attestation->send_message(imc_attestation, connection_id,
                                                        pa_tnc_msg->get_encoding(pa_tnc_msg));
                pa_tnc_msg->build(pa_tnc_msg);
                result = imc_attestation->send_message(imc_attestation, connection_id,
                                                        pa_tnc_msg->get_encoding(pa_tnc_msg));
-       
-               attr_list->destroy(attr_list);
                pa_tnc_msg->destroy(pa_tnc_msg);
        }
                pa_tnc_msg->destroy(pa_tnc_msg);
        }
+       attr_list->destroy(attr_list);
 
        return result;
 }
 
        return result;
 }
@@ -450,6 +485,9 @@ TNC_Result TNC_IMC_Terminate(TNC_IMCID imc_id)
                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
                return TNC_RESULT_NOT_INITIALIZED;
        }
                DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name);
                return TNC_RESULT_NOT_INITIALIZED;
        }
+
+       libpts_deinit();
+
        imc_attestation->destroy(imc_attestation);
        imc_attestation = NULL;
 
        imc_attestation->destroy(imc_attestation);
        imc_attestation = NULL;