first stage of file_meas refactoring
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 31 Aug 2011 14:52:31 +0000 (16:52 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 8 Sep 2011 10:08:15 +0000 (12:08 +0200)
src/libimcv/plugins/imc_attestation/imc_attestation.c
src/libimcv/plugins/imv_attestation/imv_attestation.c
src/libimcv/tcg/pts/pts.c
src/libimcv/tcg/pts/pts.h
src/libimcv/tcg/tcg_pts_attr_file_meas.c
src/libimcv/tcg/tcg_pts_attr_file_meas.h
src/libimcv/tcg/tcg_pts_attr_req_file_meas.c
src/libimcv/tcg/tcg_pts_attr_req_file_meas.h

index b267eef..937a7ec 100644 (file)
@@ -137,8 +137,8 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                                                  TNC_UInt32 msg_len,
                                                                  TNC_MessageType msg_type)
 {
-       pa_tnc_msg_t *pa_tnc_msg, *msg_to_send;
-       pa_tnc_attr_t *attr, *attr_to_send;
+       pa_tnc_msg_t *pa_tnc_msg;
+       pa_tnc_attr_t *attr;
        linked_list_t *attr_list;
        imc_state_t *state;
        imc_attestation_state_t *attestation_state;
@@ -172,7 +172,6 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                return result;
        }
        
-       msg_to_send = pa_tnc_msg_create();
        attr_list = linked_list_create();
 
        /* analyze PA-TNC attributes */
@@ -210,7 +209,7 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                }
                else if (attr->get_vendor_id(attr) == PEN_TCG)
                {
-                       switch(attr->get_type(attr))
+                       switch (attr->get_type(attr))
                        {
                                case TCG_PTS_REQ_PROTO_CAPS:
                                {
@@ -223,9 +222,9 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                        pts->set_proto_caps(pts, imc_flags & imv_flags);
 
                                        /* Send PTS Protocol Capabilities attribute */ 
-                                       attr_to_send = tcg_pts_attr_proto_caps_create(imc_flags & imv_flags, FALSE);
-                                       attr_to_send = (pa_tnc_attr_t*)attr_to_send;
-                                       attr_list->insert_last(attr_list,attr_to_send);                                 
+                                       attr = tcg_pts_attr_proto_caps_create(imc_flags & imv_flags,
+                                                                                                                 FALSE);
+                                       attr_list->insert_last(attr_list, attr);
                                        break;
                                }
                                case TCG_PTS_MEAS_ALGO:
@@ -256,11 +255,12 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                        {
                                                /* TODO send a TCG_PTS_H_ALG_NOT_SUPPORTED error */
                                        }
+
                                        /* Send Measurement Algorithm Selection attribute */ 
                                        selected_algorithm = pts->get_meas_algorithm(pts);
-                                       attr_to_send = tcg_pts_attr_meas_algo_create(selected_algorithm, TRUE);
-                                       attr_to_send = (pa_tnc_attr_t*)attr_to_send;
-                                       attr_list->insert_last(attr_list,attr_to_send);
+                                       attr = tcg_pts_attr_meas_algo_create(selected_algorithm,
+                                                                                                                TRUE);
+                                       attr_list->insert_last(attr_list, attr);
                                        break;
                                }
                                        
@@ -271,12 +271,12 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                        if (!pts->get_tpm_version_info(pts, &tpm_version_info))
                                        {
                                                /* TODO return TCG_PTS_TPM_VERS_NOT_SUPPORTED error attribute */
+                                               break;
                                        }
                                        
                                        /* Send TPM Version Info attribute */ 
-                                       attr_to_send = tcg_pts_attr_tpm_version_info_create(tpm_version_info);
-                                       attr_to_send = (pa_tnc_attr_t*)attr_to_send;
-                                       attr_list->insert_last(attr_list,attr_to_send);
+                                       attr = tcg_pts_attr_tpm_version_info_create(tpm_version_info);
+                                       attr_list->insert_last(attr_list, attr);
                                        break;
                                }
                                
