Replaced DH_NONCE state with TPM_INIT state
[strongswan.git] / src / libimcv / plugins / imv_attestation / imv_attestation_state.c
index bf21c0f..6305dac 100644 (file)
 #include "imv_attestation_state.h"
 
 #include <utils/lexparser.h>
+#include <utils/linked_list.h>
 #include <debug.h>
 
 typedef struct private_imv_attestation_state_t private_imv_attestation_state_t;
+typedef struct request_t request_t;
+
+/**
+ * PTS File/Directory Measurement request entry
+ */
+struct request_t {
+       u_int16_t id;
+       int file_id;
+       bool is_dir;
+};
 
 /**
  * Private data of an imv_attestation_state_t object.
@@ -56,6 +67,16 @@ struct private_imv_attestation_state_t {
        TNC_IMV_Evaluation_Result eval;
 
        /**
+        * Request counter
+        */
+       u_int16_t request_counter;
+
+       /**
+        * List of PTS File/Directory Measurement requests
+        */
+       linked_list_t *requests;
+
+       /**
         * PTS object
         */
        pts_t *pts;
@@ -138,7 +159,7 @@ METHOD(imv_state_t, get_reason_string, bool,
                        if (chunk_equals(lang, pref_lang))
                        {
                                *reason_language = lang;
-                               *reason_string = chunk_create(reasons[i].string, 
+                               *reason_string = chunk_create(reasons[i].string,
                                                                                strlen(reasons[i].string));
                                return TRUE;
                        }
@@ -148,7 +169,7 @@ METHOD(imv_state_t, get_reason_string, bool,
        /* no preferred language match found - use the default language */
        *reason_string =   chunk_create(reasons[0].string,
                                                                        strlen(reasons[0].string));
-       *reason_language = chunk_create(reasons[0].lang, 
+       *reason_language = chunk_create(reasons[0].lang,
                                                                        strlen(reasons[0].lang));
        return TRUE;
 }
@@ -156,6 +177,7 @@ METHOD(imv_state_t, get_reason_string, bool,
 METHOD(imv_state_t, destroy, void,
        private_imv_attestation_state_t *this)
 {
+       this->requests->destroy_function(this->requests, free);
        this->pts->destroy(this->pts);
        free(this);
 }
@@ -178,6 +200,51 @@ METHOD(imv_attestation_state_t, get_pts, pts_t*,
        return this->pts;
 }
 
+METHOD(imv_attestation_state_t, add_request, u_int16_t,
+       private_imv_attestation_state_t *this, int file_id, bool is_dir)
+{
+       request_t *request;
+
+       request = malloc_thing(request_t);
+       request->id = ++this->request_counter;
+       request->file_id = file_id;
+       request->is_dir = is_dir;
+       this->requests->insert_last(this->requests, request);
+
+       return this->request_counter;
+}
+
+METHOD(imv_attestation_state_t, check_off_request, bool,
+       private_imv_attestation_state_t *this, u_int16_t id, int *file_id,
+       bool* is_dir)
+{
+       enumerator_t *enumerator;
+       request_t *request;
+       bool found = FALSE;
+       
+       enumerator = this->requests->create_enumerator(this->requests);
+       while (enumerator->enumerate(enumerator, &request))
+       {
+               if (request->id == id)
+               {
+                       found = TRUE;
+                       *file_id = request->file_id;
+                       *is_dir = request->is_dir;
+                       this->requests->remove_at(this->requests, enumerator);
+                       free(request);
+                       break;
+               }
+       }
+       enumerator->destroy(enumerator);
+       return found;
+}
+
+METHOD(imv_attestation_state_t, get_request_count, int,
+       private_imv_attestation_state_t *this)
+{
+       return this->requests->get_count(this->requests);
+}
+
 /**
  * Described in header.
  */
@@ -199,17 +266,21 @@ imv_state_t *imv_attestation_state_create(TNC_ConnectionID connection_id)
                        .get_handshake_state = _get_handshake_state,
                        .set_handshake_state = _set_handshake_state,
                        .get_pts = _get_pts,
+                       .add_request = _add_request,
+                       .check_off_request = _check_off_request,
+                       .get_request_count = _get_request_count,
                },
                .connection_id = connection_id,
                .state = TNC_CONNECTION_STATE_CREATE,
                .handshake_state = IMV_ATTESTATION_STATE_INIT,
                .rec = TNC_IMV_ACTION_RECOMMENDATION_NO_RECOMMENDATION,
                .eval = TNC_IMV_EVALUATION_RESULT_DONT_KNOW,
+               .requests = linked_list_create(),
                .pts = pts_create(FALSE),
        );
 
        platform_info = lib->settings->get_str(lib->settings,
-                                               "libimcv.plugins.imv-attestation.platform_info", NULL);
+                                                "libimcv.plugins.imv-attestation.platform_info", NULL);
        if (platform_info)
        {
                this->pts->set_platform_info(this->pts, platform_info);