Replaced DH_NONCE state with TPM_INIT state
[strongswan.git] / src / libimcv / plugins / imv_attestation / imv_attestation_state.c
index e3165d0..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;
@@ -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,12 +266,16 @@ 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),
        );