@@ -306,11 +306,9 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                case TCG_PTS_REQ_FILE_MEAS:
                                {
                                        tcg_pts_attr_req_file_meas_t *attr_cast;
-                                       tcg_pts_attr_file_meas_t *attr_file_meas;
-                                       u_int32_t delimiter;
-                                       chunk_t path;
-                                       u_int16_t request_id;
-                                       u_int16_t meas_len;
+                                       tcg_pts_attr_file_meas_t *attr_out;
+                                       char *pathname;
+                                       u_int16_t request_id, meas_len;
                                        pts_meas_algorithms_t selected_algorithm;
                                        chunk_t file_hash;
                                        bool directory_flag;
@@ -319,12 +317,10 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                        attr_cast = (tcg_pts_attr_req_file_meas_t*)attr;
                                        directory_flag = attr_cast->get_directory_flag(attr_cast);
                                        request_id = attr_cast->get_request_id(attr_cast);
-                                       delimiter = attr_cast->get_delimiter(attr_cast);
-                                       path = attr_cast->get_file_path(attr_cast);
-                                       path = chunk_clone(path);
-
-                                       DBG3(DBG_IMC,"requested %s to be measured: %B", 
-                                            (directory_flag)? "directory":"file", &path);
+                                       pathname = attr_cast->get_pathname(attr_cast);
+                                       
+                                       DBG2(DBG_IMC, "%s to be measured: '%s'", 
+                                            directory_flag ? "directory" : "file", pathname);
                                        
                                        /* Send File Measurement attribute */
                                        selected_algorithm = pts->get_meas_algorithm(pts);
@@ -342,27 +338,28 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                        * Hash the file or directory and add them as attribute
                                        */
                                        
-                                       attr_to_send = directory_flag ? 
+                                       attr = directory_flag ? 
                                                tcg_pts_attr_file_meas_create(0, request_id, meas_len) :
                                                tcg_pts_attr_file_meas_create(1, request_id, meas_len);
-                                       attr_to_send->set_noskip_flag(attr_to_send, TRUE);
-                                       attr_file_meas = (tcg_pts_attr_file_meas_t*)attr_to_send;
+                                       attr->set_noskip_flag(attr, TRUE);
+                                       attr_out = (tcg_pts_attr_file_meas_t*)attr;
                                        
-                                       if(!directory_flag)
+                                       if (!directory_flag)
                                        {
-                                               if(pts->hash_file(pts,path,&file_hash) != true)
+                                               if (!pts->hash_file(pts, pathname, &file_hash))
                                                {
                                                        DBG1(DBG_IMC, "Hashing the given file has failed");
                                                        return TNC_RESULT_FATAL;
                                                }
-                                               attr_file_meas->add_file_meas(attr_file_meas, file_hash, path);
+                                               attr_out->add_file_meas(attr_out, file_hash, pathname);
                                        }
                                        else
                                        {
                                                enumerator_t *meas_enumerator;
                                                file_meas_entry_t *meas_entry;
                                                u_int64_t num_of_files = 0 ;
-                                               if(pts->hash_directory(pts, path, &file_measurements) != true)
+
+                                               if (!pts->hash_directory(pts, pathname, &file_measurements))
                                                {
                                                        DBG1(DBG_IMC, "Hashing the files in a given directory has failed");
                                                        return TNC_RESULT_FATAL;
@@ -372,21 +369,18 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
                                                while (meas_enumerator->enumerate(meas_enumerator, &meas_entry))
                                                {
                                                        num_of_files++;
-                                                       attr_file_meas->add_file_meas(attr_file_meas,
-                                                                               meas_entry->measurement,
-                                                                               meas_entry->file_name);
+                                                       attr_out->add_file_meas(attr_out,
+                                                                                                       meas_entry->measurement,
+                                                                                                       meas_entry->filename);
                                                }
                                                
-                                               attr_file_meas->set_number_of_files(attr_file_meas,
-                                                                               num_of_files);
+                                               attr_out->set_number_of_files(attr_out, num_of_files);
                                                meas_enumerator->destroy(meas_enumerator);
                                                file_measurements->destroy(file_measurements);
                                                
                                        }
-                                                                               
-                                       attr_to_send = (pa_tnc_attr_t*)attr_file_meas;
-                                       attr_list->insert_last(attr_list,attr_to_send);
                                        
+                                       attr_list->insert_last(attr_list, attr);
                                        break;
                                }
                                /* TODO: Not implemented yet */
@@ -424,25 +418,29 @@ TNC_Result TNC_IMC_ReceiveMessage(TNC_IMCID imc_id,
        }
        enumerator->destroy(enumerator);
        pa_tnc_msg->destroy(pa_tnc_msg);
+
+       result = TNC_RESULT_SUCCESS;
                
-       if(attr_list->get_count(attr_list))
+       if (attr_list->get_count(attr_list))
        {
-               enumerator_t *attr_enumerator = attr_list->create_enumerator(attr_list);
-               while (attr_enumerator->enumerate(attr_enumerator, &attr_to_send))
+               pa_tnc_msg = pa_tnc_msg_create();
+
+               enumerator = attr_list->create_enumerator(attr_list);
+               while (enumerator->enumerate(enumerator, &attr))
                {
-                       msg_to_send->add_attribute(msg_to_send, attr_to_send);
+                       pa_tnc_msg->add_attribute(pa_tnc_msg, attr);
                }
-               attr_enumerator->destroy(attr_enumerator);
-       }
+               enumerator->destroy(enumerator);
 
-       msg_to_send->build(msg_to_send);
-       result = imc_attestation->send_message(imc_attestation, connection_id,
-                                       msg_to_send->get_encoding(msg_to_send));
+               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);
-       msg_to_send->destroy(msg_to_send);
+               attr_list->destroy(attr_list);
+               pa_tnc_msg->destroy(pa_tnc_msg);
+       }
 
-       return TNC_RESULT_SUCCESS;
+       return result;
 }
 
 /**
index b9256c1..ead3251 100644 (file)
@@ -236,7 +236,7 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
                        /** 
                         * Add files to measure to PTS Request File Measurement attribute
                         */
-                       product = "Ubuntu 10.10 x86_64";
+                       product = "Ubuntu 11.4 i686";
 
                        if (!pts_db)
                        {
@@ -250,17 +250,12 @@ static TNC_Result send_message(TNC_ConnectionID connection_id)
                        while (enumerator->enumerate(enumerator, &id, &type, &path))
                        {
                                bool is_directory;
-                               chunk_t path_chunk;
                                
                                DBG2(DBG_IMV, "id = %d, type = %d, path = '%s'", id, type, path);
                                
-                               is_directory = (type != 0) ? true : false;
-                               path[strlen(path)] = '\0';
-                               path_chunk = chunk_create(path, strlen(path));
-                               path_chunk = chunk_clone(path_chunk);
-                               
+                               is_directory = (type != 0) ? TRUE : FALSE;
                                attr_req_file_meas = tcg_pts_attr_req_file_meas_create(is_directory, 
-                                                       (u_int16_t)id, delimiter, path_chunk);
+                                                       id, delimiter, path);
                                attr_req_file_meas->set_noskip_flag(attr_req_file_meas, TRUE);
                                msg->add_attribute(msg, attr_req_file_meas);
                        }
@@ -302,7 +297,7 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
        enumerator_t *enumerator;
        TNC_Result result;
        bool fatal_error = FALSE;
-       bool comparisons_succeeded = true;
+       bool comparisons_succeeded = TRUE;
 
        if (!imv_attestation)
        {
@@ -445,7 +440,7 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
                                        {
                                                enumerator_t *hash_enumerator;
                                                pts_meas_algorithms_t selected_algorithm;
-                                               char *product = "Ubuntu 10.10 x86_64";
+                                               char *product = "Ubuntu 11.4 i686";
                                                chunk_t db_measurement;
                                                
                                                DBG3(DBG_IMV, "Received measurement: %B", &meas_entry->measurement);
@@ -468,12 +463,14 @@ TNC_Result TNC_IMV_ReceiveMessage(TNC_IMVID imv_id,
                                                        /* Compare the received hash measurement with one saved in db */
                                                        if(chunk_equals(db_measurement, meas_entry->measurement))
                                                        {
-                                                               DBG1(DBG_IMV, "Measurement comparison succeeded for: %s", meas_entry->file_name.ptr);
+                                                               DBG1(DBG_IMV, "Measurement comparison succeeded for: %s",
+                                                                        meas_entry->filename);
                                                        }
                                                        else
                                                        {
-                                                               DBG1(DBG_IMV, "Measurement comparison failed for: %s", meas_entry->file_name.ptr);
-                                                               comparisons_succeeded = false;
+                                                               DBG1(DBG_IMV, "Measurement comparison failed for: %s",
+                                                                        meas_entry->filename);
+                                                               comparisons_succeeded = FALSE;
                                                        }
                                                }
                                                hash_enumerator->destroy(hash_enumerator);
index 0d03049..5a15b3a 100644 (file)
@@ -537,7 +537,7 @@ METHOD(pts_t, set_aik, void,
 }
 
 METHOD(pts_t, hash_file, bool,
-       private_pts_t *this, chunk_t path, chunk_t *out)
+       private_pts_t *this, char *pathname, chunk_t *out)
 {
        char buffer[PTS_BUF_SIZE];
        chunk_t path_chunk;
@@ -552,16 +552,15 @@ METHOD(pts_t, hash_file, bool,
        if (!hasher)
        {
                DBG1(DBG_IMC, "hasher %N not available", hash_algorithm_names, hash_alg);
-               return false;
+               return FALSE;
        }
-       
-       path_chunk = chunk_create_clone(malloc(path.len), path);
-       file = fopen(path_chunk.ptr, "rb");
+
+       file = fopen(pathname, "rb");
        if (!file)
        {
-               DBG1(DBG_IMC,"file '%s' can not be opened, %s", path.ptr, strerror(errno));
+               DBG1(DBG_IMC,"file '%s' can not be opened, %s", pathname, strerror(errno));
                hasher->destroy(hasher);
-               return false;
+               return FALSE;
        }
        while (TRUE)
        {
@@ -580,27 +579,27 @@ METHOD(pts_t, hash_file, bool,
        fclose(file);
        hasher->destroy(hasher);
 
-       return true;
+       return TRUE;
 }
 
 METHOD(pts_t, hash_directory, bool,
-       private_pts_t *this, chunk_t path, linked_list_t **file_measurements)
+       private_pts_t *this, char *pathname, linked_list_t **file_measurements)
 {
        DIR *dir;
        struct dirent *ent;
        chunk_t path_chunk;
        file_meas_entry_t *entry;
        linked_list_t *list = *file_measurements;
+       char filename[BUF_LEN];
        
        list = linked_list_create();
        entry = malloc_thing(file_meas_entry_t);
        
-       path_chunk = chunk_create_clone(malloc(path.len), path);
-       dir = opendir(path_chunk.ptr);
+       dir = opendir(pathname);
        if (dir == NULL)
        {
-               DBG1(DBG_IMC, "opening directory '%s' failed: %s", path.ptr, strerror(errno));
-               return false;
+               DBG1(DBG_IMC, "opening directory '%s' failed: %s", pathname, strerror(errno));
+               return FALSE;
        }
        while ((ent = readdir(dir)))
        {
@@ -608,24 +607,21 @@ METHOD(pts_t, hash_directory, bool,
                {       /* skip ".", ".." and hidden files (such as ".svn") */
                        continue;
                }
+               snprintf(filename, BUF_LEN, "%s/%s", pathname, ent->d_name);
+               entry->filename = strdup(filename);
                                
-               if(this->public.hash_file(&this->public, chunk_cat("cc", path, chunk_create(ent->d_name, strlen(ent->d_name)))
-                       , &entry->measurement) != true)
+               if (!hash_file(this, filename, &entry->measurement))
                {
                        DBG1(DBG_IMC, "Hashing the given file has failed");
-                       return false;
+                       return FALSE;
                }
-               
-               entry->file_name_len = strlen(ent->d_name);
-               entry->file_name = chunk_create(ent->d_name,strlen(ent->d_name));
-               
-               list->insert_last(list,entry);
+               list->insert_last(list, entry);
        }
                
        closedir(dir);
        
        *file_measurements = list;
-       return true;
+       return TRUE;
 }
 
 METHOD(pts_t, destroy, void,
index f88effa..f76ee8e 100644 (file)
@@ -36,9 +36,8 @@ typedef struct file_meas_entry_t file_meas_entry_t;
  * File Measurement entry
  */
 struct file_meas_entry_t {
-       chunk_t   measurement;
-       u_int16_t file_name_len;
-       chunk_t   file_name;
+       char    *filename;
+       chunk_t  measurement;
 };
 
 /**
@@ -94,8 +93,8 @@ struct pts_t {
         * Get Attestation Identity Key
         *
         * @param aik                   chunk containing a AIK naked public key or certificate
-        * @param is_naked_key          TRUE if AIK is naked public key, without certificate
-        * @return                      TRUE if AIK available
+        * @param is_naked_key  TRUE if AIK is naked public key, without certificate
+        * @return                              TRUE if AIK available
         */
        bool (*get_aik)(pts_t *this, chunk_t *aik, bool *is_naked_key);
        
@@ -103,27 +102,27 @@ struct pts_t {
         * Set Attestation Identity Key
         *
         * @param aik                   chunk containing a AIK naked public key or certificate 
-        * @param is_naked_key          TRUE if AIK is naked public key, without certificate
+        * @param is_naked_key  TRUE if AIK is naked public key, without certificate
         */
        void (*set_aik)(pts_t *this, chunk_t aik, bool is_naked_key);
        
        /**
         * Hash the given file
         *
-        * @param path                  absolute path to file to be hashed
+        * @param pathname              absolute path to file to be hashed
         * @param out                   hash output value of a given file
-        * @return                      TRUE if hashing file was successful 
+        * @return                              TRUE if hashing file was successful 
         */
-       bool (*hash_file)(pts_t *this, chunk_t path, chunk_t *out);
+       bool (*hash_file)(pts_t *this, char *pathname, chunk_t *out);
        
        /**
         * Hash the given directory
         *
-        * @param path                  absolute path to directory to be hashed
+        * @param pathname                      absolute path to directory to be hashed
         * @param file_measurements     list of hash output values of files in a given folder
         * @return                      TRUE if hashing directory was successful 
         */
-       bool (*hash_directory)(pts_t *this, chunk_t path, linked_list_t **file_measurements);
+       bool (*hash_directory)(pts_t *this, char *pathname, linked_list_t **file_measurements);
 
        /**
         * Destroys a pts_t object.
index c0b6388..efeed7e 100644 (file)
@@ -144,6 +144,7 @@ METHOD(pa_tnc_attr_t, build, void,
        bio_writer_t *writer;
        enumerator_t *enumerator;
        file_meas_entry_t *entry;
+       chunk_t filename;
        
        writer = bio_writer_create(PTS_FILE_MEAS_SIZE);
 
@@ -156,9 +157,10 @@ METHOD(pa_tnc_attr_t, build, void,
        enumerator = this->measurements->create_enumerator(this->measurements);
        while (enumerator->enumerate(enumerator, &entry))
        {
-               writer->write_data (writer, entry->measurement);
-               writer->write_uint16 (writer, entry->file_name_len);
-               writer->write_data(writer, entry->file_name);
+               filename = chunk_create(entry->filename, strlen(entry->filename));
+               writer->write_data  (writer, entry->measurement);
+               writer->write_uint16(writer, strlen(entry->filename));
+               writer->write_data  (writer, filename);
        }
        enumerator->destroy(enumerator);
 
@@ -171,7 +173,8 @@ METHOD(pa_tnc_attr_t, process, status_t,
 {
        bio_reader_t *reader;
        u_int32_t number_of_files;
-       u_int64_t number_of_files_64;
+       u_int16_t filename_length;
+       chunk_t filename;
        file_meas_entry_t *entry;
        
        if (this->value.len < PTS_FILE_MEAS_SIZE)
@@ -183,11 +186,9 @@ METHOD(pa_tnc_attr_t, process, status_t,
        reader = bio_reader_create(this->value);
        
        reader->read_uint32(reader, &number_of_files);
-       number_of_files_64 = number_of_files;
-       this->number_of_files = (number_of_files_64 << 32);
+       this->number_of_files = (u_int64_t)number_of_files << 32;
        reader->read_uint32(reader, &number_of_files);
        this->number_of_files += number_of_files;
-       
        reader->read_uint16(reader, &this->request_id);
        reader->read_uint16(reader, &this->meas_len);
        
@@ -197,9 +198,11 @@ METHOD(pa_tnc_attr_t, process, status_t,
                
                reader->read_data (reader, this->meas_len, &entry->measurement);
                entry->measurement = chunk_clone(entry->measurement);
-               reader->read_uint16 (reader, &entry->file_name_len);
-               reader->read_data(reader, entry->file_name_len, &entry->file_name);
-               entry->file_name = chunk_clone(entry->file_name);
+               reader->read_uint16 (reader, &filename_length);
+               reader->read_data(reader, filename_length, &filename);
+               entry->filename = malloc(filename.len + 1);
+               memcpy(entry->filename, filename.ptr, filename.len);
+               entry->filename[filename.len] = '\0';
                
                this->measurements->insert_last(this->measurements, entry);
        }
@@ -253,15 +256,13 @@ METHOD(tcg_pts_attr_file_meas_t, set_meas_len, void,
 }
 
 METHOD(tcg_pts_attr_file_meas_t, add_file_meas, void,
-       private_tcg_pts_attr_file_meas_t *this, chunk_t measurement,
-                                               chunk_t file_name)
+       private_tcg_pts_attr_file_meas_t *this, chunk_t measurement, char *filename)
 {
        file_meas_entry_t *entry;
 
        entry = malloc_thing(file_meas_entry_t);
        entry->measurement = measurement;
-       entry->file_name_len = file_name.len;
-       entry->file_name = file_name;
+       entry->filename = strdup(filename);
        this->measurements->insert_last(this->measurements, entry);
 }
 
index 2bb892b..90b6713 100644 (file)
@@ -42,7 +42,7 @@ struct tcg_pts_attr_file_meas_t {
        /**
         * Get Number of Files included
         *
-        * @return                              Number of Files included
+        * @return                                      Number of Files included
         */
        u_int64_t (*get_number_of_files)(tcg_pts_attr_file_meas_t *this);
        
@@ -57,14 +57,14 @@ struct tcg_pts_attr_file_meas_t {
        /**
         * Get Request ID
         *
-        * @return                              Request ID
+        * @return                                      Request ID
         */
        u_int16_t (*get_request_id)(tcg_pts_attr_file_meas_t *this);
        
        /**
         * Set Request ID
         *
-        * @param request_id                    Request ID
+        * @param request_id            Request ID
         */
        void (*set_request_id)(tcg_pts_attr_file_meas_t *this,
                                                u_int16_t request_id);
@@ -72,7 +72,7 @@ struct tcg_pts_attr_file_meas_t {
        /**
         * Get Measurement Length
         *
-        * @return                              Measurement Length
+        * @return                                      Measurement Length
         */
        u_int16_t (*get_meas_len)(tcg_pts_attr_file_meas_t *this);
        
@@ -88,16 +88,16 @@ struct tcg_pts_attr_file_meas_t {
         * Add a file measurement entry
         *
         * @param measurement           Measurement value
-        * @param file_name             File Name
+        * @param filename                      Filename
         */
        void (*add_file_meas)(tcg_pts_attr_file_meas_t *this, chunk_t measurement,
-                                               chunk_t file_name);
+                                                 char  *filename);
 
        /**
         * Enumerates over all file measurements
         * Format:  chunk_t *measurement, chunk_t *file_name
         *
-        * @return                              enumerator
+        * @return                                      enumerator
         */
        enumerator_t* (*create_file_meas_enumerator)(tcg_pts_attr_file_meas_t *this);
 };
@@ -107,17 +107,17 @@ struct tcg_pts_attr_file_meas_t {
  * 
  * @param directory_flag               Directory Contents Flag
  * @param request_id                   Request ID
- * @param delimiter                    Delimiter Character
- * @param path                         File Path
+ * @param delimiter                            Delimiter Character
+ * @param path                                 File Path
  */
 pa_tnc_attr_t* tcg_pts_attr_file_meas_create(u_int64_t number_of_files,
-                                      u_int16_t request_id,
-                                      u_int16_t meas_len);
+                                                                                        u_int16_t request_id,
+                                                                                        u_int16_t meas_len);
 
 /**
  * Creates an tcg_pts_attr_file_meas_t object from received data
  *
- * @param value                                unparsed attribute value
+ * @param value                                        unparsed attribute value
  */
 pa_tnc_attr_t* tcg_pts_attr_file_meas_create_from_data(chunk_t value);
 
index f5d2210..0f37424 100644 (file)
@@ -28,18 +28,20 @@ typedef struct private_tcg_pts_attr_req_file_meas_t private_tcg_pts_attr_req_fil
  * 
  *                       1                   2                   3
  *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
- *
  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *  |   Flags     |    Reserved    |           Request ID          |
+ *  |     Flags     |   Reserved    |          Request ID           |
  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *  |                          Delimiter                           |
+ *  |                           Delimiter                           |
  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- *  ~          Fully Qualified File Path Name (Variable Length)    ~
+ *  ~       Fully Qualified File Pathname (Variable Length)         ~
  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  */
 
 #define PTS_REQ_FILE_MEAS_SIZE                 8
 #define PTS_REQ_FILE_MEAS_RESERVED             0x00
+#define PTS_REQ_FILE_MEAS_NO_FLAGS             0x00
+
+#define DIRECTORY_CONTENTS_FLAG                        (1<<7)
 
 /**
  * Private data of an tcg_pts_attr_req_file_meas_t object.
@@ -87,9 +89,9 @@ struct private_tcg_pts_attr_req_file_meas_t {
        u_int32_t delimiter;
                
        /**
-        * Fully Qualified File Path Name
+        * Fully Qualified File Pathname
         */
-       chunk_t path;
+       char *pathname;
 
 };
 
@@ -126,21 +128,22 @@ METHOD(pa_tnc_attr_t, set_noskip_flag,void,
 METHOD(pa_tnc_attr_t, build, void,
        private_tcg_pts_attr_req_file_meas_t *this)
 {
+       u_int8_t flags = PTS_REQ_FILE_MEAS_NO_FLAGS;
+       chunk_t pathname;
        bio_writer_t *writer;
-       u_int8_t flags = 0;
-       
-       writer = bio_writer_create(PTS_REQ_FILE_MEAS_SIZE);
        
-       if (this->directory_flag)
+       if (this->directory_flag) 
        {
-               flags += 128;
+               flags |= DIRECTORY_CONTENTS_FLAG;
        }
-       writer->write_uint8(writer, flags);
-       writer->write_uint8(writer, PTS_REQ_FILE_MEAS_RESERVED);
+       pathname = chunk_create(this->pathname, strlen(this->pathname));
+
+       writer = bio_writer_create(PTS_REQ_FILE_MEAS_SIZE);
+       writer->write_uint8 (writer, flags);
+       writer->write_uint8 (writer, PTS_REQ_FILE_MEAS_RESERVED);
        writer->write_uint16(writer, this->request_id);
        writer->write_uint32(writer, this->delimiter);
-       writer->write_data (writer, this->path);
-
+       writer->write_data  (writer, pathname);
        this->value = chunk_clone(writer->get_buf(writer));
        writer->destroy(writer);
 }
@@ -151,7 +154,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
        bio_reader_t *reader;
        u_int8_t flags;
        u_int8_t reserved;
-       u_int32_t file_path_len;
+       chunk_t pathname;
        
        if (this->value.len < PTS_REQ_FILE_MEAS_SIZE)
        {
@@ -159,19 +162,21 @@ METHOD(pa_tnc_attr_t, process, status_t,
                *offset = 0;
                return FAILED;
        }
+
        reader = bio_reader_create(this->value);
-       
-       reader->read_uint8(reader, &flags);
-       if((flags >> 7) & 1) this->directory_flag = true;
-       
-       reader->read_uint8(reader, &reserved);
+       reader->read_uint8 (reader, &flags);
+       reader->read_uint8 (reader, &reserved);
        reader->read_uint16(reader, &this->request_id);
        reader->read_uint32(reader, &this->delimiter);
-       file_path_len = reader->remaining(reader);
-       
-       reader->read_data(reader, file_path_len, &this->path);
-       this->path = chunk_clone(this->path);
-       
+       reader->read_data  (reader, reader->remaining(reader), &pathname);
+
+       this->directory_flag = (flags & DIRECTORY_CONTENTS_FLAG) !=
+                                                       PTS_REQ_FILE_MEAS_NO_FLAGS;
+
+       this->pathname = malloc(pathname.len + 1);
+       memcpy(this->pathname, pathname.ptr, pathname.len);
+       this->pathname[pathname.len] = '\0';
+
        reader->destroy(reader);
        return SUCCESS; 
 }
@@ -179,8 +184,8 @@ METHOD(pa_tnc_attr_t, process, status_t,
 METHOD(pa_tnc_attr_t, destroy, void,
        private_tcg_pts_attr_req_file_meas_t *this)
 {
+       free(this->pathname);
        free(this->value.ptr);
-       free(this->path.ptr);
        free(this);
 }
 
@@ -190,56 +195,31 @@ METHOD(tcg_pts_attr_req_file_meas_t, get_directory_flag, bool,
        return this->directory_flag;
 }
 
-METHOD(tcg_pts_attr_req_file_meas_t, set_directory_flag, void,
-       private_tcg_pts_attr_req_file_meas_t *this, bool directory_flag)
-{
-       this->directory_flag = directory_flag;
-}
-
 METHOD(tcg_pts_attr_req_file_meas_t, get_request_id, u_int16_t,
        private_tcg_pts_attr_req_file_meas_t *this)
 {
        return this->request_id;
 }
 
-METHOD(tcg_pts_attr_req_file_meas_t, set_request_id, void,
-       private_tcg_pts_attr_req_file_meas_t *this, u_int16_t request_id)
-{
-       this->request_id = request_id;
-}
-
 METHOD(tcg_pts_attr_req_file_meas_t, get_delimiter, u_int32_t,
        private_tcg_pts_attr_req_file_meas_t *this)
 {
        return this->delimiter;
 }
 
-METHOD(tcg_pts_attr_req_file_meas_t, set_delimiter, void,
-       private_tcg_pts_attr_req_file_meas_t *this, u_int32_t delimiter)
-{
-       this->delimiter = delimiter;
-}
-
-METHOD(tcg_pts_attr_req_file_meas_t, get_file_path, chunk_t,
+METHOD(tcg_pts_attr_req_file_meas_t, get_pathname, char*,
        private_tcg_pts_attr_req_file_meas_t *this)
 {
-       return this->path;
-}
-
-METHOD(tcg_pts_attr_req_file_meas_t, set_file_path, void,
-       private_tcg_pts_attr_req_file_meas_t *this, chunk_t path)
-{
-       this->path = path;
+       return this->pathname;
 }
 
 /**
  * Described in header.
  */
-pa_tnc_attr_t *tcg_pts_attr_req_file_meas_create(
-                                      bool directory_flag,
-                                      u_int16_t request_id,
-                                      u_int32_t delimiter,
-                                      chunk_t path)
+pa_tnc_attr_t *tcg_pts_attr_req_file_meas_create(bool directory_flag,
+                                                                                                u_int16_t request_id,
+                                                                                                u_int32_t delimiter,
+                                                                                                char *pathname)
 {
        private_tcg_pts_attr_req_file_meas_t *this;
 
@@ -255,21 +235,17 @@ pa_tnc_attr_t *tcg_pts_attr_req_file_meas_create(
                                .process = _process,
                                .destroy = _destroy,
                        },
-                       .get_directory_flag= _get_directory_flag,
-                       .set_directory_flag= _set_directory_flag,
+                       .get_directory_flag = _get_directory_flag,
                        .get_request_id = _get_request_id,
-                       .set_request_id = _set_request_id,
                        .get_delimiter = _get_delimiter,
-                       .set_delimiter = _set_delimiter,
-                       .get_file_path = _get_file_path,
-                       .set_file_path = _set_file_path,
+                       .get_pathname = _get_pathname,
                },
                .vendor_id = PEN_TCG,
                .type = TCG_PTS_REQ_FILE_MEAS,
                .directory_flag = directory_flag,
                .request_id = request_id,
                .delimiter = delimiter,
-               .path = path,
+               .pathname = strdup(pathname),
        );
 
        return &this->public.pa_tnc_attribute;
@@ -295,14 +271,10 @@ pa_tnc_attr_t *tcg_pts_attr_req_file_meas_create_from_data(chunk_t data)
                                .process = _process,
                                .destroy = _destroy,
                        },
-                       .get_directory_flag= _get_directory_flag,
-                       .set_directory_flag= _set_directory_flag,
+                       .get_directory_flag = _get_directory_flag,
                        .get_request_id = _get_request_id,
-                       .set_request_id = _set_request_id,
                        .get_delimiter = _get_delimiter,
-                       .set_delimiter = _set_delimiter,
-                       .get_file_path = _get_file_path,
-                       .set_file_path = _set_file_path,
+                       .get_pathname = _get_pathname,
                },
                .vendor_id = PEN_TCG,
                .type = TCG_PTS_REQ_FILE_MEAS,
index fd39406..44d5c7b 100644 (file)
@@ -45,28 +45,13 @@ struct tcg_pts_attr_req_file_meas_t {
        bool (*get_directory_flag)(tcg_pts_attr_req_file_meas_t *this);
 
        /**
-        * Set flag for PTS Request File Measurement
-        *
-        * @param directory_flag                Directory Contents flag
-        */
-       void (*set_directory_flag)(tcg_pts_attr_req_file_meas_t *this, 
-                               bool directory_flag);
-       
-       /**
         * Get Request ID
         *
         * @return                              Request ID
         */
        u_int16_t (*get_request_id)(tcg_pts_attr_req_file_meas_t *this);
        
-       /**
-        * Set Request ID
-        *
-        * @param request_id                    Request ID
-        */
-       void (*set_request_id)(tcg_pts_attr_req_file_meas_t *this,
-                                               u_int16_t request_id);
-               
+
        /**
         * Get Delimiter
         *
@@ -75,42 +60,26 @@ struct tcg_pts_attr_req_file_meas_t {
        u_int32_t (*get_delimiter)(tcg_pts_attr_req_file_meas_t *this);
        
        /**
-        * Set Delimiter 
+        * Get Fully Qualified File Pathname
         *
-        * @param delimiter                     UTF-8 encoding of a Delimiter Character
+        * @return                              Pathname
         */
-       void (*set_delimiter)(tcg_pts_attr_req_file_meas_t *this,
-                                               u_int32_t delimiter);
-
-       /**
-        * Get Fully Qualified File Path Name
-        *
-        * @return                              File Path
-        */
-       chunk_t (*get_file_path)(tcg_pts_attr_req_file_meas_t *this);
+       char* (*get_pathname)(tcg_pts_attr_req_file_meas_t *this);
                
-       /**
-        * Set Fully Qualified File Path Name
-        *
-        * @param path                          File Path
-        */
-       void (*set_file_path)(tcg_pts_attr_req_file_meas_t *this,
-                                               chunk_t path);
-       
 };
 
 /**
  * Creates an tcg_pts_attr_req_file_meas_t object
  * 
- * @param directory_flag               Directory Contents Flag
- * @param request_id                   Request ID
+ * @param directory_flag       Directory Contents Flag
+ * @param request_id           Request ID
  * @param delimiter                    Delimiter Character
- * @param path                         File Path
+ * @param pathname                     File Pathname
  */
 pa_tnc_attr_t* tcg_pts_attr_req_file_meas_create(bool directory_flag,
-                                      u_int16_t request_id,
-                                      u_int32_t delimiter,
-                                      chunk_t path);
+                                                                                                u_int16_t request_id,
+                                                                                                u_int32_t delimiter,
+                                                                                                char *pathname);
 
 /**
  * Creates an tcg_pts_attr_req_file_meas_t object from received data